Elffuss BraidHub

kikocis/continue public

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