Extend the destination-boundary approach from PR #87840 to synchronous, asynchronous and streaming auxiliary dispatch, including prepared MoA requests. Keep native adapter replay intact. Co-authored-by: siyoon <siyoon@friendli.ai>
21 lines
829 B
Python
21 lines
829 B
Python
"""Message hygiene at the resolved auxiliary client boundary."""
|
|
|
|
from openai import AsyncOpenAI, OpenAI
|
|
|
|
from agent.transports.chat_completions import ChatCompletionsTransport
|
|
|
|
|
|
def prepare_chat_messages(client, kwargs: dict) -> dict:
|
|
"""Sanitize actual Chat Completions SDK requests, not native adapter replay.
|
|
|
|
Auxiliary and MoA callers can retain a prepared request before the virtual
|
|
transport sanitizes its copy. The resolved SDK client identifies the wire;
|
|
native Messages/Responses adapters must retain their reasoning sidecars.
|
|
"""
|
|
if not isinstance(client, (OpenAI, AsyncOpenAI)) or "messages" not in kwargs:
|
|
return kwargs
|
|
messages = ChatCompletionsTransport().convert_messages(
|
|
kwargs["messages"], model=kwargs.get("model")
|
|
)
|
|
return {**kwargs, "messages": messages}
|