| 1 | import { parseProxyModelName } from "@continuedev/config-yaml"; |
| 2 | import { ModelDescription } from ".."; |
| 3 | |
| 4 | export const PROVIDER_TOOL_SUPPORT: Record<string, (model: string) => boolean> = |
| 5 | { |
| 6 | "continue-proxy": (model) => { |
| 7 | try { |
| 8 | const { provider, model: _model } = parseProxyModelName(model); |
| 9 | if (provider && _model && provider !== "continue-proxy") { |
| 10 | const fn = PROVIDER_TOOL_SUPPORT[provider]; |
| 11 | if (fn) { |
| 12 | return fn(_model); |
| 13 | } |
| 14 | } |
| 15 | } catch (e) {} |
| 16 | |
| 17 | return [ |
| 18 | "claude-3-5", |
| 19 | "claude-3.5", |
| 20 | "claude-3-7", |
| 21 | "claude-3.7", |
| 22 | "claude-sonnet-4", |
| 23 | "claude-4-sonnet", |
| 24 | "gpt-4", |
| 25 | "o3", |
| 26 | "gemini", |
| 27 | "claude-opus-4", |
| 28 | "gemma", |
| 29 | ].some((part) => model.toLowerCase().startsWith(part)); |
| 30 | }, |
| 31 | anthropic: (model) => { |
| 32 | if ( |
| 33 | [ |
| 34 | "claude-3-5", |
| 35 | "claude-3.5", |
| 36 | "claude-3-7", |
| 37 | "claude-3.7", |
| 38 | "claude-sonnet-4", |
| 39 | "claude-4-sonnet", |
| 40 | "claude-opus-4", |
| 41 | ].some((part) => model.toLowerCase().startsWith(part)) |
| 42 | ) { |
| 43 | return true; |
| 44 | } |
| 45 | |
| 46 | return false; |
| 47 | }, |
| 48 | azure: (model) => { |
| 49 | if ( |
| 50 | model.toLowerCase().startsWith("gpt-4") || |
| 51 | model.toLowerCase().startsWith("o3") |
| 52 | ) |
| 53 | return true; |
| 54 | return false; |
| 55 | }, |
| 56 | openai: (model) => { |
| 57 | const lower = model.toLowerCase(); |
| 58 | // https://platform.openai.com/docs/guides/function-calling#models-supporting-function-calling |
| 59 | if ( |
| 60 | lower.startsWith("gpt-4") || |
| 61 | lower.startsWith("gpt-5") || |
| 62 | lower.startsWith("o3") |
| 63 | ) { |
| 64 | return true; |
| 65 | } |
| 66 | |
| 67 | // LGAI EXAONE models expose an OpenAI-compatible API with tool |
| 68 | // calling support when served via frameworks like vLLM |
| 69 | if (lower.includes("exaone")) { |
| 70 | return true; |
| 71 | } |
| 72 | |
| 73 | if (lower.includes("gpt-oss")) { |
| 74 | return true; |
| 75 | } |
| 76 | |
| 77 | // https://ai.google.dev/gemma/docs/capabilities/function-calling |
| 78 | if (lower.startsWith("gemma")) { |
| 79 | return true; |
| 80 | } |
| 81 | |
| 82 | // firworks-ai https://docs.fireworks.ai/guides/function-calling |
| 83 | if (model.startsWith("accounts/fireworks/models/")) { |
| 84 | switch (model.substring(26)) { |
| 85 | case "llama-v3p1-405b-instruct": |
| 86 | case "llama-v3p1-70b-instruct": |
| 87 | case "qwen2p5-72b-instruct": |
| 88 | case "firefunction-v1": |
| 89 | case "firefunction-v2": |
| 90 | return true; |
| 91 | default: |
| 92 | return false; |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | return false; |
| 97 | }, |
| 98 | cohere: (model) => { |
| 99 | return model.toLowerCase().startsWith("command"); |
| 100 | }, |
| 101 | gemini: (model) => { |
| 102 | // All gemini models support function calling |
| 103 | return model.toLowerCase().includes("gemini"); |
| 104 | }, |
| 105 | vertexai: (model) => { |
| 106 | const lowerCaseModel = model.toLowerCase(); |
| 107 | // All gemini models except flash 2.0 lite support function calling |
| 108 | if (lowerCaseModel.includes("lite")) { |
| 109 | return false; |
| 110 | } |
| 111 | return ["claude", "gemini"].some((val) => lowerCaseModel.includes(val)); |
| 112 | }, |
| 113 | xAI: (model) => { |
| 114 | const lowerCaseModel = model.toLowerCase(); |
| 115 | return ["grok-3", "grok-4"].some((val) => lowerCaseModel.includes(val)); |
| 116 | }, |
| 117 | bedrock: (model) => { |
| 118 | if ( |
| 119 | [ |
| 120 | "claude-3-5-sonnet", |
| 121 | "claude-3.5-sonnet", |
| 122 | "claude-3-7-sonnet", |
| 123 | "claude-3.7-sonnet", |
| 124 | "claude-sonnet-4", |
| 125 | "claude-4-sonnet", |
| 126 | "claude-opus-4", |
| 127 | "nova-lite", |
| 128 | "nova-pro", |
| 129 | "nova-micro", |
| 130 | "nova-premier", |
| 131 | "gpt-oss", |
| 132 | ].some((part) => model.toLowerCase().includes(part)) |
| 133 | ) { |
| 134 | return true; |
| 135 | } |
| 136 | |
| 137 | return false; |
| 138 | }, |
| 139 | mistral: (model) => { |
| 140 | // https://docs.mistral.ai/capabilities/function_calling/ |
| 141 | return ( |
| 142 | !model.toLowerCase().includes("mamba") && |
| 143 | [ |
| 144 | "devstral", |
| 145 | "codestral", |
| 146 | "mistral-large", |
| 147 | "mistral-small", |
| 148 | "pixtral", |
| 149 | "ministral", |
| 150 | "mistral-nemo", |
| 151 | "devstral", |
| 152 | ].some((part) => model.toLowerCase().includes(part)) |
| 153 | ); |
| 154 | }, |
| 155 | // https://ollama.com/search?c=tools |
| 156 | ollama: (model) => { |
| 157 | let modelName = ""; |
| 158 | // Extract the model name after the last slash to support other registries |
| 159 | if (model.includes("/")) { |
| 160 | let parts = model.split("/"); |
| 161 | modelName = parts[parts.length - 1]; |
| 162 | } else { |
| 163 | modelName = model; |
| 164 | } |
| 165 | |
| 166 | if ( |
| 167 | ["vision", "math", "guard", "mistrallite", "mistral-openorca"].some( |
| 168 | (part) => modelName.toLowerCase().includes(part), |
| 169 | ) |
| 170 | ) { |
| 171 | return false; |
| 172 | } |
| 173 | if ( |
| 174 | [ |
| 175 | "cogito", |
| 176 | "llama3.3", |
| 177 | "qwq", |
| 178 | "llama3.2", |
| 179 | "llama3.1", |
| 180 | "qwen2", |
| 181 | "qwen3", |
| 182 | "mixtral", |
| 183 | "command-r", |
| 184 | "command-a", |
| 185 | "smollm2", |
| 186 | "hermes3", |
| 187 | "athene-v2", |
| 188 | "nemotron", |
| 189 | "llama3-groq", |
| 190 | "granite3", |
| 191 | "granite-3", |
| 192 | "aya-expanse", |
| 193 | "firefunction-v2", |
| 194 | "mistral", |
| 195 | "devstral", |
| 196 | "exaone", |
| 197 | "gpt-oss", |
| 198 | ].some((part) => modelName.toLowerCase().includes(part)) |
| 199 | ) { |
| 200 | return true; |
| 201 | } |
| 202 | |
| 203 | return false; |
| 204 | }, |
| 205 | sambanova: (model) => { |
| 206 | // https://docs.sambanova.ai/cloud/docs/capabilities/function-calling |
| 207 | if ( |
| 208 | model.toLowerCase().startsWith("meta-llama-3") || |
| 209 | model.toLowerCase().includes("llama-4") || |
| 210 | model.toLowerCase().includes("deepseek") || |
| 211 | model.toLowerCase().includes("gpt") || |
| 212 | model.toLowerCase().includes("qwen") |
| 213 | ) { |
| 214 | return true; |
| 215 | } |
| 216 | |
| 217 | return false; |
| 218 | }, |
| 219 | deepseek: (model) => { |
| 220 | // https://api-docs.deepseek.com/quick_start/pricing |
| 221 | // https://api-docs.deepseek.com/guides/function_calling |
| 222 | if (model === "deepseek-reasoner" || model === "deepseek-chat") { |
| 223 | return true; |
| 224 | } |
| 225 | |
| 226 | return false; |
| 227 | }, |
| 228 | watsonx: (model) => { |
| 229 | if (model.toLowerCase().includes("guard")) { |
| 230 | return false; |
| 231 | } |
| 232 | if ( |
| 233 | [ |
| 234 | "llama-3", |
| 235 | "llama-4", |
| 236 | "mistral", |
| 237 | "codestral", |
| 238 | "granite-3", |
| 239 | "devstral", |
| 240 | ].some((part) => model.toLowerCase().includes(part)) |
| 241 | ) { |
| 242 | return true; |
| 243 | } |
| 244 | |
| 245 | return false; |
| 246 | }, |
| 247 | openrouter: (model) => { |
| 248 | // https://openrouter.ai/models?fmt=cards&supported_parameters=tools |
| 249 | |
| 250 | // Specific free models that don't support tools |
| 251 | // Fixes issue #6619 - moonshotai/kimi-k2:free causing 400 errors |
| 252 | if (model.toLowerCase() === "moonshotai/kimi-k2:free") { |
| 253 | return false; |
| 254 | } |
| 255 | |
| 256 | if ( |
| 257 | ["vision", "math", "guard", "mistrallite", "mistral-openorca"].some( |
| 258 | (part) => model.toLowerCase().includes(part), |
| 259 | ) |
| 260 | ) { |
| 261 | return false; |
| 262 | } |
| 263 | |
| 264 | const supportedPrefixes = [ |
| 265 | "openai/gpt-3.5", |
| 266 | "openai/gpt-4", |
| 267 | "openai/o1", |
| 268 | "openai/o3", |
| 269 | "openai/o4", |
| 270 | "openai/gpt-oss", |
| 271 | "anthropic/claude-3", |
| 272 | "anthropic/claude-4", |
| 273 | "microsoft/phi-3", |
| 274 | "google/gemini-flash-1.5", |
| 275 | "google/gemini-2", |
| 276 | "google/gemini-pro", |
| 277 | "x-ai/grok", |
| 278 | "qwen/qwen3", |
| 279 | "qwen/qwen-", |
| 280 | "cohere/command-r", |
| 281 | "cohere/command-a", |
| 282 | "ai21/jamba-1.6", |
| 283 | "mistralai/mistral", |
| 284 | "mistralai/ministral", |
| 285 | "mistralai/codestral", |
| 286 | "mistralai/mixtral", |
| 287 | "mistral/ministral", |
| 288 | "mistral/devstral", |
| 289 | "mistralai/pixtral", |
| 290 | "meta-llama/llama-3.3", |
| 291 | "amazon/nova", |
| 292 | "deepseek/deepseek-r1", |
| 293 | "deepseek/deepseek-chat", |
| 294 | "meta-llama/llama-4", |
| 295 | "all-hands/openhands-lm-32b", |
| 296 | "lgai-exaone/exaone", |
| 297 | ]; |
| 298 | for (const prefix of supportedPrefixes) { |
| 299 | if (model.toLowerCase().startsWith(prefix)) { |
| 300 | return true; |
| 301 | } |
| 302 | } |
| 303 | |
| 304 | const specificModels = [ |
| 305 | "qwen/qwq-32b", |
| 306 | "qwen/qwen-2.5-72b-instruct", |
| 307 | "meta-llama/llama-3.2-3b-instruct", |
| 308 | "meta-llama/llama-3-8b-instruct", |
| 309 | "meta-llama/llama-3-70b-instruct", |
| 310 | "arcee-ai/caller-large", |
| 311 | "nousresearch/hermes-3-llama-3.1-70b", |
| 312 | "moonshotai/kimi-k2", |
| 313 | ]; |
| 314 | for (const model of specificModels) { |
| 315 | if (model.toLowerCase() === model) { |
| 316 | return true; |
| 317 | } |
| 318 | } |
| 319 | |
| 320 | const supportedContains = ["llama-3.1"]; |
| 321 | for (const model of supportedContains) { |
| 322 | if (model.toLowerCase().includes(model)) { |
| 323 | return true; |
| 324 | } |
| 325 | } |
| 326 | |
| 327 | return false; |
| 328 | }, |
| 329 | moonshot: (model) => { |
| 330 | // support moonshot models |
| 331 | // https://platform.moonshot.ai/docs/pricing/chat#concepts |
| 332 | if ( |
| 333 | model.toLowerCase().startsWith("kimi") && |
| 334 | model.toLowerCase() !== "kimi-thinking-preview" |
| 335 | ) { |
| 336 | return true; |
| 337 | } |
| 338 | |
| 339 | if (model.toLowerCase().startsWith("moonshot")) { |
| 340 | return true; |
| 341 | } |
| 342 | |
| 343 | return false; |
| 344 | }, |
| 345 | novita: (model) => { |
| 346 | const lower = model.toLowerCase(); |
| 347 | |
| 348 | // Exact match models |
| 349 | const exactMatches = [ |
| 350 | "deepseek/deepseek-r1-0528", |
| 351 | "deepseek/deepseek-r1-turbo", |
| 352 | "deepseek/deepseek-v3-0324", |
| 353 | "deepseek/deepseek-v3-turbo", |
| 354 | "meta-llama/llama-3.3-70b-instruct", |
| 355 | "qwen/qwen-2.5-72b-instruct", |
| 356 | "zai-org/glm-4.5", |
| 357 | "moonshotai/kimi-k2-instruct", |
| 358 | ]; |
| 359 | |
| 360 | if (exactMatches.includes(lower)) { |
| 361 | return true; |
| 362 | } |
| 363 | |
| 364 | // Prefix match models |
| 365 | const prefixMatches = ["qwen/qwen3", "openai/gpt-oss"]; |
| 366 | |
| 367 | for (const prefix of prefixMatches) { |
| 368 | if (lower.startsWith(prefix)) { |
| 369 | return true; |
| 370 | } |
| 371 | } |
| 372 | |
| 373 | return false; |
| 374 | }, |
| 375 | }; |
| 376 | |
| 377 | export function isRecommendedAgentModel(modelName: string): boolean { |
| 378 | // AND behavior |
| 379 | const recs: RegExp[][] = [ |
| 380 | [/o[134]/], |
| 381 | [/deepseek/, /r1|reasoner/], |
| 382 | [/gemini/, /2\.5/, /pro/], |
| 383 | [/gpt-5/], |
| 384 | [/claude/, /sonnet/, /3\.7|3-7|-4/], |
| 385 | [/claude/, /opus/, /-4/], |
| 386 | ]; |
| 387 | for (const combo of recs) { |
| 388 | if (combo.every((regex) => modelName.toLowerCase().match(regex))) { |
| 389 | return true; |
| 390 | } |
| 391 | } |
| 392 | return false; |
| 393 | } |
| 394 | export function modelSupportsNativeTools(modelDescription: ModelDescription) { |
| 395 | if (modelDescription.capabilities?.tools !== undefined) { |
| 396 | return modelDescription.capabilities.tools; |
| 397 | } |
| 398 | |
| 399 | const providerSupport = PROVIDER_TOOL_SUPPORT[modelDescription.provider]; |
| 400 | if (!providerSupport) { |
| 401 | return false; |
| 402 | } |
| 403 | return providerSupport(modelDescription.model) ?? false; |
| 404 | } |