Elffuss BraidHub

kikocis/continue public

dfc814e4318e · 10.3 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 ) {
208 return true;
209 }
210
211 return false;
212 },
213 deepseek: (model) => {
214 // https://api-docs.deepseek.com/quick_start/pricing
215 // https://api-docs.deepseek.com/guides/function_calling
216 if (model === "deepseek-reasoner" || model === "deepseek-chat") {
217 return true;
218 }
219
220 return false;
221 },
222 watsonx: (model) => {
223 if (model.toLowerCase().includes("guard")) {
224 return false;
225 }
226 if (
227 [
228 "llama-3",
229 "llama-4",
230 "mistral",
231 "codestral",
232 "granite-3",
233 "devstral",
234 ].some((part) => model.toLowerCase().includes(part))
235 ) {
236 return true;
237 }
238
239 return false;
240 },
241 openrouter: (model) => {
242 // https://openrouter.ai/models?fmt=cards&supported_parameters=tools
243
244 // Specific free models that don't support tools
245 // Fixes issue #6619 - moonshotai/kimi-k2:free causing 400 errors
246 if (model.toLowerCase() === "moonshotai/kimi-k2:free") {
247 return false;
248 }
249
250 if (
251 ["vision", "math", "guard", "mistrallite", "mistral-openorca"].some(
252 (part) => model.toLowerCase().includes(part),
253 )
254 ) {
255 return false;
256 }
257
258 const supportedPrefixes = [
259 "openai/gpt-3.5",
260 "openai/gpt-4",
261 "openai/o1",
262 "openai/o3",
263 "openai/o4",
264 "openai/gpt-oss",
265 "anthropic/claude-3",
266 "anthropic/claude-4",
267 "microsoft/phi-3",
268 "google/gemini-flash-1.5",
269 "google/gemini-2",
270 "google/gemini-pro",
271 "x-ai/grok",
272 "qwen/qwen3",
273 "qwen/qwen-",
274 "cohere/command-r",
275 "cohere/command-a",
276 "ai21/jamba-1.6",
277 "mistralai/mistral",
278 "mistralai/ministral",
279 "mistralai/codestral",
280 "mistralai/mixtral",
281 "mistral/ministral",
282 "mistral/devstral",
283 "mistralai/pixtral",
284 "meta-llama/llama-3.3",
285 "amazon/nova",
286 "deepseek/deepseek-r1",
287 "deepseek/deepseek-chat",
288 "meta-llama/llama-4",
289 "all-hands/openhands-lm-32b",
290 "lgai-exaone/exaone",
291 ];
292 for (const prefix of supportedPrefixes) {
293 if (model.toLowerCase().startsWith(prefix)) {
294 return true;
295 }
296 }
297
298 const specificModels = [
299 "qwen/qwq-32b",
300 "qwen/qwen-2.5-72b-instruct",
301 "meta-llama/llama-3.2-3b-instruct",
302 "meta-llama/llama-3-8b-instruct",
303 "meta-llama/llama-3-70b-instruct",
304 "arcee-ai/caller-large",
305 "nousresearch/hermes-3-llama-3.1-70b",
306 "moonshotai/kimi-k2",
307 ];
308 for (const model of specificModels) {
309 if (model.toLowerCase() === model) {
310 return true;
311 }
312 }
313
314 const supportedContains = ["llama-3.1"];
315 for (const model of supportedContains) {
316 if (model.toLowerCase().includes(model)) {
317 return true;
318 }
319 }
320
321 return false;
322 },
323 moonshot: (model) => {
324 // support moonshot models
325 // https://platform.moonshot.ai/docs/pricing/chat#concepts
326 if (
327 model.toLowerCase().startsWith("kimi") &&
328 model.toLowerCase() !== "kimi-thinking-preview"
329 ) {
330 return true;
331 }
332
333 if (model.toLowerCase().startsWith("moonshot")) {
334 return true;
335 }
336
337 return false;
338 },
339 novita: (model) => {
340 const lower = model.toLowerCase();
341
342 // Exact match models
343 const exactMatches = [
344 "deepseek/deepseek-r1-0528",
345 "deepseek/deepseek-r1-turbo",
346 "deepseek/deepseek-v3-0324",
347 "deepseek/deepseek-v3-turbo",
348 "meta-llama/llama-3.3-70b-instruct",
349 "qwen/qwen-2.5-72b-instruct",
350 "zai-org/glm-4.5",
351 "moonshotai/kimi-k2-instruct",
352 ];
353
354 if (exactMatches.includes(lower)) {
355 return true;
356 }
357
358 // Prefix match models
359 const prefixMatches = ["qwen/qwen3", "openai/gpt-oss"];
360
361 for (const prefix of prefixMatches) {
362 if (lower.startsWith(prefix)) {
363 return true;
364 }
365 }
366
367 return false;
368 },
369 };
370
371export function isRecommendedAgentModel(modelName: string): boolean {
372 // AND behavior
373 const recs: RegExp[][] = [
374 [/o[134]/],
375 [/deepseek/, /r1|reasoner/],
376 [/gemini/, /2\.5/, /pro/],
377 [/gpt-5/],
378 [/claude/, /sonnet/, /3\.7|3-7|-4/],
379 [/claude/, /opus/, /-4/],
380 ];
381 for (const combo of recs) {
382 if (combo.every((regex) => modelName.toLowerCase().match(regex))) {
383 return true;
384 }
385 }
386 return false;
387}
388export function modelSupportsNativeTools(modelDescription: ModelDescription) {
389 if (modelDescription.capabilities?.tools !== undefined) {
390 return modelDescription.capabilities.tools;
391 }
392
393 const providerSupport = PROVIDER_TOOL_SUPPORT[modelDescription.provider];
394 if (!providerSupport) {
395 return false;
396 }
397 return providerSupport(modelDescription.model) ?? false;
398}