mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-06-16 17:55:26 -04:00
fix: Anthropic responses with multiple text blocks lose all but the first (#1255)
* fix: concatenate all Anthropic text blocks, not just the first * test: Anthropic response parsing concatenates text blocks
This commit is contained in:
+12
-5
@@ -562,11 +562,18 @@ def _build_anthropic_headers(headers):
|
||||
return h
|
||||
|
||||
def _parse_anthropic_response(data: dict) -> str:
|
||||
"""Extract text from Anthropic response."""
|
||||
for block in data.get("content", []):
|
||||
if block.get("type") == "text":
|
||||
return block.get("text", "")
|
||||
return ""
|
||||
"""Extract text from an Anthropic response.
|
||||
|
||||
The Messages API `content` is an array that can hold more than one text
|
||||
block (e.g. text split around a tool_use block, or citation-segmented
|
||||
text). Concatenate them all instead of returning only the first, which
|
||||
silently dropped the rest of the reply.
|
||||
"""
|
||||
return "".join(
|
||||
block.get("text", "")
|
||||
for block in data.get("content", [])
|
||||
if isinstance(block, dict) and block.get("type") == "text"
|
||||
)
|
||||
|
||||
|
||||
def _sanitize_llm_messages(messages: List[Dict]) -> List[Dict]:
|
||||
|
||||
Reference in New Issue
Block a user