From 0d70ec46ded3ce4a9f9f2b247b002d332de36be7 Mon Sep 17 00:00:00 2001 From: Steve Dudenhoeffer Date: Thu, 9 Jan 2025 01:18:11 -0500 Subject: [PATCH] Fix role setting for assistant-sent images in Anthropic API Anthropic API does not support assistants sending images directly, so the role is adjusted to "user" for such messages. This ensures compatibility and prevents errors when processing image messages. --- anthropic.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/anthropic.go b/anthropic.go index 784cc32..b2982dc 100644 --- a/anthropic.go +++ b/anthropic.go @@ -71,6 +71,11 @@ func (a anthropic) requestToAnthropicRequest(req Request) anth.MessagesRequest { } for _, img := range msg.Images { + // anthropic doesn't allow the assistant to send images, so we need to say it's from the user + if m.Role == anth.RoleAssistant { + m.Role = anth.RoleUser + } + if img.Base64 != "" { m.Content = append(m.Content, anth.NewImageMessageContent( anth.NewMessageContentSource(