mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-09-18 01:26: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
77 lines
2.3 KiB
Go
77 lines
2.3 KiB
Go
package tencent
|
|
|
|
// import (
|
|
// "github.com/Laisky/errors/v2"
|
|
// "fmt"
|
|
// "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"
|
|
// )
|
|
|
|
// // https://cloud.tencent.com/document/api/1729/101837
|
|
|
|
// type Adaptor struct {
|
|
// Sign string
|
|
// }
|
|
|
|
// func (a *Adaptor) Init(meta *util.RelayMeta) {
|
|
|
|
// }
|
|
|
|
// func (a *Adaptor) GetRequestURL(meta *util.RelayMeta) (string, error) {
|
|
// return fmt.Sprintf("%s/hyllm/v1/chat/completions", meta.BaseURL), nil
|
|
// }
|
|
|
|
// func (a *Adaptor) SetupRequestHeader(c *gin.Context, req *http.Request, meta *util.RelayMeta) error {
|
|
// channel.SetupCommonRequestHeader(c, req, meta)
|
|
// req.Header.Set("Authorization", a.Sign)
|
|
// req.Header.Set("X-TC-Action", meta.ActualModelName)
|
|
// 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")
|
|
// }
|
|
// apiKey := c.Request.Header.Get("Authorization")
|
|
// apiKey = strings.TrimPrefix(apiKey, "Bearer ")
|
|
// appId, secretId, secretKey, err := ParseConfig(apiKey)
|
|
// if err != nil {
|
|
// return nil, err
|
|
// }
|
|
// tencentRequest := ConvertRequest(*request)
|
|
// tencentRequest.AppId = appId
|
|
// tencentRequest.SecretId = secretId
|
|
// // we have to calculate the sign here
|
|
// a.Sign = GetSign(*tencentRequest, secretKey)
|
|
// return tencentRequest, 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 {
|
|
// var responseText string
|
|
// err, responseText = StreamHandler(c, resp)
|
|
// usage = openai.ResponseText2Usage(responseText, meta.ActualModelName, meta.PromptTokens)
|
|
// } else {
|
|
// err, usage = Handler(c, resp)
|
|
// }
|
|
// return
|
|
// }
|
|
|
|
// func (a *Adaptor) GetModelList() []string {
|
|
// return ModelList
|
|
// }
|
|
|
|
// func (a *Adaptor) GetChannelName() string {
|
|
// return "tencent"
|
|
// }
|