AI providers: correlation decision and transcript correction move to OpenAI gpt-4o-mini
One funded account (OpenAI) now covers extraction, embeddings, summaries, the ambiguous-scene correlation call and transcript correction; Groq stays optional for STT. New app/internal/llm.py picks the provider from the model name, so setting either model back to a gemini-* ID needs no code change. Usage accounting for replay runs now covers both providers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
3e9ca4be06
commit
0060ccde75
@@ -164,7 +164,7 @@ async def test_gemini_timeout_in_decide_falls_back_to_rules():
|
||||
def hang(model, prompt):
|
||||
raise httpx.ReadTimeout("The read operation timed out")
|
||||
|
||||
with patch.object(settings, "gemini_api_key", "test-key"), \
|
||||
with patch.object(settings, "openai_api_key", "test-key"), \
|
||||
patch.object(llm_correlator, "_build_decide_prompt", lambda ctx, cands: "p"), \
|
||||
patch.object(llm_correlator, "_sync_gemini", hang):
|
||||
assert await llm_correlator.decide("c1", _corr_ctx()) is None # None == keep the rules decision
|
||||
@@ -179,7 +179,7 @@ async def test_gemini_timeout_in_transcript_correction_keeps_raw_text():
|
||||
raise httpx.ReadTimeout("The read operation timed out")
|
||||
|
||||
text = "engine 5 respond to a structure fire at 12 main street smoke showing"
|
||||
with patch.object(settings, "gemini_api_key", "test-key"), \
|
||||
with patch.object(settings, "openai_api_key", "test-key"), \
|
||||
patch.object(transcript_correction, "resolve_context", AsyncMock(return_value={})), \
|
||||
patch.object(transcript_correction, "_sync_gemini", hang):
|
||||
assert await transcript_correction.correct("c1", text) == (None, None, False)
|
||||
|
||||
@@ -34,12 +34,13 @@ def test_minimal_thinking_by_default_and_usage_lands_in_the_sink():
|
||||
models = _FakeModels()
|
||||
a, b = _patched(models)
|
||||
sink = {}
|
||||
tok = gemini.collect_usage(sink)
|
||||
from app.internal import llm
|
||||
tok = llm.collect_usage(sink)
|
||||
try:
|
||||
with a, b:
|
||||
assert gemini.generate_json("m1", "p", purpose="correlation") == {"action": "link"}
|
||||
finally:
|
||||
gemini.reset_usage(tok)
|
||||
llm.reset_usage(tok)
|
||||
assert models.configs == [{"thinking_level": "minimal"}]
|
||||
assert sink == {"correlation:m1": {"calls": 1, "in": 1200, "out": 30, "thinking": 0}}
|
||||
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
"""app/internal/llm.py: provider follows the model name (2026-11-08 consolidation)."""
|
||||
from types import SimpleNamespace
|
||||
from unittest.mock import patch
|
||||
|
||||
from app.config import settings
|
||||
from app.internal import llm
|
||||
|
||||
|
||||
def test_provider_follows_model_name():
|
||||
assert llm.provider_for("gpt-4o-mini") == "openai"
|
||||
assert llm.provider_for("gemini-3.6-flash") == "gemini"
|
||||
|
||||
|
||||
def test_available_checks_the_right_key():
|
||||
with patch.object(settings, "openai_api_key", "k"), patch.object(settings, "gemini_api_key", None):
|
||||
assert llm.available("gpt-4o-mini") and not llm.available("gemini-3.6-flash")
|
||||
|
||||
|
||||
def test_defaults_are_openai():
|
||||
assert llm.provider_for(settings.corr_cheap_model) == "openai"
|
||||
assert llm.provider_for(settings.transcript_correction_model) == "openai"
|
||||
|
||||
|
||||
def test_openai_path_parses_json_and_records_usage():
|
||||
resp = SimpleNamespace(
|
||||
choices=[SimpleNamespace(message=SimpleNamespace(content='{"action": "new"}'))],
|
||||
usage=SimpleNamespace(prompt_tokens=120, completion_tokens=9),
|
||||
)
|
||||
calls = {}
|
||||
|
||||
class FakeClient:
|
||||
def __init__(self):
|
||||
self.chat = SimpleNamespace(completions=SimpleNamespace(create=self.create))
|
||||
|
||||
def create(self, **kw):
|
||||
calls.update(kw)
|
||||
return resp
|
||||
|
||||
sink = {}
|
||||
tok = llm.collect_usage(sink)
|
||||
try:
|
||||
with patch("app.internal.ai_clients.openai_client", FakeClient):
|
||||
out = llm.generate_json("gpt-4o-mini", "Return JSON", purpose="correlation")
|
||||
finally:
|
||||
llm.reset_usage(tok)
|
||||
assert out == {"action": "new"}
|
||||
assert calls["response_format"] == {"type": "json_object"}
|
||||
assert sink["correlation:gpt-4o-mini"] == {"calls": 1, "in": 120, "out": 9, "thinking": 0}
|
||||
@@ -57,7 +57,7 @@ def _api_key():
|
||||
The dev venv has no GEMINI_API_KEY, and correct() returns early without one
|
||||
— which would make every assertion below pass for the wrong reason.
|
||||
"""
|
||||
with patch.object(tc.settings, "gemini_api_key", "test-key"):
|
||||
with patch.object(tc.settings, "openai_api_key", "test-key"):
|
||||
yield
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user