-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
core[minor]: Standardize tool choice (#6111)
* core[minor]: Standardize tool choice * implement in partner pkgs * use basechatmodelcalloptions
- Loading branch information
1 parent
77904e3
commit a64203b
Showing
8 changed files
with
135 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import type { | ||
MessageCreateParams, | ||
Tool as AnthropicTool, | ||
} from "@anthropic-ai/sdk/resources/index.mjs"; | ||
import { ToolDefinition } from "@langchain/core/language_models/base"; | ||
import { RunnableToolLike } from "@langchain/core/runnables"; | ||
import { StructuredToolInterface } from "@langchain/core/tools"; | ||
|
||
export type AnthropicToolChoice = | ||
| { | ||
type: "tool"; | ||
name: string; | ||
} | ||
| "any" | ||
| "auto" | ||
| "none" | ||
| string; | ||
|
||
export type AnthropicToolTypes = | ||
| StructuredToolInterface | ||
| AnthropicTool | ||
| Record<string, unknown> | ||
| ToolDefinition | ||
| RunnableToolLike; | ||
|
||
export function handleToolChoice( | ||
toolChoice?: AnthropicToolChoice | ||
): | ||
| MessageCreateParams.ToolChoiceAuto | ||
| MessageCreateParams.ToolChoiceAny | ||
| MessageCreateParams.ToolChoiceTool | ||
| undefined { | ||
if (!toolChoice) { | ||
return undefined; | ||
} else if (toolChoice === "any") { | ||
return { | ||
type: "any", | ||
}; | ||
} else if (toolChoice === "auto") { | ||
return { | ||
type: "auto", | ||
}; | ||
} else if (typeof toolChoice === "string") { | ||
return { | ||
type: "tool", | ||
name: toolChoice, | ||
}; | ||
} else { | ||
return toolChoice; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters