fix(llm): resolve score runtime config from saved profiles
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -98,3 +98,52 @@ def test_get_nonexistent(tmp_path):
|
||||
def test_delete_nonexistent(tmp_path):
|
||||
mgr = _make_manager(tmp_path)
|
||||
assert mgr.delete("does-not-exist") is False
|
||||
|
||||
|
||||
def test_resolve_openai_client_kwargs_prefers_matching_profile(tmp_path, monkeypatch):
|
||||
"""Metric runtime should prefer the saved LLM Profile over .env defaults."""
|
||||
from rag_eval.metrics.factory import _resolve_openai_client_kwargs
|
||||
from rag_eval.settings import EvaluationSettings
|
||||
import webapp.services.profile_manager as pm_mod
|
||||
|
||||
mgr = _make_manager(tmp_path)
|
||||
mgr.create(
|
||||
name="Judge",
|
||||
model="gpt-5.5",
|
||||
base_url="http://39.107.88.131:13000",
|
||||
api_key="sk-profile",
|
||||
timeout_seconds=300,
|
||||
)
|
||||
monkeypatch.setattr(pm_mod, "profile_manager", mgr)
|
||||
|
||||
settings = EvaluationSettings(
|
||||
OPENAI_API_KEY="sk-env",
|
||||
OPENAI_BASE_URL="http://env-base/v1",
|
||||
OPENAI_TIMEOUT_SECONDS=30,
|
||||
)
|
||||
|
||||
kwargs = _resolve_openai_client_kwargs("gpt-5.5", settings)
|
||||
assert kwargs["api_key"] == "sk-profile"
|
||||
assert kwargs["base_url"] == "http://39.107.88.131:13000"
|
||||
assert kwargs["timeout"] == 300.0
|
||||
|
||||
|
||||
def test_resolve_openai_client_kwargs_falls_back_to_env(tmp_path, monkeypatch):
|
||||
"""When no saved profile matches, .env settings remain the fallback."""
|
||||
from rag_eval.metrics.factory import _resolve_openai_client_kwargs
|
||||
from rag_eval.settings import EvaluationSettings
|
||||
import webapp.services.profile_manager as pm_mod
|
||||
|
||||
mgr = _make_manager(tmp_path)
|
||||
monkeypatch.setattr(pm_mod, "profile_manager", mgr)
|
||||
|
||||
settings = EvaluationSettings(
|
||||
OPENAI_API_KEY="sk-env",
|
||||
OPENAI_BASE_URL="http://env-base/v1",
|
||||
OPENAI_TIMEOUT_SECONDS=45,
|
||||
)
|
||||
|
||||
kwargs = _resolve_openai_client_kwargs("gpt-5", settings)
|
||||
assert kwargs["api_key"] == "sk-env"
|
||||
assert kwargs["base_url"] == "http://env-base/v1"
|
||||
assert kwargs["timeout"] == 45.0
|
||||
|
||||
Reference in New Issue
Block a user