94 lines
3.1 KiB
Rust
94 lines
3.1 KiB
Rust
use super::*;
|
|
use pretty_assertions::assert_eq;
|
|
|
|
#[test]
|
|
fn parses_llama_cpp_models_list_with_extras() {
|
|
let body = br#"{"object":"list","data":[{"id":"/opt/llm/models/Qwen.gguf","object":"model","owned_by":"llamacpp","meta":{"n_ctx_train":262144,"n_vocab":248320},"max_model_len":131072}],"models":[{"slug":"ignored"}]}"#;
|
|
assert_eq!(
|
|
parse_models_list(body),
|
|
Some(vec![LocalModelEntry {
|
|
id: "/opt/llm/models/Qwen.gguf".to_string(),
|
|
context_window: Some(131_072),
|
|
}])
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn prefers_runtime_n_ctx_and_ignores_training_context() {
|
|
let body = br#"{"data":[{"id":"a","meta":{"n_ctx":8192,"n_ctx_train":262144}},{"id":"b","meta":{"n_ctx_train":262144}}]}"#;
|
|
assert_eq!(
|
|
parse_models_list(body),
|
|
Some(vec![
|
|
LocalModelEntry {
|
|
id: "a".to_string(),
|
|
context_window: Some(8192),
|
|
},
|
|
LocalModelEntry {
|
|
id: "b".to_string(),
|
|
context_window: None,
|
|
},
|
|
])
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn parses_ollama_and_lm_studio_responses() {
|
|
// Ollama `/v1/models` (OpenAI format) and native `/api/tags` shapes.
|
|
let openai = br#"{"object":"list","data":[{"id":"qwen3:8b","object":"model","created":1,"owned_by":"library"}]}"#;
|
|
let tags = br#"{"models":[{"name":"qwen3:8b","model":"qwen3:8b","size":1}]}"#;
|
|
let expected = Some(vec![LocalModelEntry {
|
|
id: "qwen3:8b".to_string(),
|
|
context_window: None,
|
|
}]);
|
|
assert_eq!(parse_models_list(openai), expected);
|
|
assert_eq!(parse_models_list(tags), expected);
|
|
// LM Studio reports max_context_length on its richer listing.
|
|
let lmstudio = br#"{"data":[{"id":"qwen2.5-7b","object":"model","max_context_length":32768},{"id":"qwen2.5-7b"},{"id":""}]}"#;
|
|
assert_eq!(
|
|
parse_models_list(lmstudio),
|
|
Some(vec![LocalModelEntry {
|
|
id: "qwen2.5-7b".to_string(),
|
|
context_window: Some(32_768),
|
|
}])
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn rejects_unrecognized_bodies() {
|
|
assert_eq!(parse_models_list(b"not json"), None);
|
|
assert_eq!(parse_models_list(br#"{"object":"list"}"#), None);
|
|
}
|
|
|
|
#[test]
|
|
fn parses_llama_cpp_props_context() {
|
|
assert_eq!(
|
|
parse_props_context_window(
|
|
br#"{"default_generation_settings":{"n_ctx":131072},"n_ctx":4096}"#
|
|
),
|
|
Some(131_072)
|
|
);
|
|
assert_eq!(parse_props_context_window(br#"{"n_ctx":4096}"#), Some(4096));
|
|
assert_eq!(parse_props_context_window(br#"{"n_ctx":0}"#), None);
|
|
}
|
|
|
|
#[test]
|
|
fn single_model_servers_share_their_context_with_aliases() {
|
|
let one = vec![LocalModelEntry {
|
|
id: "/opt/llm/models/Qwen.gguf".to_string(),
|
|
context_window: Some(131_072),
|
|
}];
|
|
assert_eq!(context_window_for("qwen3.6-35b-a3b", &one), Some(131_072));
|
|
let two = vec![
|
|
LocalModelEntry {
|
|
id: "a".to_string(),
|
|
context_window: Some(1),
|
|
},
|
|
LocalModelEntry {
|
|
id: "b".to_string(),
|
|
context_window: Some(2),
|
|
},
|
|
];
|
|
assert_eq!(context_window_for("b", &two), Some(2));
|
|
assert_eq!(context_window_for("c", &two), None);
|
|
}
|