ooai_llm.profiles¶
Serializable chat-model profiles and runtime wrapper.
- Purpose:
Provide a durable Pydantic profile that can be checked into configuration and used to create LangChain chat models through the existing factory surface. The
LLMruntime owns one profile, lazily builds the runnable, and records observed usage/cost metadata after calls.
Attributes¶
Classes¶
Serializable cache policy for a chat-model profile. |
|
Resolved model/profile metadata without constructing a chat model. |
|
Serializable configuration for creating a LangChain chat model. |
|
Stateful runtime wrapper around a serializable |
Module Contents¶
- class ooai_llm.profiles.CacheKeyPolicy(/, **data: Any)[source]¶
Bases:
pydantic.BaseModelSerializable cache policy for a chat-model profile.
- model_config[source]¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- backend: CacheBackendName | None = None[source]¶
- class ooai_llm.profiles.ChatModelProfileResolution(/, **data: Any)[source]¶
Bases:
pydantic.BaseModelResolved model/profile metadata without constructing a chat model.
- model_config[source]¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- metadata: ooai_llm.metadata.ModelInfo[source]¶
- reasoning: ooai_llm.reasoning.ReasoningResolution | None = None[source]¶
- class ooai_llm.profiles.ChatModelProfile(/, **data: Any)[source]¶
Bases:
pydantic.BaseModelSerializable configuration for creating a LangChain chat model.
- model_config[source]¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- alias: ooai_llm.settings.ModelAliasName | None = None[source]¶
- provider: str | ooai_llm.providers.Provider | None = None[source]¶
- preset: ooai_llm.settings.ModelPresetName = 'default'[source]¶
- reasoning: ooai_llm.reasoning.ReasoningInput = None[source]¶
- cache: CacheKeyPolicy | bool | None = None[source]¶
- classmethod from_json(text: str) ChatModelProfile[source]¶
Deserialize a profile from JSON text.
- create_llm(*, settings: ooai_llm.settings.AppSettings | None = None, **kwargs: Any) Any[source]¶
Create a LangChain chat model from this profile.
- create_bundle(*, settings: ooai_llm.settings.AppSettings | None = None, messages: Any = None, tools: collections.abc.Sequence[Any] | None = None, **kwargs: Any) ooai_llm.metadata.CreatedLLMBundle[source]¶
Create a chat model plus resolved metadata from this profile.
- create_runtime(*, settings: ooai_llm.settings.AppSettings | None = None, recorder: ooai_llm.callbacks.UsageRecorder | None = None, budget: ooai_llm.callbacks.BudgetPolicy | None = None, id: str | None = None, uuid: str | uuid.UUID | None = None) LLM[source]¶
Create an
LLMruntime from this profile.
- create_dspy_lm(*, settings: ooai_llm.settings.AppSettings | None = None, **kwargs: Any) Any[source]¶
Create a DSPy
LMfrom this profile.DSPy is an optional dependency and is imported lazily. Install
ooai-llm[dspy]before using this helper.
- resolve(*, settings: ooai_llm.settings.AppSettings | None = None, auto_refresh_models: bool | None = None, force_model_refresh: bool | None = None) ChatModelProfileResolution[source]¶
Resolve model, metadata, reasoning, and cache key material.
- class ooai_llm.profiles.LLM(*, profile: ChatModelProfile | collections.abc.Mapping[str, Any], settings: ooai_llm.settings.AppSettings | None = None, recorder: ooai_llm.callbacks.UsageRecorder | None = None, budget: ooai_llm.callbacks.BudgetPolicy | None = None, id: str | None = None, uuid: str | uuid.UUID | None = None)[source]¶
Stateful runtime wrapper around a serializable
ChatModelProfile.- property bundle: ooai_llm.metadata.CreatedLLMBundle[source]¶
Return the lazily built bundle.
- property model: ooai_llm.types.ModelString[source]¶
Return the resolved model string.
- property metadata: ooai_llm.metadata.ModelInfo[source]¶
Return resolved model metadata.
- property usage_events: list[ooai_llm.callbacks.UsageEvent][source]¶
Return recorded usage events.
- set_profile(profile: ChatModelProfile | collections.abc.Mapping[str, Any], *, id: str | None = None) None[source]¶
Replace the profile and invalidate the cached runnable.
- refresh(*, force: bool = False) ooai_llm.metadata.CreatedLLMBundle[source]¶
Rebuild the runnable, optionally forcing model-default refresh.
- create_dspy_lm(**kwargs: Any) Any[source]¶
Create a DSPy
LMfrom this runtime’s profile and settings.The returned object is a native DSPy LM. The richer program/runnable layer belongs in
ooai-agents.
- invoke(input: Any, config: collections.abc.Mapping[str, Any] | None = None, **kwargs: Any) Any[source]¶
Invoke the underlying chat model and record observed usage.
- async ainvoke(input: Any, config: collections.abc.Mapping[str, Any] | None = None, **kwargs: Any) Any[source]¶
Async invoke the underlying chat model and record observed usage.
- batch(inputs: collections.abc.Sequence[Any], config: collections.abc.Mapping[str, Any] | None = None, **kwargs: Any) list[Any][source]¶
Batch invoke the underlying chat model and record observed usage.
- async abatch(inputs: collections.abc.Sequence[Any], config: collections.abc.Mapping[str, Any] | None = None, **kwargs: Any) list[Any][source]¶
Async batch invoke the underlying chat model and record observed usage.