Elffuss BraidHub

kikocis/continue public

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