浏览代码

fix: anthropic messages empty raise errors (#1893)

takatost 1 年之前
父节点
当前提交
6333cf43a8
共有 1 个文件被更改,包括 3 次插入0 次删除
  1. 3 0
      api/core/model_runtime/model_providers/anthropic/llm/llm.py

+ 3 - 0
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=""))