Elffuss BraidHub

kikocis/continue public

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