Skip to content

Commit 81c0086

Browse files
committed
fix(models): route tagged ollama names that share a cloud prefix to ollama
findProviderFromModel matched provider patterns (/^gpt/, /^mistral/, /^claude/, ...) against any id that no namespace or catalog entry claimed. The browser registers the installed Ollama list, so the editor resolved a local model such as gpt-oss:20b or mistral:latest to Ollama, but the server never holds that list: execution fell through to the cloud pattern and sent the request to OpenAI or Mistral with the user's key, or failed on a missing one. Ollama lists every installed model as name:tag, and no cloud model id carries an Ollama tag, so a bare tagged name is now left unclaimed before patterns run and getProviderFromModel defaults it to Ollama, the same as every other local name. Namespaces and exact catalog ids still win first, so bedrock/...:0 and openrouter/...:free are unaffected. Saved workflows heal without a migration, and the editor, execution, permission checks and the editing validator now agree on the provider. getModelCapabilities re-implemented the pattern scan and kept reporting a cloud provider's capabilities for these names; it now falls back to findProviderFromModel so the two cannot disagree.
1 parent 3b3c0b5 commit 81c0086

4 files changed

Lines changed: 60 additions & 11 deletions

File tree

‎apps/sim/lib/workflows/editing/validation-models.test.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,15 @@ describe('model ids no provider declares', () => {
109109
expect(errors[0]?.error).toContain('Unknown model id')
110110
})
111111

112+
it.each(['gpt-oss:20b', 'mistral:latest'])(
113+
'accepts %s, an installed Ollama model sharing a cloud prefix, where it runs on Ollama',
114+
(model) => {
115+
expect(validateModel('router_v2', model)).toEqual({ errors: [], model })
116+
setEnvFlags({ isHosted: true })
117+
expect(validateModel('router_v2', model).errors[0]?.error).toContain('Unknown model id')
118+
}
119+
)
120+
112121
it.each(['hhao/qwen2.5-coder-tools', 'hf.co/bartowski/Llama-3.2-1B-Instruct-GGUF:Q4_K_M'])(
113122
'accepts a namespaced Ollama library name such as %s',
114123
(model) => {

‎apps/sim/providers/models.test.ts‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import {
33
findProviderFromModel,
44
getBaseModelProviders,
55
getHostedModels,
6+
getModelCapabilities,
67
getModelPricing,
8+
getProviderFromModel,
79
getProviderModels,
810
getStaticProviderModels,
911
isCustomModelId,
@@ -98,6 +100,28 @@ describe('custom cloud model routing', () => {
98100
})
99101
})
100102

103+
describe('tagged Ollama model names that share a cloud prefix', () => {
104+
it.each(['gpt-oss:20b', 'mistral:latest', 'GPT-OSS:120B', 'hf.co/org/gemini-like:Q4_K_M'])(
105+
'leaves %s unclaimed, so it runs on Ollama with Ollama capabilities',
106+
(model) => {
107+
expect(findProviderFromModel(model)).toBeNull()
108+
expect(getProviderFromModel(model)).toBe('ollama')
109+
expect(getModelCapabilities(model)).toBeNull()
110+
}
111+
)
112+
113+
it('still resolves untagged cloud ids, namespaced tags, and catalog ids by their provider', () => {
114+
expect(findProviderFromModel('gpt-oss-custom')).toBe('openai')
115+
expect(findProviderFromModel('mistral-large-latest')).toBe('mistral')
116+
expect(findProviderFromModel('ollama/gpt-oss:20b')).toBe('ollama')
117+
expect(findProviderFromModel('openrouter/org/model:free')).toBe('openrouter')
118+
expect(findProviderFromModel('bedrock/amazon.nova-lite-v1:0')).toBe('bedrock')
119+
expect(getModelCapabilities('ollama/gpt-oss:20b')).toEqual(
120+
PROVIDER_DEFINITIONS.ollama.capabilities
121+
)
122+
})
123+
})
124+
101125
describe('catalog featured model metadata', () => {
102126
it('defines at most one active featured model per provider', () => {
103127
for (const provider of Object.values(PROVIDER_DEFINITIONS)) {

‎apps/sim/providers/models.ts‎

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6915,6 +6915,9 @@ export function getBaseModelProviders(): Record<string, ProviderId> {
69156915
)
69166916
}
69176917

6918+
/** An Ollama model reference with its tag: `[host/][namespace/]name:tag`. */
6919+
const OLLAMA_TAGGED_MODEL_NAME = /^[\w.-]+(\/[\w.-]+)*:[\w.-]+$/
6920+
69186921
/**
69196922
* The provider that declares `model`, or `null` when none does. Resolves catalog entries and
69206923
* provider patterns without guessing a fallback provider.
@@ -6945,6 +6948,14 @@ export function findProviderFromModel(model: string): ProviderId | null {
69456948
}
69466949
}
69476950

6951+
/**
6952+
* Provider patterns are cloud model-name prefixes, and no cloud model id carries an Ollama
6953+
* `:tag`. Ollama lists every installed model with its tag (`gpt-oss:20b`, `mistral:latest`),
6954+
* so a tagged name a pattern would claim is a local model that only shares a prefix with a
6955+
* cloud family. The server never holds the installed list, so the name itself has to say so.
6956+
*/
6957+
if (OLLAMA_TAGGED_MODEL_NAME.test(normalizedModel)) return null
6958+
69486959
for (const [providerId, provider] of Object.entries(PROVIDER_DEFINITIONS)) {
69496960
if (provider.modelPatterns?.some((pattern) => pattern.test(normalizedModel))) {
69506961
return providerId as ProviderId
@@ -6995,17 +7006,8 @@ export function getModelCapabilities(modelId: string): ModelCapabilities | null
69957006
}
69967007
}
69977008

6998-
for (const provider of Object.values(PROVIDER_DEFINITIONS)) {
6999-
if (provider.modelPatterns) {
7000-
for (const pattern of provider.modelPatterns) {
7001-
if (pattern.test(modelId.toLowerCase())) {
7002-
return provider.capabilities || null
7003-
}
7004-
}
7005-
}
7006-
}
7007-
7008-
return null
7009+
const providerId = findProviderFromModel(modelId)
7010+
return providerId ? PROVIDER_DEFINITIONS[providerId]?.capabilities || null : null
70097011
}
70107012

70117013
export function getProvidersWithToolUsageControl(): string[] {

‎apps/sim/tools/llm/chat.test.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,18 @@ describe('llmChatTool.operation', () => {
3737
})
3838
).toThrow('sim-auto has no provider until the model router resolves it')
3939
})
40+
41+
it.each(['gpt-oss:20b', 'mistral:latest', 'claude-local:7b', 'gemini-tuned/chat:q4_k_m'])(
42+
'sends a locally installed Ollama model that shares a cloud prefix to Ollama: %s',
43+
(model) => {
44+
const input = llmChatTool.operation.input({
45+
model,
46+
systemPrompt: 'Translate to French',
47+
context: 'hello',
48+
}) as Record<string, unknown>
49+
50+
expect(input.provider).toBe('ollama')
51+
expect(input.model).toBe(model)
52+
}
53+
)
4054
})

0 commit comments

Comments
 (0)