Skip to content
Merged
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
12 changes: 10 additions & 2 deletions src/providers/google/chatComplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ import {
getFakeId,
} from '../utils';

type ToolCallWithSignature = ToolCall & {
thoughtSignature: string | undefined;
};

const joinSystemMessages = (messages: Message[]) =>
messages
?.filter((message) => message.role === 'system')
Expand Down Expand Up @@ -238,7 +242,7 @@ export const GoogleChatCompleteConfig: ProviderConfig = {
let parts = [];

if (message.role === 'assistant' && message.tool_calls) {
message.tool_calls.forEach((tool_call: ToolCall) => {
message.tool_calls.forEach((tool_call: ToolCallWithSignature) => {
let args;
try {
args = JSON.parse(tool_call.function.arguments);
Expand All @@ -253,6 +257,7 @@ export const GoogleChatCompleteConfig: ProviderConfig = {
name: tool_call.function.name,
args,
},
thoughtSignature: tool_call.thoughtSignature,
});
});
} else if (
Expand Down Expand Up @@ -476,6 +481,7 @@ interface GoogleResponseCandidate {
text?: string;
thought?: string; // for models like gemini-2.0-flash-thinking-exp refer: https://ai.google.dev/gemini-api/docs/thinking-mode#streaming_model_thinking
functionCall?: GoogleGenerateFunctionCall;
thoughtSignature?: string;
}[];
};
logprobsResult?: {
Expand Down Expand Up @@ -569,7 +575,7 @@ export const GoogleChatCompleteResponseTransform: (
choices:
response.candidates?.map((generation, idx) => {
// transform tool calls and content by iterating over the content parts
const toolCalls: ToolCall[] = [];
const toolCalls: ToolCallWithSignature[] = [];
let content: string | undefined;
const contentBlocks = [];
for (const part of generation.content?.parts ?? []) {
Expand All @@ -581,6 +587,7 @@ export const GoogleChatCompleteResponseTransform: (
name: part.functionCall.name,
arguments: JSON.stringify(part.functionCall.args),
},
thoughtSignature: part.thoughtSignature,
});
} else if (part.text) {
if (part.thought) {
Expand Down Expand Up @@ -722,6 +729,7 @@ export const GoogleChatCompleteStreamChunkTransform: (
name: part.functionCall.name,
arguments: JSON.stringify(part.functionCall.args),
},
thoughtSignature: part.thoughtSignature,
};
}
}),
Expand Down