( apiKey string, baseURL string, model string, maxTokens int, thinkingBudgetTokens *int, retryConfig *RetryConfig, )
| 132 | func normalizeAPIType(apiType string) string { |
| 133 | switch strings.ToLower(strings.TrimSpace(apiType)) { |
| 134 | case "", "auto": |
| 135 | return "auto" |
| 136 | case "openai", "openai-compatible", "openai_compatible", "deepseek": |
| 137 | return "openai_compatible" |
| 138 | case "anthropic", "claude": |
| 139 | return "anthropic" |
| 140 | default: |
| 141 | return "auto" |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | func useOpenAICompatible(model string, apiType string) bool { |
| 146 | switch normalizeAPIType(apiType) { |
| 147 | case "openai_compatible": |
| 148 | return true |
| 149 | case "anthropic": |
| 150 | return false |
| 151 | default: |
| 152 | return isOpenAICompatibleModel(model) |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | func AnthropicToolsToOpenAI(tools []map[string]any) []map[string]any { |
| 157 | openaiTools := make([]map[string]any, 0, len(tools)) |
| 158 | |
| 159 | for _, tool := range tools { |
| 160 | parameters, ok := tool["input_schema"] |
| 161 | if !ok { |
| 162 | parameters, ok = tool["parameters"] |
| 163 | if !ok { |
| 164 | parameters = map[string]any{} |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | openaiTools = append(openaiTools, map[string]any{ |
| 169 | "type": "function", |
| 170 | "function": map[string]any{ |
| 171 | "name": getString(tool, "name"), |
| 172 | "description": getString(tool, "description"), |
no test coverage detected