Elffuss BraidHub

kikocis/continue public

753e021a1971 · 9.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 ].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 if (
243 ["vision", "math", "guard", "mistrallite", "mistral-openorca"].some(
244 (part) => model.toLowerCase().includes(part),
245 )
246 ) {
247 return false;
248 }
249
250 const supportedPrefixes = [
251 "openai/gpt-3.5",
252 "openai/gpt-4",
253 "openai/o1",
254 "openai/o3",
255 "openai/o4",
256 "openai/gpt-oss",
257 "anthropic/claude-3",
258 "anthropic/claude-4",
259 "microsoft/phi-3",
260 "google/gemini-flash-1.5",
261 "google/gemini-2",
262 "google/gemini-pro",
263 "x-ai/grok",
264 "qwen/qwen3",
265 "qwen/qwen-",
266 "cohere/command-r",
267 "cohere/command-a",
268 "ai21/jamba-1.6",
269 "mistralai/mistral",
270 "mistralai/ministral",
271 "mistralai/codestral",
272 "mistralai/mixtral",
273 "mistral/ministral",
274 "mistral/devstral",
275 "mistralai/pixtral",
276 "meta-llama/llama-3.3",
277 "amazon/nova",
278 "deepseek/deepseek-r1",
279 "deepseek/deepseek-chat",
280 "meta-llama/llama-4",
281 "all-hands/openhands-lm-32b",
282 "lgai-exaone/exaone",
283 ];
284 for (const prefix of supportedPrefixes) {
285 if (model.toLowerCase().startsWith(prefix)) {
286 return true;
287 }
288 }
289
290 const specificModels = [
291 "qwen/qwq-32b",
292 "qwen/qwen-2.5-72b-instruct",
293 "meta-llama/llama-3.2-3b-instruct",
294 "meta-llama/llama-3-8b-instruct",
295 "meta-llama/llama-3-70b-instruct",
296 "arcee-ai/caller-large",
297 "nousresearch/hermes-3-llama-3.1-70b",
298 ];
299 for (const model of specificModels) {
300 if (model.toLowerCase() === model) {
301 return true;
302 }
303 }
304
305 const supportedContains = ["llama-3.1"];
306 for (const model of supportedContains) {
307 if (model.toLowerCase().includes(model)) {
308 return true;
309 }
310 }
311
312 return false;
313 },
314 moonshot: (model) => {
315 // support moonshot models
316 // https://platform.moonshot.ai/docs/pricing/chat#concepts
317 if (
318 model.toLowerCase().startsWith("kimi") &&
319 model.toLowerCase() !== "kimi-thinking-preview"
320 ) {
321 return true;
322 }
323
324 if (model.toLowerCase().startsWith("moonshot")) {
325 return true;
326 }
327
328 return false;
329 },
330 };
331
332export function isRecommendedAgentModel(modelName: string): boolean {
333 // AND behavior
334 const recs: RegExp[][] = [
335 [/o[134]/],
336 [/deepseek/, /r1|reasoner/],
337 [/gemini/, /2\.5/, /pro/],
338 [/gpt/, /4/],
339 [/claude/, /sonnet/, /3\.5|3\.7|3-5|3-7|-4/],
340 [/claude/, /opus/, /-4/],
341 ];
342 for (const combo of recs) {
343 if (combo.every((regex) => modelName.toLowerCase().match(regex))) {
344 return true;
345 }
346 }
347 return false;
348}
349export function modelSupportsNativeTools(modelDescription: ModelDescription) {
350 if (modelDescription.capabilities?.tools !== undefined) {
351 return modelDescription.capabilities.tools;
352 }
353
354 const providerSupport = PROVIDER_TOOL_SUPPORT[modelDescription.provider];
355 if (!providerSupport) {
356 return false;
357 }
358 return providerSupport(modelDescription.model) ?? false;
359}