Skip to content

The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.

fix(engine): the model id stays the string the picker holds

purpledfc73e79646f
diff --git a/src-tauri/src/commands/proxy.rs b/src-tauri/src/commands/proxy.rs
index 560fb42e..0f9af017 100644
--- a/src-tauri/src/commands/proxy.rs
+++ b/src-tauri/src/commands/proxy.rs
@@ -446,15 +446,16 @@ pub(crate) fn builtin_model_name_from_path(path: &str) -> String {
}
}
-/// The bare model id behind a picker id (`openai::name` becomes `name`), with
-/// a trailing `.gguf` dropped. Twin of `bareBuiltinModelName`.
+/// The bare model id behind a picker id (`openai::name` becomes `name`).
+/// Twin of `bareBuiltinModelName`, and it strips nothing else for the same
+/// reason: the id is the name the user reads back in the refusal.
fn bare_model_name(name: &str) -> &str {
let trimmed = name.trim();
let parts: Vec<&str> = trimmed.split("::").collect();
- let bare = if parts.len() == 2 { parts[1] } else { trimmed };
- match bare.len().checked_sub(5) {
- Some(cut) if bare[cut..].eq_ignore_ascii_case(".gguf") => &bare[..cut],
- _ => bare,
+ if parts.len() == 2 {
+ parts[1]
+ } else {
+ trimmed
}
}
@@ -512,7 +513,9 @@ pub(crate) fn builtin_model_conflict(
return None;
}
let asked_raw = requested_model(body)?;
- let asked = bare_model_name(&asked_raw);
+ // Through the same normaliser as the loaded path, so a request naming
+ // "model.gguf" is compared against "model" and not refused for nothing.
+ let asked = builtin_model_name_from_path(bare_model_name(&asked_raw));
if asked.is_empty() || asked == loaded {
return None;
}
diff --git a/src/lib/__tests__/builtin-model-identity.test.ts b/src/lib/__tests__/builtin-model-identity.test.ts
index 8be3c89c..72e1c9ee 100644
--- a/src/lib/__tests__/builtin-model-identity.test.ts
+++ b/src/lib/__tests__/builtin-model-identity.test.ts
@@ -49,10 +49,17 @@ describe('builtinModelNameFromPath', () => {
})
describe('bareBuiltinModelName', () => {
- it('strips the provider prefix and a trailing extension', () => {
+ it('strips the provider prefix and nothing else', () => {
expect(bareBuiltinModelName('openai::qwen2.5-0.5b')).toBe('qwen2.5-0.5b')
expect(bareBuiltinModelName('qwen2.5-0.5b')).toBe('qwen2.5-0.5b')
- expect(bareBuiltinModelName('openai::qwen2.5-0.5b.gguf')).toBe('qwen2.5-0.5b')
+ })
+
+ // Negative control: this id is a lookup key against list_bundled_models and
+ // the name in a user facing error, so it must come back verbatim. Trimming
+ // an extension here would look up the wrong entry and rename the model in
+ // the message.
+ it('leaves a name that carries the file extension intact', () => {
+ expect(bareBuiltinModelName('openai::qwen2.5-0.5b.gguf')).toBe('qwen2.5-0.5b.gguf')
})
it('leaves a name with more than one separator alone, as the registry does', () => {
@@ -66,9 +73,10 @@ describe('bareBuiltinModelName', () => {
})
describe('builtinModelMatches', () => {
- it('is true for the same model, prefixed or not', () => {
+ it('is true for the same model, prefixed or not, extension or not', () => {
expect(builtinModelMatches('/m/qwen2.5-0.5b.gguf', 'qwen2.5-0.5b')).toBe(true)
expect(builtinModelMatches('/m/qwen2.5-0.5b.gguf', 'openai::qwen2.5-0.5b')).toBe(true)
+ expect(builtinModelMatches('/m/qwen2.5-0.5b.gguf', 'openai::qwen2.5-0.5b.gguf')).toBe(true)
})
it('is FALSE for the case the counter-check measured on the box', () => {
diff --git a/src/lib/builtin-model-identity.ts b/src/lib/builtin-model-identity.ts
index 7c4bcba7..145767a2 100644
--- a/src/lib/builtin-model-identity.ts
+++ b/src/lib/builtin-model-identity.ts
@@ -43,14 +43,18 @@ export function builtinModelNameFromPath(modelPath: string | null | undefined):
/**
* The bare model id behind a picker id: `openai::qwen2.5-0.5b` and
- * `qwen2.5-0.5b` both answer `qwen2.5-0.5b`. A trailing `.gguf` is dropped so
- * a caller that passes the file name still lines up with the listing.
+ * `qwen2.5-0.5b` both answer `qwen2.5-0.5b`.
+ *
+ * Nothing else is touched. This id is a LOOKUP KEY: it is matched against the
+ * `name` of a `list_bundled_models` entry and it names the model in an error
+ * the user reads, so it has to stay the string the picker holds. Tolerance for
+ * a name that carries the file extension belongs in the comparison below, not
+ * here.
*/
export function bareBuiltinModelName(nameOrPrefixed: string | null | undefined): string {
const raw = (nameOrPrefixed ?? '').trim()
const parts = raw.split('::')
- const bare = parts.length === 2 ? parts[1] : raw
- return bare.replace(/\.gguf$/i, '')
+ return parts.length === 2 ? parts[1] : raw
}
/**
@@ -67,7 +71,9 @@ export function builtinModelMatches(
requested: string | null | undefined,
): boolean {
const loaded = builtinModelNameFromPath(loadedPath)
- const want = bareBuiltinModelName(requested)
+ // The requested name goes through the same normaliser, so a caller that
+ // passes "model.gguf" is compared against "model" and not called a mismatch.
+ const want = builtinModelNameFromPath(bareBuiltinModelName(requested))
if (!loaded || !want) return true
return loaded === want
}