ooai_llm.messages¶
Message normalization and lightweight message estimation helpers.
- Purpose:
Normalize common message inputs into both LangChain-style message objects and OpenAI/LiteLLM-style message dictionaries.
- Design:
Accept ergonomic inputs such as a bare string, a sequence of mapping objects, or an existing sequence of LangChain messages.
Convert inputs lazily so importing
ooai_llmdoes not require the full LangChain runtime until message handling is used.Keep the public surface small and provider-agnostic so the same helpers can later be reused for embeddings, tool traces, and other higher-level features.
Examples
>>> normalized = normalize_messages("hello")
>>> normalized.openai_messages[0]["role"]
'user'
>>> normalized.message_count
1
Attributes¶
Classes¶
Normalized message payload in LangChain and OpenAI-compatible forms. |
|
Optional message-derived estimate attached to model info. |
Functions¶
|
Normalize message input into LangChain and OpenAI-compatible forms. |
Module Contents¶
- type ooai_llm.messages.MessageLike = str | MessageMapping | Any[source]¶
- type ooai_llm.messages.MessagesLike = str | Sequence[MessageLike][source]¶
- class ooai_llm.messages.NormalizedMessages(/, **data: Any)[source]¶
Bases:
pydantic.BaseModelNormalized message payload in LangChain and OpenAI-compatible forms.
- Parameters:
langchain_messages – LangChain-style message objects.
openai_messages – OpenAI/LiteLLM-style message dictionaries.
- class ooai_llm.messages.MessageEstimate(/, **data: Any)[source]¶
Bases:
pydantic.BaseModelOptional message-derived estimate attached to model info.
- Parameters:
message_count – Number of normalized messages.
estimated_input_tokens – Estimated prompt/input tokens when available.
fits_context_window – Whether the estimated prompt fits the model’s context window when both values are known.
warning – Optional best-effort warning or limitation note.
- ooai_llm.messages.normalize_messages(messages: MessagesLike) NormalizedMessages[source]¶
Normalize message input into LangChain and OpenAI-compatible forms.
- Parameters:
messages – Bare prompt string, message mapping, or sequence of either.
- Returns:
Normalized message payload.