askme-public/tests/test_gpu.py
Lukasz Boryn 0e0bae4b9b feat: initial public release of askme
* local question answering over analysis notebooks with LightRAG, Neo4j, Qdrant and Ollama
* RAGAS evaluation with a generator x judge comparison matrix, fully local
* docs in README and OKF
2026-11-03 17:50:52 +01:00

40 lines
1.4 KiB
Python

"""Tests for src/askme/gpu.py."""
from __future__ import annotations
import asyncio
from unittest.mock import AsyncMock, patch
from askme.gpu import unload_llamacpp_model, unload_ollama_model
def test_unload_requests_zero_keep_alive():
"""
Scenario: free the GPU between eval phases
Given a model resident in Ollama
When unload_ollama_model("qwen2.5:7b") runs
Then Ollama is asked to generate with keep_alive=0 against settings.ollama_host
(Ollama's documented way to evict a model immediately)
"""
client = AsyncMock()
with patch("askme.gpu.ollama.AsyncClient", return_value=client) as ctor:
asyncio.run(unload_ollama_model("qwen2.5:7b"))
ctor.assert_called_once_with(host="http://localhost:11434")
client.generate.assert_awaited_once_with(model="qwen2.5:7b", keep_alive=0)
def test_unload_llamacpp_posts_to_router():
"""
Scenario: free the GPU held by the llama.cpp router
Given a model resident in the router
When unload_llamacpp_model("gemma-4-12b-qat") runs
Then POST <llamacpp_url>/models/unload is sent with that model id
"""
client = AsyncMock()
client.__aenter__.return_value = client
with patch("askme.gpu.httpx.AsyncClient", return_value=client):
asyncio.run(unload_llamacpp_model("gemma-4-12b-qat"))
client.post.assert_awaited_once_with(
"http://localhost:8080/models/unload", json={"model": "gemma-4-12b-qat"}
)