fix: normalize hyphenated model IDs for LM Studio tool support

LM Studio uses hyphenated model identifiers (e.g., "Meta-Llama-3.1-8B-Instruct-GGUF"),
but the Ollama heuristic checks for non-hyphenated patterns like "llama3.1".

This fix normalizes hyphenated model names by removing hyphens before delegating to
Ollama's tool support logic, enabling agent mode for LM Studio models with hyphenated IDs.

Added comprehensive tests for hyphenated model names including:
- Meta-Llama-3.1-8B-Instruct-GGUF
- Qwen2-7B-Instruct
- Mixtral-8x7B-Instruct-v0.1
- Case insensitivity checks
- Negative tests for unsupported models like "Llama-Vision-Free"

Addresses feedback from Cubic AI bot review.
This commit is contained in:
Varun Chawla 2026-02-07 20:12:08 -08:00
parent be5181ef31
commit 71d355ec44
2 changed files with 27 additions and 1 deletions

View file

@ -288,17 +288,38 @@ describe("PROVIDER_TOOL_SUPPORT", () => {
expect(supportsFn("mistral-7b")).toBe(true);
});
it("should return true for LM Studio hyphenated model IDs", () => {
// LM Studio uses hyphenated model identifiers like "Meta-Llama-3.1-8B-Instruct-GGUF"
expect(supportsFn("Meta-Llama-3.1-8B-Instruct-GGUF")).toBe(true);
expect(supportsFn("Meta-Llama-3.2-3B-Instruct")).toBe(true);
expect(supportsFn("Qwen2-7B-Instruct")).toBe(true);
expect(supportsFn("Mixtral-8x7B-Instruct-v0.1")).toBe(true);
expect(supportsFn("Mistral-7B-Instruct-v0.2")).toBe(true);
expect(supportsFn("llama-3.1-8b-instruct")).toBe(true);
});
it("should return false for explicitly unsupported models (same as ollama)", () => {
expect(supportsFn("vision")).toBe(false);
expect(supportsFn("math")).toBe(false);
expect(supportsFn("guard")).toBe(false);
});
it("should return false for hyphenated unsupported model names", () => {
expect(supportsFn("Llama-Vision-Free")).toBe(false);
expect(supportsFn("Math-Solver-7B")).toBe(false);
expect(supportsFn("Guard-Model")).toBe(false);
});
it("should handle case insensitivity (same as ollama)", () => {
expect(supportsFn("LLAMA3.1")).toBe(true);
expect(supportsFn("MIXTRAL-8x7b")).toBe(true);
expect(supportsFn("VISION")).toBe(false);
});
it("should handle case insensitivity with hyphenated names", () => {
expect(supportsFn("META-LLAMA-3.1-8B-INSTRUCT")).toBe(true);
expect(supportsFn("Qwen2-7B-Instruct-GGUF")).toBe(true);
});
});
describe("xAI", () => {

View file

@ -189,7 +189,12 @@ export const PROVIDER_TOOL_SUPPORT: Record<string, (model: string) => boolean> =
return false;
},
lmstudio: (model) => PROVIDER_TOOL_SUPPORT["ollama"](model),
lmstudio: (model) => {
// LM Studio uses hyphenated model IDs (e.g., "Meta-Llama-3.1-8B-Instruct-GGUF")
// Convert to format that matches Ollama's heuristic (e.g., "llama3.1")
const normalized = model.toLowerCase().replace(/-/g, "");
return PROVIDER_TOOL_SUPPORT["ollama"](normalized);
},
sambanova: (model) => {
// https://docs.sambanova.ai/cloud/docs/capabilities/function-calling
if (