mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-11-13 11:53:42 +08:00
Merge remote-tracking branch 'origin/upstream/main'
This commit is contained in:
@@ -1,22 +1,83 @@
|
||||
package ali
|
||||
|
||||
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/common"
|
||||
// "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 {
|
||||
}
|
||||
// // https://help.aliyun.com/zh/dashscope/developer-reference/api-details
|
||||
|
||||
func (a *Adaptor) Auth(c *gin.Context) error {
|
||||
return nil
|
||||
}
|
||||
// type Adaptor struct {
|
||||
// }
|
||||
|
||||
func (a *Adaptor) ConvertRequest(request *openai.GeneralOpenAIRequest) (any, error) {
|
||||
return nil, nil
|
||||
}
|
||||
// func (a *Adaptor) Init(meta *util.RelayMeta) {
|
||||
|
||||
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) {
|
||||
// fullRequestURL := fmt.Sprintf("%s/api/v1/services/aigc/text-generation/generation", meta.BaseURL)
|
||||
// if meta.Mode == constant.RelayModeEmbeddings {
|
||||
// fullRequestURL = fmt.Sprintf("%s/api/v1/services/embeddings/text-embedding/text-embedding", meta.BaseURL)
|
||||
// }
|
||||
// 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)
|
||||
// if meta.IsStream {
|
||||
// req.Header.Set("X-DashScope-SSE", "enable")
|
||||
// }
|
||||
// if c.GetString(common.ConfigKeyPlugin) != "" {
|
||||
// req.Header.Set("X-DashScope-Plugin", c.GetString(common.ConfigKeyPlugin))
|
||||
// }
|
||||
// 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 "ali"
|
||||
// }
|
||||
|
||||
6
relay/channel/ali/constants.go
Normal file
6
relay/channel/ali/constants.go
Normal file
@@ -0,0 +1,6 @@
|
||||
package ali
|
||||
|
||||
var ModelList = []string{
|
||||
"qwen-turbo", "qwen-plus", "qwen-max", "qwen-max-longcontext",
|
||||
"text-embedding-v1",
|
||||
}
|
||||
@@ -1,13 +1,7 @@
|
||||
package ali
|
||||
|
||||
// import (
|
||||
// "bufio"
|
||||
// "encoding/json"
|
||||
// "github.com/gin-gonic/gin"
|
||||
// "io"
|
||||
// "net/http"
|
||||
// "one-api/common"
|
||||
// "strings"
|
||||
// "github.com/songquanpeng/one-api/common"
|
||||
// )
|
||||
|
||||
// // https://help.aliyun.com/document_detail/613695.html?spm=a2c4g.2399480.0.0.1adb778fAdzP9w#341800c0f8w0r
|
||||
|
||||
@@ -1,71 +1,71 @@
|
||||
package ali
|
||||
|
||||
type Message struct {
|
||||
Content string `json:"content"`
|
||||
Role string `json:"role"`
|
||||
}
|
||||
// type Message struct {
|
||||
// Content string `json:"content"`
|
||||
// Role string `json:"role"`
|
||||
// }
|
||||
|
||||
type Input struct {
|
||||
//Prompt string `json:"prompt"`
|
||||
Messages []Message `json:"messages"`
|
||||
}
|
||||
// type Input struct {
|
||||
// //Prompt string `json:"prompt"`
|
||||
// Messages []Message `json:"messages"`
|
||||
// }
|
||||
|
||||
type Parameters struct {
|
||||
TopP float64 `json:"top_p,omitempty"`
|
||||
TopK int `json:"top_k,omitempty"`
|
||||
Seed uint64 `json:"seed,omitempty"`
|
||||
EnableSearch bool `json:"enable_search,omitempty"`
|
||||
IncrementalOutput bool `json:"incremental_output,omitempty"`
|
||||
}
|
||||
// type Parameters struct {
|
||||
// TopP float64 `json:"top_p,omitempty"`
|
||||
// TopK int `json:"top_k,omitempty"`
|
||||
// Seed uint64 `json:"seed,omitempty"`
|
||||
// EnableSearch bool `json:"enable_search,omitempty"`
|
||||
// IncrementalOutput bool `json:"incremental_output,omitempty"`
|
||||
// }
|
||||
|
||||
type ChatRequest struct {
|
||||
Model string `json:"model"`
|
||||
Input Input `json:"input"`
|
||||
Parameters Parameters `json:"parameters,omitempty"`
|
||||
}
|
||||
// type ChatRequest struct {
|
||||
// Model string `json:"model"`
|
||||
// Input Input `json:"input"`
|
||||
// Parameters Parameters `json:"parameters,omitempty"`
|
||||
// }
|
||||
|
||||
type EmbeddingRequest struct {
|
||||
Model string `json:"model"`
|
||||
Input struct {
|
||||
Texts []string `json:"texts"`
|
||||
} `json:"input"`
|
||||
Parameters *struct {
|
||||
TextType string `json:"text_type,omitempty"`
|
||||
} `json:"parameters,omitempty"`
|
||||
}
|
||||
// type EmbeddingRequest struct {
|
||||
// Model string `json:"model"`
|
||||
// Input struct {
|
||||
// Texts []string `json:"texts"`
|
||||
// } `json:"input"`
|
||||
// Parameters *struct {
|
||||
// TextType string `json:"text_type,omitempty"`
|
||||
// } `json:"parameters,omitempty"`
|
||||
// }
|
||||
|
||||
type Embedding struct {
|
||||
Embedding []float64 `json:"embedding"`
|
||||
TextIndex int `json:"text_index"`
|
||||
}
|
||||
// type Embedding struct {
|
||||
// Embedding []float64 `json:"embedding"`
|
||||
// TextIndex int `json:"text_index"`
|
||||
// }
|
||||
|
||||
type EmbeddingResponse struct {
|
||||
Output struct {
|
||||
Embeddings []Embedding `json:"embeddings"`
|
||||
} `json:"output"`
|
||||
Usage Usage `json:"usage"`
|
||||
Error
|
||||
}
|
||||
// type EmbeddingResponse struct {
|
||||
// Output struct {
|
||||
// Embeddings []Embedding `json:"embeddings"`
|
||||
// } `json:"output"`
|
||||
// Usage Usage `json:"usage"`
|
||||
// Error
|
||||
// }
|
||||
|
||||
type Error struct {
|
||||
Code string `json:"code"`
|
||||
Message string `json:"message"`
|
||||
RequestId string `json:"request_id"`
|
||||
}
|
||||
// type Error struct {
|
||||
// Code string `json:"code"`
|
||||
// Message string `json:"message"`
|
||||
// RequestId string `json:"request_id"`
|
||||
// }
|
||||
|
||||
type Usage struct {
|
||||
InputTokens int `json:"input_tokens"`
|
||||
OutputTokens int `json:"output_tokens"`
|
||||
TotalTokens int `json:"total_tokens"`
|
||||
}
|
||||
// type Usage struct {
|
||||
// InputTokens int `json:"input_tokens"`
|
||||
// OutputTokens int `json:"output_tokens"`
|
||||
// TotalTokens int `json:"total_tokens"`
|
||||
// }
|
||||
|
||||
type Output struct {
|
||||
Text string `json:"text"`
|
||||
FinishReason string `json:"finish_reason"`
|
||||
}
|
||||
// type Output struct {
|
||||
// Text string `json:"text"`
|
||||
// FinishReason string `json:"finish_reason"`
|
||||
// }
|
||||
|
||||
type ChatResponse struct {
|
||||
Output Output `json:"output"`
|
||||
Usage Usage `json:"usage"`
|
||||
Error
|
||||
}
|
||||
// type ChatResponse struct {
|
||||
// Output Output `json:"output"`
|
||||
// Usage Usage `json:"usage"`
|
||||
// Error
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user