Skip to content

Commit

Permalink
fix(google-common): add tool_use param when using structured outputs (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
kashifmin authored Dec 19, 2024
1 parent a7bc916 commit 82cecae
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions libs/langchain-google-common/src/chat_models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,7 @@ export abstract class ChatGoogleBase<AuthOptions>
}
const llm = this.bind({
tools,
tool_choice: functionName,
});

if (!includeRaw) {
Expand Down
14 changes: 12 additions & 2 deletions libs/langchain-google-common/src/utils/gemini.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1047,10 +1047,20 @@ export function getGeminiAPI(config?: GeminiAPIConfig): GoogleAIAPI {
return undefined;
}

if (["auto", "any", "none"].includes(parameters.tool_choice)) {
return {
functionCallingConfig: {
mode: parameters.tool_choice as "auto" | "any" | "none",
allowedFunctionNames: parameters.allowed_function_names,
},
};
}

// force tool choice to be a single function name in case of structured output
return {
functionCallingConfig: {
mode: parameters.tool_choice as "auto" | "any" | "none",
allowedFunctionNames: parameters.allowed_function_names,
mode: "any",
allowedFunctionNames: [parameters.tool_choice],
},
};
}
Expand Down

0 comments on commit 82cecae

Please sign in to comment.