Elffuss BraidHub

kikocis/continue public

a62a835baa95 · 9.0 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 // https://platform.openai.com/docs/guides/function-calling#models-supporting-function-calling
58 if (
59 model.toLowerCase().startsWith("gpt-4") ||
60 model.toLowerCase().startsWith("o3")
61 ) {
62 return true;
63 }
64 if (model.toLowerCase().includes("gpt-oss")) {
65 return true;
66 }
67 // https://ai.google.dev/gemma/docs/capabilities/function-calling
68 if (model.toLowerCase().startsWith("gemma")) {
69 return true;
70 }
71 // firworks-ai https://docs.fireworks.ai/guides/function-calling
72 if (model.startsWith("accounts/fireworks/models/")) {
73 switch (model.substring(26)) {
74 case "llama-v3p1-405b-instruct":
75 case "llama-v3p1-70b-instruct":
76 case "qwen2p5-72b-instruct":
77 case "firefunction-v1":
78 case "firefunction-v2":
79 return true;
80 default:
81 return false;
82 }
83 }
84
85 return false;
86 },
87 cohere: (model) => {
88 return model.toLowerCase().startsWith("command");
89 },
90 gemini: (model) => {
91 // All gemini models support function calling
92 return model.toLowerCase().includes("gemini");
93 },
94 vertexai: (model) => {
95 const lowerCaseModel = model.toLowerCase();
96 // All gemini models except flash 2.0 lite support function calling
97 if (lowerCaseModel.includes("lite")) {
98 return false;
99 }
100 return ["claude", "gemini"].some((val) => lowerCaseModel.includes(val));
101 },
102 bedrock: (model) => {
103 if (
104 [
105 "claude-3-5-sonnet",
106 "claude-3.5-sonnet",
107 "claude-3-7-sonnet",
108 "claude-3.7-sonnet",
109 "claude-sonnet-4",
110 "claude-4-sonnet",
111 "claude-opus-4",
112 "nova-lite",
113 "nova-pro",
114 "nova-micro",
115 "nova-premier",
116 ].some((part) => model.toLowerCase().includes(part))
117 ) {
118 return true;
119 }
120
121 return false;
122 },
123 mistral: (model) => {
124 // https://docs.mistral.ai/capabilities/function_calling/
125 return (
126 !model.toLowerCase().includes("mamba") &&
127 [
128 "devstral",
129 "codestral",
130 "mistral-large",
131 "mistral-small",
132 "pixtral",
133 "ministral",
134 "mistral-nemo",
135 "devstral",
136 ].some((part) => model.toLowerCase().includes(part))
137 );
138 },
139 // https://ollama.com/search?c=tools
140 ollama: (model) => {
141 let modelName = "";
142 // Extract the model name after the last slash to support other registries
143 if (model.includes("/")) {
144 let parts = model.split("/");
145 modelName = parts[parts.length - 1];
146 } else {
147 modelName = model;
148 }
149
150 if (
151 ["vision", "math", "guard", "mistrallite", "mistral-openorca"].some(
152 (part) => modelName.toLowerCase().includes(part),
153 )
154 ) {
155 return false;
156 }
157 if (
158 [
159 "cogito",
160 "llama3.3",
161 "qwq",
162 "llama3.2",
163 "llama3.1",
164 "qwen2",
165 "qwen3",
166 "mixtral",
167 "command-r",
168 "command-a",
169 "smollm2",
170 "hermes3",
171 "athene-v2",
172 "nemotron",
173 "llama3-groq",
174 "granite3",
175 "granite-3",
176 "aya-expanse",
177 "firefunction-v2",
178 "mistral",
179 "devstral",
180 "gpt-oss",
181 ].some((part) => modelName.toLowerCase().includes(part))
182 ) {
183 return true;
184 }
185
186 return false;
187 },
188 sambanova: (model) => {
189 // https://docs.sambanova.ai/cloud/docs/capabilities/function-calling
190 if (
191 model.toLowerCase().startsWith("meta-llama-3") ||
192 model.toLowerCase().includes("llama-4") ||
193 model.toLowerCase().includes("deepseek")
194 ) {
195 return true;
196 }
197
198 return false;
199 },
200 deepseek: (model) => {
201 // https://api-docs.deepseek.com/quick_start/pricing
202 // https://api-docs.deepseek.com/guides/function_calling
203 if (model === "deepseek-reasoner" || model === "deepseek-chat") {
204 return true;
205 }
206
207 return false;
208 },
209 watsonx: (model) => {
210 if (model.toLowerCase().includes("guard")) {
211 return false;
212 }
213 if (
214 [
215 "llama-3",
216 "llama-4",
217 "mistral",
218 "codestral",
219 "granite-3",
220 "devstral",
221 ].some((part) => model.toLowerCase().includes(part))
222 ) {
223 return true;
224 }
225
226 return false;
227 },
228 openrouter: (model) => {
229 // https://openrouter.ai/models?fmt=cards&supported_parameters=tools
230 if (
231 ["vision", "math", "guard", "mistrallite", "mistral-openorca"].some(
232 (part) => model.toLowerCase().includes(part),
233 )
234 ) {
235 return false;
236 }
237
238 const supportedPrefixes = [
239 "openai/gpt-3.5",
240 "openai/gpt-4",
241 "openai/o1",
242 "openai/o3",
243 "openai/o4",
244 "openai/gpt-oss",
245 "anthropic/claude-3",
246 "anthropic/claude-4",
247 "microsoft/phi-3",
248 "google/gemini-flash-1.5",
249 "google/gemini-2",
250 "google/gemini-pro",
251 "x-ai/grok",
252 "qwen/qwen3",
253 "qwen/qwen-",
254 "cohere/command-r",
255 "cohere/command-a",
256 "ai21/jamba-1.6",
257 "mistralai/mistral",
258 "mistralai/ministral",
259 "mistralai/codestral",
260 "mistralai/mixtral",
261 "mistral/ministral",
262 "mistral/devstral",
263 "mistralai/pixtral",
264 "meta-llama/llama-3.3",
265 "amazon/nova",
266 "deepseek/deepseek-r1",
267 "deepseek/deepseek-chat",
268 "meta-llama/llama-4",
269 "all-hands/openhands-lm-32b",
270 ];
271 for (const prefix of supportedPrefixes) {
272 if (model.toLowerCase().startsWith(prefix)) {
273 return true;
274 }
275 }
276
277 const specificModels = [
278 "qwen/qwq-32b",
279 "qwen/qwen-2.5-72b-instruct",
280 "meta-llama/llama-3.2-3b-instruct",
281 "meta-llama/llama-3-8b-instruct",
282 "meta-llama/llama-3-70b-instruct",
283 "arcee-ai/caller-large",
284 "nousresearch/hermes-3-llama-3.1-70b",
285 ];
286 for (const model of specificModels) {
287 if (model.toLowerCase() === model) {
288 return true;
289 }
290 }
291
292 const supportedContains = ["llama-3.1"];
293 for (const model of supportedContains) {
294 if (model.toLowerCase().includes(model)) {
295 return true;
296 }
297 }
298
299 return false;
300 },
301 moonshot: (model) => {
302 // support moonshot models
303 // https://platform.moonshot.ai/docs/pricing/chat#concepts
304 if (
305 model.toLowerCase().startsWith("kimi") &&
306 model.toLowerCase() !== "kimi-thinking-preview"
307 ) {
308 return true;
309 }
310
311 if (model.toLowerCase().startsWith("moonshot")) {
312 return true;
313 }
314
315 return false;
316 },
317 };
318
319export function isRecommendedAgentModel(modelName: string): boolean {
320 // AND behavior
321 const recs: RegExp[][] = [
322 [/o[134]/],
323 [/deepseek/, /r1|reasoner/],
324 [/gemini/, /2\.5/, /pro/],
325 [/gpt/, /4/],
326 [/claude/, /sonnet/, /3\.5|3\.7|3-5|3-7|-4/],
327 [/claude/, /opus/, /-4/],
328 ];
329 for (const combo of recs) {
330 if (combo.every((regex) => modelName.toLowerCase().match(regex))) {
331 return true;
332 }
333 }
334 return false;
335}
336export function modelSupportsNativeTools(modelDescription: ModelDescription) {
337 if (modelDescription.capabilities?.tools !== undefined) {
338 return modelDescription.capabilities.tools;
339 }
340 const providerSupport = PROVIDER_TOOL_SUPPORT[modelDescription.provider];
341 if (!providerSupport) {
342 return false;
343 }
344 return providerSupport(modelDescription.model) ?? false;
345}