refactor(v2/anthropic): use MultiSystem for system prompts
Switches buildRequest to emit anthReq.MultiSystem instead of anthReq.System whenever a system message is present. Upstream's MarshalJSON prefers MultiSystem when non-empty, so the wire format is unchanged for requests without cache_control. This refactor is a prerequisite for attaching cache_control markers to system parts in the next commit. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -82,13 +82,14 @@ func (p *Provider) buildRequest(req provider.Request) anth.MessagesRequest {
|
||||
}
|
||||
|
||||
var msgs []anth.Message
|
||||
var systemText string
|
||||
|
||||
for _, msg := range req.Messages {
|
||||
if msg.Role == "system" {
|
||||
if len(anthReq.System) > 0 {
|
||||
anthReq.System += "\n"
|
||||
if len(systemText) > 0 {
|
||||
systemText += "\n"
|
||||
}
|
||||
anthReq.System += msg.Content
|
||||
systemText += msg.Content
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -224,6 +225,12 @@ func (p *Provider) buildRequest(req provider.Request) anth.MessagesRequest {
|
||||
|
||||
anthReq.Messages = msgs
|
||||
|
||||
if systemText != "" {
|
||||
anthReq.MultiSystem = []anth.MessageSystemPart{
|
||||
anth.NewSystemMessagePart(systemText),
|
||||
}
|
||||
}
|
||||
|
||||
if req.Temperature != nil {
|
||||
f := float32(*req.Temperature)
|
||||
anthReq.Temperature = &f
|
||||
|
||||
Reference in New Issue
Block a user