enforce anthropic's required alternating user/assistant roles
This commit is contained in:
parent
09447b0424
commit
8e1001b5b7
10
anthropic.go
10
anthropic.go
@ -65,9 +65,19 @@ func (a anthropic) requestToAnthropicRequest(req Request) anth.MessagesRequest {
|
|||||||
Data: msg.ImageBase64,
|
Data: msg.ImageBase64,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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)
|
msgs = append(msgs, m)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for _, tool := range req.Toolbox {
|
for _, tool := range req.Toolbox {
|
||||||
res.Tools = append(res.Tools, anth.ToolDefinition{
|
res.Tools = append(res.Tools, anth.ToolDefinition{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user