-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
feat(google-common): Grounding with Google Search and Vertex AI Search #7280
Changes from 4 commits
b83b58a
2402d23
68f8180
e9f2f01
8bcbf1c
8b6ddc7
9756085
578f2ff
1967663
6eeae1f
66dd2a0
3467859
ad2063c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,32 +62,38 @@ function processToolChoice( | |
} | ||
|
||
export function convertToGeminiTools(tools: GoogleAIToolType[]): GeminiTool[] { | ||
const geminiTools: GeminiTool[] = [ | ||
{ | ||
functionDeclarations: [], | ||
}, | ||
]; | ||
const geminiTools: GeminiTool[] = []; | ||
tools.forEach((tool) => { | ||
if ( | ||
"functionDeclarations" in tool && | ||
Array.isArray(tool.functionDeclarations) | ||
) { | ||
const funcs: GeminiFunctionDeclaration[] = tool.functionDeclarations; | ||
geminiTools[0].functionDeclarations?.push(...funcs); | ||
geminiTools.push({ functionDeclarations: [...funcs] }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I vaguely remember this not working due to Google rejecting it - can you add a test using multiple traditional tools? And maybe one using search grounding alongside several tools as well There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hello @afirstenberg and @jacoblee93, Thank you for the review! We’re glad to hear that you appreciate our code contribution. We’ll make sure to add the additional test cases as requested. Please note that libs/langchain-google-vertexai/src/tests/chat_models.int.test.ts already includes test cases for grounding. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think there are some known bugs on Google's side about having multiple tools at once - but Google considers this a bug on their end. It should be possible to submit multiple tools at once and mixing functions and other tools. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes this breaks multiple functions, will revert partially |
||
} else if (isLangChainTool(tool)) { | ||
const jsonSchema = zodToGeminiParameters(tool.schema); | ||
geminiTools[0].functionDeclarations?.push({ | ||
name: tool.name, | ||
description: tool.description ?? `A function available to call.`, | ||
parameters: jsonSchema as GeminiFunctionSchema, | ||
geminiTools.push({ | ||
functionDeclarations: [ | ||
{ | ||
name: tool.name, | ||
description: tool.description ?? `A function available to call.`, | ||
parameters: jsonSchema as GeminiFunctionSchema, | ||
}, | ||
], | ||
}); | ||
} else if (isOpenAITool(tool)) { | ||
geminiTools[0].functionDeclarations?.push({ | ||
name: tool.function.name, | ||
description: | ||
tool.function.description ?? `A function available to call.`, | ||
parameters: jsonSchemaToGeminiParameters(tool.function.parameters), | ||
geminiTools.push({ | ||
functionDeclarations: [ | ||
{ | ||
name: tool.function.name, | ||
description: | ||
tool.function.description ?? `A function available to call.`, | ||
parameters: jsonSchemaToGeminiParameters(tool.function.parameters), | ||
}, | ||
], | ||
}); | ||
} else if ("googleSearchRetrieval" in tool || "retrieval" in tool) { | ||
geminiTools.push(tool); | ||
} | ||
}); | ||
return geminiTools; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would have like to see these as actual types or classes rather than as
object
, but I don't think this should hold off on merging.