Skip to content

Commit caa058a

Browse files
Fix anthropic error code 400
1 parent 14f9914 commit caa058a

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/agentlab/llm/response_api.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,12 @@ def prepare_message(self) -> List[Message]:
187187
"content": output["content"],
188188
}
189189
]
190+
if self.role == "assistant":
191+
# Strip whitespace from assistant text responses. See anthropic error code 400.
192+
for c in output["content"]:
193+
if 'text' in c:
194+
c["text"] = c["text"].strip()
195+
190196
return [output]
191197

192198
def transform_content(self, content: ContentItem) -> ContentItem:

0 commit comments

Comments
 (0)