Files
gpu-rent/tests/test_llm_runtime.py
T
Leonid Pershin 5832c5cf75 Enhance Ollama model management and performance tuning
- Updated the `provision_llm` function to utilize the `/api/tags` endpoint for verifying available models, improving accuracy in model management.
- Introduced a new `already_have_ollama_tag` function to ensure exact tag matching, preventing mismatches during model checks.
- Enhanced the `pull_stream` function to require a successful status from the API before proceeding, ensuring reliable model downloads.
- Added logic to handle unwritten blob files, improving the robustness of the model pulling process.
- Updated documentation and tests to reflect these changes, ensuring clarity and reliability in Ollama model operations.
2026-08-21 14:20:06 +03:00

71 lines
2.3 KiB
Python

from pathlib import Path
import pytest
from gpu_rent.llm_runtime import (
already_have_ollama_tag,
decide_runtime,
normalize_runtime,
parse_ollama_models,
write_ollama_models_preset,
)
def test_normalize_runtime():
assert normalize_runtime(None) == "none"
assert normalize_runtime("OLLAMA") == "ollama"
with pytest.raises(ValueError):
normalize_runtime("llamacpp")
with pytest.raises(ValueError):
normalize_runtime("foo")
def test_decide_runtime_flags_win():
assert (
decide_runtime(flag=None, ollama_flag=True, from_config="none") == "ollama"
)
assert (
decide_runtime(flag="ollama", ollama_flag=False, from_config="none") == "ollama"
)
assert decide_runtime(flag=None, ollama_flag=False, from_config="ollama") == "ollama"
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"
write_ollama_models_preset(path, "big")
assert parse_ollama_models(path)[0].name == "huihui_ai/qwen2.5-vl-abliterated:32b"
write_ollama_models_preset(path, "text")
assert parse_ollama_models(path)[0].name == "huihui_ai/qwen2.5-abliterate:7b"
def test_already_have_ollama_tag_exact_only():
have = {"qwen2.5:7b", "foo:latest"}
assert already_have_ollama_tag(have, "qwen2.5:7b")
assert not already_have_ollama_tag(have, "qwen2.5:3b")
assert already_have_ollama_tag(have, "foo")
assert already_have_ollama_tag(have, "foo:latest")