diff --git a/adapter/claude/chat.go b/adapter/claude/chat.go index 93f1df6..be6735a 100644 --- a/adapter/claude/chat.go +++ b/adapter/claude/chat.go @@ -54,12 +54,16 @@ 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 { + if message.Role == globals.System { + continue + } + // if is first message, set it to user message if !start { start = true @@ -70,11 +74,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