fix types in core gemini llm
This commit is contained in:
parent
336552a665
commit
fc9c49b218
2 changed files with 34 additions and 23 deletions
|
|
@ -23,6 +23,14 @@ import {
|
|||
convertContinueToolToGeminiFunction,
|
||||
} from "./gemini-types";
|
||||
|
||||
interface GeminiToolCallDelta extends ToolCallDelta {
|
||||
extra_content?: {
|
||||
google?: {
|
||||
thought_signature?: string;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
class Gemini extends BaseLLM {
|
||||
static providerName = "gemini";
|
||||
|
||||
|
|
@ -268,31 +276,33 @@ class Gemini extends BaseLLM {
|
|||
};
|
||||
|
||||
if (msg.toolCalls && msg.toolCalls.length) {
|
||||
msg.toolCalls.forEach((toolCall, index) => {
|
||||
if (toolCall.function?.name) {
|
||||
const signatureForCall = (toolCall as any)?.extra_content
|
||||
?.google?.thought_signature;
|
||||
(msg.toolCalls as GeminiToolCallDelta[]).forEach(
|
||||
(toolCall, index) => {
|
||||
if (toolCall.function?.name) {
|
||||
const signatureForCall =
|
||||
toolCall?.extra_content?.google?.thought_signature;
|
||||
|
||||
let thoughtSignature: string | undefined;
|
||||
if (index === 0) {
|
||||
if (typeof signatureForCall === "string") {
|
||||
thoughtSignature = signatureForCall;
|
||||
} else {
|
||||
// Fallback per https://ai.google.dev/gemini-api/docs/thought-signatures
|
||||
// for histories that were not generated by Gemini or are missing signatures.
|
||||
thoughtSignature = "skip_thought_signature_validator";
|
||||
let thoughtSignature: string | undefined;
|
||||
if (index === 0) {
|
||||
if (typeof signatureForCall === "string") {
|
||||
thoughtSignature = signatureForCall;
|
||||
} else {
|
||||
// Fallback per https://ai.google.dev/gemini-api/docs/thought-signatures
|
||||
// for histories that were not generated by Gemini or are missing signatures.
|
||||
thoughtSignature = "skip_thought_signature_validator";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assistantMsg.parts.push({
|
||||
functionCall: {
|
||||
name: toolCall.function.name,
|
||||
args: safeParseToolCallArgs(toolCall),
|
||||
},
|
||||
...(thoughtSignature && { thoughtSignature }),
|
||||
});
|
||||
}
|
||||
});
|
||||
assistantMsg.parts.push({
|
||||
functionCall: {
|
||||
name: toolCall.function.name,
|
||||
args: safeParseToolCallArgs(toolCall),
|
||||
},
|
||||
...(thoughtSignature && { thoughtSignature }),
|
||||
});
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
return assistantMsg;
|
||||
|
|
@ -387,7 +397,7 @@ class Gemini extends BaseLLM {
|
|||
if ("text" in part) {
|
||||
textParts.push({ type: "text", text: part.text });
|
||||
} else if ("functionCall" in part) {
|
||||
const thoughtSignature = (part as any)?.thoughtSignature;
|
||||
const thoughtSignature = part.thoughtSignature;
|
||||
toolCalls.push({
|
||||
type: "function",
|
||||
id: part.functionCall.id ?? uuidv4(),
|
||||
|
|
|
|||
|
|
@ -192,6 +192,7 @@ export type GeminiFunctionCallContentPart = {
|
|||
name: string;
|
||||
args: JSONSchema7Object;
|
||||
};
|
||||
thoughtSignature?: string;
|
||||
};
|
||||
|
||||
export type GeminiFunctionResponseContentPart = {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue