From a8792319a80aeba8f5fdab684450c4f29e99f663 Mon Sep 17 00:00:00 2001 From: Luciano Scarpulla Date: Wed, 6 Nov 2024 09:00:27 +0800 Subject: [PATCH 1/2] add sys prompt handling --- simplemind/providers/anthropic.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/simplemind/providers/anthropic.py b/simplemind/providers/anthropic.py index 9adc769..a1c089b 100644 --- a/simplemind/providers/anthropic.py +++ b/simplemind/providers/anthropic.py @@ -55,9 +55,15 @@ class Anthropic(BaseProvider): """Send a conversation to the Anthropic API.""" from ..models import Message - system_prompt = filter( - lambda msg: msg.role == "system", conversation.messages - ) + system_messages = [ + msg for msg in conversation.messages if msg.role == "system" + ] + if len(system_messages) > 1: + logger.warning( + "Multiple system messages found. Using the first one." + ) + + system_prompt = system_messages[0] if system_messages else None messages = [ {"role": msg.role, "content": msg.text} @@ -66,7 +72,7 @@ class Anthropic(BaseProvider): ] response = self.client.messages.create( - system=next(system_prompt, None), + system=system_prompt.text, model=conversation.llm_model or self.DEFAULT_MODEL, messages=messages, **{**self.DEFAULT_KWARGS, **kwargs}, From 2848e86dce5d75d6452573ac39a3d3b3070b646c Mon Sep 17 00:00:00 2001 From: Luciano <66913960+lucianosrp@users.noreply.github.com> Date: Wed, 6 Nov 2024 02:25:07 +0100 Subject: [PATCH 2/2] Update simplemind/providers/anthropic.py Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- simplemind/providers/anthropic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simplemind/providers/anthropic.py b/simplemind/providers/anthropic.py index 117f27f..fbf80e8 100644 --- a/simplemind/providers/anthropic.py +++ b/simplemind/providers/anthropic.py @@ -72,7 +72,7 @@ class Anthropic(BaseProvider): ] response = self.client.messages.create( - system=system_prompt.text, + system=system_prompt.text if system_prompt else None, model=conversation.llm_model or self.DEFAULT_MODEL, messages=messages, **{**self.DEFAULT_KWARGS, **kwargs},