From 1b161f92645244ea36d21c9961ad71d9e65e51d7 Mon Sep 17 00:00:00 2001 From: tangxingyu Date: Sat, 30 Mar 2024 23:05:40 +0800 Subject: [PATCH 1/2] fix claude system message --- adapter/claude/chat.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/adapter/claude/chat.go b/adapter/claude/chat.go index 93f1df6..4472ff0 100644 --- a/adapter/claude/chat.go +++ b/adapter/claude/chat.go @@ -60,6 +60,12 @@ func (c *ChatInstance) ConvertMessages(props *adaptercommon.ChatProps) []globals result := make([]globals.Message, 0) for _, message := range props.Message { + + // System message is set when constructing Chatbody + if message.Role == globals.System { + continue + } + // if is first message, set it to user message if !start { start = true @@ -70,11 +76,6 @@ func (c *ChatInstance) ConvertMessages(props *adaptercommon.ChatProps) []globals continue } - // if is system message, set it to user message - if message.Role == globals.System { - continue - } - // anthropic api does not allow multi-same role messages if len(result) > 0 && result[len(result)-1].Role == message.Role { result[len(result)-1].Content += "\n" + message.Content From 6fea649f7c0673745deb9a286dec3465eaaa50e3 Mon Sep 17 00:00:00 2001 From: Minghan Zhang <112773885+zmh-program@users.noreply.github.com> Date: Sat, 30 Mar 2024 23:11:25 +0800 Subject: [PATCH 2/2] chore: update claude format --- adapter/claude/chat.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/adapter/claude/chat.go b/adapter/claude/chat.go index 4472ff0..be6735a 100644 --- a/adapter/claude/chat.go +++ b/adapter/claude/chat.go @@ -54,14 +54,12 @@ func (c *ChatInstance) GetTokens(props *adaptercommon.ChatProps) int { } func (c *ChatInstance) ConvertMessages(props *adaptercommon.ChatProps) []globals.Message { - // anthropic api: top message must be user message, system message is not allowed + // anthropic api: top message must be user message, only `user` and `assistant` role messages are allowd start := false result := make([]globals.Message, 0) for _, message := range props.Message { - - // System message is set when constructing Chatbody if message.Role == globals.System { continue }