fix: prevent truncated Ollama answers
This commit is contained in:
@@ -155,11 +155,57 @@ def test_geo_assistant_sends_grounded_context_without_thinking_trace(monkeypatch
|
||||
assert captured["path"] == "/api/chat"
|
||||
assert captured["payload"]["stream"] is False
|
||||
assert captured["payload"]["think"] is False
|
||||
assert captured["payload"]["options"]["num_ctx"] == 16_384
|
||||
assert "Gebruik uitsluitend feiten en cijfers uit CONTEXT_JSON" in captured["payload"]["messages"][0]["content"]
|
||||
assert "scope.label is het exact geanalyseerde gebied" in captured["payload"]["messages"][0]["content"]
|
||||
assert "water_volume_available" in captured["payload"]["messages"][0]["content"]
|
||||
|
||||
|
||||
def test_geo_assistant_rejects_truncated_ollama_answer(monkeypatch) -> None:
|
||||
service = GeoAssistantService(ollama_settings())
|
||||
monkeypatch.setattr(service, "list_models", lambda: [AssistantModelRead(name="qwen3.5:9b")])
|
||||
monkeypatch.setattr(
|
||||
service,
|
||||
"_build_context",
|
||||
lambda *args, **kwargs: (
|
||||
{"scope": {"label": "Gemeente Mol"}},
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
"Gemeente Mol",
|
||||
),
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
service,
|
||||
"_request_json",
|
||||
lambda path, payload=None: {
|
||||
"done": True,
|
||||
"done_reason": "length",
|
||||
"message": {"role": "assistant", "content": "Een onvolledige zin"},
|
||||
},
|
||||
)
|
||||
|
||||
with pytest.raises(AppError) as exc_info:
|
||||
service.query(
|
||||
object(),
|
||||
project_id=uuid4(),
|
||||
payload=AssistantQueryRequest(question="Hoe evolueerde Mol?"),
|
||||
)
|
||||
|
||||
assert exc_info.value.code == "OLLAMA_RESPONSE_TRUNCATED"
|
||||
|
||||
|
||||
def test_unraid_ollama_context_window_is_configurable() -> None:
|
||||
compose = (ROOT / "docker-compose.unraid.yml").read_text(encoding="utf-8")
|
||||
template = (ROOT / "deploy/unraid/geointel-unraid-template.xml").read_text(encoding="utf-8")
|
||||
env_example = (ROOT / "deploy/unraid/geointel.env.example").read_text(encoding="utf-8")
|
||||
|
||||
assert "OLLAMA_CONTEXT_TOKENS: ${OLLAMA_CONTEXT_TOKENS:-16384}" in compose
|
||||
assert 'Target="OLLAMA_CONTEXT_TOKENS"' in template
|
||||
assert "OLLAMA_CONTEXT_TOKENS=16384" in env_example
|
||||
|
||||
|
||||
def test_temporal_comparison_preserves_all_compatible_semantic_metrics() -> None:
|
||||
earlier = {
|
||||
"metrics": [
|
||||
|
||||
Reference in New Issue
Block a user