Skip to content

Fix specifying media uris for google vertex #242

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/chat_models/chat_vertex_ai.ex
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ defmodule LangChain.ChatModels.ChatVertexAI do
%{
"fileData" => %{
"mimeType" => Keyword.fetch!(part.options, :media),
"data" => part.content
"fileUri" => part.content
}
}
end
Expand Down
2 changes: 1 addition & 1 deletion test/chat_models/chat_google_ai_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ defmodule ChatModels.ChatGoogleAITest do
} = tool_result
end

test "generate a map containing a text and an image part (bug #209)", %{google_ai: google_ai} do
test "generate a map containing text and inline image parts", %{google_ai: google_ai} do
messages = [
%LangChain.Message{
content:
Expand Down
54 changes: 54 additions & 0 deletions test/chat_models/chat_vertex_ai_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,60 @@ defmodule ChatModels.ChatVertexAITest do
assert %{"temperature" => 1.0, "topK" => 1.0, "topP" => 1.0} = config
end

test "generate a map containing a text, inline image, and image url parts", %{
vertex_ai: google_ai
} do
messages = [
%LangChain.Message{
content:
"You are an expert at providing an image description for assistive technology and SEO benefits.",
role: :system
},
%LangChain.Message{
content: [
%LangChain.Message.ContentPart{
type: :text,
content: "This is the text."
},
%LangChain.Message.ContentPart{
type: :image,
content: "/9j/4AAQSkz",
options: [media: "image/jpeg"]
},
%LangChain.Message.ContentPart{
type: :image_url,
content: "http://localhost:1234/image.jpg",
options: [media: "image/jpeg"]
}
],
role: :user
}
]

data = ChatVertexAI.for_api(google_ai, messages, [])
assert %{"contents" => [msg1]} = data

assert %{
"parts" => [
%{
"text" => "This is the text."
},
%{
"inlineData" => %{
"mimeType" => "image/jpeg",
"data" => "/9j/4AAQSkz"
}
},
%{
"fileData" => %{
"fileUri" => "http://localhost:1234/image.jpg",
"mimeType" => "image/jpeg"
}
}
]
} = msg1
end

test "generates a map containing user and assistant messages", %{vertex_ai: vertex_ai} do
user_message = "Hello Assistant!"
assistant_message = "Hello User!"
Expand Down