mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-09-19 01:56: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
71 lines
2.1 KiB
Go
71 lines
2.1 KiB
Go
package xunfei
|
|
|
|
// import (
|
|
// "github.com/Laisky/errors/v2"
|
|
// "github.com/gin-gonic/gin"
|
|
// "github.com/songquanpeng/one-api/relay/channel"
|
|
// "github.com/songquanpeng/one-api/relay/channel/openai"
|
|
// "github.com/songquanpeng/one-api/relay/model"
|
|
// "github.com/songquanpeng/one-api/relay/util"
|
|
// "io"
|
|
// "net/http"
|
|
// "strings"
|
|
// )
|
|
|
|
// type Adaptor struct {
|
|
// request *model.GeneralOpenAIRequest
|
|
// }
|
|
|
|
// func (a *Adaptor) Init(meta *util.RelayMeta) {
|
|
|
|
// }
|
|
|
|
// func (a *Adaptor) GetRequestURL(meta *util.RelayMeta) (string, error) {
|
|
// return "", nil
|
|
// }
|
|
|
|
// func (a *Adaptor) SetupRequestHeader(c *gin.Context, req *http.Request, meta *util.RelayMeta) error {
|
|
// channel.SetupCommonRequestHeader(c, req, meta)
|
|
// // check DoResponse for auth part
|
|
// 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")
|
|
// }
|
|
// a.request = request
|
|
// return nil, nil
|
|
// }
|
|
|
|
// func (a *Adaptor) DoRequest(c *gin.Context, meta *util.RelayMeta, requestBody io.Reader) (*http.Response, error) {
|
|
// // xunfei's request is not http request, so we don't need to do anything here
|
|
// dummyResp := &http.Response{}
|
|
// dummyResp.StatusCode = http.StatusOK
|
|
// return dummyResp, nil
|
|
// }
|
|
|
|
// func (a *Adaptor) DoResponse(c *gin.Context, resp *http.Response, meta *util.RelayMeta) (usage *model.Usage, err *model.ErrorWithStatusCode) {
|
|
// splits := strings.Split(meta.APIKey, "|")
|
|
// if len(splits) != 3 {
|
|
// return nil, openai.ErrorWrapper(errors.New("invalid auth"), "invalid_auth", http.StatusBadRequest)
|
|
// }
|
|
// if a.request == nil {
|
|
// return nil, openai.ErrorWrapper(errors.New("request is nil"), "request_is_nil", http.StatusBadRequest)
|
|
// }
|
|
// if meta.IsStream {
|
|
// err, usage = StreamHandler(c, *a.request, splits[0], splits[1], splits[2])
|
|
// } else {
|
|
// err, usage = Handler(c, *a.request, splits[0], splits[1], splits[2])
|
|
// }
|
|
// return
|
|
// }
|
|
|
|
// func (a *Adaptor) GetModelList() []string {
|
|
// return ModelList
|
|
// }
|
|
|
|
// func (a *Adaptor) GetChannelName() string {
|
|
// return "xunfei"
|
|
// }
|