mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-09-19 10:06:37 +08:00
- Refactor constant definitions and organization - Clean up package level variables and functions - Introduce new `relaymode` and `apitype` packages for constant definitions - Refactor and simplify code in several packages including `openai`, `relay/channel/baidu`, `relay/util`, `relay/controller`, `relay/channeltype` - Add helper functions in `relay/channeltype` package to convert channel type constants to corresponding API type constants - Remove deprecated functions such as `ResponseText2Usage` from `relay/channel/openai/helper.go` - Modify code in `relay/util/validation.go` and related files to use new `validator.ValidateTextRequest` function - Rename `util` package to `relaymode` and update related imports in several packages
94 lines
3.1 KiB
Go
94 lines
3.1 KiB
Go
package baidu
|
|
|
|
// import (
|
|
// "github.com/Laisky/errors/v2"
|
|
// "github.com/gin-gonic/gin"
|
|
// "github.com/songquanpeng/one-api/relay/channel"
|
|
// "github.com/songquanpeng/one-api/relay/constant"
|
|
// "github.com/songquanpeng/one-api/relay/model"
|
|
// "github.com/songquanpeng/one-api/relay/util"
|
|
// "io"
|
|
// "net/http"
|
|
// )
|
|
|
|
// // type Adaptor struct {
|
|
// // }
|
|
|
|
// func (a *Adaptor) Init(meta *util.RelayMeta) {
|
|
|
|
// }
|
|
|
|
// func (a *Adaptor) GetRequestURL(meta *util.RelayMeta) (string, error) {
|
|
// // https://cloud.baidu.com/doc/WENXINWORKSHOP/s/clntwmv7t
|
|
// var fullRequestURL string
|
|
// switch meta.ActualModelName {
|
|
// case "ERNIE-Bot-4":
|
|
// fullRequestURL = "https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/completions_pro"
|
|
// case "ERNIE-Bot-8K":
|
|
// fullRequestURL = "https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/ernie_bot_8k"
|
|
// case "ERNIE-Bot":
|
|
// fullRequestURL = "https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/completions"
|
|
// case "ERNIE-Speed":
|
|
// fullRequestURL = "https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/ernie_speed"
|
|
// case "ERNIE-Bot-turbo":
|
|
// fullRequestURL = "https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/eb-instant"
|
|
// case "BLOOMZ-7B":
|
|
// fullRequestURL = "https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/bloomz_7b1"
|
|
// case "Embedding-V1":
|
|
// fullRequestURL = "https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/embeddings/embedding-v1"
|
|
// }
|
|
// var accessToken string
|
|
// var err error
|
|
// if accessToken, err = GetAccessToken(meta.APIKey); err != nil {
|
|
// return "", err
|
|
// }
|
|
// fullRequestURL += "?access_token=" + accessToken
|
|
// return fullRequestURL, nil
|
|
// }
|
|
|
|
// func (a *Adaptor) SetupRequestHeader(c *gin.Context, req *http.Request, meta *util.RelayMeta) error {
|
|
// channel.SetupCommonRequestHeader(c, req, meta)
|
|
// req.Header.Set("Authorization", "Bearer "+meta.APIKey)
|
|
// return nil
|
|
// }
|
|
|
|
// func (a *Adaptor) ConvertRequest(c *gin.Context, relayMode int, request *model.GeneralOpenAIRequest) (any, error) {
|
|
// if request == nil {
|
|
// return nil, errors.New("request is nil")
|
|
// }
|
|
// switch relayMode {
|
|
// case constant.RelayModeEmbeddings:
|
|
// baiduEmbeddingRequest := ConvertEmbeddingRequest(*request)
|
|
// return baiduEmbeddingRequest, nil
|
|
// default:
|
|
// baiduRequest := ConvertRequest(*request)
|
|
// return baiduRequest, nil
|
|
// }
|
|
// }
|
|
|
|
// func (a *Adaptor) DoRequest(c *gin.Context, meta *util.RelayMeta, requestBody io.Reader) (*http.Response, error) {
|
|
// return channel.DoRequestHelper(a, c, meta, requestBody)
|
|
// }
|
|
|
|
// func (a *Adaptor) DoResponse(c *gin.Context, resp *http.Response, meta *util.RelayMeta) (usage *model.Usage, err *model.ErrorWithStatusCode) {
|
|
// if meta.IsStream {
|
|
// err, usage = StreamHandler(c, resp)
|
|
// } else {
|
|
// switch meta.Mode {
|
|
// case constant.RelayModeEmbeddings:
|
|
// err, usage = EmbeddingHandler(c, resp)
|
|
// default:
|
|
// err, usage = Handler(c, resp)
|
|
// }
|
|
// }
|
|
// return
|
|
// }
|
|
|
|
// func (a *Adaptor) GetModelList() []string {
|
|
// return ModelList
|
|
// }
|
|
|
|
// func (a *Adaptor) GetChannelName() string {
|
|
// return "baidu"
|
|
// }
|