Skip to content

armgit / dspy

Public Imported from GitHub
0

DSPy: The framework for programming—not prompting—language models

Python

Update vendored lm15 to a550dab (declared providers) (#10440)

Maxime Rivest95a8e37e5fba
diff --git a/dspy/_vendor/lm15-provenance.txt b/dspy/_vendor/lm15-provenance.txt
index 27598c413..6e978af9f 100644
--- a/dspy/_vendor/lm15-provenance.txt
+++ b/dspy/_vendor/lm15-provenance.txt
@@ -1,5 +1,5 @@
source=https://github.com/cmpnd-ai/lm15-python.git
version=1.0.0rc3
-commit=cd5d4d73a3cc3bbea9fc7901b7b3c26007e7bf37
+commit=a550dab27333a1cb6a4a163c20577edab9fa872e
contract=7677980e36c8bd0b14ae9bfc79e49446f403ad22
-split=caf92f0781a0598b01cd7c25c81d250afd28babf
+split=8c8b885e05738b141cbc4a2691f0772966927f0c
diff --git a/dspy/_vendor/lm15/registry.py b/dspy/_vendor/lm15/registry.py
index 92f9a90f6..ff8051093 100644
--- a/dspy/_vendor/lm15/registry.py
+++ b/dspy/_vendor/lm15/registry.py
@@ -9,6 +9,14 @@ server's quirks. The router, the doctor, the vet surface dump (and
through it the contract's support matrix) and the docs tables all read
this table. Nothing else lists providers.
+A third source of entries, with the same shape, is the caller:
+``RouterConfig(providers=(ProviderDefinition.chat(...), ...))`` declares a
+provider this table does not list (a hosted gateway, a service lm15 has
+not receipted yet). A declared entry names its compat *object* rather
+than a preset name, is routable only through routers built with that
+config, and answers ``Resolution.declared`` — it carries no live receipt,
+and lm15 says so rather than pretend.
+
Two kinds of entries share one shape:
- **adapter-owned** — the dialect class carries its own manifest
@@ -69,6 +77,7 @@ from .providers import (
)
__all__ = [
+ "Compat",
"Dialect",
"ProviderDefinition",
"PROVIDERS",
@@ -80,6 +89,18 @@ __all__ = [
# dialect plus an access policy (plus a compat preset for the chat dialect).
Dialect = Literal["openai-responses", "openai-chat", "anthropic", "gemini"]
+# A compat value: a preset name for a registry entry (validated against
+# the dialect's table below), or the object itself for a declared entry.
+Compat = OpenAIResponsesCompat | OpenAIChatCompat | AnthropicCompat
+
+# Per dialect: the compat class a bound entry may carry as an object, and
+# the sync/async classes that speak it. A dialect absent here cannot bind.
+_DIALECTS: dict[str, tuple[type, type, type]] = {
+ "openai-responses": (OpenAIResponsesCompat, OpenAILM, AsyncOpenAILM),
+ "openai-chat": (OpenAIChatCompat, OpenAIChatLM, AsyncOpenAIChatLM),
+ "anthropic": (AnthropicCompat, AnthropicLM, AsyncAnthropicLM),
+}
+
# Per dialect: the compat preset constructor and the preset → base URL table
# a bound entry is validated against. A dialect absent here cannot bind.
@@ -106,7 +127,14 @@ class ProviderDefinition:
``access`` the credential chain, headers, surfaces and default
base URL (``lm15.access``); for a bound entry the
router passes this to the dialect constructor.
- ``compat`` Chat Completions preset name (bound entries only).
+ ``compat`` compat preset name (bound registry entries), or the
+ compat object itself (a declared entry, whose
+ preset lives in the caller's code, not lm15's
+ tables).
+ ``aliases`` extra input spellings of the provider, canonical
+ form (``fireworks-ai`` for litellm's
+ ``fireworks_ai/``); accepted as ``alias:model``
+ and ``alias/model``, never emitted.
``placeholder_key`` the key a keyless local server accepts when nothing
is configured (AUTH-1 last rung); None otherwise.
``console_url`` where a human gets a key (docs, doctor hints).
@@ -119,10 +147,11 @@ class ProviderDefinition:
adapter: type
async_adapter: type
access: AccessPolicy
- compat: str | None = None
+ compat: str | Compat | None = None
placeholder_key: str | None = None
console_url: str | None = None
note: str = ""
+ aliases: tuple[str, ...] = ()
def __post_init__(self) -> None:
if self.id != canonical_provider(self.id):
@@ -131,6 +160,37 @@ class ProviderDefinition:
raise ValueError(f"{self.id}: access policy names provider {self.access.provider!r}")
if self.placeholder_key is not None and self.access.env_keys:
raise ValueError(f"{self.id}: a keyless local server declares no env_keys")
+ if not isinstance(self.aliases, tuple) or not all(isinstance(a, str) and a for a in self.aliases):
+ raise TypeError(f"{self.id}: aliases is a tuple of non-empty strings")
+ canonical = tuple(canonical_provider(a) for a in self.aliases)
+ if canonical != self.aliases:
+ raise ValueError(f"{self.id}: aliases are hyphenated: {canonical!r}")
+ if len(set(self.aliases)) != len(self.aliases) or self.id in self.aliases:
+ raise ValueError(f"{self.id}: aliases repeat a spelling")
+ if self.compat is not None and not isinstance(self.compat, str):
+ # A compat object: the dialect's own class, and a place to send
+ # the request (a bound entry has no preset table row to read a
+ # URL from; a hosted entry renders its host template).
+ if self.dialect not in _DIALECTS:
+ raise ValueError(f"{self.id}: dialect {self.dialect!r} takes no compat")
+ compat_cls = _DIALECTS[self.dialect][0]
+ if not isinstance(self.compat, compat_cls):
+ raise TypeError(
+ f"{self.id}: compat for dialect {self.dialect!r} is a {compat_cls.__name__}, "
+ f"got {type(self.compat).__name__}"
+ )
+ if not self.hosted and not self.access.base_url:
+ raise ValueError(f"{self.id}: a declared provider names its base_url on the access policy")
+ if not self.hosted and self.access.credential_policy != "key":
+ # The router binds a bound entry as cls(api_key=..., access=...,
+ # compat=...); the OAuth policies build self-resolving
+ # constructors that take no access policy, so a bound OAuth
+ # entry would silently lose its declaration.
+ raise ValueError(
+ f"{self.id}: a declared provider is key-based; credential_policy "
+ f"{self.access.credential_policy!r} needs its own adapter class"
+ )
+ return
if self.hosted:
# A cloud door (AUTH-10 host): the base URL is a template rendered
# over the host settings at construction, so the compat-table URL
@@ -179,6 +239,74 @@ class ProviderDefinition:
def base_url(self) -> str | None:
return self.access.base_url
+ @property
+ def spellings(self) -> tuple[str, ...]:
+ """Every canonical input spelling: the id, then the aliases."""
+ return (self.id, *self.aliases)
+
+ # ─── declaring a provider (RouterConfig(providers=...)) ─────────────
+
+ @classmethod
+ def chat(
+ cls,
+ access: AccessPolicy,
+ *,
+ compat: OpenAIChatCompat | str,
+ aliases: tuple[str, ...] = (),
+ placeholder_key: str | None = None,
+ console_url: str | None = None,
+ note: str = "",
+ ) -> ProviderDefinition:
+ """A provider speaking the OpenAI Chat Completions wire: ``access``
+ names it (``AccessPolicy(provider=..., env_keys=..., base_url=...)``)
+ and ``compat`` describes the server's spellings
+ (:class:`~lm15.compat.OpenAIChatCompat`)."""
+ return cls._bound("openai-chat", access, compat=compat, aliases=aliases, placeholder_key=placeholder_key,
+ console_url=console_url, note=note)
+
+ @classmethod
+ def responses(
+ cls,
+ access: AccessPolicy,
+ *,
+ compat: OpenAIResponsesCompat | str,
+ aliases: tuple[str, ...] = (),
+ console_url: str | None = None,
+ note: str = "",
+ ) -> ProviderDefinition:
+ """A provider speaking the OpenAI Responses wire."""
+ return cls._bound("openai-responses", access, compat=compat, aliases=aliases, console_url=console_url, note=note)
+
+ @classmethod
+ def anthropic(
+ cls,
+ access: AccessPolicy,
+ *,
+ compat: AnthropicCompat | str,
+ aliases: tuple[str, ...] = (),
+ console_url: str | None = None,
+ note: str = "",
+ ) -> ProviderDefinition:
+ """A provider speaking the Anthropic Messages wire."""
+ return cls._bound("anthropic", access, compat=compat, aliases=aliases, console_url=console_url, note=note)
+
+ @classmethod
+ def _bound(cls, dialect: Dialect, access: AccessPolicy, *, compat, aliases=(), placeholder_key=None,
+ console_url=None, note="") -> ProviderDefinition:
+ _, adapter, async_adapter = _DIALECTS[dialect]
+ return cls(
+ id=canonical_provider(access.provider),
+ dialect=dialect,
+ adapter=adapter,
+ async_adapter=async_adapter,
+ access=access,
+ compat=compat,
+ placeholder_key=placeholder_key,
+ console_url=console_url,
+ note=note,
+ aliases=tuple(aliases),
+ )
+
def _adapter_owned(
id: str,
@@ -207,16 +335,7 @@ def _responses_bound(
console_url: str | None = None,
note: str = "",
) -> ProviderDefinition:
- return ProviderDefinition(
- id=access.provider,
- dialect="openai-responses",
- adapter=OpenAILM,
- async_adapter=AsyncOpenAILM,
- access=access,
- compat=compat,
- console_url=console_url,
- note=note,
- )
+ return ProviderDefinition.responses(access, compat=compat, console_url=console_url, note=note)
def _chat_bound(
@@ -227,17 +346,8 @@ def _chat_bound(
console_url: str | None = None,
note: str = "",
) -> ProviderDefinition:
- return ProviderDefinition(
- id=access.provider,
- dialect="openai-chat",
- adapter=OpenAIChatLM,
- async_adapter=AsyncOpenAIChatLM,
- access=access,
- compat=compat or access.provider,
- placeholder_key=placeholder_key,
- console_url=console_url,
- note=note,
- )
+ return ProviderDefinition.chat(access, compat=compat or access.provider, placeholder_key=placeholder_key,
+ console_url=console_url, note=note)
def _anthropic_bound(
@@ -247,16 +357,7 @@ def _anthropic_bound(
console_url: str | None = None,
note: str = "",
) -> ProviderDefinition:
- return ProviderDefinition(
- id=access.provider,
- dialect="anthropic",
- adapter=AnthropicLM,
- async_adapter=AsyncAnthropicLM,
- access=access,
- compat=compat,
- console_url=console_url,
- note=note,
- )
+ return ProviderDefinition.anthropic(access, compat=compat, console_url=console_url, note=note)
def _hosted(
diff --git a/dspy/_vendor/lm15/router.py b/dspy/_vendor/lm15/router.py
index 674001de1..b281e86c4 100644
--- a/dspy/_vendor/lm15/router.py
+++ b/dspy/_vendor/lm15/router.py
@@ -83,7 +83,7 @@ from .result import AsyncResponseStream, ResponseStream
from .errors import AmbiguousModelError, NotConfiguredError, UnknownModelError
from .models import ModelInfo, ModelRegistry
from .providers import Credential
-from .registry import PROVIDERS, ProviderDefinition, canonical_provider as _canonical_provider
+from .registry import PROVIDERS, Compat, ProviderDefinition, canonical_provider as _canonical_provider
from .adaptation import AdaptationPolicy, check_policy
from .transports import Timeouts
from .types import Request, Response, StreamEvent
@@ -158,8 +158,60 @@ ASYNC_ADAPTERS: Mapping[str, type] = MappingProxyType(
)
-def _definition(provider: str) -> ProviderDefinition | None:
- return PROVIDERS.get(provider)
+class _Table(Mapping[str, type]):
+ """What one router routes with: the adapter-owned classes of one
+ direction (sync or async) plus every bound definition it knows — the
+ registry's receipted entries and the config's declared ones
+ (``RouterConfig(providers=...)``). A plain mapping of classes (the
+ module views, a test's fakes) means the registry alone."""
+
+ __slots__ = ("_adapters", "_aliases", "definitions", "is_async")
+
+ def __init__(self, adapters: Mapping[str, type], declared: tuple[ProviderDefinition, ...], *, is_async: bool) -> None:
+ self._adapters = adapters
+ self.definitions: Mapping[str, ProviderDefinition] = MappingProxyType(
+ {**PROVIDERS, **{d.id: d for d in declared}}
+ )
+ self.is_async = is_async
+ self._aliases: Mapping[str, str] = MappingProxyType(
+ {alias: d.id for d in declared for alias in d.aliases}
+ )
+
+ def __getitem__(self, key: str) -> type:
+ return self._adapters[key]
+
+ def __iter__(self):
+ return iter(self._adapters)
+
+ def __len__(self) -> int:
+ return len(self._adapters)
+
+ def alias(self, name: str) -> str | None:
+ """The provider id a declared alias names, or None."""
+ return self._aliases.get(name)
+
+
+def _table(adapters: Mapping[str, type], config: RouterConfig) -> Mapping[str, type]:
+ """``adapters`` as a router uses it: unchanged when nothing is declared
+ (the module views keep their identity), else wrapped with the config's
+ declared providers."""
+ if not config.providers:
+ return adapters
+ return _Table(adapters, config.providers, is_async=adapters is ASYNC_ADAPTERS)
+
+
+def _definitions(adapters: Mapping[str, type]) -> Mapping[str, ProviderDefinition]:
+ return adapters.definitions if isinstance(adapters, _Table) else PROVIDERS
+
+
+def _definition(provider: str, adapters: Mapping[str, type] | None = None) -> ProviderDefinition | None:
+ return _definitions(ADAPTERS if adapters is None else adapters).get(provider)
+
+
+def _declared(provider: str, adapters: Mapping[str, type]) -> bool:
+ """True when ``provider`` comes from ``RouterConfig(providers=...)``,
+ not the receipted registry."""
+ return provider not in PROVIDERS and provider in _definitions(adapters)
def _credential_policy(provider: str, adapters: Mapping[str, type] | None = None) -> str:
@@ -173,7 +225,7 @@ def _credential_policy(provider: str, adapters: Mapping[str, type] | None = None
substitute fake classes; a provider found there but not in the
registry answers with its class manifest.
"""
- definition = _definition(provider)
+ definition = _definition(provider, adapters)
if definition is not None:
return definition.credential_policy
lookup = ADAPTERS if adapters is None else adapters
@@ -219,7 +271,7 @@ def _bound(provider: str, adapters: Mapping[str, type]) -> ProviderDefinition |
is adapter-owned (a key of ``adapters``) or unknown."""
if provider in adapters:
return None
- definition = PROVIDERS.get(provider)
+ definition = _definitions(adapters).get(provider)
return definition if definition is not None and definition.bound else None
@@ -227,15 +279,24 @@ def _routable(provider: str, adapters: Mapping[str, type]) -> bool:
return provider in adapters or _bound(provider, adapters) is not None
+def _provider_id(name: str, adapters: Mapping[str, type]) -> str:
+ """A canonical input spelling → the provider it names: a declared
+ alias resolves to its provider; anything else is itself."""
+ if isinstance(adapters, _Table):
+ return adapters.alias(name) or name
+ return name
+
+
def _adapter_for(provider: str, adapters: Mapping[str, type]) -> type:
if provider in adapters:
return adapters[provider]
- definition = PROVIDERS[provider] # bound entry: its dialect class
- return definition.async_adapter if adapters is ASYNC_ADAPTERS else definition.adapter
+ definition = _definitions(adapters)[provider] # bound entry: its dialect class
+ is_async = adapters.is_async if isinstance(adapters, _Table) else adapters is ASYNC_ADAPTERS
+ return definition.async_adapter if is_async else definition.adapter
def _bound_ids(adapters: Mapping[str, type]) -> set[str]:
- return {d.id for d in PROVIDERS.values() if d.bound and d.id not in adapters}
+ return {d.id for d in _definitions(adapters).values() if d.bound and d.id not in adapters}
def _check_provider_keyed(config: RouterConfig, adapters: Mapping[str, type]) -> None:
@@ -310,9 +371,14 @@ class Resolution:
# None for OAuth providers or when an
# explicit api_keys entry overrides env
model_info: ModelInfo | None = None # catalog metadata when source == "catalog"
- compat: str | None = None # compat preset name when routed through
+ compat: str | Compat | None = None # compat preset name when routed through
# a bound registry entry (CHAT_PRESET_ROUTES
- # or an Anthropic-dialect binding)
+ # or an Anthropic-dialect binding); the
+ # compat object for a declared provider
+ declared: bool = False # provider from RouterConfig(providers=),
+ # not the receipted registry
+ credential_policy: str = "key" # the provider's AccessPolicy.credential_policy
+ placeholder_key: str | None = None # a keyless local server's default key
def describe(self) -> str:
"""One-paragraph human-readable explanation of this resolution."""
@@ -326,11 +392,17 @@ class Resolution:
elif self.source == "rule" and self.rule is not None:
note = f" — {self.rule.note}" if self.rule.note else ""
parts.append(f"via built-in rule prefix={self.rule.prefix!r}{note}")
- if self.compat is not None:
+ if isinstance(self.compat, str):
parts.append(f"compat preset {self.compat!r}")
+ elif self.compat is not None:
+ parts.append(f"compat {type(self.compat).__name__} object")
+ if self.declared:
+ parts.append("declared by RouterConfig(providers=...) — no lm15 receipts")
parts.append(f"wire model {self.model!r}")
- definition = _bound(self.provider, ADAPTERS)
- policy = _credential_policy(self.provider)
+ # Pure data: the resolution carries its provider's credential facts
+ # (a declared provider is not in the module tables — greptile on
+ # dspy#10440, 2026-09-17).
+ policy = self.credential_policy
if policy == "oauth-unless-explicit":
# resolve() is pure (no file reads), so it describes the chain
# rather than asserting a winner.
@@ -342,7 +414,7 @@ class Resolution:
parts.append(f"key from ${self.env_key}")
elif policy == "oauth":
parts.append("local OAuth credential (no env key)")
- elif definition is not None and definition.placeholder_key is not None:
+ elif self.placeholder_key is not None:
parts.append("key from explicit api_keys or the preset's local-server default")
else:
parts.append("key from explicit api_keys")
@@ -377,6 +449,17 @@ class RouterConfig:
the cloud doors (azure, bedrock, vertex): their URL is derived from
``settings`` (resource, region), and an entry for one is refused.
+ ``providers`` declares providers the registry does not list — a
+ gateway, a service lm15 has not receipted — as
+ :class:`~lm15.registry.ProviderDefinition` values
+ (``ProviderDefinition.chat(access, compat=OpenAIChatCompat(...))``).
+ They route like registry entries in every router built with this
+ config (``id:model``, ``id/model``, each alias likewise), take
+ ``api_keys``/``base_urls`` entries, and answer
+ ``Resolution.declared``: no live receipt backs them, and lm15 says so.
+ An id or alias that a registry entry or litellm prefix already spells
+ is refused: one string, one door.
+
``timeouts`` (:class:`lm15.Timeouts`) and ``max_connections`` shape the
one transport the router builds and shares across its LMs; defaults
are the provider SDKs' (connect 10 s, read/write/pool 600 s, 100
@@ -404,9 +487,11 @@ class RouterConfig:
# record nothing), "refuse" (every adaptation is an error before the
# wire). Applied to every LM the router builds.
adaptations: AdaptationPolicy = field(default="note", kw_only=True)
+ providers: tuple[ProviderDefinition, ...] = field(default=(), kw_only=True)
def __post_init__(self) -> None:
check_policy(self.adaptations)
+ _check_declared(self.providers)
if self.timeouts is not None and not isinstance(self.timeouts, Timeouts):
raise TypeError(
f"RouterConfig(timeouts=...) takes lm15.Timeouts, got {type(self.timeouts).__name__}; "
@@ -441,6 +526,34 @@ class RouterConfig:
# ------------------------------------------------------------- internals ----
+def _check_declared(providers: object) -> None:
+ """``RouterConfig(providers=...)``: definitions only, each spelling
+ (id and aliases) naming one door that nothing built in already names."""
+ if not isinstance(providers, tuple):
+ raise TypeError(
+ f"RouterConfig(providers=...) takes a tuple of ProviderDefinition, got {type(providers).__name__}"
+ )
+ taken: dict[str, str] = {}
+ for definition in providers:
+ if not isinstance(definition, ProviderDefinition):
+ raise TypeError(
+ f"RouterConfig(providers=...): {definition!r} is not a ProviderDefinition; "
+ "declare one with ProviderDefinition.chat(access, compat=...)"
+ )
+ for spelling in definition.spellings:
+ built_in = PROVIDERS[spelling].id if spelling in PROVIDERS else _LITELLM_CANONICAL.get(spelling)
+ if built_in is not None:
+ raise NotConfiguredError(
+ f"RouterConfig(providers=...): {spelling!r} already names lm15's {built_in!r} door; "
+ "a declared provider takes a new id and aliases"
+ )
+ if spelling in taken:
+ raise NotConfiguredError(
+ f"RouterConfig(providers=...): {spelling!r} is spelled by both {taken[spelling]!r} and {definition.id!r}"
+ )
+ taken[spelling] = definition.id
+
+
def _resolution(
*,
requested: str,
@@ -463,6 +576,9 @@ def _resolution(
env_key=_env_key_for(provider, config, adapters),
model_info=model_info,
compat=definition.compat if definition is not None else None,
+ declared=_declared(provider, adapters),
+ credential_policy=_credential_policy(provider, adapters),
+ placeholder_key=definition.placeholder_key if definition is not None else None,
)
@@ -482,7 +598,7 @@ def _resolve(model: str, config: RouterConfig, adapters: Mapping[str, type]) ->
# else matches either).
object_provider = getattr(model, "provider", None)
if isinstance(object_provider, str) and object_provider:
- object_provider = _canonical_provider(object_provider)
+ object_provider = _provider_id(_canonical_provider(object_provider), adapters)
else:
object_provider = None
if object_provider is not None and _routable(object_provider, adapters):
@@ -498,7 +614,7 @@ def _resolve(model: str, config: RouterConfig, adapters: Mapping[str, type]) ->
# Rung 1: explicit provider prefix (split on FIRST colon).
if ":" in model:
raw_head, rest = model.split(":", 1)
- head = _canonical_provider(raw_head)
+ head = _provider_id(_canonical_provider(raw_head), adapters)
if _routable(head, adapters) and rest:
return _resolution(
requested=requested,
@@ -543,7 +659,7 @@ def _resolve(model: str, config: RouterConfig, adapters: Mapping[str, type]) ->
providers=providers,
)
info = narrowed[0]
- catalog_provider = _canonical_provider(info.provider)
+ catalog_provider = _provider_id(_canonical_provider(info.provider), adapters)
if not _routable(catalog_provider, adapters):
raise UnknownModelError(
f"model {model!r} resolved in the catalog to provider "
@@ -870,6 +986,12 @@ LITELLM_PROVIDER_PREFIXES: Mapping[str, str] = MappingProxyType({
"azure": "azure-chat",
})
+# The same prefixes in canonical spelling, for the collision check a
+# declared provider's spellings go through (`_check_declared`).
+_LITELLM_CANONICAL: Mapping[str, str] = MappingProxyType(
+ {_canonical_provider(prefix): provider for prefix, provider in LITELLM_PROVIDER_PREFIXES.items()}
+)
+
# Keyword arguments of `create()` / `completion()` that configure the
# CLIENT, not the request: refused with the lm15 place they belong.
_CLIENT_KEYWORDS: Mapping[str, str] = MappingProxyType({
@@ -891,14 +1013,16 @@ _CLIENT_KEYWORDS: Mapping[str, str] = MappingProxyType({
})
-def openai_chat_model_string(model: str) -> str:
+def openai_chat_model_string(model: str, *, providers: tuple[ProviderDefinition, ...] = ()) -> str:
"""The lm15 model string for a model string written for the OpenAI SDK
or litellm (`playbooks/api-family.md` § Ingest):
- an lm15 string (``provider:model``) is left alone;
- litellm's ``provider/model`` maps its prefix through
:data:`LITELLM_PROVIDER_PREFIXES` (only the first segment; a model
- id may contain slashes itself: ``groq/openai/gpt-oss-20b``);
+ id may contain slashes itself: ``groq/openai/gpt-oss-20b``), or
+ through a declared provider's id and aliases (``providers``, the
+ config's ``RouterConfig(providers=...)``; either spelling);
- a bare name routes by lm15's rules, except that OpenAI's models go
to the Chat Completions door (``openai-chat:``) — the endpoint both
libraries were using — not the Responses API.
@@ -909,9 +1033,16 @@ def openai_chat_model_string(model: str) -> str:
if sep and rest:
provider = LITELLM_PROVIDER_PREFIXES.get(head)
if provider is None:
+ canonical = _canonical_provider(head)
+ for definition in providers:
+ if canonical in definition.spellings:
+ provider = definition.id
+ break
+ if provider is None:
+ known = sorted({*LITELLM_PROVIDER_PREFIXES, *(s for d in providers for s in d.spellings)})
raise UnknownModelError(
f"could not read {model!r} as a litellm model string: {head!r} is not a provider prefix lm15 "
- f"has a door for (known: {', '.join(sorted(LITELLM_PROVIDER_PREFIXES))}); write it as lm15's "
+ f"has a door for (known: {', '.join(known)}); write it as lm15's "
"provider:model instead",
model=model,
)
@@ -942,6 +1073,7 @@ class LMRouter:
"""
def __init__(self, config: RouterConfig = RouterConfig()) -> None:
+ self._adapters = _table(type(self)._adapters, config)
_check_provider_keyed(config, self._adapters)
self.config = config
self._lms: dict[str, object] = {}
@@ -1040,7 +1172,7 @@ class LMRouter:
litellm were using. Like ``resolve()``: no network, no credential
invocation or secret values in the result — "which provider, which env var"
before any key exists."""
- resolution = self.resolve(openai_chat_model_string(model))
+ resolution = self.resolve(openai_chat_model_string(model, providers=self.config.providers))
if resolution.source == "rule" and resolution.provider == "openai":
resolution = self.resolve(f"openai-chat:{resolution.model}")
return resolution
@@ -1107,6 +1239,7 @@ class AsyncLMRouter:
"""
def __init__(self, config: RouterConfig = RouterConfig()) -> None:
+ self._adapters = _table(type(self)._adapters, config)
_check_provider_keyed(config, self._adapters)
self.config = config
self._lms: dict[str, object] = {}