Files
llm-in-text/backend/tests/test_llm.py
T

63 lines
1.6 KiB
Python
Raw Normal View History

import asyncio
import importlib
import sys
from pathlib import Path
import pytest
BACKEND_DIR = Path(__file__).resolve().parents[1]
if str(BACKEND_DIR) not in sys.path:
sys.path.insert(0, str(BACKEND_DIR))
try:
llm = importlib.import_module("llm")
except ModuleNotFoundError:
pytest.skip("llm module dependencies are not available", allow_module_level=True)
def test_call_ollama_messages_roles_with_system(monkeypatch):
captured = {}
async def fake_generate(**kwargs):
captured["kwargs"] = kwargs
return {"response": "ok"}
monkeypatch.setattr(llm.client, "generate", fake_generate)
result = asyncio.run(
llm.call_ollama(
"user prompt body",
system_prompt="system prompt body",
tag="test",
temperature=0.1,
)
)
assert result["content"] == "ok"
assert captured["kwargs"]["prompt"] == "system prompt body\n\nuser prompt body"
assert captured["kwargs"]["raw"] is True
def test_call_ollama_messages_roles_without_system(monkeypatch):
captured = {}
async def fake_generate(**kwargs):
captured["kwargs"] = kwargs
return {"response": "ok"}
monkeypatch.setattr(llm.client, "generate", fake_generate)
result = asyncio.run(
llm.call_ollama(
"user prompt only",
system_prompt="",
tag="test-no-system",
temperature=0.1,
)
)
assert result["content"] == "ok"
assert captured["kwargs"]["prompt"] == "user prompt only"
assert captured["kwargs"]["raw"] is True