Skip to content

Commit

Permalink
fix: claude can not handle empty string (#11238)
Browse files Browse the repository at this point in the history
Signed-off-by: yihong0618 <[email protected]>
  • Loading branch information
yihong0618 authored Dec 2, 2024
1 parent 1d8385f commit 02572e8
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions api/core/model_runtime/model_providers/anthropic/llm/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,10 @@ def _convert_prompt_messages(self, prompt_messages: Sequence[PromptMessage]) ->
if isinstance(message, UserPromptMessage):
message = cast(UserPromptMessage, message)
if isinstance(message.content, str):
# handle empty user prompt see #10013 #10520
# responses, ignore user prompts containing only whitespace, the Claude API can't handle it.
if not message.content.strip():
continue
message_dict = {"role": "user", "content": message.content}
prompt_message_dicts.append(message_dict)
else:
Expand Down

0 comments on commit 02572e8

Please sign in to comment.