mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-11-12 19:33:41 +08:00
Merge remote-tracking branch 'origin/upstream/main'
This commit is contained in:
@@ -1,22 +1,62 @@
|
||||
package zhipu
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/songquanpeng/one-api/relay/channel/openai"
|
||||
"net/http"
|
||||
)
|
||||
// import (
|
||||
// "errors"
|
||||
// "fmt"
|
||||
// "github.com/gin-gonic/gin"
|
||||
// "github.com/songquanpeng/one-api/relay/channel"
|
||||
// "github.com/songquanpeng/one-api/relay/model"
|
||||
// "github.com/songquanpeng/one-api/relay/util"
|
||||
// "io"
|
||||
// "net/http"
|
||||
// )
|
||||
|
||||
type Adaptor struct {
|
||||
}
|
||||
// type Adaptor struct {
|
||||
// }
|
||||
|
||||
func (a *Adaptor) Auth(c *gin.Context) error {
|
||||
return nil
|
||||
}
|
||||
// func (a *Adaptor) Init(meta *util.RelayMeta) {
|
||||
|
||||
func (a *Adaptor) ConvertRequest(request *openai.GeneralOpenAIRequest) (any, error) {
|
||||
return nil, nil
|
||||
}
|
||||
// }
|
||||
|
||||
func (a *Adaptor) DoResponse(c *gin.Context, resp *http.Response) (*openai.ErrorWithStatusCode, *openai.Usage, error) {
|
||||
return nil, nil, nil
|
||||
}
|
||||
// func (a *Adaptor) GetRequestURL(meta *util.RelayMeta) (string, error) {
|
||||
// method := "invoke"
|
||||
// if meta.IsStream {
|
||||
// method = "sse-invoke"
|
||||
// }
|
||||
// return fmt.Sprintf("%s/api/paas/v3/model-api/%s/%s", meta.BaseURL, meta.ActualModelName, method), nil
|
||||
// }
|
||||
|
||||
// func (a *Adaptor) SetupRequestHeader(c *gin.Context, req *http.Request, meta *util.RelayMeta) error {
|
||||
// channel.SetupCommonRequestHeader(c, req, meta)
|
||||
// token := GetToken(meta.APIKey)
|
||||
// req.Header.Set("Authorization", token)
|
||||
// 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")
|
||||
// }
|
||||
// return ConvertRequest(*request), 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 {
|
||||
// err, usage = Handler(c, resp)
|
||||
// }
|
||||
// return
|
||||
// }
|
||||
|
||||
// func (a *Adaptor) GetModelList() []string {
|
||||
// return ModelList
|
||||
// }
|
||||
|
||||
// func (a *Adaptor) GetChannelName() string {
|
||||
// return "zhipu"
|
||||
// }
|
||||
|
||||
5
relay/channel/zhipu/constants.go
Normal file
5
relay/channel/zhipu/constants.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package zhipu
|
||||
|
||||
// var ModelList = []string{
|
||||
// "chatglm_turbo", "chatglm_pro", "chatglm_std", "chatglm_lite",
|
||||
// }
|
||||
@@ -1,46 +1,46 @@
|
||||
package zhipu
|
||||
|
||||
import (
|
||||
"github.com/songquanpeng/one-api/relay/channel/openai"
|
||||
"time"
|
||||
)
|
||||
// import (
|
||||
// "github.com/songquanpeng/one-api/relay/model"
|
||||
// "time"
|
||||
// )
|
||||
|
||||
type Message struct {
|
||||
Role string `json:"role"`
|
||||
Content string `json:"content"`
|
||||
}
|
||||
// type Message struct {
|
||||
// Role string `json:"role"`
|
||||
// Content string `json:"content"`
|
||||
// }
|
||||
|
||||
type Request struct {
|
||||
Prompt []Message `json:"prompt"`
|
||||
Temperature float64 `json:"temperature,omitempty"`
|
||||
TopP float64 `json:"top_p,omitempty"`
|
||||
RequestId string `json:"request_id,omitempty"`
|
||||
Incremental bool `json:"incremental,omitempty"`
|
||||
}
|
||||
// type Request struct {
|
||||
// Prompt []Message `json:"prompt"`
|
||||
// Temperature float64 `json:"temperature,omitempty"`
|
||||
// TopP float64 `json:"top_p,omitempty"`
|
||||
// RequestId string `json:"request_id,omitempty"`
|
||||
// Incremental bool `json:"incremental,omitempty"`
|
||||
// }
|
||||
|
||||
type ResponseData struct {
|
||||
TaskId string `json:"task_id"`
|
||||
RequestId string `json:"request_id"`
|
||||
TaskStatus string `json:"task_status"`
|
||||
Choices []Message `json:"choices"`
|
||||
openai.Usage `json:"usage"`
|
||||
}
|
||||
// type ResponseData struct {
|
||||
// TaskId string `json:"task_id"`
|
||||
// RequestId string `json:"request_id"`
|
||||
// TaskStatus string `json:"task_status"`
|
||||
// Choices []Message `json:"choices"`
|
||||
// model.Usage `json:"usage"`
|
||||
// }
|
||||
|
||||
type Response struct {
|
||||
Code int `json:"code"`
|
||||
Msg string `json:"msg"`
|
||||
Success bool `json:"success"`
|
||||
Data ResponseData `json:"data"`
|
||||
}
|
||||
// type Response struct {
|
||||
// Code int `json:"code"`
|
||||
// Msg string `json:"msg"`
|
||||
// Success bool `json:"success"`
|
||||
// Data ResponseData `json:"data"`
|
||||
// }
|
||||
|
||||
type StreamMetaResponse struct {
|
||||
RequestId string `json:"request_id"`
|
||||
TaskId string `json:"task_id"`
|
||||
TaskStatus string `json:"task_status"`
|
||||
openai.Usage `json:"usage"`
|
||||
}
|
||||
// type StreamMetaResponse struct {
|
||||
// RequestId string `json:"request_id"`
|
||||
// TaskId string `json:"task_id"`
|
||||
// TaskStatus string `json:"task_status"`
|
||||
// model.Usage `json:"usage"`
|
||||
// }
|
||||
|
||||
type tokenData struct {
|
||||
Token string
|
||||
ExpiryTime time.Time
|
||||
}
|
||||
// type tokenData struct {
|
||||
// Token string
|
||||
// ExpiryTime time.Time
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user