Skip to main content

Functions

FUNC extract_model_tool_requests

extract_model_tool_requests(tools: dict[str, Callable], response: dict[str, Any]) -> dict[str, ModelToolCall] | None
Extracts tool calls from the dict representation of an OpenAI-like chat response object.

FUNC chat_completion_delta_merge

chat_completion_delta_merge(chunks: list[dict], force_all_tool_calls_separate: bool = False) -> dict
Takes a list of deltas from ChatCompletionChunks and merges them into a single dict representing the ChatCompletion choice. Args:
  • chunks: the list of dicts that represent the message deltas
  • force_all_tool_calls_separate: if True, tool calls in separate message deltas will not be merged (even if their index values are the same); use when providers do not return the correct index value for tool calls. If using this option, all tool calls must be fully populated in a single delta since they won’t be merged.

FUNC message_to_openai_message

message_to_openai_message(msg: Message)
Serializes a mellea Message object to the message format required by OpenAI compatible api providers.

FUNC messages_to_docs

messages_to_docs(msgs: list[Message]) -> list[dict[str, str]]
Extracts the docs from a list of messages.