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

Function convertOpenAIToolChoice

src/api/providers/minimax.ts:22–51  ·  view source on GitHub ↗

* Converts OpenAI tool_choice to Anthropic ToolChoice format

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

Source from the content-addressed store, hash-verified

20 * Converts OpenAI tool_choice to Anthropic ToolChoice format
21 */
22function convertOpenAIToolChoice(
23 toolChoice: OpenAI.Chat.ChatCompletionCreateParams["tool_choice"],
24): Anthropic.Messages.MessageCreateParams["tool_choice"] | undefined {
25 if (!toolChoice) {
26 return undefined
27 }
28
29 if (typeof toolChoice === "string") {
30 switch (toolChoice) {
31 case "none":
32 return undefined // Anthropic doesn't have "none", just omit tools
33 case "auto":
34 return { type: "auto" }
35 case "required":
36 return { type: "any" }
37 default:
38 return { type: "auto" }
39 }
40 }
41
42 // Handle object form { type: "function", function: { name: string } }
43 if (typeof toolChoice === "object" && "function" in toolChoice) {
44 return {
45 type: "tool",
46 name: toolChoice.function.name,
47 }
48 }
49
50 return { type: "auto" }
51}
52
53export class MiniMaxHandler extends BaseProvider implements SingleCompletionHandler {
54 private options: ApiHandlerOptions

Callers 1

createMessageMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected