Skip to content

Craft Anything: understand how any software works, and craft your own.

Rust

Handle generic GGUF paths and numeric task versions in chat discovery (#675)

Afloat75bf5a3f0df2
diff --git a/crates/ai/src/detect.rs b/crates/ai/src/detect.rs
index d5b65af9..b5875715 100644
--- a/crates/ai/src/detect.rs
+++ b/crates/ai/src/detect.rs
@@ -74,9 +74,15 @@ const NOT_CHAT: &[&str] = &["embed", "embedding", "embeddings", "embeddinggemma"
/// The first model a server lists that can chat. A specialised model isn't a chat fallback.
pub(crate) fn chat_model(models: &[String]) -> Option<String> {
+ let specialised =
+ |name: &str| name.split(|c: char| !c.is_ascii_alphanumeric()).any(|token| NOT_CHAT.contains(&token.trim_end_matches(|c: char| c.is_ascii_digit())));
let chats = |m: &&String| {
- let name = m.rsplit('/').next().unwrap_or(m).to_ascii_lowercase();
- !name.split(|c: char| !c.is_ascii_alphanumeric()).any(|token| NOT_CHAT.contains(&token))
+ let lower = m.to_ascii_lowercase();
+ let (directory, name) = lower.rsplit_once(['/', '\\']).unwrap_or(("", lower.as_str()));
+ // A generic GGUF filename needs its model directory; arbitrary ancestors do not identify it.
+ let generic_gguf = name == "model.gguf" || name == "ggml-model.gguf" || (name.starts_with("ggml-model-") && name.ends_with(".gguf"));
+ let model_directory = directory.rsplit(['/', '\\']).next().unwrap_or_default();
+ !(specialised(name) || generic_gguf && specialised(model_directory))
};
models.iter().find(chats).cloned()
}
@@ -282,6 +288,9 @@ fn remote_agents(host: String) -> Vec<Detected> {
.collect()
}
+#[cfg(test)]
+mod model_id_tests;
+
#[cfg(test)]
mod tests {
use super::*;
diff --git a/crates/ai/src/detect/model_id_tests.rs b/crates/ai/src/detect/model_id_tests.rs
new file mode 100644
index 00000000..15806ba5
--- /dev/null
+++ b/crates/ai/src/detect/model_id_tests.rs
@@ -0,0 +1,57 @@
+use super::{chat_model, probe_local};
+
+#[test]
+fn gguf_paths_keep_specialised_model_directories() {
+ for model in [
+ "bge-small/ggml-model-f16.gguf",
+ "bge-small/ggml-model.gguf",
+ "bge-small/model.gguf",
+ "models/bert-bge-small/ggml-model-f16.GGUF",
+ r"models\bge-small\ggml-model-f16.gguf",
+ ] {
+ assert!(chat_model(&[model.into()]).is_none(), "{model}");
+ }
+}
+
+#[test]
+fn numeric_task_versions_are_not_chat_models() {
+ for model in ["snowflake-arctic-embed2:latest", "vendor/embedding3", "vendor/rerank12", "XTTS2", "vendor/whisper3"] {
+ assert!(chat_model(&[model.into()]).is_none(), "{model}");
+ }
+}
+
+#[test]
+fn publishers_and_non_task_words_still_chat() {
+ for model in [
+ "matts/llama-3-instruct",
+ "embedding-author/qwen-2.5-instruct",
+ "embed2/qwen-3",
+ "whisper/gemma-3",
+ "embedded-chat",
+ "vendor/embedded2-chat",
+ "vendor/embed2publisher-chat",
+ "vendor/embed2text-chat",
+ "vendor/bge2x-chat",
+ "models/matts/llama-3.gguf",
+ "models/embedded-chat/ggml-model-f16.gguf",
+ "/profiles/whisper/models/qwen3.gguf",
+ "models/embedding/qwen3.gguf",
+ ] {
+ assert_eq!(chat_model(&[model.into()]).as_deref(), Some(model), "{model}");
+ }
+}
+
+#[test]
+fn discovery_skips_specialised_paths_and_versions_before_chat() {
+ let url = crate::tests::serve(
+ "200 OK",
+ r#"{"object":"list","data":[{"id":"bge-small/ggml-model-f16.gguf"},{"id":"snowflake-arctic-embed2:latest"},{"id":"matts/llama-3-instruct"}]}"#,
+ );
+ assert_eq!(probe_local("Local", &url).unwrap().suggestion.model, "matts/llama-3-instruct");
+}
+
+#[test]
+fn discovery_does_not_offer_a_specialised_path_or_version_only_server() {
+ let url = crate::tests::serve("200 OK", r#"{"object":"list","data":[{"id":"snowflake-arctic-embed2:latest"},{"id":"bge-small/ggml-model-f16.gguf"}]}"#);
+ assert!(probe_local("Local", &url).is_none());
+}
diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md
index 5ee13baa..49c1c37c 100644
--- a/docs/ROADMAP.md
+++ b/docs/ROADMAP.md
@@ -248,6 +248,8 @@ been run live.
Windows, macOS and Linux (`LM_STUDIO_SETTINGS` is from memory of its folders, not verified)
- [ ] See why Bionic or LM Studio can't be picked (#140)
- [x] Do not select an embedding, ranking or transcription model as a chat backend when a local server has no chat models — claimed: Afloat16, branch bugfix/r5.4-nonchat-model-detection-20261103
+- [x] Recognize specialised model file paths and numeric task-name versions during local chat setup
+ — claimed: Afloat16, branch bugfix/r5.4-model-task-identifiers-20261103
### R5.5 API-key builds fail in words people can use
Owner: open · Status: todo
diff --git a/docs/STATUS.md b/docs/STATUS.md
index 90d20849..08dc7470 100644
--- a/docs/STATUS.md
+++ b/docs/STATUS.md
@@ -304,3 +304,12 @@ If the turn fails or is cancelled after consuming a note, its reset is saved bef
so reopening keeps the new request's full allowance. The original failure or cancellation remains
the result; a reset that cannot be saved is reported separately and never overwrites a broken
or newer record. Scripted turns cover both outcomes, blank notes and unreadable records.
+
+## Local model identifier task hints
+
+Automatic local setup recognizes numeric suffixes on known embedding, reranking and speech task
+tokens. Generic GGUF filenames (`ggml-model-*.gguf`, `ggml-model.gguf` and `model.gguf`) also keep
+their immediate model directory as a task hint, with either path separator. Named model files,
+publisher prefixes and unrelated words are not classified by arbitrary ancestor directories.
+Regression tests cover mixed model lists and servers listing only specialised models through
+the local discovery API. Classification remains a name heuristic; it does not probe model capabilities.