Skip to content

Commit

Permalink
fix(google-genai): Update fileData & inlineData to kebab case
Browse files Browse the repository at this point in the history
Google Gemini HTTP API requires file_data and inline_data to be in kebab case. This is different to the SDKs which use Snake case.

It is possible to use Snake case but with mixed results (e.g. inlineData works, but fileData does not), however officially both should be kebab (see Shell docs): https://ai.google.dev/api/files and have been tested working.
  • Loading branch information
hongkongkiwi committed Jan 30, 2025
1 parent 05eedae commit e82129a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ beforeAll(async () => {
role: "user",
parts: [
{
fileData: {
mimeType: fileResult.file.mimeType,
fileUri: fileResult.file.uri,
file_data: {
mime_type: fileResult.file.mimeType,
file_uri: fileResult.file.uri,
},
},
],
Expand Down
18 changes: 9 additions & 9 deletions libs/langchain-google-genai/src/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,17 @@ export function convertAuthorToRole(
function messageContentMedia(content: MessageContentComplex): Part {
if ("mimeType" in content && "data" in content) {
return {
inlineData: {
mimeType: content.mimeType,
inline_data: {
mime_type: content.mimeType,
data: content.data,
},
};
}
if ("mimeType" in content && "fileUri" in content) {
return {
fileData: {
mimeType: content.mimeType,
fileUri: content.fileUri,
file_data: {
mime_type: content.mimeType,
file_uri: content.fileUri,
},
};
}
Expand Down Expand Up @@ -164,9 +164,9 @@ export function convertMessageContentToParts(
}

return {
inlineData: {
inline_data: {
data,
mimeType,
mime_type: mimeType,
},
};
} else if (c.type === "media") {
Expand All @@ -186,8 +186,8 @@ export function convertMessageContentToParts(
typeof c.data === "string"
) {
return {
inlineData: {
mimeType: c.type,
inline_data: {
mime_type: c.type,
data: c.data,
},
};
Expand Down

0 comments on commit e82129a

Please sign in to comment.