|
|
|
@@ -3,17 +3,17 @@ package deepseek
|
|
|
|
|
import (
|
|
|
|
|
"errors"
|
|
|
|
|
"fmt"
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
|
"io"
|
|
|
|
|
"net/http"
|
|
|
|
|
"one-api/dto"
|
|
|
|
|
"one-api/relay/channel"
|
|
|
|
|
"one-api/relay/channel/claude"
|
|
|
|
|
"one-api/relay/channel/openai"
|
|
|
|
|
relaycommon "one-api/relay/common"
|
|
|
|
|
"one-api/relay/constant"
|
|
|
|
|
"one-api/types"
|
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type Adaptor struct {
|
|
|
|
@@ -25,7 +25,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) {
|
|
|
|
|
adaptor := openai.Adaptor{}
|
|
|
|
|
adaptor := claude.Adaptor{}
|
|
|
|
|
return adaptor.ConvertClaudeRequest(c, info, req)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -44,14 +44,19 @@ func (a *Adaptor) Init(info *relaycommon.RelayInfo) {
|
|
|
|
|
|
|
|
|
|
func (a *Adaptor) GetRequestURL(info *relaycommon.RelayInfo) (string, error) {
|
|
|
|
|
fimBaseUrl := info.ChannelBaseUrl
|
|
|
|
|
if !strings.HasSuffix(info.ChannelBaseUrl, "/beta") {
|
|
|
|
|
fimBaseUrl += "/beta"
|
|
|
|
|
}
|
|
|
|
|
switch info.RelayMode {
|
|
|
|
|
case constant.RelayModeCompletions:
|
|
|
|
|
return fmt.Sprintf("%s/completions", fimBaseUrl), nil
|
|
|
|
|
switch info.RelayFormat {
|
|
|
|
|
case types.RelayFormatClaude:
|
|
|
|
|
return fmt.Sprintf("%s/anthropic/v1/messages", info.ChannelBaseUrl), nil
|
|
|
|
|
default:
|
|
|
|
|
return fmt.Sprintf("%s/v1/chat/completions", info.ChannelBaseUrl), nil
|
|
|
|
|
if !strings.HasSuffix(info.ChannelBaseUrl, "/beta") {
|
|
|
|
|
fimBaseUrl += "/beta"
|
|
|
|
|
}
|
|
|
|
|
switch info.RelayMode {
|
|
|
|
|
case constant.RelayModeCompletions:
|
|
|
|
|
return fmt.Sprintf("%s/completions", fimBaseUrl), nil
|
|
|
|
|
default:
|
|
|
|
|
return fmt.Sprintf("%s/v1/chat/completions", info.ChannelBaseUrl), nil
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -87,12 +92,17 @@ 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) {
|
|
|
|
|
if info.IsStream {
|
|
|
|
|
usage, err = openai.OaiStreamHandler(c, info, resp)
|
|
|
|
|
} else {
|
|
|
|
|
usage, err = openai.OpenaiHandler(c, info, resp)
|
|
|
|
|
switch info.RelayFormat {
|
|
|
|
|
case types.RelayFormatClaude:
|
|
|
|
|
if info.IsStream {
|
|
|
|
|
return claude.ClaudeStreamHandler(c, resp, info, claude.RequestModeMessage)
|
|
|
|
|
} else {
|
|
|
|
|
return claude.ClaudeHandler(c, resp, info, claude.RequestModeMessage)
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
adaptor := openai.Adaptor{}
|
|
|
|
|
return adaptor.DoResponse(c, resp, info)
|
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (a *Adaptor) GetModelList() []string {
|
|
|
|
|