mirror of
https://github.com/linux-do/new-api.git
synced 2025-12-27 09:05:57 +08:00
feat: 初步重构
This commit is contained in:
57
relay/channel/adapter.go
Normal file
57
relay/channel/adapter.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package channel
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"io"
|
||||
"net/http"
|
||||
"one-api/dto"
|
||||
"one-api/relay/channel/ali"
|
||||
"one-api/relay/channel/baidu"
|
||||
"one-api/relay/channel/claude"
|
||||
"one-api/relay/channel/gemini"
|
||||
"one-api/relay/channel/openai"
|
||||
"one-api/relay/channel/palm"
|
||||
"one-api/relay/channel/tencent"
|
||||
"one-api/relay/channel/xunfei"
|
||||
"one-api/relay/channel/zhipu"
|
||||
relaycommon "one-api/relay/common"
|
||||
"one-api/relay/constant"
|
||||
)
|
||||
|
||||
type Adaptor interface {
|
||||
// Init IsStream bool
|
||||
Init(info *relaycommon.RelayInfo, request dto.GeneralOpenAIRequest)
|
||||
GetRequestURL(info *relaycommon.RelayInfo) (string, error)
|
||||
SetupRequestHeader(c *gin.Context, req *http.Request, info *relaycommon.RelayInfo) error
|
||||
ConvertRequest(c *gin.Context, relayMode int, request *dto.GeneralOpenAIRequest) (any, error)
|
||||
DoRequest(c *gin.Context, info *relaycommon.RelayInfo, requestBody io.Reader) (*http.Response, error)
|
||||
DoResponse(c *gin.Context, resp *http.Response, info *relaycommon.RelayInfo) (usage *dto.Usage, err *dto.OpenAIErrorWithStatusCode)
|
||||
GetModelList() []string
|
||||
GetChannelName() string
|
||||
}
|
||||
|
||||
func GetAdaptor(apiType int) Adaptor {
|
||||
switch apiType {
|
||||
//case constant.APITypeAIProxyLibrary:
|
||||
// return &aiproxy.Adaptor{}
|
||||
case constant.APITypeAli:
|
||||
return &ali.Adaptor{}
|
||||
case constant.APITypeAnthropic:
|
||||
return &claude.Adaptor{}
|
||||
case constant.APITypeBaidu:
|
||||
return &baidu.Adaptor{}
|
||||
case constant.APITypeGemini:
|
||||
return &gemini.Adaptor{}
|
||||
case constant.APITypeOpenAI:
|
||||
return &openai.Adaptor{}
|
||||
case constant.APITypePaLM:
|
||||
return &palm.Adaptor{}
|
||||
case constant.APITypeTencent:
|
||||
return &tencent.Adaptor{}
|
||||
case constant.APITypeXunfei:
|
||||
return &xunfei.Adaptor{}
|
||||
case constant.APITypeZhipu:
|
||||
return &zhipu.Adaptor{}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user