mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-11 22:51:28 +00:00
fix(auto_router): handle content-block message format in routing (#25370)
When a chat message uses the OpenAI multi-modal content format
(content: [{"type": "text", "text": "..."}]) instead of a plain
string, message_content becomes a list. Passing a list as the
embedding input causes providers that only accept strings or arrays
of strings (e.g. LM Studio, OpenRouter) to return HTTP 400.
Extract text parts from content blocks before passing to the
semantic router so any embedding backend receives a plain string.
Fixes: https://github.com/BerriAI/litellm/issues/19016
Co-authored-by: stelloxx <stelloxx@users.noreply.github.com>
This commit is contained in:
parent
2dac54b732
commit
2964761e0c
1 changed files with 9 additions and 1 deletions
|
|
@ -120,7 +120,15 @@ class AutoRouter(CustomLogger):
|
|||
)
|
||||
|
||||
user_message: Dict[str, str] = messages[-1]
|
||||
message_content: str = user_message.get("content", "")
|
||||
message_content: Union[str, list] = user_message.get("content", "")
|
||||
# Handle content as a list of content blocks (OpenAI multi-modal format).
|
||||
# Embedding models expect a plain string; extract text parts when needed.
|
||||
if isinstance(message_content, list):
|
||||
message_content = " ".join(
|
||||
block.get("text", "")
|
||||
for block in message_content
|
||||
if isinstance(block, dict) and block.get("type") == "text"
|
||||
)
|
||||
route_choice: Optional[Union[RouteChoice, List[RouteChoice]]] = self.routelayer(
|
||||
text=message_content
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue