Skip to content

Commit

Permalink
Use a type guard
Browse files Browse the repository at this point in the history
  • Loading branch information
jacoblee93 committed Dec 30, 2024
1 parent 3be6942 commit de56086
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions libs/langchain-google-common/src/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function processToolChoice(
throw new Error("Object inputs for tool_choice not supported.");
}

function isGeminiTool(tool: GoogleAIToolType): boolean {
function isGeminiTool(tool: GoogleAIToolType): tool is GeminiTool {
for (const toolAttribute of GeminiToolAttributes) {
if (toolAttribute in tool) {
return true;
Expand All @@ -71,7 +71,7 @@ function isGeminiTool(tool: GoogleAIToolType): boolean {
return false;
}

function isGeminiNonFunctionTool(tool: GoogleAIToolType): boolean {
function isGeminiNonFunctionTool(tool: GoogleAIToolType): tool is GeminiTool {
return isGeminiTool(tool) && !("functionDeclaration" in tool);
}

Expand All @@ -80,7 +80,7 @@ export function convertToGeminiTools(tools: GoogleAIToolType[]): GeminiTool[] {
let functionDeclarationsIndex = -1;
tools.forEach((tool) => {
if (isGeminiNonFunctionTool(tool)) {
geminiTools.push(tool as GeminiTool);
geminiTools.push(tool);
} else {
if (functionDeclarationsIndex === -1) {
geminiTools.push({
Expand Down

0 comments on commit de56086

Please sign in to comment.