refactor(adaptor): extract common header operations into a separate function
This commit is contained in:
@@ -7,7 +7,6 @@ import (
|
|||||||
"one-api/dto"
|
"one-api/dto"
|
||||||
"one-api/relay/channel/claude"
|
"one-api/relay/channel/claude"
|
||||||
relaycommon "one-api/relay/common"
|
relaycommon "one-api/relay/common"
|
||||||
"one-api/setting/model_setting"
|
|
||||||
"one-api/types"
|
"one-api/types"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
@@ -52,11 +51,7 @@ func (a *Adaptor) GetRequestURL(info *relaycommon.RelayInfo) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *Adaptor) SetupRequestHeader(c *gin.Context, req *http.Header, info *relaycommon.RelayInfo) error {
|
func (a *Adaptor) SetupRequestHeader(c *gin.Context, req *http.Header, info *relaycommon.RelayInfo) error {
|
||||||
anthropicBeta := c.Request.Header.Get("anthropic-beta")
|
claude.CommonClaudeHeadersOperation(c, req, info)
|
||||||
if anthropicBeta != "" {
|
|
||||||
req.Set("anthropic-beta", anthropicBeta)
|
|
||||||
}
|
|
||||||
model_setting.GetClaudeSettings().WriteHeaders(info.OriginModelName, req)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -64,6 +64,15 @@ func (a *Adaptor) GetRequestURL(info *relaycommon.RelayInfo) (string, error) {
|
|||||||
return baseURL, nil
|
return baseURL, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CommonClaudeHeadersOperation(c *gin.Context, req *http.Header, info *relaycommon.RelayInfo) {
|
||||||
|
// common headers operation
|
||||||
|
anthropicBeta := c.Request.Header.Get("anthropic-beta")
|
||||||
|
if anthropicBeta != "" {
|
||||||
|
req.Set("anthropic-beta", anthropicBeta)
|
||||||
|
}
|
||||||
|
model_setting.GetClaudeSettings().WriteHeaders(info.OriginModelName, req)
|
||||||
|
}
|
||||||
|
|
||||||
func (a *Adaptor) SetupRequestHeader(c *gin.Context, req *http.Header, info *relaycommon.RelayInfo) error {
|
func (a *Adaptor) SetupRequestHeader(c *gin.Context, req *http.Header, info *relaycommon.RelayInfo) error {
|
||||||
channel.SetupApiRequestHeader(info, c, req)
|
channel.SetupApiRequestHeader(info, c, req)
|
||||||
req.Set("x-api-key", info.ApiKey)
|
req.Set("x-api-key", info.ApiKey)
|
||||||
@@ -72,11 +81,7 @@ func (a *Adaptor) SetupRequestHeader(c *gin.Context, req *http.Header, info *rel
|
|||||||
anthropicVersion = "2023-06-01"
|
anthropicVersion = "2023-06-01"
|
||||||
}
|
}
|
||||||
req.Set("anthropic-version", anthropicVersion)
|
req.Set("anthropic-version", anthropicVersion)
|
||||||
anthropicBeta := c.Request.Header.Get("anthropic-beta")
|
CommonClaudeHeadersOperation(c, req, info)
|
||||||
if anthropicBeta != "" {
|
|
||||||
req.Set("anthropic-beta", anthropicBeta)
|
|
||||||
}
|
|
||||||
model_setting.GetClaudeSettings().WriteHeaders(info.OriginModelName, req)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user