refactor: add GetRatio to Adaptor

This commit is contained in:
WqyJh
2025-01-14 14:38:26 +08:00
parent 3915ce9814
commit 0ad609ade6
70 changed files with 1038 additions and 467 deletions

View File

@@ -12,6 +12,7 @@ import (
"github.com/songquanpeng/one-api/relay/adaptor/doubao"
"github.com/songquanpeng/one-api/relay/adaptor/minimax"
"github.com/songquanpeng/one-api/relay/adaptor/novita"
"github.com/songquanpeng/one-api/relay/billing/ratio"
"github.com/songquanpeng/one-api/relay/channeltype"
"github.com/songquanpeng/one-api/relay/meta"
"github.com/songquanpeng/one-api/relay/model"
@@ -118,9 +119,14 @@ func (a *Adaptor) DoResponse(c *gin.Context, resp *http.Response, meta *meta.Met
return
}
func (a *Adaptor) GetRatio(meta *meta.Meta) *ratio.Ratio {
_, ratioMap := GetCompatibleChannelMeta(a.ChannelType)
return adaptor.GetRatioHelper(meta, ratioMap)
}
func (a *Adaptor) GetModelList() []string {
_, modelList := GetCompatibleChannelMeta(a.ChannelType)
return modelList
_, ratioMap := GetCompatibleChannelMeta(a.ChannelType)
return adaptor.GetModelListHelper(ratioMap)
}
func (a *Adaptor) GetChannelName() string {

View File

@@ -15,6 +15,7 @@ import (
"github.com/songquanpeng/one-api/relay/adaptor/stepfun"
"github.com/songquanpeng/one-api/relay/adaptor/togetherai"
"github.com/songquanpeng/one-api/relay/adaptor/xai"
"github.com/songquanpeng/one-api/relay/billing/ratio"
"github.com/songquanpeng/one-api/relay/channeltype"
)
@@ -36,39 +37,39 @@ var CompatibleChannels = []int{
channeltype.XAI,
}
func GetCompatibleChannelMeta(channelType int) (string, []string) {
func GetCompatibleChannelMeta(channelType int) (string, map[string]ratio.Ratio) {
switch channelType {
case channeltype.Azure:
return "azure", ModelList
return "azure", RatioMap
case channeltype.AI360:
return "360", ai360.ModelList
return "360", ai360.RatioMap
case channeltype.Moonshot:
return "moonshot", moonshot.ModelList
return "moonshot", moonshot.RatioMap
case channeltype.Baichuan:
return "baichuan", baichuan.ModelList
return "baichuan", baichuan.RatioMap
case channeltype.Minimax:
return "minimax", minimax.ModelList
return "minimax", minimax.RatioMap
case channeltype.Mistral:
return "mistralai", mistral.ModelList
return "mistralai", mistral.RatioMap
case channeltype.Groq:
return "groq", groq.ModelList
return "groq", groq.RatioMap
case channeltype.LingYiWanWu:
return "lingyiwanwu", lingyiwanwu.ModelList
return "lingyiwanwu", lingyiwanwu.RatioMap
case channeltype.StepFun:
return "stepfun", stepfun.ModelList
return "stepfun", stepfun.RatioMap
case channeltype.DeepSeek:
return "deepseek", deepseek.ModelList
return "deepseek", deepseek.RatioMap
case channeltype.TogetherAI:
return "together.ai", togetherai.ModelList
return "together.ai", togetherai.RatioMap
case channeltype.Doubao:
return "doubao", doubao.ModelList
return "doubao", doubao.RatioMap
case channeltype.Novita:
return "novita", novita.ModelList
return "novita", novita.RatioMap
case channeltype.SiliconFlow:
return "siliconflow", siliconflow.ModelList
return "siliconflow", siliconflow.RatioMap
case channeltype.XAI:
return "xai", xai.ModelList
return "xai", xai.RatioMap
default:
return "openai", ModelList
return "openai", RatioMap
}
}

View File

@@ -1,27 +1,61 @@
package openai
var ModelList = []string{
"gpt-3.5-turbo", "gpt-3.5-turbo-0301", "gpt-3.5-turbo-0613", "gpt-3.5-turbo-1106", "gpt-3.5-turbo-0125",
"gpt-3.5-turbo-16k", "gpt-3.5-turbo-16k-0613",
"gpt-3.5-turbo-instruct",
"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-4o-2024-08-06",
"gpt-4o-2024-11-20",
"chatgpt-4o-latest",
"gpt-4o-mini", "gpt-4o-mini-2024-07-18",
"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",
"text-moderation-latest", "text-moderation-stable",
"text-davinci-edit-001",
"davinci-002", "babbage-002",
"dall-e-2", "dall-e-3",
"whisper-1",
"tts-1", "tts-1-1106", "tts-1-hd", "tts-1-hd-1106",
"o1", "o1-2024-12-17",
"o1-preview", "o1-preview-2024-09-12",
"o1-mini", "o1-mini-2024-09-12",
import "github.com/songquanpeng/one-api/relay/billing/ratio"
var RatioMap = map[string]ratio.Ratio{
"gpt-4": {Input: 15, Output: 30},
"gpt-4-0314": {Input: 15, Output: 30},
"gpt-4-0613": {Input: 15, Output: 30},
"gpt-4-32k": {Input: 30, Output: 60},
"gpt-4-32k-0314": {Input: 30, Output: 60},
"gpt-4-32k-0613": {Input: 30, Output: 60},
"gpt-4-1106-preview": {Input: 5, Output: 15},
"gpt-4-0125-preview": {Input: 5, Output: 15},
"gpt-4-turbo-preview": {Input: 5, Output: 15}, // $0.01 / 1K tokens
"gpt-4-turbo": {Input: 5, Output: 15}, // $0.01 / 1K tokens
"gpt-4-turbo-2024-04-09": {Input: 5, Output: 15}, // $0.01 / 1K tokens
"gpt-4o": {Input: 1.25, Output: 5}, // $0.005 / 1K tokens
"chatgpt-4o-latest": {Input: 2.5, Output: 7.5}, // $0.005 / 1K tokens
"gpt-4o-2024-05-13": {Input: 2.5, Output: 7.5}, // $0.005 / 1K tokens
"gpt-4o-2024-08-06": {Input: 1.25, Output: 5}, // $0.0025 / 1K tokens
"gpt-4o-2024-11-20": {Input: 1.25, Output: 5}, // $0.0025 / 1K tokens
"gpt-4o-mini": {Input: 0.075, Output: 0.3}, // $0.00015 / 1K tokens
"gpt-4o-mini-2024-07-18": {Input: 0.075, Output: 0.3}, // $0.00015 / 1K tokens
"gpt-4-vision-preview": {Input: 5, Output: 15}, // $0.01 / 1K tokens
"gpt-3.5-turbo": {Input: 0.25, Output: 0.75}, // $0.0005 / 1K tokens
"gpt-3.5-turbo-0301": {Input: 0.75, Output: 1}, // $0.0015 / 1K tokens
"gpt-3.5-turbo-0613": {Input: 0.75, Output: 1}, // $0.0015 / 1K tokens
"gpt-3.5-turbo-16k": {Input: 1.5, Output: 2}, // $0.003 / 1K tokens
"gpt-3.5-turbo-16k-0613": {Input: 1.5, Output: 2}, // $0.003 / 1K tokens
"gpt-3.5-turbo-instruct": {Input: 0.75, Output: 1}, // $0.0015 / 1K tokens
"gpt-3.5-turbo-1106": {Input: 0.5, Output: 1}, // $0.001 / 1K tokens
"gpt-3.5-turbo-0125": {Input: 0.25, Output: 0.75}, // $0.0005 / 1K tokens
"davinci-002": {Input: 1, Output: 1}, // $0.002 / 1K tokens
"babbage-002": {Input: 0.2, Output: 0.2}, // $0.0004 / 1K tokens
"text-ada-001": {Input: 0.2, Output: 0.2}, // $0.0004 / 1K tokens
"text-babbage-001": {Input: 0.25, Output: 0.25}, // $0.0005 / 1K tokens
"text-curie-001": {Input: 1, Output: 1}, // $0.002 / 1K tokens
"text-davinci-002": {Input: 10, Output: 10}, // $0.02 / 1K tokens
"text-davinci-003": {Input: 10, Output: 10}, // $0.02 / 1K tokens
"text-davinci-edit-001": {Input: 10, Output: 10}, // $0.02 / 1K tokens
"code-davinci-edit-001": {Input: 10, Output: 10}, // $0.02 / 1K tokens
"whisper-1": {Input: 1, Output: 1}, // $0.006 / minute -> $0.002 / 20 seconds -> $0.002 / 1K tokens -> 20 seconds / 1K tokens
"tts-1": {Input: 7.5, Output: 7.5}, // $0.015 / 1K characters
"tts-1-1106": {Input: 7.5, Output: 7.5}, // $0.015 / 1K characters
"tts-1-hd": {Input: 15, Output: 15}, // $0.030 / 1K characters
"tts-1-hd-1106": {Input: 15, Output: 15}, // $0.030 / 1K characters
"davinci": {Input: 10, Output: 10}, // $0.02 / 1K tokens
"curie": {Input: 10, Output: 10}, // $0.02 / 1K tokens
"babbage": {Input: 10, Output: 10}, // $0.02 / 1K tokens
"ada": {Input: 10, Output: 10}, // $0.02 / 1K tokens
"text-embedding-ada-002": {Input: 0.05, Output: 0}, // $0.001 / 1K tokens
"text-embedding-3-small": {Input: 0.01, Output: 0}, // $0.0002 / 1K tokens
"text-embedding-3-large": {Input: 0.065, Output: 0}, // $0.0013 / 1K tokens
"text-search-ada-doc-001": {Input: 10, Output: 0}, // $0.02 / 1K tokens
"text-moderation-stable": {Input: 0.1, Output: 0}, // $0.002 / 1K tokens
"text-moderation-latest": {Input: 0.1, Output: 0}, // $0.002 / 1K tokens
"omni-moderation-latest": {Input: 0.1, Output: 0}, // $0.002 / 1K tokens
"omni-moderation-2024-09-26": {Input: 0.1, Output: 0}, // $0.002 / 1K tokens
"dall-e-2": {Input: 0.02 * ratio.USD, Output: 0}, // $0.016 - $0.020 / image
"dall-e-3": {Input: 0.04 * ratio.USD, Output: 0}, // $0.040 - $0.120 / image
}