| """Configurable inference seam (server/model.py) — env-selected, network-free."""
|
| from server import model
|
|
|
|
|
| def _fake_resp(content):
|
| class R:
|
| def raise_for_status(self):
|
| pass
|
|
|
| def json(self):
|
| return {"choices": [{"message": {"content": content}}], "usage": {}}
|
|
|
| return R()
|
|
|
|
|
| def test_remote_branch_used_when_base_url_set(monkeypatch):
|
| monkeypatch.setattr(model, "INFERENCE_BASE_URL", "http://localhost:9/v1")
|
|
|
| monkeypatch.setattr(model, "get_llm", lambda: (_ for _ in ()).throw(AssertionError("local used")))
|
|
|
| calls = {}
|
|
|
| def fake_post(url, json, headers, timeout):
|
| calls["url"] = url
|
| calls["body"] = json
|
| return _fake_resp('{"events": []}')
|
|
|
| monkeypatch.setattr("requests.post", fake_post)
|
|
|
| out = model.complete_json([{"role": "user", "content": "hi"}], {"type": "object"})
|
| assert out == '{"events": []}'
|
| assert calls["url"].endswith("/chat/completions")
|
| assert calls["body"]["response_format"]["type"] == "json_schema"
|
|
|
|
|
| def test_local_branch_when_base_url_unset(monkeypatch):
|
| monkeypatch.setattr(model, "INFERENCE_BASE_URL", "")
|
|
|
| def no_network(*a, **k):
|
| raise AssertionError("remote must not be called when INFERENCE_BASE_URL is unset")
|
|
|
| monkeypatch.setattr("requests.post", no_network)
|
|
|
| class FakeLLM:
|
| def create_chat_completion(self, **kw):
|
| return {"choices": [{"message": {"content": "{}"}}], "usage": {}}
|
|
|
| monkeypatch.setattr(model, "get_llm", lambda: FakeLLM())
|
| assert model.complete_json([{"role": "user", "content": "hi"}], {"type": "object"}) == "{}"
|
|
|