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:
2026-04-09 19:26:55 +00:00
parent 01b18dcf32
commit a6b5544674
2 changed files with 94 additions and 3 deletions

View File

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