From ec4fd57ea6a7fdf1d96b0b3efa4d9e41a7a474d7 Mon Sep 17 00:00:00 2001 From: "Laisky.Cai" Date: Tue, 16 Jul 2024 01:22:12 +0000 Subject: [PATCH] fix: Implement improved headers for anthropic API requests. Here is the summary of the commit in imperative tone and bullet points: - Update relay/adaptor/anthropic/adaptor.go to set default values for `anthropic-version` and `anthropic-beta` headers. - Refine condition for setting `anthropic-beta` header based on specific model types. --- relay/adaptor/anthropic/adaptor.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/relay/adaptor/anthropic/adaptor.go b/relay/adaptor/anthropic/adaptor.go index 07efb3c7..60a1eccc 100644 --- a/relay/adaptor/anthropic/adaptor.go +++ b/relay/adaptor/anthropic/adaptor.go @@ -4,6 +4,7 @@ import ( "fmt" "io" "net/http" + "strings" "github.com/Laisky/errors/v2" "github.com/gin-gonic/gin" @@ -34,6 +35,13 @@ func (a *Adaptor) SetupRequestHeader(c *gin.Context, req *http.Request, meta *me } req.Header.Set("anthropic-version", anthropicVersion) req.Header.Set("anthropic-beta", "messages-2023-12-15") + + // https://x.com/alexalbert__/status/1812921642143900036 + // claude-3-5-sonnet can support 8k context + if strings.HasPrefix(meta.ActualModelName, "claude-3-5-sonnet") { + req.Header.Set("anthropic-beta", "max-tokens-3-5-sonnet-2024-07-15") + } + return nil }