Compare commits

...

2 Commits

Author SHA1 Message Date
Happy-Engineer
8195831e70
Merge 3fd1f844ec into 1f87676d52 2024-11-15 18:08:28 +08:00
郭卫东
3fd1f844ec fix: avoid got at least one message error when there was no user message for Claude llm 2024-09-27 09:29:01 +08:00

View File

@ -538,6 +538,10 @@ class AnthropicLargeLanguageModel(LargeLanguageModel):
else: else:
raise ValueError(f"Got unknown type {message}") raise ValueError(f"Got unknown type {message}")
# if no user message, add a system message as the user message to avoid at least one message error
if not prompt_message_dicts:
prompt_message_dicts.append({"role": "user", "content": system})
return system, prompt_message_dicts return system, prompt_message_dicts
def _convert_one_message_to_text(self, message: PromptMessage) -> str: def _convert_one_message_to_text(self, message: PromptMessage) -> str: