enforce anthropic's required alternating user/assistant roles
This commit is contained in:
parent
09447b0424
commit
8e1001b5b7
12
anthropic.go
12
anthropic.go
@ -65,7 +65,17 @@ func (a anthropic) requestToAnthropicRequest(req Request) anth.MessagesRequest {
|
|||||||
Data: msg.ImageBase64,
|
Data: msg.ImageBase64,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
msgs = append(msgs, m)
|
|
||||||
|
// if this has the same role as the previous message, we can append it to the previous message
|
||||||
|
// as anthropic expects alternating assistant and user roles
|
||||||
|
|
||||||
|
if len(msgs) > 0 && msgs[len(msgs)-1].Role == role {
|
||||||
|
m2 := &msgs[len(msgs)-1]
|
||||||
|
|
||||||
|
m2.Content = append(m2.Content, m.Content...)
|
||||||
|
} else {
|
||||||
|
msgs = append(msgs, m)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user