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:
parent
6e2b5a33c0
commit
0d70ec46de
@ -71,6 +71,11 @@ func (a anthropic) requestToAnthropicRequest(req Request) anth.MessagesRequest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, img := range msg.Images {
|
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 != "" {
|
if img.Base64 != "" {
|
||||||
m.Content = append(m.Content, anth.NewImageMessageContent(
|
m.Content = append(m.Content, anth.NewImageMessageContent(
|
||||||
anth.NewMessageContentSource(
|
anth.NewMessageContentSource(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user