Skip to content

Commit b71aaac

Browse files
committed
improvement(models): share the ollama model-name rule between the resolver and the validator
1 parent 81c0086 commit b71aaac

3 files changed

Lines changed: 6 additions & 8 deletions

File tree

‎apps/sim/lib/workflows/editing/validation.ts‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import {
5151
isCustomModelId,
5252
isEvaluationModel,
5353
isKnownModelId,
54+
OLLAMA_MODEL_NAME,
5455
suggestModelIdsForUnknownModel,
5556
} from '@/providers/models'
5657
import { isPiByokOnlyMode } from '@/providers/pi-providers'
@@ -589,9 +590,6 @@ function isStoredFile(value: unknown): boolean {
589590
return isPlainRecord(value) && Boolean(value.name) && Boolean(value.path)
590591
}
591592

592-
/** An Ollama model name: `[namespace/]name[:tag]`, e.g. `llama3.1:8b` or `hf.co/org/model:Q4_K_M`. */
593-
const OLLAMA_MODEL_NAME = /^[\w.-]+(\/[\w.-]+)*(:[\w.-]+)?$/
594-
595593
/**
596594
* Validates a value against its expected subBlock type
597595
* Returns validation result with the value or an error

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ describe('custom cloud model routing', () => {
101101
})
102102

103103
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',
104+
it.each(['gpt-oss:20b', 'mistral:latest', 'GPT-OSS:120B', 'claude-local:7b'])(
105+
'leaves %s unclaimed, so it runs on Ollama with no cloud capabilities',
106106
(model) => {
107107
expect(findProviderFromModel(model)).toBeNull()
108108
expect(getProviderFromModel(model)).toBe('ollama')

‎apps/sim/providers/models.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6915,8 +6915,8 @@ 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.-]+$/
6918+
/** An Ollama model name, `[host/][namespace/]name[:tag]`: `llama3.1:8b`, `hf.co/org/model:Q4_K_M`. */
6919+
export const OLLAMA_MODEL_NAME = /^[\w.-]+(\/[\w.-]+)*(:[\w.-]+)?$/
69206920

69216921
/**
69226922
* The provider that declares `model`, or `null` when none does. Resolves catalog entries and
@@ -6954,7 +6954,7 @@ export function findProviderFromModel(model: string): ProviderId | null {
69546954
* so a tagged name a pattern would claim is a local model that only shares a prefix with a
69556955
* cloud family. The server never holds the installed list, so the name itself has to say so.
69566956
*/
6957-
if (OLLAMA_TAGGED_MODEL_NAME.test(normalizedModel)) return null
6957+
if (normalizedModel.includes(':') && OLLAMA_MODEL_NAME.test(normalizedModel)) return null
69586958

69596959
for (const [providerId, provider] of Object.entries(PROVIDER_DEFINITIONS)) {
69606960
if (provider.modelPatterns?.some((pattern) => pattern.test(normalizedModel))) {

0 commit comments

Comments
 (0)