mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-11-10 02:23:43 +08:00
Merge branch 'main' into patch/images-edits
This commit is contained in:
@@ -1,7 +1,11 @@
|
||||
package minimax
|
||||
|
||||
// https://www.minimaxi.com/document/guides/chat-model/V2?id=65e0736ab2845de20908e2dd
|
||||
|
||||
var ModelList = []string{
|
||||
"abab5.5s-chat",
|
||||
"abab5.5-chat",
|
||||
"abab6.5-chat",
|
||||
"abab6.5s-chat",
|
||||
"abab6-chat",
|
||||
"abab5.5-chat",
|
||||
"abab5.5s-chat",
|
||||
}
|
||||
|
||||
@@ -86,9 +86,13 @@ func (a *Adaptor) DoResponse(c *gin.Context, resp *http.Response, meta *meta.Met
|
||||
if meta.IsStream {
|
||||
var responseText string
|
||||
err, responseText, usage = StreamHandler(c, resp, meta.Mode)
|
||||
if usage == nil {
|
||||
if usage == nil || usage.TotalTokens == 0 {
|
||||
usage = ResponseText2Usage(responseText, meta.ActualModelName, meta.PromptTokens)
|
||||
}
|
||||
if usage.TotalTokens != 0 && usage.PromptTokens == 0 { // some channels don't return prompt tokens & completion tokens
|
||||
usage.PromptTokens = meta.PromptTokens
|
||||
usage.CompletionTokens = usage.TotalTokens - meta.PromptTokens
|
||||
}
|
||||
} else {
|
||||
switch meta.Mode {
|
||||
case relaymode.ImagesGenerations:
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"github.com/songquanpeng/one-api/relay/adaptor/mistral"
|
||||
"github.com/songquanpeng/one-api/relay/adaptor/moonshot"
|
||||
"github.com/songquanpeng/one-api/relay/adaptor/stepfun"
|
||||
"github.com/songquanpeng/one-api/relay/adaptor/togetherai"
|
||||
"github.com/songquanpeng/one-api/relay/channeltype"
|
||||
)
|
||||
|
||||
@@ -24,6 +25,7 @@ var CompatibleChannels = []int{
|
||||
channeltype.LingYiWanWu,
|
||||
channeltype.StepFun,
|
||||
channeltype.DeepSeek,
|
||||
channeltype.TogetherAI,
|
||||
}
|
||||
|
||||
func GetCompatibleChannelMeta(channelType int) (string, []string) {
|
||||
@@ -48,6 +50,8 @@ func GetCompatibleChannelMeta(channelType int) (string, []string) {
|
||||
return "stepfun", stepfun.ModelList
|
||||
case channeltype.DeepSeek:
|
||||
return "deepseek", deepseek.ModelList
|
||||
case channeltype.TogetherAI:
|
||||
return "together.ai", togetherai.ModelList
|
||||
default:
|
||||
return "openai", ModelList
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ var ModelList = []string{
|
||||
"gpt-4", "gpt-4-0314", "gpt-4-0613", "gpt-4-1106-preview", "gpt-4-0125-preview",
|
||||
"gpt-4-32k", "gpt-4-32k-0314", "gpt-4-32k-0613",
|
||||
"gpt-4-turbo-preview", "gpt-4-turbo", "gpt-4-turbo-2024-04-09",
|
||||
"gpt-4o", "gpt-4o-2024-05-13",
|
||||
"gpt-4-vision-preview",
|
||||
"text-embedding-ada-002", "text-embedding-3-small", "text-embedding-3-large",
|
||||
"text-curie-001", "text-babbage-001", "text-ada-001", "text-davinci-002", "text-davinci-003",
|
||||
|
||||
@@ -24,6 +24,10 @@ func InitTokenEncoders() {
|
||||
logger.FatalLog(fmt.Sprintf("failed to get gpt-3.5-turbo token encoder: %s", err.Error()))
|
||||
}
|
||||
defaultTokenEncoder = gpt35TokenEncoder
|
||||
gpt4oTokenEncoder, err := tiktoken.EncodingForModel("gpt-4o")
|
||||
if err != nil {
|
||||
logger.FatalLog(fmt.Sprintf("failed to get gpt-4o token encoder: %s", err.Error()))
|
||||
}
|
||||
gpt4TokenEncoder, err := tiktoken.EncodingForModel("gpt-4")
|
||||
if err != nil {
|
||||
logger.FatalLog(fmt.Sprintf("failed to get gpt-4 token encoder: %s", err.Error()))
|
||||
@@ -31,6 +35,8 @@ func InitTokenEncoders() {
|
||||
for model := range billingratio.ModelRatio {
|
||||
if strings.HasPrefix(model, "gpt-3.5") {
|
||||
tokenEncoderMap[model] = gpt35TokenEncoder
|
||||
} else if strings.HasPrefix(model, "gpt-4o") {
|
||||
tokenEncoderMap[model] = gpt4oTokenEncoder
|
||||
} else if strings.HasPrefix(model, "gpt-4") {
|
||||
tokenEncoderMap[model] = gpt4TokenEncoder
|
||||
} else {
|
||||
|
||||
10
relay/adaptor/togetherai/constants.go
Normal file
10
relay/adaptor/togetherai/constants.go
Normal file
@@ -0,0 +1,10 @@
|
||||
package togetherai
|
||||
|
||||
// https://docs.together.ai/docs/inference-models
|
||||
|
||||
var ModelList = []string{
|
||||
"meta-llama/Llama-3-70b-chat-hf",
|
||||
"deepseek-ai/deepseek-coder-33b-instruct",
|
||||
"mistralai/Mixtral-8x22B-Instruct-v0.1",
|
||||
"Qwen/Qwen1.5-72B-Chat",
|
||||
}
|
||||
@@ -49,3 +49,8 @@ var ImagePromptLengthLimitations = map[string]int{
|
||||
"wanx-v1": 4000,
|
||||
"cogview-3": 833,
|
||||
}
|
||||
|
||||
var ImageOriginModelName = map[string]string{
|
||||
"ali-stable-diffusion-xl": "stable-diffusion-xl",
|
||||
"ali-stable-diffusion-v1.5": "stable-diffusion-v1.5",
|
||||
}
|
||||
|
||||
@@ -32,6 +32,8 @@ var ModelRatio = map[string]float64{
|
||||
"gpt-4-turbo-preview": 5, // $0.01 / 1K tokens
|
||||
"gpt-4-turbo": 5, // $0.01 / 1K tokens
|
||||
"gpt-4-turbo-2024-04-09": 5, // $0.01 / 1K tokens
|
||||
"gpt-4o": 2.5, // $0.005 / 1K tokens
|
||||
"gpt-4o-2024-05-13": 2.5, // $0.005 / 1K tokens
|
||||
"gpt-4-vision-preview": 5, // $0.01 / 1K tokens
|
||||
"gpt-3.5-turbo": 0.25, // $0.0005 / 1K tokens
|
||||
"gpt-3.5-turbo-0301": 0.75,
|
||||
@@ -138,6 +140,8 @@ var ModelRatio = map[string]float64{
|
||||
"Baichuan2-Turbo-192k": 0.016 * RMB,
|
||||
"Baichuan2-53B": 0.02 * RMB,
|
||||
// https://api.minimax.chat/document/price
|
||||
"abab6.5-chat": 0.03 * RMB,
|
||||
"abab6.5s-chat": 0.01 * RMB,
|
||||
"abab6-chat": 0.1 * RMB,
|
||||
"abab5.5-chat": 0.015 * RMB,
|
||||
"abab5.5s-chat": 0.005 * RMB,
|
||||
@@ -169,7 +173,7 @@ var ModelRatio = map[string]float64{
|
||||
"command-light": 0.5,
|
||||
"command-light-nightly": 0.5,
|
||||
"command-r": 0.5 / 1000 * USD,
|
||||
"command-r-plus ": 3.0 / 1000 * USD,
|
||||
"command-r-plus": 3.0 / 1000 * USD,
|
||||
// https://platform.deepseek.com/api-docs/pricing/
|
||||
"deepseek-chat": 1.0 / 1000 * RMB,
|
||||
"deepseek-coder": 1.0 / 1000 * RMB,
|
||||
@@ -278,7 +282,9 @@ func GetCompletionRatio(name string) float64 {
|
||||
return 4.0 / 3.0
|
||||
}
|
||||
if strings.HasPrefix(name, "gpt-4") {
|
||||
if strings.HasPrefix(name, "gpt-4-turbo") || strings.HasSuffix(name, "preview") {
|
||||
if strings.HasPrefix(name, "gpt-4-turbo") ||
|
||||
strings.HasPrefix(name, "gpt-4o") ||
|
||||
strings.HasSuffix(name, "preview") {
|
||||
return 3
|
||||
}
|
||||
return 2
|
||||
|
||||
@@ -40,6 +40,7 @@ const (
|
||||
DeepSeek
|
||||
Cloudflare
|
||||
DeepL
|
||||
TogetherAI
|
||||
|
||||
Dummy
|
||||
)
|
||||
|
||||
@@ -40,6 +40,7 @@ var ChannelBaseURLs = []string{
|
||||
"https://api.deepseek.com", // 36
|
||||
"https://api.cloudflare.com", // 37
|
||||
"https://api-free.deepl.com", // 38
|
||||
"https://api.together.xyz", // 39
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
||||
@@ -53,6 +53,16 @@ func (e GeneralErrorResponse) ToMessage() string {
|
||||
}
|
||||
|
||||
func RelayErrorHandler(resp *http.Response) (ErrorWithStatusCode *model.ErrorWithStatusCode) {
|
||||
if resp == nil {
|
||||
return &model.ErrorWithStatusCode{
|
||||
StatusCode: 500,
|
||||
Error: model.Error{
|
||||
Message: "resp is nil",
|
||||
Type: "upstream_error",
|
||||
Code: "bad_response",
|
||||
},
|
||||
}
|
||||
}
|
||||
ErrorWithStatusCode = &model.ErrorWithStatusCode{
|
||||
StatusCode: resp.StatusCode,
|
||||
Error: model.Error{
|
||||
|
||||
@@ -208,6 +208,9 @@ func getMappedModelName(modelName string, mapping map[string]string) (string, bo
|
||||
|
||||
func isErrorHappened(meta *meta.Meta, resp *http.Response) bool {
|
||||
if resp == nil {
|
||||
if meta.ChannelType == channeltype.AwsClaude {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
|
||||
@@ -57,6 +57,11 @@ func RelayImageHelper(c *gin.Context, relayMode int) *relaymodel.ErrorWithStatus
|
||||
return openai.ErrorWrapper(err, "get_image_cost_ratio_failed", http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
imageModel := imageRequest.Model
|
||||
// Convert the original image model
|
||||
imageRequest.Model, _ = getMappedModelName(imageRequest.Model, billingratio.ImageOriginModelName)
|
||||
c.Set("response_format", imageRequest.ResponseFormat)
|
||||
|
||||
var requestBody io.Reader
|
||||
if strings.ToLower(c.GetString(ctxkey.ContentType)) == "application/json" &&
|
||||
isModelMapped || meta.ChannelType == channeltype.Azure { // make Azure channel request body
|
||||
@@ -92,7 +97,7 @@ func RelayImageHelper(c *gin.Context, relayMode int) *relaymodel.ErrorWithStatus
|
||||
requestBody = bytes.NewBuffer(jsonStr)
|
||||
}
|
||||
|
||||
modelRatio := billingratio.GetModelRatio(imageRequest.Model)
|
||||
modelRatio := billingratio.GetModelRatio(imageModel)
|
||||
groupRatio := billingratio.GetGroupRatio(meta.Group)
|
||||
ratio := modelRatio * groupRatio
|
||||
userQuota, err := model.CacheGetUserQuota(ctx, meta.UserId)
|
||||
|
||||
Reference in New Issue
Block a user