Skip to content

Commit 289cbcc

Browse files
committed
simplify tool choice
1 parent f76c0f3 commit 289cbcc

File tree

3 files changed

+7
-8
lines changed

3 files changed

+7
-8
lines changed

packages/ai/ai/src/AiLanguageModel.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,13 @@ export interface IdentifiedSchema<A, I, R> extends Schema.Schema<A, I, R> {
5656
* - `auto` (default): The model can decide whether or not to call tools, as well as which tools to call.
5757
* - `required`: The model **must** call a tool but can decide which tool will be called.
5858
* - `none`: The model **must not** call a tool.
59-
* - `{ type: "tool", name: <tool_name> }`: The model must call the specified tool.
59+
* - `{ tool: <tool_name> }`: The model must call the specified tool.
6060
*
6161
* @since 1.0.0
6262
* @category Models
6363
*/
6464
export type ToolChoice<Tool extends AiTool.Any> = "auto" | "none" | "required" | {
65-
readonly type: "tool"
66-
readonly name: Tool["name"]
65+
readonly tool: Tool["name"]
6766
}
6867

6968
/**
@@ -95,7 +94,7 @@ export interface GenerateTextOptions<Tools extends AiTool.Any> {
9594
* - `auto` (default): The model can decide whether or not to call tools, as well as which tools to call.
9695
* - `required`: The model **must** call a tool but can decide which tool will be called.
9796
* - `none`: The model **must not** call a tool.
98-
* - `{ type: "tool", name: <tool_name> }`: The model must call the specified tool.
97+
* - `{ tool: <tool_name> }`: The model must call the specified tool.
9998
*/
10099
readonly toolChoice?: ToolChoice<Tools>
101100

@@ -286,7 +285,7 @@ export interface AiLanguageModelOptions {
286285
* - `auto` (default): The model can decide whether or not to call tools, as well as which tools to call.
287286
* - `required`: The model **must** call a tool but can decide which tool will be called.
288287
* - `none`: The model **must not** call a tool.
289-
* - `{ type: "tool", name: <tool_name> }`: The model must call the specified tool.
288+
* - `{ tool: <tool_name> }`: The model must call the specified tool.
290289
*/
291290
readonly toolChoice: ToolChoice<any>
292291
/**
@@ -383,7 +382,7 @@ export const make = <Config>(opts: {
383382
const system = Option.fromNullable(options.system)
384383
const decode = Schema.decodeUnknown(options.schema)
385384
const tool = convertStructured(toolCallId, options.schema)
386-
const toolChoice = { type: "tool", name: tool.name } as const
385+
const toolChoice = { tool: tool.name } as const
387386
const response = yield* opts.generateText({ prompt, system, tools: [tool], toolChoice, span })
388387
const toolCallPart = response.parts.find((part): part is AiResponse.ToolCallPart =>
389388
part._tag === "ToolCallPart" && part.name === toolCallId

packages/ai/anthropic/src/AnthropicLanguageModel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ const make = Effect.gen(function*() {
157157
} else if (typeof options.toolChoice === "string") {
158158
toolChoice = { type: options.toolChoice }
159159
} else {
160-
toolChoice = options.toolChoice
160+
toolChoice = { type: "tool", name: options.toolChoice.tool }
161161
}
162162
}
163163
const messages = yield* makeMessages(method, prompt)

packages/ai/openai/src/OpenAiLanguageModel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ const make = Effect.gen(function*() {
179179
if (options.toolChoice === "auto" || options.toolChoice === "required") {
180180
toolChoice = options.toolChoice
181181
} else if (typeof options.toolChoice === "object") {
182-
toolChoice = { type: "function", function: { name: options.toolChoice.name } }
182+
toolChoice = { type: "function", function: { name: options.toolChoice.tool } }
183183
}
184184
}
185185
const messages = yield* makeMessages(method, system, prompt)

0 commit comments

Comments
 (0)