mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-01 23:59:55 +08:00
fix(doctor): preserve resolved provider configuration in probes
This commit is contained in:
@@ -337,7 +337,7 @@ def _redact_error(exc: Exception, config: Any) -> str:
|
||||
|
||||
async def _probe_provider(config: Any) -> None:
|
||||
from deeptutor.services.config.loader import get_agent_params
|
||||
from deeptutor.services.llm import complete
|
||||
from deeptutor.services.llm.factory import complete_with_config
|
||||
|
||||
# Share the Settings probe's configurable budget. A 64-token cap can be
|
||||
# exhausted by hidden reasoning before a healthy model emits even "OK".
|
||||
@@ -351,17 +351,11 @@ async def _probe_provider(config: Any) -> None:
|
||||
except (TypeError, ValueError):
|
||||
max_tokens = 4096
|
||||
|
||||
response = await complete(
|
||||
model=str(config.model),
|
||||
response = await complete_with_config(
|
||||
config,
|
||||
prompt="Reply with OK.",
|
||||
system_prompt="Reply with only OK.",
|
||||
binding=str(config.binding),
|
||||
api_key=str(config.api_key or ""),
|
||||
base_url=str(config.effective_url or config.base_url or ""),
|
||||
api_version=config.api_version,
|
||||
temperature=0,
|
||||
extra_headers=config.extra_headers,
|
||||
reasoning_effort=config.reasoning_effort,
|
||||
max_retries=0,
|
||||
allow_image_fallback=False,
|
||||
max_tokens=max_tokens,
|
||||
|
||||
@@ -210,15 +210,14 @@ async def test_online_probe_success_is_reported(tmp_path) -> None:
|
||||
async def test_online_probe_uses_configured_budget(
|
||||
monkeypatch, tmp_path, configured_budget, expected
|
||||
) -> None:
|
||||
import deeptutor.services.llm as llm
|
||||
|
||||
captured = {}
|
||||
|
||||
async def fake_complete(**kwargs):
|
||||
async def fake_complete(config, **kwargs):
|
||||
captured.update(kwargs)
|
||||
captured["config"] = config
|
||||
return "OK"
|
||||
|
||||
monkeypatch.setattr(llm, "complete", fake_complete)
|
||||
monkeypatch.setattr("deeptutor.services.llm.factory.complete_with_config", fake_complete)
|
||||
(tmp_path / "agents.yaml").write_text(
|
||||
json.dumps({"diagnostics": {"llm_probe": {"max_tokens": configured_budget}}}),
|
||||
encoding="utf-8",
|
||||
@@ -251,13 +250,13 @@ async def test_online_probe_allows_reasoning_before_visible_output(
|
||||
) -> None:
|
||||
"""A healthy reasoning endpoint must not fail because the probe truncates it."""
|
||||
|
||||
async def fake_complete(**kwargs):
|
||||
async def fake_complete(config, **kwargs):
|
||||
return response if kwargs["max_tokens"] >= 4096 else ""
|
||||
|
||||
def missing_settings(module):
|
||||
raise FileNotFoundError("agents.yaml")
|
||||
|
||||
monkeypatch.setattr("deeptutor.services.llm.complete", fake_complete)
|
||||
monkeypatch.setattr("deeptutor.services.llm.factory.complete_with_config", fake_complete)
|
||||
monkeypatch.setattr("deeptutor.services.config.loader.get_agent_params", missing_settings)
|
||||
report = await run_diagnostics(
|
||||
online=True,
|
||||
@@ -272,15 +271,14 @@ async def test_online_probe_allows_reasoning_before_visible_output(
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_online_probe_preserves_empty_custom_endpoint_api_key(monkeypatch, tmp_path) -> None:
|
||||
import deeptutor.services.llm as llm
|
||||
|
||||
captured = {}
|
||||
|
||||
async def fake_complete(**kwargs):
|
||||
async def fake_complete(config, **kwargs):
|
||||
captured.update(kwargs)
|
||||
captured["config"] = config
|
||||
return "OK"
|
||||
|
||||
monkeypatch.setattr(llm, "complete", fake_complete)
|
||||
monkeypatch.setattr("deeptutor.services.llm.factory.complete_with_config", fake_complete)
|
||||
|
||||
report = await run_diagnostics(
|
||||
online=True,
|
||||
@@ -297,7 +295,44 @@ async def test_online_probe_preserves_empty_custom_endpoint_api_key(monkeypatch,
|
||||
)
|
||||
|
||||
assert report.ok is True
|
||||
assert captured["api_key"] == ""
|
||||
assert captured["config"].api_key == ""
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_online_probe_preserves_resolved_provider_protocol(monkeypatch, tmp_path) -> None:
|
||||
from deeptutor.services.llm.config import LLMConfig
|
||||
|
||||
config = LLMConfig(
|
||||
model="custom-reasoner",
|
||||
provider_name="custom",
|
||||
provider_mode="direct",
|
||||
binding="openai",
|
||||
api_key="",
|
||||
base_url="https://models.example.com/v1",
|
||||
wire_api="responses",
|
||||
extra_headers={"X-Tenant": "tenant-a"},
|
||||
)
|
||||
captured = {}
|
||||
|
||||
async def fake_complete(snapshot, **kwargs):
|
||||
captured["config"] = snapshot
|
||||
captured.update(kwargs)
|
||||
return "OK"
|
||||
|
||||
monkeypatch.setattr("deeptutor.services.llm.factory.complete_with_config", fake_complete)
|
||||
report = await run_diagnostics(
|
||||
online=True,
|
||||
resolve_llm=lambda: config,
|
||||
data_root=tmp_path,
|
||||
load_rag_config=lambda: {"defaults": {}, "knowledge_bases": {}},
|
||||
)
|
||||
|
||||
assert report.ok is True
|
||||
assert captured["config"] is config
|
||||
assert config.wire_api == "responses"
|
||||
assert config.extra_headers == {"X-Tenant": "tenant-a"}
|
||||
assert "binding" not in captured
|
||||
assert "api_key" not in captured
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
||||
Reference in New Issue
Block a user