From 3fd1f844ec16964228971643460ac6e23126de71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=AD=E5=8D=AB=E4=B8=9C?= Date: Thu, 26 Sep 2024 13:50:00 +0800 Subject: [PATCH] fix: avoid got at least one message error when there was no user message for Claude llm --- api/core/model_runtime/model_providers/anthropic/llm/llm.py | 4 ++++ 1 file changed, 4 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 46e1b415b8..70fe9e7e6a 100644 --- a/api/core/model_runtime/model_providers/anthropic/llm/llm.py +++ b/api/core/model_runtime/model_providers/anthropic/llm/llm.py @@ -538,6 +538,10 @@ class AnthropicLargeLanguageModel(LargeLanguageModel): else: 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 def _convert_one_message_to_text(self, message: PromptMessage) -> str: