From 6333cf43a8ac62618592a7066978cfabae4e50ba Mon Sep 17 00:00:00 2001 From: takatost Date: Wed, 3 Jan 2024 22:12:14 +0800 Subject: [PATCH] fix: anthropic messages empty raise errors (#1893) --- api/core/model_runtime/model_providers/anthropic/llm/llm.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/api/core/model_runtime/model_providers/anthropic/llm/llm.py b/api/core/model_runtime/model_providers/anthropic/llm/llm.py index 564e2c6b3..425f3e539 100644 --- a/api/core/model_runtime/model_providers/anthropic/llm/llm.py +++ b/api/core/model_runtime/model_providers/anthropic/llm/llm.py @@ -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=""))