Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions apps/sim/lib/workflows/editing/validation-models.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,15 @@ describe('model ids no provider declares', () => {
expect(errors[0]?.error).toContain('Unknown model id')
})

it.each(['gpt-oss:20b', 'mistral:latest'])(
'accepts %s, an installed Ollama model sharing a cloud prefix, where it runs on Ollama',
(model) => {
expect(validateModel('router_v2', model)).toEqual({ errors: [], model })
setEnvFlags({ isHosted: true })
expect(validateModel('router_v2', model).errors[0]?.error).toContain('Unknown model id')
}
)

it.each(['hhao/qwen2.5-coder-tools', 'hf.co/bartowski/Llama-3.2-1B-Instruct-GGUF:Q4_K_M'])(
'accepts a namespaced Ollama library name such as %s',
(model) => {
Expand Down
4 changes: 1 addition & 3 deletions apps/sim/lib/workflows/editing/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import {
isCustomModelId,
isEvaluationModel,
isKnownModelId,
OLLAMA_MODEL_NAME,
suggestModelIdsForUnknownModel,
} from '@/providers/models'
import { isPiByokOnlyMode } from '@/providers/pi-providers'
Expand Down Expand Up @@ -589,9 +590,6 @@ function isStoredFile(value: unknown): boolean {
return isPlainRecord(value) && Boolean(value.name) && Boolean(value.path)
}

/** An Ollama model name: `[namespace/]name[:tag]`, e.g. `llama3.1:8b` or `hf.co/org/model:Q4_K_M`. */
const OLLAMA_MODEL_NAME = /^[\w.-]+(\/[\w.-]+)*(:[\w.-]+)?$/

/**
* Validates a value against its expected subBlock type
* Returns validation result with the value or an error
Expand Down
24 changes: 24 additions & 0 deletions apps/sim/providers/models.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import {
findProviderFromModel,
getBaseModelProviders,
getHostedModels,
getModelCapabilities,
getModelPricing,
getProviderFromModel,
getProviderModels,
getStaticProviderModels,
isCustomModelId,
Expand Down Expand Up @@ -98,6 +100,28 @@ describe('custom cloud model routing', () => {
})
})

describe('tagged Ollama model names that share a cloud prefix', () => {
it.each(['gpt-oss:20b', 'mistral:latest', 'GPT-OSS:120B', 'claude-local:7b'])(
'leaves %s unclaimed, so it runs on Ollama with no cloud capabilities',
(model) => {
expect(findProviderFromModel(model)).toBeNull()
expect(getProviderFromModel(model)).toBe('ollama')
expect(getModelCapabilities(model)).toBeNull()
}
)

it('still resolves untagged cloud ids, namespaced tags, and catalog ids by their provider', () => {
expect(findProviderFromModel('gpt-oss-custom')).toBe('openai')
expect(findProviderFromModel('mistral-large-latest')).toBe('mistral')
expect(findProviderFromModel('ollama/gpt-oss:20b')).toBe('ollama')
expect(findProviderFromModel('openrouter/org/model:free')).toBe('openrouter')
expect(findProviderFromModel('bedrock/amazon.nova-lite-v1:0')).toBe('bedrock')
expect(getModelCapabilities('ollama/gpt-oss:20b')).toEqual(
PROVIDER_DEFINITIONS.ollama.capabilities
)
})
})

describe('catalog featured model metadata', () => {
it('defines at most one active featured model per provider', () => {
for (const provider of Object.values(PROVIDER_DEFINITIONS)) {
Expand Down
24 changes: 13 additions & 11 deletions apps/sim/providers/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6915,6 +6915,9 @@ export function getBaseModelProviders(): Record<string, ProviderId> {
)
}

/** An Ollama model name, `[host/][namespace/]name[:tag]`: `llama3.1:8b`, `hf.co/org/model:Q4_K_M`. */
export const OLLAMA_MODEL_NAME = /^[\w.-]+(\/[\w.-]+)*(:[\w.-]+)?$/

/**
* The provider that declares `model`, or `null` when none does. Resolves catalog entries and
* provider patterns without guessing a fallback provider.
Expand Down Expand Up @@ -6945,6 +6948,14 @@ export function findProviderFromModel(model: string): ProviderId | null {
}
}

/**
* Provider patterns are cloud model-name prefixes, and no cloud model id carries an Ollama
* `:tag`. Ollama lists every installed model with its tag (`gpt-oss:20b`, `mistral:latest`),
* so a tagged name a pattern would claim is a local model that only shares a prefix with a
* cloud family. The server never holds the installed list, so the name itself has to say so.
*/
if (normalizedModel.includes(':') && OLLAMA_MODEL_NAME.test(normalizedModel)) return null

for (const [providerId, provider] of Object.entries(PROVIDER_DEFINITIONS)) {
if (provider.modelPatterns?.some((pattern) => pattern.test(normalizedModel))) {
return providerId as ProviderId
Expand Down Expand Up @@ -6995,17 +7006,8 @@ export function getModelCapabilities(modelId: string): ModelCapabilities | null
}
}

for (const provider of Object.values(PROVIDER_DEFINITIONS)) {
if (provider.modelPatterns) {
for (const pattern of provider.modelPatterns) {
if (pattern.test(modelId.toLowerCase())) {
return provider.capabilities || null
}
}
}
}

return null
const providerId = findProviderFromModel(modelId)
return providerId ? PROVIDER_DEFINITIONS[providerId]?.capabilities || null : null
}

export function getProvidersWithToolUsageControl(): string[] {
Expand Down
14 changes: 14 additions & 0 deletions apps/sim/tools/llm/chat.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,18 @@ describe('llmChatTool.operation', () => {
})
).toThrow('sim-auto has no provider until the model router resolves it')
})

it.each(['gpt-oss:20b', 'mistral:latest', 'claude-local:7b', 'gemini-tuned/chat:q4_k_m'])(
'sends a locally installed Ollama model that shares a cloud prefix to Ollama: %s',
(model) => {
const input = llmChatTool.operation.input({
model,
systemPrompt: 'Translate to French',
context: 'hello',
}) as Record<string, unknown>

expect(input.provider).toBe('ollama')
expect(input.model).toBe(model)
}
)
})
Loading