MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / mapToolChoice

Function mapToolChoice

src/api/providers/openai-compatible.ts:109–138  ·  view source on GitHub ↗

* Map OpenAI tool_choice to AI SDK toolChoice format.

(
		toolChoice: OpenAI.Chat.ChatCompletionCreateParams["tool_choice"],
	)

Source from the content-addressed store, hash-verified

107 * Map OpenAI tool_choice to AI SDK toolChoice format.
108 */
109 protected mapToolChoice(
110 toolChoice: OpenAI.Chat.ChatCompletionCreateParams["tool_choice"],
111 ): "auto" | "none" | "required" | { type: "tool"; toolName: string } | undefined {
112 if (!toolChoice) {
113 return undefined
114 }
115
116 // Handle string values
117 if (typeof toolChoice === "string") {
118 switch (toolChoice) {
119 case "auto":
120 return "auto"
121 case "none":
122 return "none"
123 case "required":
124 return "required"
125 default:
126 return "auto"
127 }
128 }
129
130 // Handle object values (OpenAI ChatCompletionNamedToolChoice format)
131 if (typeof toolChoice === "object" && "type" in toolChoice) {
132 if (toolChoice.type === "function" && "function" in toolChoice && toolChoice.function?.name) {
133 return { type: "tool", toolName: toolChoice.function.name }
134 }
135 }
136
137 return undefined
138 }
139
140 /**
141 * Get the max tokens parameter to include in the request.

Callers 1

createMessageMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected