From fb11c445753b3ce475b9821937864b24edd880cf Mon Sep 17 00:00:00 2001 From: Nate Date: Wed, 21 May 2025 14:58:01 -0700 Subject: [PATCH] update toolSupport and tests to always return a boolean. and for continue-proxy to expect full model string --- core/llm/toolSupport.test.ts | 116 ++++++--- core/llm/toolSupport.ts | 474 ++++++++++++++++++----------------- 2 files changed, 323 insertions(+), 267 deletions(-) diff --git a/core/llm/toolSupport.test.ts b/core/llm/toolSupport.test.ts index c92bb93ee..59e85f285 100644 --- a/core/llm/toolSupport.test.ts +++ b/core/llm/toolSupport.test.ts @@ -6,39 +6,57 @@ describe("PROVIDER_TOOL_SUPPORT", () => { const supportsFn = PROVIDER_TOOL_SUPPORT["continue-proxy"]; it("should return true for Claude 3.5 models", () => { - expect(supportsFn("claude-3-5-sonnet")).toBe(true); - expect(supportsFn("claude-3.5-sonnet")).toBe(true); + expect( + supportsFn("ownerSlug/packageSlug/anthropic/claude-3-5-sonnet"), + ).toBe(true); + expect( + supportsFn("ownerSlug/packageSlug/anthropic/claude-3.5-sonnet"), + ).toBe(true); }); it("should return true for Claude 3.7 models", () => { - expect(supportsFn("claude-3-7-haiku")).toBe(true); - expect(supportsFn("claude-3.7-sonnet")).toBe(true); + expect( + supportsFn("ownerSlug/packageSlug/anthropic/claude-3-7-haiku"), + ).toBe(true); + expect( + supportsFn("ownerSlug/packageSlug/anthropic/claude-3.7-sonnet"), + ).toBe(true); }); it("should return true for GPT-4 models", () => { - expect(supportsFn("gpt-4-turbo")).toBe(true); - expect(supportsFn("gpt-4-1106-preview")).toBe(true); + expect(supportsFn("ownerSlug/packageSlug/openai/gpt-4-turbo")).toBe(true); + expect( + supportsFn("ownerSlug/packageSlug/openai/gpt-4-1106-preview"), + ).toBe(true); }); it("should return true for O3 models", () => { - expect(supportsFn("o3-preview")).toBe(true); + expect(supportsFn("ownerSlug/packageSlug/openai/o3-preview")).toBe(true); }); it("should return true for Gemini models", () => { - expect(supportsFn("gemini-pro")).toBe(true); - expect(supportsFn("gemini-1.5-pro")).toBe(true); + expect(supportsFn("ownerSlug/packageSlug/gemini/gemini-pro")).toBe(true); + expect(supportsFn("ownerSlug/packageSlug/gemini/gemini-1.5-pro")).toBe( + true, + ); }); it("should return false for unsupported models", () => { - expect(supportsFn("gpt-3.5-turbo")).toBe(false); - expect(supportsFn("claude-2")).toBe(false); - expect(supportsFn("llama-3")).toBe(false); + expect(supportsFn("ownerSlug/packageSlug/openai/gpt-3.5-turbo")).toBe( + false, + ); + expect(supportsFn("ownerSlug/packageSlug/anthropic/claude-2")).toBe( + false, + ); + expect(supportsFn("ownerSlug/packageSlug/together/llama-3")).toBe(false); }); it("should handle case insensitivity", () => { - expect(supportsFn("CLAUDE-3-5-sonnet")).toBe(true); - expect(supportsFn("GPT-4-turbo")).toBe(true); - expect(supportsFn("GEMINI-pro")).toBe(true); + expect( + supportsFn("ownerSlug/packageSlug/anthropic/CLAUDE-3-5-sonnet"), + ).toBe(true); + expect(supportsFn("ownerSlug/packageSlug/openai/GPT-4-turbo")).toBe(true); + expect(supportsFn("ownerSlug/packageSlug/gemini/GEMINI-pro")).toBe(true); }); }); @@ -56,8 +74,8 @@ describe("PROVIDER_TOOL_SUPPORT", () => { }); it("should return undefined for unsupported models", () => { - expect(supportsFn("claude-2")).toBeUndefined(); - expect(supportsFn("claude-instant")).toBeUndefined(); + expect(supportsFn("claude-2")).toBe(false); + expect(supportsFn("claude-instant")).toBe(false); }); it("should handle case insensitivity", () => { @@ -81,8 +99,8 @@ describe("PROVIDER_TOOL_SUPPORT", () => { }); it("should return undefined for unsupported models", () => { - expect(supportsFn("gpt-3.5-turbo")).toBeUndefined(); - expect(supportsFn("davinci")).toBeUndefined(); + expect(supportsFn("gpt-3.5-turbo")).toBe(false); + expect(supportsFn("davinci")).toBe(false); }); it("should handle case insensitivity", () => { @@ -115,31 +133,49 @@ describe("PROVIDER_TOOL_SUPPORT", () => { const supportsFn = PROVIDER_TOOL_SUPPORT["bedrock"]; it("should return true for Claude 3.5 Sonnet models", () => { - expect(supportsFn("anthropic.claude-3-5-sonnet-20240620-v1:0")).toBe(true); - expect(supportsFn("anthropic.claude-3.5-sonnet-20240620-v1:0")).toBe(true); + expect(supportsFn("anthropic.claude-3-5-sonnet-20240620-v1:0")).toBe( + true, + ); + expect(supportsFn("anthropic.claude-3.5-sonnet-20240620-v1:0")).toBe( + true, + ); }); it("should return true for Claude 3.7 Sonnet models", () => { - expect(supportsFn("anthropic.claude-3-7-sonnet-20240620-v1:0")).toBe(true); - expect(supportsFn("anthropic.claude-3.7-sonnet-20240620-v1:0")).toBe(true); + expect(supportsFn("anthropic.claude-3-7-sonnet-20240620-v1:0")).toBe( + true, + ); + expect(supportsFn("anthropic.claude-3.7-sonnet-20240620-v1:0")).toBe( + true, + ); }); it("should return undefined for Claude Haiku and Opus models", () => { - expect(supportsFn("anthropic.claude-3-5-haiku-20240307-v1:0")).toBeUndefined(); - expect(supportsFn("anthropic.claude-3.5-haiku-20240620-v1:0")).toBeUndefined(); - expect(supportsFn("anthropic.claude-3-7-haiku-20240620-v1:0")).toBeUndefined(); - expect(supportsFn("anthropic.claude-3-5-opus-20240620-v1:0")).toBeUndefined(); - expect(supportsFn("anthropic.claude-3.7-opus-20240620-v1:0")).toBeUndefined(); + expect(supportsFn("anthropic.claude-3-5-haiku-20240307-v1:0")).toBe( + false, + ); + expect(supportsFn("anthropic.claude-3.5-haiku-20240620-v1:0")).toBe( + false, + ); + expect(supportsFn("anthropic.claude-3-7-haiku-20240620-v1:0")).toBe( + false, + ); + expect(supportsFn("anthropic.claude-3-5-opus-20240620-v1:0")).toBe(false); + expect(supportsFn("anthropic.claude-3.7-opus-20240620-v1:0")).toBe(false); }); it("should return undefined for other unsupported models", () => { - expect(supportsFn("anthropic.claude-instant-v1")).toBeUndefined(); - expect(supportsFn("anthropic.titan-text-express-v1")).toBeUndefined(); + expect(supportsFn("anthropic.claude-instant-v1")).toBe(false); + expect(supportsFn("anthropic.titan-text-express-v1")).toBe(false); }); it("should handle case insensitivity", () => { - expect(supportsFn("ANTHROPIC.CLAUDE-3-5-SONNET-20240620-v1:0")).toBe(true); - expect(supportsFn("ANTHROPIC.CLAUDE-3.7-SONNET-20240620-v1:0")).toBe(true); + expect(supportsFn("ANTHROPIC.CLAUDE-3-5-SONNET-20240620-v1:0")).toBe( + true, + ); + expect(supportsFn("ANTHROPIC.CLAUDE-3.7-SONNET-20240620-v1:0")).toBe( + true, + ); }); }); @@ -203,9 +239,9 @@ describe("PROVIDER_TOOL_SUPPORT", () => { }); it("should return undefined for other models", () => { - expect(supportsFn("llama2")).toBeUndefined(); - expect(supportsFn("phi-2")).toBeUndefined(); - expect(supportsFn("falcon")).toBeUndefined(); + expect(supportsFn("llama2")).toBe(false); + expect(supportsFn("phi-2")).toBe(false); + expect(supportsFn("falcon")).toBe(false); }); it("should handle case insensitivity", () => { @@ -218,16 +254,16 @@ describe("PROVIDER_TOOL_SUPPORT", () => { describe("edge cases", () => { it("should handle empty model names", () => { expect(PROVIDER_TOOL_SUPPORT["continue-proxy"]("")).toBe(false); - expect(PROVIDER_TOOL_SUPPORT["anthropic"]("")).toBeUndefined(); - expect(PROVIDER_TOOL_SUPPORT["openai"]("")).toBeUndefined(); + expect(PROVIDER_TOOL_SUPPORT["anthropic"]("")).toBe(false); + expect(PROVIDER_TOOL_SUPPORT["openai"]("")).toBe(false); expect(PROVIDER_TOOL_SUPPORT["gemini"]("")).toBe(false); - expect(PROVIDER_TOOL_SUPPORT["bedrock"]("")).toBeUndefined(); - expect(PROVIDER_TOOL_SUPPORT["ollama"]("")).toBeUndefined(); + expect(PROVIDER_TOOL_SUPPORT["bedrock"]("")).toBe(false); + expect(PROVIDER_TOOL_SUPPORT["ollama"]("")).toBe(false); }); it("should handle non-existent provider", () => { // @ts-ignore - Testing runtime behavior with invalid provider - expect(PROVIDER_TOOL_SUPPORT["non-existent"]).toBeUndefined(); + expect(PROVIDER_TOOL_SUPPORT["non-existent"]).toBe(undefined); }); }); }); diff --git a/core/llm/toolSupport.ts b/core/llm/toolSupport.ts index 050f5e510..cc0c4fa68 100644 --- a/core/llm/toolSupport.ts +++ b/core/llm/toolSupport.ts @@ -1,235 +1,255 @@ import { parseProxyModelName } from "@continuedev/config-yaml"; -export const PROVIDER_TOOL_SUPPORT: Record< - string, - (model: string) => boolean | undefined -> = { - "continue-proxy": (model) => { - const { provider, model: _model } = parseProxyModelName(model); - if (provider && _model && provider !== "continue-proxy") { - const fn = PROVIDER_TOOL_SUPPORT[provider]; - if (fn) { - return fn(_model); +export const PROVIDER_TOOL_SUPPORT: Record boolean> = + { + "continue-proxy": (model) => { + try { + const { provider, model: _model } = parseProxyModelName(model); + if (provider && _model && provider !== "continue-proxy") { + const fn = PROVIDER_TOOL_SUPPORT[provider]; + if (fn) { + return fn(_model); + } + } + } catch (e) {} + + return [ + "claude-3-5", + "claude-3.5", + "claude-3-7", + "claude-3.7", + "gpt-4", + "o3", + "gemini", + ].some((part) => model.toLowerCase().startsWith(part)); + }, + anthropic: (model) => { + if ( + ["claude-3-5", "claude-3.5", "claude-3-7", "claude-3.7"].some((part) => + model.toLowerCase().startsWith(part), + ) + ) { + return true; } - } - return [ - "claude-3-5", - "claude-3.5", - "claude-3-7", - "claude-3.7", - "gpt-4", - "o3", - "gemini", - ].some((part) => model.toLowerCase().startsWith(part)); - }, - anthropic: (model) => { - if ( - ["claude-3-5", "claude-3.5", "claude-3-7", "claude-3.7"].some((part) => - model.toLowerCase().startsWith(part), + + return false; + }, + azure: (model) => { + if ( + model.toLowerCase().startsWith("gpt-4") || + model.toLowerCase().startsWith("o3") ) - ) { - return true; - } - }, - azure: (model) => { - if ( - model.toLowerCase().startsWith("gpt-4") || - model.toLowerCase().startsWith("o3") - ) - return true; - return false; - }, - openai: (model) => { - // https://platform.openai.com/docs/guides/function-calling#models-supporting-function-calling - if ( - model.toLowerCase().startsWith("gpt-4") || - model.toLowerCase().startsWith("o3") - ) { - return true; - } - // firworks-ai https://docs.fireworks.ai/guides/function-calling - if (model.startsWith("accounts/fireworks/models/")) { - switch (model.substring(26)) { - case "llama-v3p1-405b-instruct": - case "llama-v3p1-70b-instruct": - case "qwen2p5-72b-instruct": - case "firefunction-v1": - case "firefunction-v2": + return true; + return false; + }, + openai: (model) => { + // https://platform.openai.com/docs/guides/function-calling#models-supporting-function-calling + if ( + model.toLowerCase().startsWith("gpt-4") || + model.toLowerCase().startsWith("o3") + ) { + return true; + } + // firworks-ai https://docs.fireworks.ai/guides/function-calling + if (model.startsWith("accounts/fireworks/models/")) { + switch (model.substring(26)) { + case "llama-v3p1-405b-instruct": + case "llama-v3p1-70b-instruct": + case "qwen2p5-72b-instruct": + case "firefunction-v1": + case "firefunction-v2": + return true; + default: + return false; + } + } + + return false; + }, + gemini: (model) => { + // All gemini models support function calling + return model.toLowerCase().includes("gemini"); + }, + vertexai: (model) => { + // All gemini models except flash 2.0 lite support function calling + return ( + model.toLowerCase().includes("gemini") && + !model.toLowerCase().includes("lite") + ); + }, + bedrock: (model) => { + // For Bedrock, only support Claude Sonnet models with versions 3.5/3-5 and 3.7/3-7 + if ( + model.toLowerCase().includes("sonnet") && + ["claude-3-5", "claude-3.5", "claude-3-7", "claude-3.7"].some((part) => + model.toLowerCase().includes(part), + ) + ) { + return true; + } + + return false; + }, + mistral: (model) => { + // https://docs.mistral.ai/capabilities/function_calling/ + return ( + !model.toLowerCase().includes("mamba") && + [ + "codestral", + "mistral-large", + "mistral-small", + "pixtral", + "ministral", + "mistral-nemo", + ].some((part) => model.toLowerCase().includes(part)) + ); + }, + // https://ollama.com/search?c=tools + ollama: (model) => { + let modelName = ""; + // Extract the model name after the last slash to support other registries + if (model.includes("/")) { + let parts = model.split("/"); + modelName = parts[parts.length - 1]; + } else { + modelName = model; + } + + if ( + ["vision", "math", "guard", "mistrallite", "mistral-openorca"].some( + (part) => modelName.toLowerCase().includes(part), + ) + ) { + return false; + } + if ( + [ + "cogito", + "llama3.3", + "qwq", + "llama3.2", + "llama3.1", + "qwen2", + "qwen3", + "mixtral", + "command-r", + "smollm2", + "hermes3", + "athene-v2", + "nemotron", + "llama3-groq", + "granite3", + "granite-3", + "aya-expanse", + "firefunction-v2", + "mistral", + ].some((part) => modelName.toLowerCase().includes(part)) + ) { + return true; + } + + return false; + }, + sambanova: (model) => { + // https://docs.sambanova.ai/cloud/docs/capabilities/function-calling + if ( + model.toLowerCase().startsWith("meta-llama-3") || + model.toLowerCase().includes("llama-4") || + model.toLowerCase().includes("deepseek") + ) { + return true; + } + + return false; + }, + deepseek: (model) => { + if (model !== "deepseek-reasoner") { + return true; + } + + return false; + }, + watsonx: (model) => { + if (model.toLowerCase().includes("guard")) { + return false; + } + if ( + ["llama-3", "llama-4", "mistral", "codestral", "granite-3"].some( + (part) => model.toLowerCase().includes(part), + ) + ) { + return true; + } + + return false; + }, + openrouter: (model) => { + // https://openrouter.ai/models?fmt=cards&supported_parameters=tools + if ( + ["vision", "math", "guard", "mistrallite", "mistral-openorca"].some( + (part) => model.toLowerCase().includes(part), + ) + ) { + return false; + } + + const supportedPrefixes = [ + "openai/gpt-3.5", + "openai/gpt-4", + "openai/o1", + "openai/o3", + "openai/o4", + "anthropic/claude-3", + "microsoft/phi-3", + "google/gemini-flash-1.5", + "google/gemini-2", + "google/gemini-pro", + "x-ai/grok", + "qwen/qwen3", + "qwen/qwen-", + "cohere/command-r", + "ai21/jamba-1.6", + "mistralai/mistral", + "mistralai/ministral", + "mistralai/codestral", + "mistralai/mixtral", + "mistral/ministral", + "mistralai/pixtral", + "meta-llama/llama-3.3", + "amazon/nova", + "deepseek/deepseek-r1", + "deepseek/deepseek-chat", + "meta-llama/llama-4", + "all-hands/openhands-lm-32b", + ]; + for (const prefix of supportedPrefixes) { + if (model.toLowerCase().startsWith(prefix)) { return true; - default: - return false; + } + } + + const specificModels = [ + "qwen/qwq-32b", + "qwen/qwen-2.5-72b-instruct", + "meta-llama/llama-3.2-3b-instruct", + "meta-llama/llama-3-8b-instruct", + "meta-llama/llama-3-70b-instruct", + "arcee-ai/caller-large", + "nousresearch/hermes-3-llama-3.1-70b", + ]; + for (const model of specificModels) { + if (model.toLowerCase() === model) { + return true; + } + } + + const supportedContains = ["llama-3.1"]; + for (const model of supportedContains) { + if (model.toLowerCase().includes(model)) { + return true; + } } - } - }, - gemini: (model) => { - // All gemini models support function calling - return model.toLowerCase().includes("gemini"); - }, - vertexai: (model) => { - // All gemini models except flash 2.0 lite support function calling - return ( - model.toLowerCase().includes("gemini") && - !model.toLowerCase().includes("lite") - ); - }, - bedrock: (model) => { - // For Bedrock, only support Claude Sonnet models with versions 3.5/3-5 and 3.7/3-7 - if ( - model.toLowerCase().includes("sonnet") && - ["claude-3-5", "claude-3.5", "claude-3-7", "claude-3.7"].some((part) => - model.toLowerCase().includes(part), - ) - ) { - return true; - } - }, - mistral: (model) => { - // https://docs.mistral.ai/capabilities/function_calling/ - return ( - !model.toLowerCase().includes("mamba") && - [ - "codestral", - "mistral-large", - "mistral-small", - "pixtral", - "ministral", - "mistral-nemo", - ].some((part) => model.toLowerCase().includes(part)) - ); - }, - // https://ollama.com/search?c=tools - ollama: (model) => { - let modelName = ""; - // Extract the model name after the last slash to support other registries - if (model.includes("/")) { - let parts = model.split("/"); - modelName = parts[parts.length - 1]; - } else { - modelName = model; - } - if ( - ["vision", "math", "guard", "mistrallite", "mistral-openorca"].some( - (part) => modelName.toLowerCase().includes(part), - ) - ) { return false; - } - if ( - [ - "cogito", - "llama3.3", - "qwq", - "llama3.2", - "llama3.1", - "qwen2", - "qwen3", - "mixtral", - "command-r", - "smollm2", - "hermes3", - "athene-v2", - "nemotron", - "llama3-groq", - "granite3", - "granite-3", - "aya-expanse", - "firefunction-v2", - "mistral", - ].some((part) => modelName.toLowerCase().includes(part)) - ) { - return true; - } - }, - sambanova: (model) => { - // https://docs.sambanova.ai/cloud/docs/capabilities/function-calling - if ( - model.toLowerCase().startsWith("meta-llama-3") || - model.toLowerCase().includes("llama-4") || - model.toLowerCase().includes("deepseek") - ) { - return true; - } - }, - deepseek: (model) => { - if (model !== "deepseek-reasoner") { - return true; - } - }, - watsonx: (model) => { - if (model.toLowerCase().includes("guard")) return false; - if ( - ["llama-3", "llama-4", "mistral", "codestral", "granite-3"].some((part) => - model.toLowerCase().includes(part), - ) - ) - return true; - }, - openrouter: (model) => { - // https://openrouter.ai/models?fmt=cards&supported_parameters=tools - if ( - ["vision", "math", "guard", "mistrallite", "mistral-openorca"].some( - (part) => model.toLowerCase().includes(part), - ) - ) { - return false; - } - - const supportedPrefixes = [ - "openai/gpt-3.5", - "openai/gpt-4", - "openai/o1", - "openai/o3", - "openai/o4", - "anthropic/claude-3", - "microsoft/phi-3", - "google/gemini-flash-1.5", - "google/gemini-2", - "google/gemini-pro", - "x-ai/grok", - "qwen/qwen3", - "qwen/qwen-", - "cohere/command-r", - "ai21/jamba-1.6", - "mistralai/mistral", - "mistralai/ministral", - "mistralai/codestral", - "mistralai/mixtral", - "mistral/ministral", - "mistralai/pixtral", - "meta-llama/llama-3.3", - "amazon/nova", - "deepseek/deepseek-r1", - "deepseek/deepseek-chat", - "meta-llama/llama-4", - "all-hands/openhands-lm-32b", - ]; - for (const prefix of supportedPrefixes) { - if (model.toLowerCase().startsWith(prefix)) { - return true; - } - } - - const specificModels = [ - "qwen/qwq-32b", - "qwen/qwen-2.5-72b-instruct", - "meta-llama/llama-3.2-3b-instruct", - "meta-llama/llama-3-8b-instruct", - "meta-llama/llama-3-70b-instruct", - "arcee-ai/caller-large", - "nousresearch/hermes-3-llama-3.1-70b", - ]; - for (const model of specificModels) { - if (model.toLowerCase() === model) { - return true; - } - } - - const supportedContains = ["llama-3.1"]; - for (const model of supportedContains) { - if (model.toLowerCase().includes(model)) { - return true; - } - } - }, -}; + }, + };