mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-04-28 22:18:38 +00:00
Merge pull request #1984 from RedwindA/feat/claude-fetchModels
feat: add GetClaudeAuthHeader function and update FetchUpstreamModels to support Anthropic channel type
This commit is contained in:
@@ -127,6 +127,14 @@ func GetAuthHeader(token string) http.Header {
|
|||||||
return h
|
return h
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetClaudeAuthHeader get claude auth header
|
||||||
|
func GetClaudeAuthHeader(token string) http.Header {
|
||||||
|
h := http.Header{}
|
||||||
|
h.Add("x-api-key", token)
|
||||||
|
h.Add("anthropic-version", "2023-06-01")
|
||||||
|
return h
|
||||||
|
}
|
||||||
|
|
||||||
func GetResponseBody(method, url string, channel *model.Channel, headers http.Header) ([]byte, error) {
|
func GetResponseBody(method, url string, channel *model.Channel, headers http.Header) ([]byte, error) {
|
||||||
req, err := http.NewRequest(method, url, nil)
|
req, err := http.NewRequest(method, url, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -198,9 +198,10 @@ func FetchUpstreamModels(c *gin.Context) {
|
|||||||
// 获取响应体 - 根据渠道类型决定是否添加 AuthHeader
|
// 获取响应体 - 根据渠道类型决定是否添加 AuthHeader
|
||||||
var body []byte
|
var body []byte
|
||||||
key := strings.Split(channel.Key, "\n")[0]
|
key := strings.Split(channel.Key, "\n")[0]
|
||||||
if channel.Type == constant.ChannelTypeGemini {
|
switch channel.Type {
|
||||||
body, err = GetResponseBody("GET", url, channel, GetAuthHeader(key)) // Use AuthHeader since Gemini now forces it
|
case constant.ChannelTypeAnthropic:
|
||||||
} else {
|
body, err = GetResponseBody("GET", url, channel, GetClaudeAuthHeader(key))
|
||||||
|
default:
|
||||||
body, err = GetResponseBody("GET", url, channel, GetAuthHeader(key))
|
body, err = GetResponseBody("GET", url, channel, GetAuthHeader(key))
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user