fix(llm): bedrock throw errors if content contains empty string (#4935)

This commit is contained in:
Xingyao Wang
2024-11-12 09:53:22 -06:00
committed by GitHub
parent b54724ac3f
commit 910b283ac2
2 changed files with 10 additions and 1 deletions

View File

@@ -98,6 +98,13 @@ class Message(BaseModel):
content.extend(d)
ret: dict = {'content': content, 'role': self.role}
# pop content if it's empty
if not content or (
len(content) == 1
and content[0]['type'] == 'text'
and content[0]['text'] == ''
):
ret.pop('content')
if role_tool_with_prompt_caching:
ret['cache_control'] = {'type': 'ephemeral'}