ooai_llm.types

Typed model-string helpers.

Purpose:

Provide a reusable Pydantic root model for provider/model strings that can be used across chat, embeddings, rerankers, and related model families.

Design:
  • Store the canonical raw model string as a RootModel[str].

  • Reuse provider normalization and inference logic from ooai_llm.providers.

  • Offer ergonomic class methods for parsing, construction, conversion to LangChain and LiteLLM naming styles, and provider enrichment.

Examples

>>> model = ModelString.parse("gpt-5.4-mini")
>>> model.provider
<Provider.OPENAI: 'openai'>
>>> model.as_litellm()
'openai/gpt-5.4-mini'

Classes

ModelString

Root model for provider/model strings.

Module Contents

class ooai_llm.types.ModelString[source]

Bases: pydantic.RootModel[str]

Root model for provider/model strings.

Parameters:

root – Raw model string, optionally provider-prefixed.

Examples

>>> ModelString("openai:gpt-5.4-mini").model_name
'gpt-5.4-mini'
>>> ModelString.parse("anthropic/claude-sonnet-4").provider
<Provider.ANTHROPIC: 'anthropic'>
model_config[source]
property provider: ooai_llm.providers.Provider | None[source]

Return the canonical provider when present or inferable.

property provider_prefix: str | None[source]

Return the canonical provider prefix string when available.

property litellm_provider_prefix: str | None[source]

Return the canonical LiteLLM provider prefix when available.

property model_name: str[source]

Return the unprefixed model name.

property is_prefixed: bool[source]

Whether the model string includes an explicit provider prefix.

property is_litellm_style: bool[source]

Whether the raw model string uses LiteLLM’s slash separator.

property is_langchain_style: bool[source]

Whether the raw model string uses LangChain’s colon separator.

property is_bare: bool[source]

Whether the model string omits an explicit provider prefix.

classmethod parse(value: str | Self) Self[source]

Parse a raw string or return the existing model-string instance.

Parameters:

value – Model string or model-string instance.

Returns:

Parsed model-string instance.

classmethod from_parts(model_name: str, *, provider: ooai_llm.providers.Provider | str | None = None) Self[source]

Build a model string from parts.

Parameters:
  • model_name – Bare model name.

  • provider – Optional provider enum or alias.

Returns:

Constructed model-string instance.

classmethod from_litellm(model_name: str) Self[source]

Parse a LiteLLM-style model string.

Parameters:

model_name – Provider-prefixed or bare LiteLLM model string.

Returns:

Canonical model-string instance using LangChain-style provider separators.

classmethod infer(model_name: str) Self[source]

Create a provider-prefixed model string when inference succeeds.

Parameters:

model_name – Bare or prefixed model string.

Returns:

Canonicalized model-string instance.

split() tuple[ooai_llm.providers.Provider | None, str][source]

Return the provider and model-name components.

Returns:

Tuple of (provider, model_name).

with_provider(provider: ooai_llm.providers.Provider | str) Self[source]

Return a provider-prefixed model string.

Parameters:

provider – Provider enum or alias.

Returns:

New provider-prefixed model-string instance.

ensure_provider(provider: ooai_llm.providers.Provider | str | None = None) Self[source]

Return a provider-prefixed model string when possible.

Parameters:

provider – Explicit provider to apply. If omitted, provider inference is attempted.

Returns:

Provider-prefixed model-string instance when possible, otherwise the original value.

without_provider() str[source]

Return only the bare model name.

Returns:

Unprefixed model name.

canonical() Self[source]

Return the canonical model string.

Returns:

Provider-prefixed model string when the provider can be inferred, otherwise the original string.

as_langchain() str[source]

Return the string in LangChain-style provider:model form.

Returns:

LangChain-style model string when possible.

as_langchain_model_string() Self[source]

Return a LangChain-style typed model string.

Returns:

Canonical model string using provider:model when possible.

as_litellm() str[source]

Return the string in LiteLLM-style provider/model form.

Returns:

LiteLLM-style model string when the provider is known, otherwise the bare model name.

__str__() str[source]

Return the raw model string.