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.
This commit is contained in:
Steve Dudenhoeffer 2025-01-09 01:18:11 -05:00
parent 6e2b5a33c0
commit 0d70ec46de

View File

@ -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(