fix: anthropic messages empty raise errors (#1893)

This commit is contained in:
takatost 2024-01-03 22:12:14 +08:00 committed by GitHub
parent 91ee62d1ab
commit 6333cf43a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -252,6 +252,9 @@ class AnthropicLargeLanguageModel(LargeLanguageModel):
:param messages: List of PromptMessage to combine.
:return: Combined string with necessary human_prompt and ai_prompt tags.
"""
if not messages:
return ''
messages = messages.copy() # don't mutate the original list
if not isinstance(messages[-1], AssistantPromptMessage):
messages.append(AssistantPromptMessage(content=""))