agentic-humanitarian-data-analyst / tests /adapters /test_modal_chat_model.py
yannsay's picture
Deploy clean to build-small-hackathon org (32B Qwen, step-3 table)
aa1d0aa verified
Raw
History Blame Contribute Delete
1.42 kB
import pytest
def test_modal_chat_model_raises_without_env(monkeypatch):
monkeypatch.delenv("MODAL_INFERENCE_URL", raising=False)
monkeypatch.delenv("MODAL_API_KEY", raising=False)
from adapters.modal_chat_model import ModalChatModel
with pytest.raises(KeyError):
ModalChatModel()
def test_modal_chat_model_init_with_env(monkeypatch):
monkeypatch.setenv("MODAL_INFERENCE_URL", "https://example.modal.run")
monkeypatch.setenv("MODAL_API_KEY", "test-key")
monkeypatch.setenv("MODAL_MODEL_ID", "Qwen/Qwen2.5-32B-Instruct")
from adapters.modal_chat_model import ModalChatModel
model = ModalChatModel()
assert model is not None
# base_url and model id wired from env
assert model._llm.openai_api_base == "https://example.modal.run/v1"
assert model._llm.model_name == "Qwen/Qwen2.5-32B-Instruct"
def test_modal_chat_model_uses_temperature_zero(monkeypatch):
"""Determinism + primary truncation fix: structured calls must sample at temperature 0,
not the model's 0.6 default (which rambles to max_tokens → truncated JSON)."""
monkeypatch.setenv("MODAL_INFERENCE_URL", "https://example.modal.run")
monkeypatch.setenv("MODAL_API_KEY", "test-key")
monkeypatch.setenv("MODAL_MODEL_ID", "Qwen/Qwen2.5-32B-Instruct")
from adapters.modal_chat_model import ModalChatModel
model = ModalChatModel()
assert model._llm.temperature == 0