mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-15 21:03:19 +00:00
fix(ai): Ensure unique tool call IDs in Google provider
- Google provider sometimes returns duplicate or missing tool call IDs - Added counter to ensure unique IDs for each tool call - Check for duplicates and generate new ID when needed - Fixes issues with multiple tool calls having the same ID
This commit is contained in:
parent
7d1daac39e
commit
6c3580828d
1 changed files with 11 additions and 1 deletions
|
|
@ -33,6 +33,9 @@ export interface GoogleOptions extends GenerateOptions {
|
|||
};
|
||||
}
|
||||
|
||||
// Counter for generating unique tool call IDs
|
||||
let toolCallCounter = 0;
|
||||
|
||||
export const streamGoogle: GenerateFunction<"google-generative-ai"> = (
|
||||
model: Model<"google-generative-ai">,
|
||||
context: Context,
|
||||
|
|
@ -131,7 +134,14 @@ export const streamGoogle: GenerateFunction<"google-generative-ai"> = (
|
|||
currentBlock = null;
|
||||
}
|
||||
|
||||
const toolCallId = part.functionCall.id || `${part.functionCall.name}_${Date.now()}`;
|
||||
// Generate unique ID if not provided or if it's a duplicate
|
||||
const providedId = part.functionCall.id;
|
||||
const needsNewId =
|
||||
!providedId || output.content.some((b) => b.type === "toolCall" && b.id === providedId);
|
||||
const toolCallId = needsNewId
|
||||
? `${part.functionCall.name}_${Date.now()}_${++toolCallCounter}`
|
||||
: providedId;
|
||||
|
||||
const toolCall: ToolCall = {
|
||||
type: "toolCall",
|
||||
id: toolCallId,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue