Skip to content

Official Codebase of 3DCodeVerse

Python

models: health probes build their bare model through registry.build_chat_model — _bare_model restated the provider ladder

gaoypengfdc2a1307f20
diff --git a/harness/codeverse3d/models/health.py b/harness/codeverse3d/models/health.py
index 7d12d026..4abc87fc 100644
--- a/harness/codeverse3d/models/health.py
+++ b/harness/codeverse3d/models/health.py
@@ -23,6 +23,8 @@ import concurrent.futures as cf
import logging
from dataclasses import dataclass
+from codeverse3d.models.registry import build_chat_model
+
log = logging.getLogger(__name__)
#: enough of the pool to tell an outage from one unlucky key, without a long probe
@@ -112,18 +114,9 @@ def _probe_prompt(tokens: int = PROBE_TOKENS) -> str:
def _bare_model(model_id: str, timeout_s: float):
- """The model with retries switched off — a probe that retries measures nothing."""
- provider, _, name = model_id.partition(":")
- if not name:
- provider, name = "gemini", provider
- if provider == "gemini":
- from codeverse3d.models.gemini import GeminiModel
-
- return GeminiModel(name, timeout_s=timeout_s, max_attempts=1, storm_attempts=0)
- if provider == "anthropic":
- from codeverse3d.models.anthropic import AnthropicModel
-
- return AnthropicModel(name, timeout_s=timeout_s, max_attempts=1)
- from codeverse3d.models.openai import OpenAIModel # everything else, as models.registry does
-
- return OpenAIModel(name, timeout_s=timeout_s, max_attempts=1)
+ """The model with retries switched off — a probe that retries measures nothing. A bare
+ name is a gemini model."""
+ if ":" not in model_id:
+ model_id = f"gemini:{model_id}"
+ extra = {"storm_attempts": 0} if model_id.startswith("gemini:") else {}
+ return build_chat_model(model_id, timeout_s=timeout_s, max_attempts=1, **extra)
diff --git a/harness/codeverse3d/models/registry.py b/harness/codeverse3d/models/registry.py
index 2db022f6..36e54e74 100644
--- a/harness/codeverse3d/models/registry.py
+++ b/harness/codeverse3d/models/registry.py
@@ -7,6 +7,7 @@ active, otherwise a per-process log) — always: the ledger is the only record o
from __future__ import annotations
from functools import lru_cache
+from typing import Any
from codeverse3d.models.base import ChatModel
@@ -27,19 +28,20 @@ def get_chat_model(model_id: str) -> ChatModel:
"""The (metered) ChatModel for ``<provider>:<model>``."""
from codeverse3d.cost.instrument import metered_chat_model
- return metered_chat_model(_build_chat_model(model_id))
+ return metered_chat_model(build_chat_model(model_id))
-def _build_chat_model(model_id: str) -> ChatModel:
+def build_chat_model(model_id: str, **kw: Any) -> ChatModel:
+ """The bare (unmetered) model for ``<provider>:<model>``; ``kw`` goes to its constructor."""
provider, model = parse_model_id(model_id)
if provider == "gemini":
from codeverse3d.models.gemini import GeminiModel
- return GeminiModel(model)
+ return GeminiModel(model, **kw)
if provider == "anthropic":
from codeverse3d.models.anthropic import AnthropicModel
- return AnthropicModel(model)
+ return AnthropicModel(model, **kw)
from codeverse3d.models.openai import OpenAIModel
- return OpenAIModel(model)
+ return OpenAIModel(model, **kw)
diff --git a/harness/tests/cost/test_instrument.py b/harness/tests/cost/test_instrument.py
index 0fcc2ee8..2e69cac7 100644
--- a/harness/tests/cost/test_instrument.py
+++ b/harness/tests/cost/test_instrument.py
@@ -159,7 +159,7 @@ def test_the_proxy_forwards_everything_else():
def test_get_chat_model_hands_out_a_metered_model(monkeypatch: pytest.MonkeyPatch):
from codeverse3d.models import registry
- monkeypatch.setattr(registry, "_build_chat_model", lambda mid: FakeChat())
+ monkeypatch.setattr(registry, "build_chat_model", lambda mid: FakeChat())
registry.get_chat_model.cache_clear()
try:
assert isinstance(registry.get_chat_model("gemini:gemini-3.7-flash"), MeteredChatModel)
diff --git a/harness/tests/flywheel_cli/test_captions.py b/harness/tests/flywheel_cli/test_captions.py
index 40d9a6e5..a74990ba 100644
--- a/harness/tests/flywheel_cli/test_captions.py
+++ b/harness/tests/flywheel_cli/test_captions.py
@@ -81,7 +81,7 @@ def test_caption_cmd_writes_the_captioner_row_into_the_run_ledger(fake_run, monk
select.package(ws.root, 1)
ledger = open_run_ledger(ws.root) # the run already keeps one (create=False appends)
ledger.path.touch()
- monkeypatch.setattr(R, "_build_chat_model", lambda _mid: FakeModel([GOOD]))
+ monkeypatch.setattr(R, "build_chat_model", lambda _mid: FakeModel([GOOD]))
r = CliRunner().invoke(app, ["flywheel", "caption", ws.root.name, "--runs-dir", str(ws.root.parent),
"--model", "fake:fake"])
assert r.exit_code == 0, r.output