mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-17 09:34:48 +00:00
refactor(opencode): drop narration comments and pin the model sets to the cost map
This commit is contained in:
parent
f83c840e9d
commit
b5bc7a0878
4 changed files with 31 additions and 23 deletions
|
|
@ -26,14 +26,9 @@ from litellm.llms.opencode.common_utils import (
|
|||
)
|
||||
from litellm.types.router import GenericLiteLLMParams
|
||||
|
||||
# ---------- surface base URL ( /v1/messages appended downstream ) ----------
|
||||
|
||||
ZEN_MESSAGES_BASE: Final = "https://opencode.ai/zen"
|
||||
|
||||
# ------------------------------------------------------------------- model sets
|
||||
# Models the gateway serves via the Anthropic Messages wire format, per surface.
|
||||
# Source: models.dev ``npm == @ai-sdk/anthropic`` classification.
|
||||
#
|
||||
# These live in code rather than being read from the cost map's ``mode`` field
|
||||
# because ``litellm.model_cost`` is fetched from the published remote map at
|
||||
# import, and a provider's entries only appear there once released. Routing that
|
||||
|
|
@ -87,9 +82,6 @@ def is_messages_model(surface: str, model: str) -> bool:
|
|||
return bare in OPENCODE_MESSAGES_MODELS.get(surface, frozenset())
|
||||
|
||||
|
||||
# ------------------------------------------------------------------ config class
|
||||
|
||||
|
||||
class OpenCodeMessagesConfig(AnthropicMessagesConfig):
|
||||
"""Anthropic Messages config for the OpenCode gateway.
|
||||
|
||||
|
|
@ -152,7 +144,6 @@ class OpenCodeMessagesConfig(AnthropicMessagesConfig):
|
|||
Both surfaces authenticate ``/v1/messages`` with ``x-api-key``
|
||||
(Anthropic default); Bearer returns 401 "Missing API key" on both.
|
||||
"""
|
||||
# -- key resolution (same chain as chat arm) ---------------------------
|
||||
# A missing key is rejected here: the base class resolves one from
|
||||
# ANTHROPIC_API_KEY, which would send a first-party Anthropic
|
||||
# credential to opencode.ai.
|
||||
|
|
@ -165,15 +156,6 @@ class OpenCodeMessagesConfig(AnthropicMessagesConfig):
|
|||
|
||||
base_url: Final = resolve_opencode_api_base(self.surface, api_base) or self._base_url()
|
||||
|
||||
# -- auth header per surface -------------------------------------------
|
||||
# OpenCode does not support OAuth, so we can skip the OAuth check that
|
||||
# the base class performs. Both surfaces authenticate /v1/messages with
|
||||
# x-api-key (verified live: Bearer returns 401 "Missing API key" on both
|
||||
# Zen and Go), so leave headers empty and let the base class inject
|
||||
# x-api-key.
|
||||
# NOTE: this intentionally diverges from the chat arm, which uses Bearer.
|
||||
|
||||
# -- base class handles defaults, beta headers, content-type ----------
|
||||
resolved_headers, resolved_base_url = super().validate_anthropic_messages_environment(
|
||||
headers=headers,
|
||||
model=model,
|
||||
|
|
|
|||
|
|
@ -3525,11 +3525,6 @@ def _complete_opencode(
|
|||
else base_headers
|
||||
)
|
||||
|
||||
# Part of the catalogue is served over the Anthropic Messages wire format.
|
||||
# Those models go through the Anthropic chat handler, which translates
|
||||
# OpenAI input to Anthropic and the Anthropic reply back to a ModelResponse
|
||||
# (and handles streaming and acompletion natively) — the same path the
|
||||
# first-party anthropic provider takes.
|
||||
from litellm.llms.opencode.chat.messages_transformation import is_messages_model
|
||||
|
||||
if is_messages_model(surface, model):
|
||||
|
|
|
|||
|
|
@ -99,6 +99,21 @@ class TestMessagesModelSet:
|
|||
with pytest.raises(AttributeError):
|
||||
OPENCODE_MESSAGES_MODELS["zen"].add("brand-new-model")
|
||||
|
||||
@pytest.mark.parametrize("surface", ["zen", "go"])
|
||||
def test_set_agrees_with_cost_map_mode(self, surface):
|
||||
"""Every model the cost map publishes routes to messages exactly when its mode says messages."""
|
||||
from litellm.litellm_core_utils.get_model_cost_map import GetModelCostMap
|
||||
|
||||
published = {
|
||||
key.split("/", 1)[1]: entry["mode"]
|
||||
for key, entry in GetModelCostMap.load_local_model_cost_map().items()
|
||||
if entry.get("litellm_provider") == f"opencode_{surface}"
|
||||
}
|
||||
assert published
|
||||
assert {model for model in published if is_messages_model(surface, model)} == {
|
||||
model for model, mode in published.items() if mode == "messages"
|
||||
}
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# is_messages_model routing
|
||||
|
|
|
|||
|
|
@ -407,6 +407,22 @@ class TestCostMap:
|
|||
entry = litellm.model_cost[model_key]
|
||||
return entry
|
||||
|
||||
@pytest.mark.parametrize("surface", ["zen", "go"])
|
||||
def test_responses_set_agrees_with_cost_map_mode(self, surface):
|
||||
"""Every model the cost map publishes routes to responses exactly when its mode says responses."""
|
||||
from litellm.litellm_core_utils.get_model_cost_map import GetModelCostMap
|
||||
from litellm.llms.opencode.common_utils import is_responses_model
|
||||
|
||||
published = {
|
||||
key.split("/", 1)[1]: entry["mode"]
|
||||
for key, entry in GetModelCostMap.load_local_model_cost_map().items()
|
||||
if entry.get("litellm_provider") == f"opencode_{surface}"
|
||||
}
|
||||
assert published
|
||||
assert {model for model in published if is_responses_model(surface, model)} == {
|
||||
model for model, mode in published.items() if mode == "responses"
|
||||
}
|
||||
|
||||
# --- gpt-5.6 series ---
|
||||
|
||||
def test_gpt_5_6_sol(self):
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue