Skip to content

Commit

Permalink
fix: avoid got at least one message error when there was no user mess…
Browse files Browse the repository at this point in the history
…age for Claude llm
  • Loading branch information
dwgeneral committed Sep 26, 2024
1 parent a0b0809 commit cfc1169
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 @@ -538,6 +538,10 @@ def _convert_prompt_messages(self, prompt_messages: list[PromptMessage]) -> tupl
else:
raise ValueError(f"Got unknown type {message}")

# if there is no user message, add a system message as the user message to avoid the model at least one message error
if not prompt_message_dicts:
prompt_message_dicts.append({"role": "user", "content": system})

return system, prompt_message_dicts

def _convert_one_message_to_text(self, message: PromptMessage) -> str:
Expand Down

0 comments on commit cfc1169

Please sign in to comment.