mirror of
https://github.com/headroomlabs-ai/headroom.git
synced 2026-11-22 13:29:19 +08:00
chore(providers): remove dead provider and model helpers
Remove helpers that nothing calls: the four get_default_*_model/dim accessors and MLModelConfig.total_memory_estimate in models/config.py (callers read ML_MODEL_DEFAULTS fields directly), opencode/config.py's _render_provider_block, _opencode_home_dir (OPENCODE_HOME is resolved by install.paths.opencode_config_path) and the test-only append_headroom_plugin, the unused litellm model_cost import in providers/litellm.py, and the test-only codex fetch_chatgpt_codex_model_ids wrapper. The codex fetch test now calls fetch_chatgpt_codex_model_entries, the function production uses, so the fetch path keeps its coverage. Evidence: a word search for each name across the repo and the consumer repos finds only its definition (plus tests for the two test-only helpers). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
a9815bbb5f
commit
91e11e406d
@@ -106,40 +106,6 @@ class MLModelConfig:
|
||||
"""
|
||||
return self._memory_estimates.get(model_name, 100)
|
||||
|
||||
def total_memory_estimate(self) -> int:
|
||||
"""Get total estimated memory if all configured models are loaded.
|
||||
|
||||
Returns:
|
||||
Total estimated memory in MB.
|
||||
"""
|
||||
return (
|
||||
self.get_memory_estimate(self.sentence_transformer)
|
||||
+ self.get_memory_estimate(self.siglip)
|
||||
+ self.get_memory_estimate(self.spacy)
|
||||
+ self.get_memory_estimate(self.technique_router)
|
||||
)
|
||||
|
||||
|
||||
# Singleton instance - import this to get defaults
|
||||
ML_MODEL_DEFAULTS = MLModelConfig()
|
||||
|
||||
|
||||
# Convenience accessors for common use cases
|
||||
def get_default_embedding_model() -> str:
|
||||
"""Get the default sentence transformer model name."""
|
||||
return ML_MODEL_DEFAULTS.sentence_transformer
|
||||
|
||||
|
||||
def get_default_embedding_dim() -> int:
|
||||
"""Get the default embedding dimension."""
|
||||
return ML_MODEL_DEFAULTS.sentence_transformer_dim
|
||||
|
||||
|
||||
def get_default_spacy_model() -> str:
|
||||
"""Get the default spaCy model name."""
|
||||
return ML_MODEL_DEFAULTS.spacy
|
||||
|
||||
|
||||
def get_default_siglip_model() -> str:
|
||||
"""Get the default SIGLIP model name."""
|
||||
return ML_MODEL_DEFAULTS.siglip
|
||||
|
||||
@@ -270,29 +270,6 @@ async def fetch_chatgpt_codex_model_entries(
|
||||
return None
|
||||
|
||||
|
||||
async def fetch_chatgpt_codex_model_ids(
|
||||
http_client: CodexModelRegistryHttpClient,
|
||||
headers: Mapping[str, str],
|
||||
requested_client_version: str | None,
|
||||
options: CodexModelRegistryOptions = CodexModelRegistryOptions(),
|
||||
) -> tuple[str, ...] | None:
|
||||
"""Fetch Codex model slugs from ChatGPT, returning None when fallback should apply."""
|
||||
model_entries = await fetch_chatgpt_codex_model_entries(
|
||||
http_client,
|
||||
headers,
|
||||
requested_client_version,
|
||||
options,
|
||||
)
|
||||
if model_entries is None:
|
||||
return None
|
||||
return tuple(
|
||||
slug
|
||||
for entry in model_entries
|
||||
for slug in (entry.get("slug"),)
|
||||
if isinstance(slug, str) and slug
|
||||
)
|
||||
|
||||
|
||||
async def fetch_chatgpt_codex_models_response(
|
||||
http_client: CodexModelRegistryHttpClient,
|
||||
headers: Mapping[str, str],
|
||||
|
||||
@@ -46,7 +46,6 @@ try:
|
||||
litellm.set_verbose = False
|
||||
|
||||
from litellm import get_model_info as litellm_get_model_info
|
||||
from litellm import model_cost as litellm_model_cost
|
||||
from litellm import token_counter as litellm_token_counter
|
||||
|
||||
LITELLM_AVAILABLE = True
|
||||
@@ -54,7 +53,6 @@ except ImportError:
|
||||
LITELLM_AVAILABLE = False
|
||||
litellm = None # type: ignore[assignment]
|
||||
litellm_token_counter = None # type: ignore[assignment]
|
||||
litellm_model_cost = None # type: ignore[assignment]
|
||||
litellm_get_model_info = None # type: ignore[assignment]
|
||||
|
||||
|
||||
|
||||
@@ -64,14 +64,6 @@ def headroom_provider_entry(port: int) -> dict[str, Any]:
|
||||
}
|
||||
|
||||
|
||||
def _opencode_home_dir() -> Path:
|
||||
"""Return the OpenCode home/config directory."""
|
||||
env_path = os.environ.get("OPENCODE_HOME", "").strip()
|
||||
if env_path:
|
||||
return Path(env_path).expanduser()
|
||||
return Path.home() / ".config" / "opencode"
|
||||
|
||||
|
||||
def opencode_config_paths() -> tuple[Path, Path]:
|
||||
"""Return the selected config and its canonical Headroom backup path."""
|
||||
config_file = opencode_config_path()
|
||||
@@ -134,17 +126,6 @@ def strip_opencode_headroom_blocks(content: str, *, remove_mcp: bool = True) ->
|
||||
return content.strip()
|
||||
|
||||
|
||||
def _render_provider_block(port: int) -> str:
|
||||
"""Render a Headroom provider block as a JSON comment-wrapped snippet."""
|
||||
provider = {"headroom": headroom_provider_entry(port)}
|
||||
lines = [
|
||||
_PROVIDER_MARKER_START,
|
||||
f'"provider": {json.dumps(provider, indent=2)},',
|
||||
_PROVIDER_MARKER_END,
|
||||
]
|
||||
return "\n".join(lines)
|
||||
|
||||
|
||||
def _strip_jsonc_comments(text: str) -> str:
|
||||
"""Remove JSONC line and block comments while preserving quoted strings."""
|
||||
output: list[str] = []
|
||||
@@ -245,26 +226,6 @@ def _inject_key_into_json(data: dict[str, Any], key: str, value: Any) -> dict[st
|
||||
return data
|
||||
|
||||
|
||||
def append_headroom_plugin(config: dict[str, object]) -> bool:
|
||||
"""Append the optional OpenCode plugin entry if it is not already present."""
|
||||
plugin = config.get("plugin")
|
||||
if plugin is None:
|
||||
config["plugin"] = [HEADROOM_OPENCODE_PLUGIN]
|
||||
return True
|
||||
|
||||
if not isinstance(plugin, list):
|
||||
return False
|
||||
|
||||
for entry in plugin:
|
||||
if entry == HEADROOM_OPENCODE_PLUGIN:
|
||||
return False
|
||||
if isinstance(entry, list) and entry and entry[0] == HEADROOM_OPENCODE_PLUGIN:
|
||||
return False
|
||||
|
||||
plugin.append(HEADROOM_OPENCODE_PLUGIN)
|
||||
return True
|
||||
|
||||
|
||||
def inject_opencode_provider_config(port: int, *, keep_user_entries: bool = False) -> None:
|
||||
"""Inject a Headroom model provider into OpenCode's config file.
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ from headroom.providers.codex import (
|
||||
)
|
||||
from headroom.providers.codex.model_metadata import (
|
||||
codex_model_registry_entry,
|
||||
fetch_chatgpt_codex_model_ids,
|
||||
fetch_chatgpt_codex_model_entries,
|
||||
normalize_codex_registry_headers,
|
||||
synthetic_model_get_response,
|
||||
synthetic_models_list_response,
|
||||
@@ -113,13 +113,14 @@ async def test_codex_model_registry_fetch_returns_slugs() -> None:
|
||||
|
||||
client = FakeClient()
|
||||
|
||||
model_ids = await fetch_chatgpt_codex_model_ids(
|
||||
entries = await fetch_chatgpt_codex_model_entries(
|
||||
client,
|
||||
{"authorization": "Bearer token", "chatgpt-account-id": "acct"},
|
||||
"0.135.0",
|
||||
)
|
||||
|
||||
assert model_ids == ("gpt-5.5", "gpt-5.4")
|
||||
assert entries is not None
|
||||
assert [entry["slug"] for entry in entries] == ["gpt-5.5", "gpt-5.4"]
|
||||
assert client.calls == [
|
||||
(
|
||||
"https://chatgpt.com/backend-api/codex/models?client_version=0.135.0",
|
||||
|
||||
@@ -11,7 +11,6 @@ from headroom.providers.opencode.config import (
|
||||
HEADROOM_OPENCODE_PLUGIN,
|
||||
_inject_key_into_json,
|
||||
_parse_json_loose,
|
||||
append_headroom_plugin,
|
||||
inject_opencode_provider_config,
|
||||
opencode_config_paths,
|
||||
snapshot_opencode_config_if_unwrapped,
|
||||
@@ -477,24 +476,6 @@ def test_inject_provider_config_preserves_unrelated_top_level_keys(
|
||||
assert "headroom" in config.get("provider", {})
|
||||
|
||||
|
||||
def test_append_headroom_plugin_adds_plugin_once() -> None:
|
||||
config: dict[str, object] = {"plugin": ["some-plugin"]}
|
||||
|
||||
assert append_headroom_plugin(config) is True
|
||||
assert append_headroom_plugin(config) is False
|
||||
|
||||
assert config["plugin"] == ["some-plugin", HEADROOM_OPENCODE_PLUGIN]
|
||||
|
||||
|
||||
def test_append_headroom_plugin_preserves_configured_tuple_entry() -> None:
|
||||
config: dict[str, object] = {
|
||||
"plugin": [[HEADROOM_OPENCODE_PLUGIN, {"proxyUrl": "http://127.0.0.1:8787"}]]
|
||||
}
|
||||
|
||||
assert append_headroom_plugin(config) is False
|
||||
assert config["plugin"] == [[HEADROOM_OPENCODE_PLUGIN, {"proxyUrl": "http://127.0.0.1:8787"}]]
|
||||
|
||||
|
||||
def test_inject_provider_config_no_crash_on_unwriteable_dir(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
|
||||
Reference in New Issue
Block a user