fix: anthropic system prompt not working (#2885)

This commit is contained in:
Su Yang 2024-03-19 15:50:02 +08:00 committed by GitHub
parent 507aa6d949
commit 2dee8a25d5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -342,12 +342,20 @@ class AnthropicLargeLanguageModel(LargeLanguageModel):
Convert prompt messages to dict list and system
"""
system = ""
prompt_message_dicts = []
first_loop = True
for message in prompt_messages:
if isinstance(message, SystemPromptMessage):
system += message.content + ("\n" if not system else "")
else:
message.content=message.content.strip()
if first_loop:
system=message.content
first_loop=False
else:
system+="\n"
system+=message.content
prompt_message_dicts = []
for message in prompt_messages:
if not isinstance(message, SystemPromptMessage):
prompt_message_dicts.append(self._convert_prompt_message_to_dict(message))
return system, prompt_message_dicts