* Converts OpenAI tool_choice to Anthropic ToolChoice format
( toolChoice: OpenAI.Chat.ChatCompletionCreateParams["tool_choice"], )
| 20 | * Converts OpenAI tool_choice to Anthropic ToolChoice format |
| 21 | */ |
| 22 | function 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 | |
| 53 | export class MiniMaxHandler extends BaseProvider implements SingleCompletionHandler { |
| 54 | private options: ApiHandlerOptions |