Elffuss BraidHub

kikocis/continue public

e31fcddb0dec · 10.4 KiBRawPermalink
1import { parseProxyModelName } from "@continuedev/config-yaml";
2import { ModelDescription } from "..";
3
4export 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 bedrock: (model) => {
114 if (
115 [
116 "claude-3-5-sonnet",
117 "claude-3.5-sonnet",
118 "claude-3-7-sonnet",
119 "claude-3.7-sonnet",
120 "claude-sonnet-4",
121 "claude-4-sonnet",
122 "claude-opus-4",
123 "nova-lite",
124 "nova-pro",
125 "nova-micro",
126 "nova-premier",
127 "gpt-oss",
128 ].some((part) => model.toLowerCase().includes(part))
129 ) {
130 return true;
131 }
132
133 return false;
134 },
135 mistral: (model) => {
136 // https://docs.mistral.ai/capabilities/function_calling/
137 return (
138 !model.toLowerCase().includes("mamba") &&
139 [
140 "devstral",
141 "codestral",
142 "mistral-large",
143 "mistral-small",
144 "pixtral",
145 "ministral",
146 "mistral-nemo",
147 "devstral",
148 ].some((part) => model.toLowerCase().includes(part))
149 );
150 },
151 // https://ollama.com/search?c=tools
152 ollama: (model) => {
153 let modelName = "";
154 // Extract the model name after the last slash to support other registries
155 if (model.includes("/")) {
156 let parts = model.split("/");
157 modelName = parts[parts.length - 1];
158 } else {
159 modelName = model;
160 }
161
162 if (
163 ["vision", "math", "guard", "mistrallite", "mistral-openorca"].some(
164 (part) => modelName.toLowerCase().includes(part),
165 )
166 ) {
167 return false;
168 }
169 if (
170 [
171 "cogito",
172 "llama3.3",
173 "qwq",
174 "llama3.2",
175 "llama3.1",
176 "qwen2",
177 "qwen3",
178 "mixtral",
179 "command-r",
180 "command-a",
181 "smollm2",
182 "hermes3",
183 "athene-v2",
184 "nemotron",
185 "llama3-groq",
186 "granite3",
187 "granite-3",
188 "aya-expanse",
189 "firefunction-v2",
190 "mistral",
191 "devstral",
192 "exaone",
193 "gpt-oss",
194 ].some((part) => modelName.toLowerCase().includes(part))
195 ) {
196 return true;
197 }
198
199 return false;
200 },
201 sambanova: (model) => {
202 // https://docs.sambanova.ai/cloud/docs/capabilities/function-calling
203 if (
204 model.toLowerCase().startsWith("meta-llama-3") ||
205 model.toLowerCase().includes("llama-4") ||
206 model.toLowerCase().includes("deepseek") ||
207 model.toLowerCase().includes("gpt") ||
208 model.toLowerCase().includes("qwen")
209 ) {
210 return true;
211 }
212
213 return false;
214 },
215 deepseek: (model) => {
216 // https://api-docs.deepseek.com/quick_start/pricing
217 // https://api-docs.deepseek.com/guides/function_calling
218 if (model === "deepseek-reasoner" || model === "deepseek-chat") {
219 return true;
220 }
221
222 return false;
223 },
224 watsonx: (model) => {
225 if (model.toLowerCase().includes("guard")) {
226 return false;
227 }
228 if (
229 [
230 "llama-3",
231 "llama-4",
232 "mistral",
233 "codestral",
234 "granite-3",
235 "devstral",
236 ].some((part) => model.toLowerCase().includes(part))
237 ) {
238 return true;
239 }
240
241 return false;
242 },
243 openrouter: (model) => {
244 // https://openrouter.ai/models?fmt=cards&supported_parameters=tools
245
246 // Specific free models that don't support tools
247 // Fixes issue #6619 - moonshotai/kimi-k2:free causing 400 errors
248 if (model.toLowerCase() === "moonshotai/kimi-k2:free") {
249 return false;
250 }
251
252 if (
253 ["vision", "math", "guard", "mistrallite", "mistral-openorca"].some(
254 (part) => model.toLowerCase().includes(part),
255 )
256 ) {
257 return false;
258 }
259
260 const supportedPrefixes = [
261 "openai/gpt-3.5",
262 "openai/gpt-4",
263 "openai/o1",
264 "openai/o3",
265 "openai/o4",
266 "openai/gpt-oss",
267 "anthropic/claude-3",
268 "anthropic/claude-4",
269 "microsoft/phi-3",
270 "google/gemini-flash-1.5",
271 "google/gemini-2",
272 "google/gemini-pro",
273 "x-ai/grok",
274 "qwen/qwen3",
275 "qwen/qwen-",
276 "cohere/command-r",
277 "cohere/command-a",
278 "ai21/jamba-1.6",
279 "mistralai/mistral",
280 "mistralai/ministral",
281 "mistralai/codestral",
282 "mistralai/mixtral",
283 "mistral/ministral",
284 "mistral/devstral",
285 "mistralai/pixtral",
286 "meta-llama/llama-3.3",
287 "amazon/nova",
288 "deepseek/deepseek-r1",
289 "deepseek/deepseek-chat",
290 "meta-llama/llama-4",
291 "all-hands/openhands-lm-32b",
292 "lgai-exaone/exaone",
293 ];
294 for (const prefix of supportedPrefixes) {
295 if (model.toLowerCase().startsWith(prefix)) {
296 return true;
297 }
298 }
299
300 const specificModels = [
301 "qwen/qwq-32b",
302 "qwen/qwen-2.5-72b-instruct",
303 "meta-llama/llama-3.2-3b-instruct",
304 "meta-llama/llama-3-8b-instruct",
305 "meta-llama/llama-3-70b-instruct",
306 "arcee-ai/caller-large",
307 "nousresearch/hermes-3-llama-3.1-70b",
308 "moonshotai/kimi-k2",
309 ];
310 for (const model of specificModels) {
311 if (model.toLowerCase() === model) {
312 return true;
313 }
314 }
315
316 const supportedContains = ["llama-3.1"];
317 for (const model of supportedContains) {
318 if (model.toLowerCase().includes(model)) {
319 return true;
320 }
321 }
322
323 return false;
324 },
325 moonshot: (model) => {
326 // support moonshot models
327 // https://platform.moonshot.ai/docs/pricing/chat#concepts
328 if (
329 model.toLowerCase().startsWith("kimi") &&
330 model.toLowerCase() !== "kimi-thinking-preview"
331 ) {
332 return true;
333 }
334
335 if (model.toLowerCase().startsWith("moonshot")) {
336 return true;
337 }
338
339 return false;
340 },
341 novita: (model) => {
342 const lower = model.toLowerCase();
343
344 // Exact match models
345 const exactMatches = [
346 "deepseek/deepseek-r1-0528",
347 "deepseek/deepseek-r1-turbo",
348 "deepseek/deepseek-v3-0324",
349 "deepseek/deepseek-v3-turbo",
350 "meta-llama/llama-3.3-70b-instruct",
351 "qwen/qwen-2.5-72b-instruct",
352 "zai-org/glm-4.5",
353 "moonshotai/kimi-k2-instruct",
354 ];
355
356 if (exactMatches.includes(lower)) {
357 return true;
358 }
359
360 // Prefix match models
361 const prefixMatches = ["qwen/qwen3", "openai/gpt-oss"];
362
363 for (const prefix of prefixMatches) {
364 if (lower.startsWith(prefix)) {
365 return true;
366 }
367 }
368
369 return false;
370 },
371 };
372
373export function isRecommendedAgentModel(modelName: string): boolean {
374 // AND behavior
375 const recs: RegExp[][] = [
376 [/o[134]/],
377 [/deepseek/, /r1|reasoner/],
378 [/gemini/, /2\.5/, /pro/],
379 [/gpt-5/],
380 [/claude/, /sonnet/, /3\.7|3-7|-4/],
381 [/claude/, /opus/, /-4/],
382 ];
383 for (const combo of recs) {
384 if (combo.every((regex) => modelName.toLowerCase().match(regex))) {
385 return true;
386 }
387 }
388 return false;
389}
390export function modelSupportsNativeTools(modelDescription: ModelDescription) {
391 if (modelDescription.capabilities?.tools !== undefined) {
392 return modelDescription.capabilities.tools;
393 }
394
395 const providerSupport = PROVIDER_TOOL_SUPPORT[modelDescription.provider];
396 if (!providerSupport) {
397 return false;
398 }
399 return providerSupport(modelDescription.model) ?? false;
400}