- Revised model URLs and descriptions in `llamacpp-models.example.yaml` and `ollama-models.example.yaml` to reflect new recommendations and vision capabilities. - Updated the LLM runtime logic to support vision projectors and improved model resolution handling. - Enhanced the installation script to conditionally include vision projectors when available. - Added tests to validate the inclusion of vision projectors in model presets and ensure proper URL remapping for deprecated models. - Improved documentation to clarify model usage and configuration options.
89 lines
2.9 KiB
Python
89 lines
2.9 KiB
Python
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from gpu_rent.llm_runtime import (
|
|
decide_runtime,
|
|
normalize_runtime,
|
|
parse_llamacpp_models,
|
|
parse_ollama_models,
|
|
remap_llamacpp_url,
|
|
write_ollama_models_preset,
|
|
)
|
|
|
|
|
|
def test_normalize_runtime():
|
|
assert normalize_runtime(None) == "none"
|
|
assert normalize_runtime("OLLAMA") == "ollama"
|
|
assert normalize_runtime("llama-cpp") == "llamacpp"
|
|
with pytest.raises(ValueError):
|
|
normalize_runtime("foo")
|
|
|
|
|
|
def test_decide_runtime_flags_win():
|
|
assert (
|
|
decide_runtime(flag=None, ollama_flag=True, llamacpp_flag=False, from_config="none")
|
|
== "ollama"
|
|
)
|
|
assert (
|
|
decide_runtime(flag="llamacpp", ollama_flag=False, llamacpp_flag=False, from_config="ollama")
|
|
== "llamacpp"
|
|
)
|
|
with pytest.raises(ValueError):
|
|
decide_runtime(flag=None, ollama_flag=True, llamacpp_flag=True, from_config="none")
|
|
|
|
|
|
def test_parse_ollama_models(tmp_path: Path):
|
|
path = tmp_path / "m.yaml"
|
|
path.write_text(
|
|
"models:\n - name: huihui_ai/qwen2.5-abliterate:7b\n default: true\n - qwen2.5:3b\n",
|
|
encoding="utf-8",
|
|
)
|
|
entries = parse_ollama_models(path)
|
|
assert [e.name for e in entries] == [
|
|
"huihui_ai/qwen2.5-abliterate:7b",
|
|
"qwen2.5:3b",
|
|
]
|
|
assert entries[0].default is True
|
|
|
|
|
|
def test_parse_empty_manifest(tmp_path: Path):
|
|
path = tmp_path / "empty.yaml"
|
|
path.write_text("models: []\n", encoding="utf-8")
|
|
assert parse_ollama_models(path) == []
|
|
assert parse_ollama_models(tmp_path / "missing.yaml") == []
|
|
|
|
|
|
def test_write_preset(tmp_path: Path):
|
|
path = tmp_path / "out.yaml"
|
|
write_ollama_models_preset(path, "recommended")
|
|
entries = parse_ollama_models(path)
|
|
assert entries[0].name == "huihui_ai/qwen2.5-vl-abliterated:7b"
|
|
|
|
|
|
def test_write_llamacpp_preset_includes_mmproj(tmp_path: Path):
|
|
from gpu_rent.llm_runtime import write_llamacpp_models_preset
|
|
|
|
path = tmp_path / "lc.yaml"
|
|
write_llamacpp_models_preset(path, "recommended")
|
|
entries = parse_llamacpp_models(path)
|
|
assert len(entries) == 1
|
|
assert "VL" in entries[0].url or "vl" in entries[0].url.lower()
|
|
assert entries[0].mmproj_url
|
|
assert "mmproj" in entries[0].mmproj_url
|
|
|
|
|
|
def test_remap_dead_bartowski_abliterate_url(tmp_path: Path):
|
|
dead = (
|
|
"https://huggingface.co/bartowski/huihui-ai_Qwen2.5-7B-Instruct-abliterated-GGUF/"
|
|
"resolve/main/huihui-ai_Qwen2.5-7B-Instruct-abliterated-Q4_K_M.gguf"
|
|
)
|
|
fixed = remap_llamacpp_url(dead)
|
|
assert "RichardErkhov" in fixed
|
|
assert "Q4_K_M.gguf" in fixed
|
|
path = tmp_path / "lc.yaml"
|
|
path.write_text(f"models:\n - url: {dead}\n default: true\n", encoding="utf-8")
|
|
entries = parse_llamacpp_models(path)
|
|
assert len(entries) == 1
|
|
assert entries[0].url == fixed
|