|
@@ -24,11 +24,8 @@ import (
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
const (
|
|
|
- contextKeyTTSRequest = "volcengine_tts_request"
|
|
|
|
|
- contextKeyResponseFormat = "response_format"
|
|
|
|
|
- DoubaoCodingPlan = "doubao-coding-plan"
|
|
|
|
|
- DoubaoCodingPlanClaudeBaseURL = "https://ark.cn-beijing.volces.com/api/coding"
|
|
|
|
|
- DoubaoCodingPlanOpenAIBaseURL = "https://ark.cn-beijing.volces.com/api/coding/v3"
|
|
|
|
|
|
|
+ contextKeyTTSRequest = "volcengine_tts_request"
|
|
|
|
|
+ contextKeyResponseFormat = "response_format"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
type Adaptor struct {
|
|
type Adaptor struct {
|
|
@@ -40,7 +37,7 @@ func (a *Adaptor) ConvertGeminiRequest(*gin.Context, *relaycommon.RelayInfo, *dt
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func (a *Adaptor) ConvertClaudeRequest(c *gin.Context, info *relaycommon.RelayInfo, req *dto.ClaudeRequest) (any, error) {
|
|
func (a *Adaptor) ConvertClaudeRequest(c *gin.Context, info *relaycommon.RelayInfo, req *dto.ClaudeRequest) (any, error) {
|
|
|
- if info.ChannelBaseUrl == DoubaoCodingPlan {
|
|
|
|
|
|
|
+ if _, ok := channelconstant.ChannelSpecialBases[info.ChannelBaseUrl]; ok {
|
|
|
adaptor := claude.Adaptor{}
|
|
adaptor := claude.Adaptor{}
|
|
|
return adaptor.ConvertClaudeRequest(c, info, req)
|
|
return adaptor.ConvertClaudeRequest(c, info, req)
|
|
|
}
|
|
}
|
|
@@ -243,11 +240,12 @@ func (a *Adaptor) GetRequestURL(info *relaycommon.RelayInfo) (string, error) {
|
|
|
if baseUrl == "" {
|
|
if baseUrl == "" {
|
|
|
baseUrl = channelconstant.ChannelBaseURLs[channelconstant.ChannelTypeVolcEngine]
|
|
baseUrl = channelconstant.ChannelBaseURLs[channelconstant.ChannelTypeVolcEngine]
|
|
|
}
|
|
}
|
|
|
|
|
+ specialPlan, hasSpecialPlan := channelconstant.ChannelSpecialBases[baseUrl]
|
|
|
|
|
|
|
|
switch info.RelayFormat {
|
|
switch info.RelayFormat {
|
|
|
case types.RelayFormatClaude:
|
|
case types.RelayFormatClaude:
|
|
|
- if baseUrl == DoubaoCodingPlan {
|
|
|
|
|
- return fmt.Sprintf("%s/v1/messages", DoubaoCodingPlanClaudeBaseURL), nil
|
|
|
|
|
|
|
+ if hasSpecialPlan && specialPlan.ClaudeBaseURL != "" {
|
|
|
|
|
+ return fmt.Sprintf("%s/v1/messages", specialPlan.ClaudeBaseURL), nil
|
|
|
}
|
|
}
|
|
|
if strings.HasPrefix(info.UpstreamModelName, "bot") {
|
|
if strings.HasPrefix(info.UpstreamModelName, "bot") {
|
|
|
return fmt.Sprintf("%s/api/v3/bots/chat/completions", baseUrl), nil
|
|
return fmt.Sprintf("%s/api/v3/bots/chat/completions", baseUrl), nil
|
|
@@ -256,8 +254,8 @@ func (a *Adaptor) GetRequestURL(info *relaycommon.RelayInfo) (string, error) {
|
|
|
default:
|
|
default:
|
|
|
switch info.RelayMode {
|
|
switch info.RelayMode {
|
|
|
case constant.RelayModeChatCompletions:
|
|
case constant.RelayModeChatCompletions:
|
|
|
- if baseUrl == DoubaoCodingPlan {
|
|
|
|
|
- return fmt.Sprintf("%s/chat/completions", DoubaoCodingPlanOpenAIBaseURL), nil
|
|
|
|
|
|
|
+ if hasSpecialPlan && specialPlan.OpenAIBaseURL != "" {
|
|
|
|
|
+ return fmt.Sprintf("%s/chat/completions", specialPlan.OpenAIBaseURL), nil
|
|
|
}
|
|
}
|
|
|
if strings.HasPrefix(info.UpstreamModelName, "bot") {
|
|
if strings.HasPrefix(info.UpstreamModelName, "bot") {
|
|
|
return fmt.Sprintf("%s/api/v3/bots/chat/completions", baseUrl), nil
|
|
return fmt.Sprintf("%s/api/v3/bots/chat/completions", baseUrl), nil
|
|
@@ -345,11 +343,13 @@ func (a *Adaptor) DoRequest(c *gin.Context, info *relaycommon.RelayInfo, request
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func (a *Adaptor) DoResponse(c *gin.Context, resp *http.Response, info *relaycommon.RelayInfo) (usage any, err *types.NewAPIError) {
|
|
func (a *Adaptor) DoResponse(c *gin.Context, resp *http.Response, info *relaycommon.RelayInfo) (usage any, err *types.NewAPIError) {
|
|
|
- if info.RelayFormat == types.RelayFormatClaude && info.ChannelBaseUrl == DoubaoCodingPlan {
|
|
|
|
|
- if info.IsStream {
|
|
|
|
|
- return claude.ClaudeStreamHandler(c, resp, info, claude.RequestModeMessage)
|
|
|
|
|
|
|
+ if info.RelayFormat == types.RelayFormatClaude {
|
|
|
|
|
+ if _, ok := channelconstant.ChannelSpecialBases[info.ChannelBaseUrl]; ok {
|
|
|
|
|
+ if info.IsStream {
|
|
|
|
|
+ return claude.ClaudeStreamHandler(c, resp, info, claude.RequestModeMessage)
|
|
|
|
|
+ }
|
|
|
|
|
+ return claude.ClaudeHandler(c, resp, info, claude.RequestModeMessage)
|
|
|
}
|
|
}
|
|
|
- return claude.ClaudeHandler(c, resp, info, claude.RequestModeMessage)
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if info.RelayMode == constant.RelayModeAudioSpeech {
|
|
if info.RelayMode == constant.RelayModeAudioSpeech {
|