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.
This commit is contained in:
Laisky.Cai 2024-07-16 01:22:12 +00:00
parent c1418df1fd
commit ec4fd57ea6

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"io" "io"
"net/http" "net/http"
"strings"
"github.com/Laisky/errors/v2" "github.com/Laisky/errors/v2"
"github.com/gin-gonic/gin" "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-version", anthropicVersion)
req.Header.Set("anthropic-beta", "messages-2023-12-15") 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 return nil
} }