mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-11-21 23:46:49 +08:00
Compare commits
48 Commits
v0.6.11-pr
...
3d7d87c554
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3d7d87c554 | ||
|
|
974331a028 | ||
|
|
a529eab39e | ||
|
|
2174039fce | ||
|
|
9ce714ac8d | ||
|
|
7d2fc27c0f | ||
|
|
4d3add220e | ||
|
|
04de01c798 | ||
|
|
cf0ce425e6 | ||
|
|
e1ee4fe7d9 | ||
|
|
1e19c333c9 | ||
|
|
93d54a7ef5 | ||
|
|
9a7967e9bb | ||
|
|
c7742de0fc | ||
|
|
a8a303b4ee | ||
|
|
abf9d113af | ||
|
|
5f5521bc9a | ||
|
|
77267aa1b8 | ||
|
|
dfcf8868fe | ||
|
|
c2bd301e0a | ||
|
|
8df4a2670b | ||
|
|
7ac553541b | ||
|
|
a5c517c27a | ||
|
|
3f421c4f04 | ||
|
|
1ce6a226f6 | ||
|
|
cafd0a0327 | ||
|
|
8b8cd03e85 | ||
|
|
54c38de813 | ||
|
|
d6284bf6b0 | ||
|
|
df5d2ca93d | ||
|
|
fef7ae048b | ||
|
|
6916debf66 | ||
|
|
53da209134 | ||
|
|
517f6ad211 | ||
|
|
10aba11f18 | ||
|
|
4d011c5f98 | ||
|
|
eb96aa635e | ||
|
|
c715f2bc1d | ||
|
|
cbf8413a39 | ||
|
|
dde3cff708 | ||
|
|
aca72dc979 | ||
|
|
533f9853ac | ||
|
|
9746803a2f | ||
|
|
6eb4e788c7 | ||
|
|
f8fcb1d258 | ||
|
|
9c931b7d43 | ||
|
|
4882fd60ab | ||
|
|
a9f42abb59 |
@@ -72,7 +72,7 @@ _✨ 通过标准的 OpenAI API 格式访问所有的大模型,开箱即用
|
|||||||
+ [x] [Anthropic Claude 系列模型](https://anthropic.com) (支持 AWS Claude)
|
+ [x] [Anthropic Claude 系列模型](https://anthropic.com) (支持 AWS Claude)
|
||||||
+ [x] [Google PaLM2/Gemini 系列模型](https://developers.generativeai.google)
|
+ [x] [Google PaLM2/Gemini 系列模型](https://developers.generativeai.google)
|
||||||
+ [x] [Mistral 系列模型](https://mistral.ai/)
|
+ [x] [Mistral 系列模型](https://mistral.ai/)
|
||||||
+ [x] [字节跳动豆包大模型](https://console.volcengine.com/ark/region:ark+cn-beijing/model)
|
+ [x] [字节跳动豆包大模型(火山引擎)](https://www.volcengine.com/experience/ark?utm_term=202502dsinvite&ac=DSASUQY5&rc=2QXCA1VI)
|
||||||
+ [x] [百度文心一言系列模型](https://cloud.baidu.com/doc/WENXINWORKSHOP/index.html)
|
+ [x] [百度文心一言系列模型](https://cloud.baidu.com/doc/WENXINWORKSHOP/index.html)
|
||||||
+ [x] [阿里通义千问系列模型](https://help.aliyun.com/document_detail/2400395.html)
|
+ [x] [阿里通义千问系列模型](https://help.aliyun.com/document_detail/2400395.html)
|
||||||
+ [x] [讯飞星火认知大模型](https://www.xfyun.cn/doc/spark/Web.html)
|
+ [x] [讯飞星火认知大模型](https://www.xfyun.cn/doc/spark/Web.html)
|
||||||
@@ -115,7 +115,7 @@ _✨ 通过标准的 OpenAI API 格式访问所有的大模型,开箱即用
|
|||||||
19. 支持丰富的**自定义**设置,
|
19. 支持丰富的**自定义**设置,
|
||||||
1. 支持自定义系统名称,logo 以及页脚。
|
1. 支持自定义系统名称,logo 以及页脚。
|
||||||
2. 支持自定义首页和关于页面,可以选择使用 HTML & Markdown 代码进行自定义,或者使用一个单独的网页通过 iframe 嵌入。
|
2. 支持自定义首页和关于页面,可以选择使用 HTML & Markdown 代码进行自定义,或者使用一个单独的网页通过 iframe 嵌入。
|
||||||
20. 支持通过系统访问令牌调用管理 API,进而**在无需二开的情况下扩展和自定义** One API 的功能,详情请参考此处 [API 文档](./docs/API.md)。。
|
20. 支持通过系统访问令牌调用管理 API,进而**在无需二开的情况下扩展和自定义** One API 的功能,详情请参考此处 [API 文档](./docs/API.md)。
|
||||||
21. 支持 Cloudflare Turnstile 用户校验。
|
21. 支持 Cloudflare Turnstile 用户校验。
|
||||||
22. 支持用户管理,支持**多种用户登录注册方式**:
|
22. 支持用户管理,支持**多种用户登录注册方式**:
|
||||||
+ 邮箱登录注册(支持注册邮箱白名单)以及通过邮箱进行密码重置。
|
+ 邮箱登录注册(支持注册邮箱白名单)以及通过邮箱进行密码重置。
|
||||||
|
|||||||
@@ -163,4 +163,4 @@ var UserContentRequestProxy = env.String("USER_CONTENT_REQUEST_PROXY", "")
|
|||||||
var UserContentRequestTimeout = env.Int("USER_CONTENT_REQUEST_TIMEOUT", 30)
|
var UserContentRequestTimeout = env.Int("USER_CONTENT_REQUEST_TIMEOUT", 30)
|
||||||
|
|
||||||
var EnforceIncludeUsage = env.Bool("ENFORCE_INCLUDE_USAGE", false)
|
var EnforceIncludeUsage = env.Bool("ENFORCE_INCLUDE_USAGE", false)
|
||||||
var TestPrompt = env.String("TEST_PROMPT", "Print your model name exactly and do not output without any other text.")
|
var TestPrompt = env.String("TEST_PROMPT", "Output only your specific model name with no additional text.")
|
||||||
|
|||||||
23
common/file/file.go
Normal file
23
common/file/file.go
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
package file
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/base64"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetFileFromUrl(url string) (mimeType string, data string, err error) {
|
||||||
|
resp, err := http.Get(url)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
buffer := bytes.NewBuffer(nil)
|
||||||
|
_, err = buffer.ReadFrom(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
mimeType = resp.Header.Get("Content-Type")
|
||||||
|
data = base64.StdEncoding.EncodeToString(buffer.Bytes())
|
||||||
|
return
|
||||||
|
}
|
||||||
@@ -112,6 +112,13 @@ type DeepSeekUsageResponse struct {
|
|||||||
} `json:"balance_infos"`
|
} `json:"balance_infos"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type OpenRouterResponse struct {
|
||||||
|
Data struct {
|
||||||
|
TotalCredits float64 `json:"total_credits"`
|
||||||
|
TotalUsage float64 `json:"total_usage"`
|
||||||
|
} `json:"data"`
|
||||||
|
}
|
||||||
|
|
||||||
// GetAuthHeader get auth header
|
// GetAuthHeader get auth header
|
||||||
func GetAuthHeader(token string) http.Header {
|
func GetAuthHeader(token string) http.Header {
|
||||||
h := http.Header{}
|
h := http.Header{}
|
||||||
@@ -285,6 +292,22 @@ func updateChannelDeepSeekBalance(channel *model.Channel) (float64, error) {
|
|||||||
return balance, nil
|
return balance, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func updateChannelOpenRouterBalance(channel *model.Channel) (float64, error) {
|
||||||
|
url := "https://openrouter.ai/api/v1/credits"
|
||||||
|
body, err := GetResponseBody("GET", url, channel, GetAuthHeader(channel.Key))
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
response := OpenRouterResponse{}
|
||||||
|
err = json.Unmarshal(body, &response)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
balance := response.Data.TotalCredits - response.Data.TotalUsage
|
||||||
|
channel.UpdateBalance(balance)
|
||||||
|
return balance, nil
|
||||||
|
}
|
||||||
|
|
||||||
func updateChannelBalance(channel *model.Channel) (float64, error) {
|
func updateChannelBalance(channel *model.Channel) (float64, error) {
|
||||||
baseURL := channeltype.ChannelBaseURLs[channel.Type]
|
baseURL := channeltype.ChannelBaseURLs[channel.Type]
|
||||||
if channel.GetBaseURL() == "" {
|
if channel.GetBaseURL() == "" {
|
||||||
@@ -313,6 +336,8 @@ func updateChannelBalance(channel *model.Channel) (float64, error) {
|
|||||||
return updateChannelSiliconFlowBalance(channel)
|
return updateChannelSiliconFlowBalance(channel)
|
||||||
case channeltype.DeepSeek:
|
case channeltype.DeepSeek:
|
||||||
return updateChannelDeepSeekBalance(channel)
|
return updateChannelDeepSeekBalance(channel)
|
||||||
|
case channeltype.OpenRouter:
|
||||||
|
return updateChannelOpenRouterBalance(channel)
|
||||||
default:
|
default:
|
||||||
return 0, errors.New("尚未实现")
|
return 0, errors.New("尚未实现")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -153,6 +153,7 @@ func testChannel(ctx context.Context, channel *model.Channel, request *relaymode
|
|||||||
rawResponse := w.Body.String()
|
rawResponse := w.Body.String()
|
||||||
_, responseMessage, err = parseTestResponse(rawResponse)
|
_, responseMessage, err = parseTestResponse(rawResponse)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
logger.SysError(fmt.Sprintf("failed to parse error: %s, \nresponse: %s", err.Error(), rawResponse))
|
||||||
return "", err, nil
|
return "", err, nil
|
||||||
}
|
}
|
||||||
result := w.Result()
|
result := w.Result()
|
||||||
|
|||||||
@@ -135,30 +135,32 @@ func InitDB() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func migrateDB() error {
|
func migrateDB() error {
|
||||||
var err error
|
if env.Bool("StartSqlMigration", false) {
|
||||||
if err = DB.AutoMigrate(&Channel{}); err != nil {
|
var err error
|
||||||
return err
|
if err = DB.AutoMigrate(&Channel{}); err != nil {
|
||||||
}
|
return err
|
||||||
if err = DB.AutoMigrate(&Token{}); err != nil {
|
}
|
||||||
return err
|
if err = DB.AutoMigrate(&Token{}); err != nil {
|
||||||
}
|
return err
|
||||||
if err = DB.AutoMigrate(&User{}); err != nil {
|
}
|
||||||
return err
|
if err = DB.AutoMigrate(&User{}); err != nil {
|
||||||
}
|
return err
|
||||||
if err = DB.AutoMigrate(&Option{}); err != nil {
|
}
|
||||||
return err
|
if err = DB.AutoMigrate(&Option{}); err != nil {
|
||||||
}
|
return err
|
||||||
if err = DB.AutoMigrate(&Redemption{}); err != nil {
|
}
|
||||||
return err
|
if err = DB.AutoMigrate(&Redemption{}); err != nil {
|
||||||
}
|
return err
|
||||||
if err = DB.AutoMigrate(&Ability{}); err != nil {
|
}
|
||||||
return err
|
if err = DB.AutoMigrate(&Ability{}); err != nil {
|
||||||
}
|
return err
|
||||||
if err = DB.AutoMigrate(&Log{}); err != nil {
|
}
|
||||||
return err
|
if err = DB.AutoMigrate(&Log{}); err != nil {
|
||||||
}
|
return err
|
||||||
if err = DB.AutoMigrate(&Channel{}); err != nil {
|
}
|
||||||
return err
|
if err = DB.AutoMigrate(&Channel{}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,6 +64,9 @@ func GetAdaptor(apiType int) adaptor.Adaptor {
|
|||||||
return &proxy.Adaptor{}
|
return &proxy.Adaptor{}
|
||||||
case apitype.Replicate:
|
case apitype.Replicate:
|
||||||
return &replicate.Adaptor{}
|
return &replicate.Adaptor{}
|
||||||
|
case apitype.CozeV3:
|
||||||
|
return &coze.AdaptorV3{}
|
||||||
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,10 +14,14 @@ var ModelList = []string{
|
|||||||
"qwen2-72b-instruct", "qwen2-57b-a14b-instruct", "qwen2-7b-instruct", "qwen2-1.5b-instruct", "qwen2-0.5b-instruct",
|
"qwen2-72b-instruct", "qwen2-57b-a14b-instruct", "qwen2-7b-instruct", "qwen2-1.5b-instruct", "qwen2-0.5b-instruct",
|
||||||
"qwen1.5-110b-chat", "qwen1.5-72b-chat", "qwen1.5-32b-chat", "qwen1.5-14b-chat", "qwen1.5-7b-chat", "qwen1.5-1.8b-chat", "qwen1.5-0.5b-chat",
|
"qwen1.5-110b-chat", "qwen1.5-72b-chat", "qwen1.5-32b-chat", "qwen1.5-14b-chat", "qwen1.5-7b-chat", "qwen1.5-1.8b-chat", "qwen1.5-0.5b-chat",
|
||||||
"qwen-72b-chat", "qwen-14b-chat", "qwen-7b-chat", "qwen-1.8b-chat", "qwen-1.8b-longcontext-chat",
|
"qwen-72b-chat", "qwen-14b-chat", "qwen-7b-chat", "qwen-1.8b-chat", "qwen-1.8b-longcontext-chat",
|
||||||
|
"qvq-72b-preview",
|
||||||
|
"qwen2.5-vl-72b-instruct", "qwen2.5-vl-7b-instruct", "qwen2.5-vl-2b-instruct", "qwen2.5-vl-1b-instruct", "qwen2.5-vl-0.5b-instruct",
|
||||||
"qwen2-vl-7b-instruct", "qwen2-vl-2b-instruct", "qwen-vl-v1", "qwen-vl-chat-v1",
|
"qwen2-vl-7b-instruct", "qwen2-vl-2b-instruct", "qwen-vl-v1", "qwen-vl-chat-v1",
|
||||||
"qwen2-audio-instruct", "qwen-audio-chat",
|
"qwen2-audio-instruct", "qwen-audio-chat",
|
||||||
"qwen2.5-math-72b-instruct", "qwen2.5-math-7b-instruct", "qwen2.5-math-1.5b-instruct", "qwen2-math-72b-instruct", "qwen2-math-7b-instruct", "qwen2-math-1.5b-instruct",
|
"qwen2.5-math-72b-instruct", "qwen2.5-math-7b-instruct", "qwen2.5-math-1.5b-instruct", "qwen2-math-72b-instruct", "qwen2-math-7b-instruct", "qwen2-math-1.5b-instruct",
|
||||||
"qwen2.5-coder-32b-instruct", "qwen2.5-coder-14b-instruct", "qwen2.5-coder-7b-instruct", "qwen2.5-coder-3b-instruct", "qwen2.5-coder-1.5b-instruct", "qwen2.5-coder-0.5b-instruct",
|
"qwen2.5-coder-32b-instruct", "qwen2.5-coder-14b-instruct", "qwen2.5-coder-7b-instruct", "qwen2.5-coder-3b-instruct", "qwen2.5-coder-1.5b-instruct", "qwen2.5-coder-0.5b-instruct",
|
||||||
"text-embedding-v1", "text-embedding-v3", "text-embedding-v2", "text-embedding-async-v2", "text-embedding-async-v1",
|
"text-embedding-v1", "text-embedding-v3", "text-embedding-v2", "text-embedding-async-v2", "text-embedding-async-v1",
|
||||||
"ali-stable-diffusion-xl", "ali-stable-diffusion-v1.5", "wanx-v1",
|
"ali-stable-diffusion-xl", "ali-stable-diffusion-v1.5", "wanx-v1",
|
||||||
|
"qwen-mt-plus", "qwen-mt-turbo",
|
||||||
|
"deepseek-r1", "deepseek-v3", "deepseek-r1-distill-qwen-1.5b", "deepseek-r1-distill-qwen-7b", "deepseek-r1-distill-qwen-14b", "deepseek-r1-distill-qwen-32b", "deepseek-r1-distill-llama-8b", "deepseek-r1-distill-llama-70b",
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,12 @@ func ConvertRequest(request model.GeneralOpenAIRequest) *ChatRequest {
|
|||||||
enableSearch = true
|
enableSearch = true
|
||||||
aliModel = strings.TrimSuffix(aliModel, EnableSearchModelSuffix)
|
aliModel = strings.TrimSuffix(aliModel, EnableSearchModelSuffix)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enableThinking := false
|
||||||
|
if request.ReasoningEffort != nil {
|
||||||
|
enableThinking = true
|
||||||
|
}
|
||||||
|
|
||||||
request.TopP = helper.Float64PtrMax(request.TopP, 0.9999)
|
request.TopP = helper.Float64PtrMax(request.TopP, 0.9999)
|
||||||
return &ChatRequest{
|
return &ChatRequest{
|
||||||
Model: aliModel,
|
Model: aliModel,
|
||||||
@@ -52,6 +58,7 @@ func ConvertRequest(request model.GeneralOpenAIRequest) *ChatRequest {
|
|||||||
TopK: request.TopK,
|
TopK: request.TopK,
|
||||||
ResultFormat: "message",
|
ResultFormat: "message",
|
||||||
Tools: request.Tools,
|
Tools: request.Tools,
|
||||||
|
EnableThinking: enableThinking,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ type Parameters struct {
|
|||||||
Temperature *float64 `json:"temperature,omitempty"`
|
Temperature *float64 `json:"temperature,omitempty"`
|
||||||
ResultFormat string `json:"result_format,omitempty"`
|
ResultFormat string `json:"result_format,omitempty"`
|
||||||
Tools []model.Tool `json:"tools,omitempty"`
|
Tools []model.Tool `json:"tools,omitempty"`
|
||||||
|
EnableThinking bool `json:"enable_thinking,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ChatRequest struct {
|
type ChatRequest struct {
|
||||||
|
|||||||
21
relay/adaptor/alibailian/constants.go
Normal file
21
relay/adaptor/alibailian/constants.go
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
package alibailian
|
||||||
|
|
||||||
|
// https://help.aliyun.com/zh/model-studio/getting-started/models
|
||||||
|
|
||||||
|
var ModelList = []string{
|
||||||
|
"qwen-turbo",
|
||||||
|
"qwen-plus",
|
||||||
|
"qwen-long",
|
||||||
|
"qwen-max",
|
||||||
|
"qwen-coder-plus",
|
||||||
|
"qwen-coder-plus-latest",
|
||||||
|
"qwen-coder-turbo",
|
||||||
|
"qwen-coder-turbo-latest",
|
||||||
|
"qwen-mt-plus",
|
||||||
|
"qwen-mt-turbo",
|
||||||
|
"qwq-32b-preview",
|
||||||
|
|
||||||
|
"deepseek-r1",
|
||||||
|
"deepseek-v3",
|
||||||
|
"deepseek-v3.1",
|
||||||
|
}
|
||||||
19
relay/adaptor/alibailian/main.go
Normal file
19
relay/adaptor/alibailian/main.go
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
package alibailian
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/songquanpeng/one-api/relay/meta"
|
||||||
|
"github.com/songquanpeng/one-api/relay/relaymode"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetRequestURL(meta *meta.Meta) (string, error) {
|
||||||
|
switch meta.Mode {
|
||||||
|
case relaymode.ChatCompletions:
|
||||||
|
return fmt.Sprintf("%s/compatible-mode/v1/chat/completions", meta.BaseURL), nil
|
||||||
|
case relaymode.Embeddings:
|
||||||
|
return fmt.Sprintf("%s/compatible-mode/v1/embeddings", meta.BaseURL), nil
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
return "", fmt.Errorf("unsupported relay mode %d for ali bailian", meta.Mode)
|
||||||
|
}
|
||||||
75
relay/adaptor/coze/adaptor_v3.go
Normal file
75
relay/adaptor/coze/adaptor_v3.go
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
package coze
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/songquanpeng/one-api/relay/adaptor"
|
||||||
|
"github.com/songquanpeng/one-api/relay/adaptor/openai"
|
||||||
|
"github.com/songquanpeng/one-api/relay/meta"
|
||||||
|
"github.com/songquanpeng/one-api/relay/model"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
type AdaptorV3 struct {
|
||||||
|
meta *meta.Meta
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *AdaptorV3) Init(meta *meta.Meta) {
|
||||||
|
a.meta = meta
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *AdaptorV3) GetRequestURL(meta *meta.Meta) (string, error) {
|
||||||
|
return fmt.Sprintf("%s/v3/chat", meta.BaseURL), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *AdaptorV3) SetupRequestHeader(c *gin.Context, req *http.Request, meta *meta.Meta) error {
|
||||||
|
adaptor.SetupCommonRequestHeader(c, req, meta)
|
||||||
|
req.Header.Set("Authorization", "Bearer "+meta.APIKey)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *AdaptorV3) ConvertRequest(c *gin.Context, relayMode int, request *model.GeneralOpenAIRequest) (any, error) {
|
||||||
|
if request == nil {
|
||||||
|
return nil, errors.New("request is nil")
|
||||||
|
}
|
||||||
|
request.User = a.meta.Config.UserID
|
||||||
|
return V3ConvertRequest(*request), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *AdaptorV3) ConvertImageRequest(request *model.ImageRequest) (any, error) {
|
||||||
|
if request == nil {
|
||||||
|
return nil, errors.New("request is nil")
|
||||||
|
}
|
||||||
|
return request, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *AdaptorV3) DoRequest(c *gin.Context, meta *meta.Meta, requestBody io.Reader) (*http.Response, error) {
|
||||||
|
return adaptor.DoRequestHelper(a, c, meta, requestBody)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *AdaptorV3) DoResponse(c *gin.Context, resp *http.Response, meta *meta.Meta) (usage *model.Usage, err *model.ErrorWithStatusCode) {
|
||||||
|
var responseText *string
|
||||||
|
if meta.IsStream {
|
||||||
|
err, responseText = V3StreamHandler(c, resp)
|
||||||
|
} else {
|
||||||
|
err, responseText = V3Handler(c, resp, meta.PromptTokens, meta.ActualModelName)
|
||||||
|
}
|
||||||
|
if responseText != nil {
|
||||||
|
usage = openai.ResponseText2Usage(*responseText, meta.ActualModelName, meta.PromptTokens)
|
||||||
|
} else {
|
||||||
|
usage = &model.Usage{}
|
||||||
|
}
|
||||||
|
usage.PromptTokens = meta.PromptTokens
|
||||||
|
usage.TotalTokens = usage.PromptTokens + usage.CompletionTokens
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *AdaptorV3) GetModelList() []string {
|
||||||
|
return ModelList
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *AdaptorV3) GetChannelName() string {
|
||||||
|
return "CozeV3"
|
||||||
|
}
|
||||||
@@ -1,6 +1,9 @@
|
|||||||
package coze
|
package coze
|
||||||
|
|
||||||
import "github.com/songquanpeng/one-api/relay/adaptor/coze/constant/event"
|
import (
|
||||||
|
"github.com/songquanpeng/one-api/relay/adaptor/coze/constant/event"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
func event2StopReason(e *string) string {
|
func event2StopReason(e *string) string {
|
||||||
if e == nil || *e == event.Message {
|
if e == nil || *e == event.Message {
|
||||||
@@ -8,3 +11,16 @@ func event2StopReason(e *string) string {
|
|||||||
}
|
}
|
||||||
return "stop"
|
return "stop"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func splitOnDoubleNewline(data []byte, atEOF bool) (advance int, token []byte, err error) {
|
||||||
|
if atEOF && len(data) == 0 {
|
||||||
|
return 0, nil, nil
|
||||||
|
}
|
||||||
|
if i := strings.Index(string(data), "\n\n"); i >= 0 {
|
||||||
|
return i + 1, data[0:i], nil
|
||||||
|
}
|
||||||
|
if atEOF {
|
||||||
|
return len(data), data, nil
|
||||||
|
}
|
||||||
|
return 0, nil, nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,19 +4,18 @@ import (
|
|||||||
"bufio"
|
"bufio"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/songquanpeng/one-api/common/render"
|
|
||||||
"io"
|
|
||||||
"net/http"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/songquanpeng/one-api/common"
|
"github.com/songquanpeng/one-api/common"
|
||||||
"github.com/songquanpeng/one-api/common/conv"
|
"github.com/songquanpeng/one-api/common/conv"
|
||||||
"github.com/songquanpeng/one-api/common/helper"
|
"github.com/songquanpeng/one-api/common/helper"
|
||||||
"github.com/songquanpeng/one-api/common/logger"
|
"github.com/songquanpeng/one-api/common/logger"
|
||||||
|
"github.com/songquanpeng/one-api/common/render"
|
||||||
"github.com/songquanpeng/one-api/relay/adaptor/coze/constant/messagetype"
|
"github.com/songquanpeng/one-api/relay/adaptor/coze/constant/messagetype"
|
||||||
"github.com/songquanpeng/one-api/relay/adaptor/openai"
|
"github.com/songquanpeng/one-api/relay/adaptor/openai"
|
||||||
"github.com/songquanpeng/one-api/relay/model"
|
"github.com/songquanpeng/one-api/relay/model"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// https://www.coze.com/open
|
// https://www.coze.com/open
|
||||||
@@ -57,6 +56,32 @@ func ConvertRequest(textRequest model.GeneralOpenAIRequest) *Request {
|
|||||||
return &cozeRequest
|
return &cozeRequest
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func V3ConvertRequest(textRequest model.GeneralOpenAIRequest) *V3Request {
|
||||||
|
cozeRequest := V3Request{
|
||||||
|
UserId: textRequest.User,
|
||||||
|
Stream: textRequest.Stream,
|
||||||
|
BotId: strings.TrimPrefix(textRequest.Model, "bot-"),
|
||||||
|
}
|
||||||
|
if cozeRequest.UserId == "" {
|
||||||
|
cozeRequest.UserId = "any"
|
||||||
|
}
|
||||||
|
for i, message := range textRequest.Messages {
|
||||||
|
if i == len(textRequest.Messages)-1 {
|
||||||
|
cozeRequest.AdditionalMessages = append(cozeRequest.AdditionalMessages, Message{
|
||||||
|
Role: "user",
|
||||||
|
Content: message.CozeV3StringContent(),
|
||||||
|
})
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
cozeMessage := Message{
|
||||||
|
Role: message.Role,
|
||||||
|
Content: message.CozeV3StringContent(),
|
||||||
|
}
|
||||||
|
cozeRequest.AdditionalMessages = append(cozeRequest.AdditionalMessages, cozeMessage)
|
||||||
|
}
|
||||||
|
return &cozeRequest
|
||||||
|
}
|
||||||
|
|
||||||
func StreamResponseCoze2OpenAI(cozeResponse *StreamResponse) (*openai.ChatCompletionsStreamResponse, *Response) {
|
func StreamResponseCoze2OpenAI(cozeResponse *StreamResponse) (*openai.ChatCompletionsStreamResponse, *Response) {
|
||||||
var response *Response
|
var response *Response
|
||||||
var stopReason string
|
var stopReason string
|
||||||
@@ -80,6 +105,28 @@ func StreamResponseCoze2OpenAI(cozeResponse *StreamResponse) (*openai.ChatComple
|
|||||||
return &openaiResponse, response
|
return &openaiResponse, response
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func V3StreamResponseCoze2OpenAI(cozeResponse *V3StreamResponse) (*openai.ChatCompletionsStreamResponse, *Response) {
|
||||||
|
var response *Response
|
||||||
|
var choice openai.ChatCompletionsStreamResponseChoice
|
||||||
|
|
||||||
|
choice.Delta.Role = cozeResponse.Role
|
||||||
|
choice.Delta.Content = cozeResponse.Content
|
||||||
|
|
||||||
|
var openaiResponse openai.ChatCompletionsStreamResponse
|
||||||
|
openaiResponse.Object = "chat.completion.chunk"
|
||||||
|
openaiResponse.Choices = []openai.ChatCompletionsStreamResponseChoice{choice}
|
||||||
|
openaiResponse.Id = cozeResponse.ConversationId
|
||||||
|
|
||||||
|
if cozeResponse.Usage.TokenCount > 0 {
|
||||||
|
openaiResponse.Usage = &model.Usage{
|
||||||
|
PromptTokens: cozeResponse.Usage.InputCount,
|
||||||
|
CompletionTokens: cozeResponse.Usage.OutputCount,
|
||||||
|
TotalTokens: cozeResponse.Usage.TokenCount,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return &openaiResponse, response
|
||||||
|
}
|
||||||
|
|
||||||
func ResponseCoze2OpenAI(cozeResponse *Response) *openai.TextResponse {
|
func ResponseCoze2OpenAI(cozeResponse *Response) *openai.TextResponse {
|
||||||
var responseText string
|
var responseText string
|
||||||
for _, message := range cozeResponse.Messages {
|
for _, message := range cozeResponse.Messages {
|
||||||
@@ -107,6 +154,26 @@ func ResponseCoze2OpenAI(cozeResponse *Response) *openai.TextResponse {
|
|||||||
return &fullTextResponse
|
return &fullTextResponse
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func V3ResponseCoze2OpenAI(cozeResponse *V3Response) *openai.TextResponse {
|
||||||
|
choice := openai.TextResponseChoice{
|
||||||
|
Index: 0,
|
||||||
|
Message: model.Message{
|
||||||
|
Role: "assistant",
|
||||||
|
Content: cozeResponse.Data.Content,
|
||||||
|
Name: nil,
|
||||||
|
},
|
||||||
|
FinishReason: "stop",
|
||||||
|
}
|
||||||
|
fullTextResponse := openai.TextResponse{
|
||||||
|
Id: fmt.Sprintf("chatcmpl-%s", cozeResponse.Data.ConversationId),
|
||||||
|
Model: "coze-bot",
|
||||||
|
Object: "chat.completion",
|
||||||
|
Created: helper.GetTimestamp(),
|
||||||
|
Choices: []openai.TextResponseChoice{choice},
|
||||||
|
}
|
||||||
|
return &fullTextResponse
|
||||||
|
}
|
||||||
|
|
||||||
func StreamHandler(c *gin.Context, resp *http.Response) (*model.ErrorWithStatusCode, *string) {
|
func StreamHandler(c *gin.Context, resp *http.Response) (*model.ErrorWithStatusCode, *string) {
|
||||||
var responseText string
|
var responseText string
|
||||||
createdTime := helper.GetTimestamp()
|
createdTime := helper.GetTimestamp()
|
||||||
@@ -162,6 +229,63 @@ func StreamHandler(c *gin.Context, resp *http.Response) (*model.ErrorWithStatusC
|
|||||||
return nil, &responseText
|
return nil, &responseText
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func V3StreamHandler(c *gin.Context, resp *http.Response) (*model.ErrorWithStatusCode, *string) {
|
||||||
|
var responseText string
|
||||||
|
createdTime := helper.GetTimestamp()
|
||||||
|
scanner := bufio.NewScanner(resp.Body)
|
||||||
|
scanner.Split(splitOnDoubleNewline)
|
||||||
|
common.SetEventStreamHeaders(c)
|
||||||
|
var modelName string
|
||||||
|
for scanner.Scan() {
|
||||||
|
part := scanner.Text()
|
||||||
|
part = strings.TrimPrefix(part, "\n")
|
||||||
|
parts := strings.Split(part, "\n")
|
||||||
|
if len(parts) != 2 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if !strings.HasPrefix(parts[0], "event:") || !strings.HasPrefix(parts[1], "data:") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
event, data := strings.TrimSpace(parts[0][6:]), strings.TrimSpace(parts[1][5:])
|
||||||
|
if event == "conversation.message.delta" || event == "conversation.chat.completed" {
|
||||||
|
data = strings.TrimSuffix(data, "\r")
|
||||||
|
var cozeResponse V3StreamResponse
|
||||||
|
err := json.Unmarshal([]byte(data), &cozeResponse)
|
||||||
|
if err != nil {
|
||||||
|
logger.SysError("error unmarshalling stream response: " + err.Error())
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
response, _ := V3StreamResponseCoze2OpenAI(&cozeResponse)
|
||||||
|
if response == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, choice := range response.Choices {
|
||||||
|
responseText += conv.AsString(choice.Delta.Content)
|
||||||
|
}
|
||||||
|
response.Model = modelName
|
||||||
|
response.Created = createdTime
|
||||||
|
|
||||||
|
err = render.ObjectData(c, response)
|
||||||
|
if err != nil {
|
||||||
|
logger.SysError(err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err := scanner.Err(); err != nil {
|
||||||
|
logger.SysError("error reading stream: " + err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
render.Done(c)
|
||||||
|
err := resp.Body.Close()
|
||||||
|
if err != nil {
|
||||||
|
return openai.ErrorWrapper(err, "close_response_body_failed", http.StatusInternalServerError), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, &responseText
|
||||||
|
}
|
||||||
|
|
||||||
func Handler(c *gin.Context, resp *http.Response, promptTokens int, modelName string) (*model.ErrorWithStatusCode, *string) {
|
func Handler(c *gin.Context, resp *http.Response, promptTokens int, modelName string) (*model.ErrorWithStatusCode, *string) {
|
||||||
responseBody, err := io.ReadAll(resp.Body)
|
responseBody, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -200,3 +324,42 @@ func Handler(c *gin.Context, resp *http.Response, promptTokens int, modelName st
|
|||||||
}
|
}
|
||||||
return nil, &responseText
|
return nil, &responseText
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func V3Handler(c *gin.Context, resp *http.Response, promptTokens int, modelName string) (*model.ErrorWithStatusCode, *string) {
|
||||||
|
responseBody, err := io.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
return openai.ErrorWrapper(err, "read_response_body_failed", http.StatusInternalServerError), nil
|
||||||
|
}
|
||||||
|
err = resp.Body.Close()
|
||||||
|
if err != nil {
|
||||||
|
return openai.ErrorWrapper(err, "close_response_body_failed", http.StatusInternalServerError), nil
|
||||||
|
}
|
||||||
|
var cozeResponse V3Response
|
||||||
|
err = json.Unmarshal(responseBody, &cozeResponse)
|
||||||
|
if err != nil {
|
||||||
|
return openai.ErrorWrapper(err, "unmarshal_response_body_failed", http.StatusInternalServerError), nil
|
||||||
|
}
|
||||||
|
if cozeResponse.Code != 0 {
|
||||||
|
return &model.ErrorWithStatusCode{
|
||||||
|
Error: model.Error{
|
||||||
|
Message: cozeResponse.Msg,
|
||||||
|
Code: cozeResponse.Code,
|
||||||
|
},
|
||||||
|
StatusCode: resp.StatusCode,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
fullTextResponse := V3ResponseCoze2OpenAI(&cozeResponse)
|
||||||
|
fullTextResponse.Model = modelName
|
||||||
|
jsonResponse, err := json.Marshal(fullTextResponse)
|
||||||
|
if err != nil {
|
||||||
|
return openai.ErrorWrapper(err, "marshal_response_body_failed", http.StatusInternalServerError), nil
|
||||||
|
}
|
||||||
|
c.Writer.Header().Set("Content-Type", "application/json")
|
||||||
|
c.Writer.WriteHeader(resp.StatusCode)
|
||||||
|
_, err = c.Writer.Write(jsonResponse)
|
||||||
|
var responseText string
|
||||||
|
if len(fullTextResponse.Choices) > 0 {
|
||||||
|
responseText = fullTextResponse.Choices[0].Message.StringContent()
|
||||||
|
}
|
||||||
|
return nil, &responseText
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,9 +2,9 @@ package coze
|
|||||||
|
|
||||||
type Message struct {
|
type Message struct {
|
||||||
Role string `json:"role"`
|
Role string `json:"role"`
|
||||||
Type string `json:"type"`
|
Type string `json:"type,omitempty"`
|
||||||
Content string `json:"content"`
|
Content string `json:"content"`
|
||||||
ContentType string `json:"content_type"`
|
ContentType string `json:"content_type,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ErrorInformation struct {
|
type ErrorInformation struct {
|
||||||
@@ -36,3 +36,52 @@ type StreamResponse struct {
|
|||||||
ConversationId string `json:"conversation_id,omitempty"`
|
ConversationId string `json:"conversation_id,omitempty"`
|
||||||
ErrorInformation *ErrorInformation `json:"error_information,omitempty"`
|
ErrorInformation *ErrorInformation `json:"error_information,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type V3StreamResponse struct {
|
||||||
|
Id string `json:"id"`
|
||||||
|
ConversationId string `json:"conversation_id"`
|
||||||
|
BotId string `json:"bot_id"`
|
||||||
|
Role string `json:"role"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
Content string `json:"content"`
|
||||||
|
ContentType string `json:"content_type"`
|
||||||
|
ChatId string `json:"chat_id"`
|
||||||
|
CreatedAt int `json:"created_at"`
|
||||||
|
CompletedAt int `json:"completed_at"`
|
||||||
|
LastError struct {
|
||||||
|
Code int `json:"code"`
|
||||||
|
Msg string `json:"msg"`
|
||||||
|
} `json:"last_error"`
|
||||||
|
Status string `json:"status"`
|
||||||
|
Usage struct {
|
||||||
|
TokenCount int `json:"token_count"`
|
||||||
|
OutputCount int `json:"output_count"`
|
||||||
|
InputCount int `json:"input_count"`
|
||||||
|
} `json:"usage"`
|
||||||
|
SectionId string `json:"section_id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type V3Response struct {
|
||||||
|
Data struct {
|
||||||
|
Id string `json:"id"`
|
||||||
|
ConversationId string `json:"conversation_id"`
|
||||||
|
BotId string `json:"bot_id"`
|
||||||
|
Content string `json:"content"`
|
||||||
|
ContentType string `json:"content_type"`
|
||||||
|
CreatedAt int `json:"created_at"`
|
||||||
|
LastError struct {
|
||||||
|
Code int `json:"code"`
|
||||||
|
Msg string `json:"msg"`
|
||||||
|
} `json:"last_error"`
|
||||||
|
Status string `json:"status"`
|
||||||
|
} `json:"data"`
|
||||||
|
Code int `json:"code"`
|
||||||
|
Msg string `json:"msg"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type V3Request struct {
|
||||||
|
BotId string `json:"bot_id"`
|
||||||
|
UserId string `json:"user_id"`
|
||||||
|
AdditionalMessages []Message `json:"additional_messages"`
|
||||||
|
Stream bool `json:"stream"`
|
||||||
|
}
|
||||||
|
|||||||
@@ -5,9 +5,10 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/songquanpeng/one-api/common/config"
|
||||||
"github.com/songquanpeng/one-api/common/helper"
|
"github.com/songquanpeng/one-api/common/helper"
|
||||||
channelhelper "github.com/songquanpeng/one-api/relay/adaptor"
|
channelhelper "github.com/songquanpeng/one-api/relay/adaptor"
|
||||||
"github.com/songquanpeng/one-api/relay/adaptor/openai"
|
"github.com/songquanpeng/one-api/relay/adaptor/openai"
|
||||||
@@ -20,17 +21,12 @@ type Adaptor struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *Adaptor) Init(meta *meta.Meta) {
|
func (a *Adaptor) Init(meta *meta.Meta) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Adaptor) GetRequestURL(meta *meta.Meta) (string, error) {
|
func (a *Adaptor) GetRequestURL(meta *meta.Meta) (string, error) {
|
||||||
var defaultVersion string
|
defaultVersion := config.GeminiVersion
|
||||||
switch meta.ActualModelName {
|
if strings.Contains(meta.ActualModelName, "gemini-2") ||
|
||||||
case "gemini-2.0-flash-exp",
|
strings.Contains(meta.ActualModelName, "gemini-1.5") {
|
||||||
"gemini-2.0-flash-thinking-exp",
|
|
||||||
"gemini-2.0-flash-thinking-exp-01-21":
|
|
||||||
defaultVersion = "v1beta"
|
|
||||||
default:
|
|
||||||
defaultVersion = "v1beta"
|
defaultVersion = "v1beta"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,35 @@
|
|||||||
package gemini
|
package gemini
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/songquanpeng/one-api/relay/adaptor/geminiv2"
|
||||||
|
)
|
||||||
|
|
||||||
// https://ai.google.dev/models/gemini
|
// https://ai.google.dev/models/gemini
|
||||||
|
|
||||||
var ModelList = []string{
|
var ModelList = geminiv2.ModelList
|
||||||
"gemini-pro", "gemini-1.0-pro",
|
|
||||||
"gemini-1.5-flash", "gemini-1.5-pro",
|
// ModelsSupportSystemInstruction is the list of models that support system instruction.
|
||||||
"text-embedding-004", "aqa",
|
//
|
||||||
"gemini-2.0-flash-exp",
|
// https://cloud.google.com/vertex-ai/generative-ai/docs/learn/prompts/system-instructions
|
||||||
"gemini-2.0-flash-thinking-exp", "gemini-2.0-flash-thinking-exp-01-21",
|
var ModelsSupportSystemInstruction = []string{
|
||||||
|
// "gemini-1.0-pro-002",
|
||||||
|
// "gemini-1.5-flash", "gemini-1.5-flash-001", "gemini-1.5-flash-002",
|
||||||
|
// "gemini-1.5-flash-8b",
|
||||||
|
// "gemini-1.5-pro", "gemini-1.5-pro-001", "gemini-1.5-pro-002",
|
||||||
|
// "gemini-1.5-pro-experimental",
|
||||||
|
"gemini-2.0-flash", "gemini-2.0-flash-exp",
|
||||||
|
"gemini-2.0-flash-thinking-exp-01-21",
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsModelSupportSystemInstruction check if the model support system instruction.
|
||||||
|
//
|
||||||
|
// Because the main version of Go is 1.20, slice.Contains cannot be used
|
||||||
|
func IsModelSupportSystemInstruction(model string) bool {
|
||||||
|
for _, m := range ModelsSupportSystemInstruction {
|
||||||
|
if m == model {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import (
|
|||||||
|
|
||||||
"github.com/songquanpeng/one-api/common"
|
"github.com/songquanpeng/one-api/common"
|
||||||
"github.com/songquanpeng/one-api/common/config"
|
"github.com/songquanpeng/one-api/common/config"
|
||||||
|
"github.com/songquanpeng/one-api/common/file"
|
||||||
"github.com/songquanpeng/one-api/common/helper"
|
"github.com/songquanpeng/one-api/common/helper"
|
||||||
"github.com/songquanpeng/one-api/common/image"
|
"github.com/songquanpeng/one-api/common/image"
|
||||||
"github.com/songquanpeng/one-api/common/logger"
|
"github.com/songquanpeng/one-api/common/logger"
|
||||||
@@ -66,6 +67,23 @@ func ConvertRequest(textRequest model.GeneralOpenAIRequest) *ChatRequest {
|
|||||||
MaxOutputTokens: textRequest.MaxTokens,
|
MaxOutputTokens: textRequest.MaxTokens,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if textRequest.ReasoningEffort != nil {
|
||||||
|
var thinkBudget int
|
||||||
|
switch *textRequest.ReasoningEffort {
|
||||||
|
case "low":
|
||||||
|
thinkBudget = 1000
|
||||||
|
case "medium":
|
||||||
|
thinkBudget = 8000
|
||||||
|
case "high":
|
||||||
|
thinkBudget = 24000
|
||||||
|
}
|
||||||
|
geminiRequest.GenerationConfig.ThinkingConfig = &ThinkingConfig{
|
||||||
|
ThinkingBudget: thinkBudget,
|
||||||
|
IncludeThoughts: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if textRequest.ResponseFormat != nil {
|
if textRequest.ResponseFormat != nil {
|
||||||
if mimeType, ok := mimeTypeMap[textRequest.ResponseFormat.Type]; ok {
|
if mimeType, ok := mimeTypeMap[textRequest.ResponseFormat.Type]; ok {
|
||||||
geminiRequest.GenerationConfig.ResponseMimeType = mimeType
|
geminiRequest.GenerationConfig.ResponseMimeType = mimeType
|
||||||
@@ -76,22 +94,13 @@ func ConvertRequest(textRequest model.GeneralOpenAIRequest) *ChatRequest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if textRequest.Tools != nil {
|
if textRequest.Tools != nil {
|
||||||
functions := make([]model.Function, 0, len(textRequest.Tools))
|
geminiRequest.Tools = textRequest.Tools
|
||||||
for _, tool := range textRequest.Tools {
|
|
||||||
functions = append(functions, tool.Function)
|
|
||||||
}
|
|
||||||
geminiRequest.Tools = []ChatTools{
|
|
||||||
{
|
|
||||||
FunctionDeclarations: functions,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
} else if textRequest.Functions != nil {
|
|
||||||
geminiRequest.Tools = []ChatTools{
|
|
||||||
{
|
|
||||||
FunctionDeclarations: textRequest.Functions,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if textRequest.Functions != nil {
|
||||||
|
geminiRequest.Tools = textRequest.Functions
|
||||||
|
}
|
||||||
|
|
||||||
shouldAddDummyModelMessage := false
|
shouldAddDummyModelMessage := false
|
||||||
for _, message := range textRequest.Messages {
|
for _, message := range textRequest.Messages {
|
||||||
content := ChatContent{
|
content := ChatContent{
|
||||||
@@ -110,6 +119,14 @@ func ConvertRequest(textRequest model.GeneralOpenAIRequest) *ChatRequest {
|
|||||||
parts = append(parts, Part{
|
parts = append(parts, Part{
|
||||||
Text: part.Text,
|
Text: part.Text,
|
||||||
})
|
})
|
||||||
|
} else if part.Type == model.ContentTypeInputFile {
|
||||||
|
mimeType, data, _ := file.GetFileFromUrl(part.File.FileData)
|
||||||
|
parts = append(parts, Part{
|
||||||
|
InlineData: &InlineData{
|
||||||
|
MimeType: mimeType,
|
||||||
|
Data: data,
|
||||||
|
},
|
||||||
|
})
|
||||||
} else if part.Type == model.ContentTypeImageURL {
|
} else if part.Type == model.ContentTypeImageURL {
|
||||||
imageNum += 1
|
imageNum += 1
|
||||||
if imageNum > VisionMaxImageNum {
|
if imageNum > VisionMaxImageNum {
|
||||||
@@ -132,9 +149,16 @@ func ConvertRequest(textRequest model.GeneralOpenAIRequest) *ChatRequest {
|
|||||||
}
|
}
|
||||||
// Converting system prompt to prompt from user for the same reason
|
// Converting system prompt to prompt from user for the same reason
|
||||||
if content.Role == "system" {
|
if content.Role == "system" {
|
||||||
content.Role = "user"
|
|
||||||
shouldAddDummyModelMessage = true
|
shouldAddDummyModelMessage = true
|
||||||
|
if IsModelSupportSystemInstruction(textRequest.Model) {
|
||||||
|
geminiRequest.SystemInstruction = &content
|
||||||
|
geminiRequest.SystemInstruction.Role = ""
|
||||||
|
continue
|
||||||
|
} else {
|
||||||
|
content.Role = "user"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
geminiRequest.Contents = append(geminiRequest.Contents, content)
|
geminiRequest.Contents = append(geminiRequest.Contents, content)
|
||||||
|
|
||||||
// If a system message is the last message, we need to add a dummy model message to make gemini happy
|
// If a system message is the last message, we need to add a dummy model message to make gemini happy
|
||||||
@@ -192,6 +216,21 @@ func (g *ChatResponse) GetResponseText() string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (g *ChatResponse) GetResponseTextAndThought() (content string, thought string) {
|
||||||
|
if g == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if len(g.Candidates) > 0 && len(g.Candidates[0].Content.Parts) > 0 {
|
||||||
|
contentPart := g.Candidates[0].Content.Parts[0]
|
||||||
|
if contentPart.Thought {
|
||||||
|
thought = contentPart.Text
|
||||||
|
return
|
||||||
|
}
|
||||||
|
content = contentPart.Text
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
type ChatCandidate struct {
|
type ChatCandidate struct {
|
||||||
Content ChatContent `json:"content"`
|
Content ChatContent `json:"content"`
|
||||||
FinishReason string `json:"finishReason"`
|
FinishReason string `json:"finishReason"`
|
||||||
@@ -256,7 +295,11 @@ func responseGeminiChat2OpenAI(response *ChatResponse) *openai.TextResponse {
|
|||||||
if i > 0 {
|
if i > 0 {
|
||||||
builder.WriteString("\n")
|
builder.WriteString("\n")
|
||||||
}
|
}
|
||||||
builder.WriteString(part.Text)
|
if part.Thought {
|
||||||
|
builder.WriteString(fmt.Sprintf("<think>%s</think>\n", part.Text))
|
||||||
|
} else {
|
||||||
|
builder.WriteString(part.Text)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
choice.Message.Content = builder.String()
|
choice.Message.Content = builder.String()
|
||||||
}
|
}
|
||||||
@@ -271,7 +314,7 @@ func responseGeminiChat2OpenAI(response *ChatResponse) *openai.TextResponse {
|
|||||||
|
|
||||||
func streamResponseGeminiChat2OpenAI(geminiResponse *ChatResponse) *openai.ChatCompletionsStreamResponse {
|
func streamResponseGeminiChat2OpenAI(geminiResponse *ChatResponse) *openai.ChatCompletionsStreamResponse {
|
||||||
var choice openai.ChatCompletionsStreamResponseChoice
|
var choice openai.ChatCompletionsStreamResponseChoice
|
||||||
choice.Delta.Content = geminiResponse.GetResponseText()
|
choice.Delta.Content, choice.Delta.ReasoningContent = geminiResponse.GetResponseTextAndThought()
|
||||||
//choice.FinishReason = &constant.StopFinishReason
|
//choice.FinishReason = &constant.StopFinishReason
|
||||||
var response openai.ChatCompletionsStreamResponse
|
var response openai.ChatCompletionsStreamResponse
|
||||||
response.Id = fmt.Sprintf("chatcmpl-%s", random.GetUUID())
|
response.Id = fmt.Sprintf("chatcmpl-%s", random.GetUUID())
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
package gemini
|
package gemini
|
||||||
|
|
||||||
type ChatRequest struct {
|
type ChatRequest struct {
|
||||||
Contents []ChatContent `json:"contents"`
|
Contents []ChatContent `json:"contents"`
|
||||||
SafetySettings []ChatSafetySettings `json:"safety_settings,omitempty"`
|
SafetySettings []ChatSafetySettings `json:"safety_settings,omitempty"`
|
||||||
GenerationConfig ChatGenerationConfig `json:"generation_config,omitempty"`
|
GenerationConfig ChatGenerationConfig `json:"generation_config,omitempty"`
|
||||||
Tools []ChatTools `json:"tools,omitempty"`
|
Tools interface{} `json:"tools,omitempty"`
|
||||||
|
SystemInstruction *ChatContent `json:"system_instruction,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type EmbeddingRequest struct {
|
type EmbeddingRequest struct {
|
||||||
@@ -39,6 +40,11 @@ type InlineData struct {
|
|||||||
Data string `json:"data"`
|
Data string `json:"data"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type FileData struct {
|
||||||
|
MimeType string `json:"mime_type"`
|
||||||
|
FileUri string `json:"file_uri"`
|
||||||
|
}
|
||||||
|
|
||||||
type FunctionCall struct {
|
type FunctionCall struct {
|
||||||
FunctionName string `json:"name"`
|
FunctionName string `json:"name"`
|
||||||
Arguments any `json:"args"`
|
Arguments any `json:"args"`
|
||||||
@@ -48,6 +54,8 @@ type Part struct {
|
|||||||
Text string `json:"text,omitempty"`
|
Text string `json:"text,omitempty"`
|
||||||
InlineData *InlineData `json:"inlineData,omitempty"`
|
InlineData *InlineData `json:"inlineData,omitempty"`
|
||||||
FunctionCall *FunctionCall `json:"functionCall,omitempty"`
|
FunctionCall *FunctionCall `json:"functionCall,omitempty"`
|
||||||
|
Thought bool `json:"thought,omitempty"`
|
||||||
|
FileData *FileData `json:"fileData,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ChatContent struct {
|
type ChatContent struct {
|
||||||
@@ -65,12 +73,18 @@ type ChatTools struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ChatGenerationConfig struct {
|
type ChatGenerationConfig struct {
|
||||||
ResponseMimeType string `json:"responseMimeType,omitempty"`
|
ResponseMimeType string `json:"responseMimeType,omitempty"`
|
||||||
ResponseSchema any `json:"responseSchema,omitempty"`
|
ResponseSchema any `json:"responseSchema,omitempty"`
|
||||||
Temperature *float64 `json:"temperature,omitempty"`
|
Temperature *float64 `json:"temperature,omitempty"`
|
||||||
TopP *float64 `json:"topP,omitempty"`
|
TopP *float64 `json:"topP,omitempty"`
|
||||||
TopK float64 `json:"topK,omitempty"`
|
TopK float64 `json:"topK,omitempty"`
|
||||||
MaxOutputTokens int `json:"maxOutputTokens,omitempty"`
|
MaxOutputTokens int `json:"maxOutputTokens,omitempty"`
|
||||||
CandidateCount int `json:"candidateCount,omitempty"`
|
CandidateCount int `json:"candidateCount,omitempty"`
|
||||||
StopSequences []string `json:"stopSequences,omitempty"`
|
StopSequences []string `json:"stopSequences,omitempty"`
|
||||||
|
ThinkingConfig *ThinkingConfig `json:"thinkingConfig,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ThinkingConfig struct {
|
||||||
|
ThinkingBudget int `json:"thinkingBudget"`
|
||||||
|
IncludeThoughts bool `json:"includeThoughts"`
|
||||||
}
|
}
|
||||||
|
|||||||
15
relay/adaptor/geminiv2/constants.go
Normal file
15
relay/adaptor/geminiv2/constants.go
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
package geminiv2
|
||||||
|
|
||||||
|
// https://ai.google.dev/models/gemini
|
||||||
|
|
||||||
|
var ModelList = []string{
|
||||||
|
"gemini-pro", "gemini-1.0-pro",
|
||||||
|
// "gemma-2-2b-it", "gemma-2-9b-it", "gemma-2-27b-it",
|
||||||
|
"gemini-1.5-flash", "gemini-1.5-flash-8b",
|
||||||
|
"gemini-1.5-pro", "gemini-1.5-pro-experimental",
|
||||||
|
"text-embedding-004", "aqa",
|
||||||
|
"gemini-2.0-flash", "gemini-2.0-flash-exp",
|
||||||
|
"gemini-2.0-flash-lite-preview-02-05",
|
||||||
|
"gemini-2.0-flash-thinking-exp-01-21",
|
||||||
|
"gemini-2.0-pro-exp-02-05",
|
||||||
|
}
|
||||||
14
relay/adaptor/geminiv2/main.go
Normal file
14
relay/adaptor/geminiv2/main.go
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
package geminiv2
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/songquanpeng/one-api/relay/meta"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetRequestURL(meta *meta.Meta) (string, error) {
|
||||||
|
baseURL := strings.TrimSuffix(meta.BaseURL, "/")
|
||||||
|
requestPath := strings.TrimPrefix(meta.RequestURLPath, "/v1")
|
||||||
|
return fmt.Sprintf("%s%s", baseURL, requestPath), nil
|
||||||
|
}
|
||||||
@@ -10,8 +10,10 @@ import (
|
|||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
|
||||||
"github.com/songquanpeng/one-api/relay/adaptor"
|
"github.com/songquanpeng/one-api/relay/adaptor"
|
||||||
|
"github.com/songquanpeng/one-api/relay/adaptor/alibailian"
|
||||||
"github.com/songquanpeng/one-api/relay/adaptor/baiduv2"
|
"github.com/songquanpeng/one-api/relay/adaptor/baiduv2"
|
||||||
"github.com/songquanpeng/one-api/relay/adaptor/doubao"
|
"github.com/songquanpeng/one-api/relay/adaptor/doubao"
|
||||||
|
"github.com/songquanpeng/one-api/relay/adaptor/geminiv2"
|
||||||
"github.com/songquanpeng/one-api/relay/adaptor/minimax"
|
"github.com/songquanpeng/one-api/relay/adaptor/minimax"
|
||||||
"github.com/songquanpeng/one-api/relay/adaptor/novita"
|
"github.com/songquanpeng/one-api/relay/adaptor/novita"
|
||||||
"github.com/songquanpeng/one-api/relay/channeltype"
|
"github.com/songquanpeng/one-api/relay/channeltype"
|
||||||
@@ -43,7 +45,6 @@ func (a *Adaptor) GetRequestURL(meta *meta.Meta) (string, error) {
|
|||||||
requestURL = fmt.Sprintf("%s?api-version=%s", requestURL, meta.Config.APIVersion)
|
requestURL = fmt.Sprintf("%s?api-version=%s", requestURL, meta.Config.APIVersion)
|
||||||
task := strings.TrimPrefix(requestURL, "/v1/")
|
task := strings.TrimPrefix(requestURL, "/v1/")
|
||||||
model_ := meta.ActualModelName
|
model_ := meta.ActualModelName
|
||||||
model_ = strings.Replace(model_, ".", "", -1)
|
|
||||||
//https://github.com/songquanpeng/one-api/issues/1191
|
//https://github.com/songquanpeng/one-api/issues/1191
|
||||||
// {your endpoint}/openai/deployments/{your azure_model}/chat/completions?api-version={api_version}
|
// {your endpoint}/openai/deployments/{your azure_model}/chat/completions?api-version={api_version}
|
||||||
requestURL = fmt.Sprintf("/openai/deployments/%s/%s", model_, task)
|
requestURL = fmt.Sprintf("/openai/deployments/%s/%s", model_, task)
|
||||||
@@ -56,6 +57,10 @@ func (a *Adaptor) GetRequestURL(meta *meta.Meta) (string, error) {
|
|||||||
return novita.GetRequestURL(meta)
|
return novita.GetRequestURL(meta)
|
||||||
case channeltype.BaiduV2:
|
case channeltype.BaiduV2:
|
||||||
return baiduv2.GetRequestURL(meta)
|
return baiduv2.GetRequestURL(meta)
|
||||||
|
case channeltype.AliBailian:
|
||||||
|
return alibailian.GetRequestURL(meta)
|
||||||
|
case channeltype.GeminiOpenAICompatible:
|
||||||
|
return geminiv2.GetRequestURL(meta)
|
||||||
default:
|
default:
|
||||||
return GetFullRequestURL(meta.BaseURL, meta.RequestURLPath, meta.ChannelType), nil
|
return GetFullRequestURL(meta.BaseURL, meta.RequestURLPath, meta.ChannelType), nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,16 +2,19 @@ package openai
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/songquanpeng/one-api/relay/adaptor/ai360"
|
"github.com/songquanpeng/one-api/relay/adaptor/ai360"
|
||||||
|
"github.com/songquanpeng/one-api/relay/adaptor/alibailian"
|
||||||
"github.com/songquanpeng/one-api/relay/adaptor/baichuan"
|
"github.com/songquanpeng/one-api/relay/adaptor/baichuan"
|
||||||
"github.com/songquanpeng/one-api/relay/adaptor/baiduv2"
|
"github.com/songquanpeng/one-api/relay/adaptor/baiduv2"
|
||||||
"github.com/songquanpeng/one-api/relay/adaptor/deepseek"
|
"github.com/songquanpeng/one-api/relay/adaptor/deepseek"
|
||||||
"github.com/songquanpeng/one-api/relay/adaptor/doubao"
|
"github.com/songquanpeng/one-api/relay/adaptor/doubao"
|
||||||
|
"github.com/songquanpeng/one-api/relay/adaptor/geminiv2"
|
||||||
"github.com/songquanpeng/one-api/relay/adaptor/groq"
|
"github.com/songquanpeng/one-api/relay/adaptor/groq"
|
||||||
"github.com/songquanpeng/one-api/relay/adaptor/lingyiwanwu"
|
"github.com/songquanpeng/one-api/relay/adaptor/lingyiwanwu"
|
||||||
"github.com/songquanpeng/one-api/relay/adaptor/minimax"
|
"github.com/songquanpeng/one-api/relay/adaptor/minimax"
|
||||||
"github.com/songquanpeng/one-api/relay/adaptor/mistral"
|
"github.com/songquanpeng/one-api/relay/adaptor/mistral"
|
||||||
"github.com/songquanpeng/one-api/relay/adaptor/moonshot"
|
"github.com/songquanpeng/one-api/relay/adaptor/moonshot"
|
||||||
"github.com/songquanpeng/one-api/relay/adaptor/novita"
|
"github.com/songquanpeng/one-api/relay/adaptor/novita"
|
||||||
|
"github.com/songquanpeng/one-api/relay/adaptor/openrouter"
|
||||||
"github.com/songquanpeng/one-api/relay/adaptor/siliconflow"
|
"github.com/songquanpeng/one-api/relay/adaptor/siliconflow"
|
||||||
"github.com/songquanpeng/one-api/relay/adaptor/stepfun"
|
"github.com/songquanpeng/one-api/relay/adaptor/stepfun"
|
||||||
"github.com/songquanpeng/one-api/relay/adaptor/togetherai"
|
"github.com/songquanpeng/one-api/relay/adaptor/togetherai"
|
||||||
@@ -76,6 +79,12 @@ func GetCompatibleChannelMeta(channelType int) (string, []string) {
|
|||||||
return "baiduv2", baiduv2.ModelList
|
return "baiduv2", baiduv2.ModelList
|
||||||
case channeltype.XunfeiV2:
|
case channeltype.XunfeiV2:
|
||||||
return "xunfeiv2", xunfeiv2.ModelList
|
return "xunfeiv2", xunfeiv2.ModelList
|
||||||
|
case channeltype.OpenRouter:
|
||||||
|
return "openrouter", openrouter.ModelList
|
||||||
|
case channeltype.AliBailian:
|
||||||
|
return "alibailian", alibailian.ModelList
|
||||||
|
case channeltype.GeminiOpenAICompatible:
|
||||||
|
return "geminiv2", geminiv2.ModelList
|
||||||
default:
|
default:
|
||||||
return "openai", ModelList
|
return "openai", ModelList
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ 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", "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-16k", "gpt-3.5-turbo-16k-0613",
|
||||||
"gpt-3.5-turbo-instruct",
|
"gpt-3.5-turbo-instruct",
|
||||||
"gpt-4", "gpt-4-0314", "gpt-4-0613", "gpt-4-1106-preview", "gpt-4-0125-preview",
|
"gpt-4", "gpt-4.1", "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-32k", "gpt-4-32k-0314", "gpt-4-32k-0613",
|
||||||
"gpt-4-turbo-preview", "gpt-4-turbo", "gpt-4-turbo-2024-04-09",
|
"gpt-4-turbo-preview", "gpt-4-turbo", "gpt-4-turbo-2024-04-09",
|
||||||
"gpt-4o", "gpt-4o-2024-05-13",
|
"gpt-4o", "gpt-4o-2024-05-13",
|
||||||
|
|||||||
@@ -17,6 +17,9 @@ func ResponseText2Usage(responseText string, modelName string, promptTokens int)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetFullRequestURL(baseURL string, requestURL string, channelType int) string {
|
func GetFullRequestURL(baseURL string, requestURL string, channelType int) string {
|
||||||
|
if channelType == channeltype.OpenAICompatible {
|
||||||
|
return fmt.Sprintf("%s%s", strings.TrimSuffix(baseURL, "/"), strings.TrimPrefix(requestURL, "/v1"))
|
||||||
|
}
|
||||||
fullRequestURL := fmt.Sprintf("%s%s", baseURL, requestURL)
|
fullRequestURL := fmt.Sprintf("%s%s", baseURL, requestURL)
|
||||||
|
|
||||||
if strings.HasPrefix(baseURL, "https://gateway.ai.cloudflare.com") {
|
if strings.HasPrefix(baseURL, "https://gateway.ai.cloudflare.com") {
|
||||||
|
|||||||
235
relay/adaptor/openrouter/constants.go
Normal file
235
relay/adaptor/openrouter/constants.go
Normal file
@@ -0,0 +1,235 @@
|
|||||||
|
package openrouter
|
||||||
|
|
||||||
|
var ModelList = []string{
|
||||||
|
"01-ai/yi-large",
|
||||||
|
"aetherwiing/mn-starcannon-12b",
|
||||||
|
"ai21/jamba-1-5-large",
|
||||||
|
"ai21/jamba-1-5-mini",
|
||||||
|
"ai21/jamba-instruct",
|
||||||
|
"aion-labs/aion-1.0",
|
||||||
|
"aion-labs/aion-1.0-mini",
|
||||||
|
"aion-labs/aion-rp-llama-3.1-8b",
|
||||||
|
"allenai/llama-3.1-tulu-3-405b",
|
||||||
|
"alpindale/goliath-120b",
|
||||||
|
"alpindale/magnum-72b",
|
||||||
|
"amazon/nova-lite-v1",
|
||||||
|
"amazon/nova-micro-v1",
|
||||||
|
"amazon/nova-pro-v1",
|
||||||
|
"anthracite-org/magnum-v2-72b",
|
||||||
|
"anthracite-org/magnum-v4-72b",
|
||||||
|
"anthropic/claude-2",
|
||||||
|
"anthropic/claude-2.0",
|
||||||
|
"anthropic/claude-2.0:beta",
|
||||||
|
"anthropic/claude-2.1",
|
||||||
|
"anthropic/claude-2.1:beta",
|
||||||
|
"anthropic/claude-2:beta",
|
||||||
|
"anthropic/claude-3-haiku",
|
||||||
|
"anthropic/claude-3-haiku:beta",
|
||||||
|
"anthropic/claude-3-opus",
|
||||||
|
"anthropic/claude-3-opus:beta",
|
||||||
|
"anthropic/claude-3-sonnet",
|
||||||
|
"anthropic/claude-3-sonnet:beta",
|
||||||
|
"anthropic/claude-3.5-haiku",
|
||||||
|
"anthropic/claude-3.5-haiku-20241022",
|
||||||
|
"anthropic/claude-3.5-haiku-20241022:beta",
|
||||||
|
"anthropic/claude-3.5-haiku:beta",
|
||||||
|
"anthropic/claude-3.5-sonnet",
|
||||||
|
"anthropic/claude-3.5-sonnet-20240620",
|
||||||
|
"anthropic/claude-3.5-sonnet-20240620:beta",
|
||||||
|
"anthropic/claude-3.5-sonnet:beta",
|
||||||
|
"cognitivecomputations/dolphin-mixtral-8x22b",
|
||||||
|
"cognitivecomputations/dolphin-mixtral-8x7b",
|
||||||
|
"cohere/command",
|
||||||
|
"cohere/command-r",
|
||||||
|
"cohere/command-r-03-2024",
|
||||||
|
"cohere/command-r-08-2024",
|
||||||
|
"cohere/command-r-plus",
|
||||||
|
"cohere/command-r-plus-04-2024",
|
||||||
|
"cohere/command-r-plus-08-2024",
|
||||||
|
"cohere/command-r7b-12-2024",
|
||||||
|
"databricks/dbrx-instruct",
|
||||||
|
"deepseek/deepseek-chat",
|
||||||
|
"deepseek/deepseek-chat-v2.5",
|
||||||
|
"deepseek/deepseek-chat:free",
|
||||||
|
"deepseek/deepseek-r1",
|
||||||
|
"deepseek/deepseek-r1-distill-llama-70b",
|
||||||
|
"deepseek/deepseek-r1-distill-llama-70b:free",
|
||||||
|
"deepseek/deepseek-r1-distill-llama-8b",
|
||||||
|
"deepseek/deepseek-r1-distill-qwen-1.5b",
|
||||||
|
"deepseek/deepseek-r1-distill-qwen-14b",
|
||||||
|
"deepseek/deepseek-r1-distill-qwen-32b",
|
||||||
|
"deepseek/deepseek-r1:free",
|
||||||
|
"eva-unit-01/eva-llama-3.33-70b",
|
||||||
|
"eva-unit-01/eva-qwen-2.5-32b",
|
||||||
|
"eva-unit-01/eva-qwen-2.5-72b",
|
||||||
|
"google/gemini-2.0-flash-001",
|
||||||
|
"google/gemini-2.0-flash-exp:free",
|
||||||
|
"google/gemini-2.0-flash-lite-preview-02-05:free",
|
||||||
|
"google/gemini-2.0-flash-thinking-exp-1219:free",
|
||||||
|
"google/gemini-2.0-flash-thinking-exp:free",
|
||||||
|
"google/gemini-2.0-pro-exp-02-05:free",
|
||||||
|
"google/gemini-exp-1206:free",
|
||||||
|
"google/gemini-flash-1.5",
|
||||||
|
"google/gemini-flash-1.5-8b",
|
||||||
|
"google/gemini-flash-1.5-8b-exp",
|
||||||
|
"google/gemini-pro",
|
||||||
|
"google/gemini-pro-1.5",
|
||||||
|
"google/gemini-pro-vision",
|
||||||
|
"google/gemma-2-27b-it",
|
||||||
|
"google/gemma-2-9b-it",
|
||||||
|
"google/gemma-2-9b-it:free",
|
||||||
|
"google/gemma-7b-it",
|
||||||
|
"google/learnlm-1.5-pro-experimental:free",
|
||||||
|
"google/palm-2-chat-bison",
|
||||||
|
"google/palm-2-chat-bison-32k",
|
||||||
|
"google/palm-2-codechat-bison",
|
||||||
|
"google/palm-2-codechat-bison-32k",
|
||||||
|
"gryphe/mythomax-l2-13b",
|
||||||
|
"gryphe/mythomax-l2-13b:free",
|
||||||
|
"huggingfaceh4/zephyr-7b-beta:free",
|
||||||
|
"infermatic/mn-inferor-12b",
|
||||||
|
"inflection/inflection-3-pi",
|
||||||
|
"inflection/inflection-3-productivity",
|
||||||
|
"jondurbin/airoboros-l2-70b",
|
||||||
|
"liquid/lfm-3b",
|
||||||
|
"liquid/lfm-40b",
|
||||||
|
"liquid/lfm-7b",
|
||||||
|
"mancer/weaver",
|
||||||
|
"meta-llama/llama-2-13b-chat",
|
||||||
|
"meta-llama/llama-2-70b-chat",
|
||||||
|
"meta-llama/llama-3-70b-instruct",
|
||||||
|
"meta-llama/llama-3-8b-instruct",
|
||||||
|
"meta-llama/llama-3-8b-instruct:free",
|
||||||
|
"meta-llama/llama-3.1-405b",
|
||||||
|
"meta-llama/llama-3.1-405b-instruct",
|
||||||
|
"meta-llama/llama-3.1-70b-instruct",
|
||||||
|
"meta-llama/llama-3.1-8b-instruct",
|
||||||
|
"meta-llama/llama-3.2-11b-vision-instruct",
|
||||||
|
"meta-llama/llama-3.2-11b-vision-instruct:free",
|
||||||
|
"meta-llama/llama-3.2-1b-instruct",
|
||||||
|
"meta-llama/llama-3.2-3b-instruct",
|
||||||
|
"meta-llama/llama-3.2-90b-vision-instruct",
|
||||||
|
"meta-llama/llama-3.3-70b-instruct",
|
||||||
|
"meta-llama/llama-3.3-70b-instruct:free",
|
||||||
|
"meta-llama/llama-guard-2-8b",
|
||||||
|
"microsoft/phi-3-medium-128k-instruct",
|
||||||
|
"microsoft/phi-3-medium-128k-instruct:free",
|
||||||
|
"microsoft/phi-3-mini-128k-instruct",
|
||||||
|
"microsoft/phi-3-mini-128k-instruct:free",
|
||||||
|
"microsoft/phi-3.5-mini-128k-instruct",
|
||||||
|
"microsoft/phi-4",
|
||||||
|
"microsoft/wizardlm-2-7b",
|
||||||
|
"microsoft/wizardlm-2-8x22b",
|
||||||
|
"minimax/minimax-01",
|
||||||
|
"mistralai/codestral-2501",
|
||||||
|
"mistralai/codestral-mamba",
|
||||||
|
"mistralai/ministral-3b",
|
||||||
|
"mistralai/ministral-8b",
|
||||||
|
"mistralai/mistral-7b-instruct",
|
||||||
|
"mistralai/mistral-7b-instruct-v0.1",
|
||||||
|
"mistralai/mistral-7b-instruct-v0.3",
|
||||||
|
"mistralai/mistral-7b-instruct:free",
|
||||||
|
"mistralai/mistral-large",
|
||||||
|
"mistralai/mistral-large-2407",
|
||||||
|
"mistralai/mistral-large-2411",
|
||||||
|
"mistralai/mistral-medium",
|
||||||
|
"mistralai/mistral-nemo",
|
||||||
|
"mistralai/mistral-nemo:free",
|
||||||
|
"mistralai/mistral-small",
|
||||||
|
"mistralai/mistral-small-24b-instruct-2501",
|
||||||
|
"mistralai/mistral-small-24b-instruct-2501:free",
|
||||||
|
"mistralai/mistral-tiny",
|
||||||
|
"mistralai/mixtral-8x22b-instruct",
|
||||||
|
"mistralai/mixtral-8x7b",
|
||||||
|
"mistralai/mixtral-8x7b-instruct",
|
||||||
|
"mistralai/pixtral-12b",
|
||||||
|
"mistralai/pixtral-large-2411",
|
||||||
|
"neversleep/llama-3-lumimaid-70b",
|
||||||
|
"neversleep/llama-3-lumimaid-8b",
|
||||||
|
"neversleep/llama-3-lumimaid-8b:extended",
|
||||||
|
"neversleep/llama-3.1-lumimaid-70b",
|
||||||
|
"neversleep/llama-3.1-lumimaid-8b",
|
||||||
|
"neversleep/noromaid-20b",
|
||||||
|
"nothingiisreal/mn-celeste-12b",
|
||||||
|
"nousresearch/hermes-2-pro-llama-3-8b",
|
||||||
|
"nousresearch/hermes-3-llama-3.1-405b",
|
||||||
|
"nousresearch/hermes-3-llama-3.1-70b",
|
||||||
|
"nousresearch/nous-hermes-2-mixtral-8x7b-dpo",
|
||||||
|
"nousresearch/nous-hermes-llama2-13b",
|
||||||
|
"nvidia/llama-3.1-nemotron-70b-instruct",
|
||||||
|
"nvidia/llama-3.1-nemotron-70b-instruct:free",
|
||||||
|
"openai/chatgpt-4o-latest",
|
||||||
|
"openai/gpt-3.5-turbo",
|
||||||
|
"openai/gpt-3.5-turbo-0125",
|
||||||
|
"openai/gpt-3.5-turbo-0613",
|
||||||
|
"openai/gpt-3.5-turbo-1106",
|
||||||
|
"openai/gpt-3.5-turbo-16k",
|
||||||
|
"openai/gpt-3.5-turbo-instruct",
|
||||||
|
"openai/gpt-4",
|
||||||
|
"openai/gpt-4-0314",
|
||||||
|
"openai/gpt-4-1106-preview",
|
||||||
|
"openai/gpt-4-32k",
|
||||||
|
"openai/gpt-4-32k-0314",
|
||||||
|
"openai/gpt-4-turbo",
|
||||||
|
"openai/gpt-4-turbo-preview",
|
||||||
|
"openai/gpt-4o",
|
||||||
|
"openai/gpt-4o-2024-05-13",
|
||||||
|
"openai/gpt-4o-2024-08-06",
|
||||||
|
"openai/gpt-4o-2024-11-20",
|
||||||
|
"openai/gpt-4o-mini",
|
||||||
|
"openai/gpt-4o-mini-2024-07-18",
|
||||||
|
"openai/gpt-4o:extended",
|
||||||
|
"openai/o1",
|
||||||
|
"openai/o1-mini",
|
||||||
|
"openai/o1-mini-2024-09-12",
|
||||||
|
"openai/o1-preview",
|
||||||
|
"openai/o1-preview-2024-09-12",
|
||||||
|
"openai/o3-mini",
|
||||||
|
"openai/o3-mini-high",
|
||||||
|
"openchat/openchat-7b",
|
||||||
|
"openchat/openchat-7b:free",
|
||||||
|
"openrouter/auto",
|
||||||
|
"perplexity/llama-3.1-sonar-huge-128k-online",
|
||||||
|
"perplexity/llama-3.1-sonar-large-128k-chat",
|
||||||
|
"perplexity/llama-3.1-sonar-large-128k-online",
|
||||||
|
"perplexity/llama-3.1-sonar-small-128k-chat",
|
||||||
|
"perplexity/llama-3.1-sonar-small-128k-online",
|
||||||
|
"perplexity/sonar",
|
||||||
|
"perplexity/sonar-reasoning",
|
||||||
|
"pygmalionai/mythalion-13b",
|
||||||
|
"qwen/qvq-72b-preview",
|
||||||
|
"qwen/qwen-2-72b-instruct",
|
||||||
|
"qwen/qwen-2-7b-instruct",
|
||||||
|
"qwen/qwen-2-7b-instruct:free",
|
||||||
|
"qwen/qwen-2-vl-72b-instruct",
|
||||||
|
"qwen/qwen-2-vl-7b-instruct",
|
||||||
|
"qwen/qwen-2.5-72b-instruct",
|
||||||
|
"qwen/qwen-2.5-7b-instruct",
|
||||||
|
"qwen/qwen-2.5-coder-32b-instruct",
|
||||||
|
"qwen/qwen-max",
|
||||||
|
"qwen/qwen-plus",
|
||||||
|
"qwen/qwen-turbo",
|
||||||
|
"qwen/qwen-vl-plus:free",
|
||||||
|
"qwen/qwen2.5-vl-72b-instruct:free",
|
||||||
|
"qwen/qwq-32b-preview",
|
||||||
|
"raifle/sorcererlm-8x22b",
|
||||||
|
"sao10k/fimbulvetr-11b-v2",
|
||||||
|
"sao10k/l3-euryale-70b",
|
||||||
|
"sao10k/l3-lunaris-8b",
|
||||||
|
"sao10k/l3.1-70b-hanami-x1",
|
||||||
|
"sao10k/l3.1-euryale-70b",
|
||||||
|
"sao10k/l3.3-euryale-70b",
|
||||||
|
"sophosympatheia/midnight-rose-70b",
|
||||||
|
"sophosympatheia/rogue-rose-103b-v0.2:free",
|
||||||
|
"teknium/openhermes-2.5-mistral-7b",
|
||||||
|
"thedrummer/rocinante-12b",
|
||||||
|
"thedrummer/unslopnemo-12b",
|
||||||
|
"undi95/remm-slerp-l2-13b",
|
||||||
|
"undi95/toppy-m-7b",
|
||||||
|
"undi95/toppy-m-7b:free",
|
||||||
|
"x-ai/grok-2-1212",
|
||||||
|
"x-ai/grok-2-vision-1212",
|
||||||
|
"x-ai/grok-beta",
|
||||||
|
"x-ai/grok-vision-beta",
|
||||||
|
"xwin-lm/xwin-lm-70b",
|
||||||
|
}
|
||||||
@@ -16,10 +16,12 @@ import (
|
|||||||
|
|
||||||
var ModelList = []string{
|
var ModelList = []string{
|
||||||
"gemini-pro", "gemini-pro-vision",
|
"gemini-pro", "gemini-pro-vision",
|
||||||
"gemini-1.5-pro-001", "gemini-1.5-flash-001",
|
"gemini-exp-1206",
|
||||||
"gemini-1.5-pro-002", "gemini-1.5-flash-002",
|
"gemini-1.5-pro-001", "gemini-1.5-pro-002",
|
||||||
"gemini-2.0-flash-exp",
|
"gemini-1.5-flash-001", "gemini-1.5-flash-002",
|
||||||
"gemini-2.0-flash-thinking-exp", "gemini-2.0-flash-thinking-exp-01-21",
|
"gemini-2.0-flash-exp", "gemini-2.0-flash-001",
|
||||||
|
"gemini-2.0-flash-lite-preview-02-05",
|
||||||
|
"gemini-2.0-flash-thinking-exp-01-21",
|
||||||
}
|
}
|
||||||
|
|
||||||
type Adaptor struct {
|
type Adaptor struct {
|
||||||
|
|||||||
@@ -1,5 +1,14 @@
|
|||||||
package xai
|
package xai
|
||||||
|
|
||||||
|
//https://console.x.ai/
|
||||||
|
|
||||||
var ModelList = []string{
|
var ModelList = []string{
|
||||||
|
"grok-2",
|
||||||
|
"grok-vision-beta",
|
||||||
|
"grok-2-vision-1212",
|
||||||
|
"grok-2-vision",
|
||||||
|
"grok-2-vision-latest",
|
||||||
|
"grok-2-1212",
|
||||||
|
"grok-2-latest",
|
||||||
"grok-beta",
|
"grok-beta",
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,6 @@ const (
|
|||||||
VertexAI
|
VertexAI
|
||||||
Proxy
|
Proxy
|
||||||
Replicate
|
Replicate
|
||||||
|
CozeV3
|
||||||
Dummy // this one is only for count, do not add any channel after this
|
Dummy // this one is only for count, do not add any channel after this
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ var modelRatioLock sync.RWMutex
|
|||||||
var ModelRatio = map[string]float64{
|
var ModelRatio = map[string]float64{
|
||||||
// https://openai.com/pricing
|
// https://openai.com/pricing
|
||||||
"gpt-4": 15,
|
"gpt-4": 15,
|
||||||
|
"gpt-4.1": 15,
|
||||||
"gpt-4-0314": 15,
|
"gpt-4-0314": 15,
|
||||||
"gpt-4-0613": 15,
|
"gpt-4-0613": 15,
|
||||||
"gpt-4-32k": 30,
|
"gpt-4-32k": 30,
|
||||||
@@ -59,6 +60,8 @@ var ModelRatio = map[string]float64{
|
|||||||
"o1-preview-2024-09-12": 7.5,
|
"o1-preview-2024-09-12": 7.5,
|
||||||
"o1-mini": 1.5, // $3.00 / 1M input tokens
|
"o1-mini": 1.5, // $3.00 / 1M input tokens
|
||||||
"o1-mini-2024-09-12": 1.5,
|
"o1-mini-2024-09-12": 1.5,
|
||||||
|
"o3-mini": 1.5, // $3.00 / 1M input tokens
|
||||||
|
"o3-mini-2025-01-31": 1.5,
|
||||||
"davinci-002": 1, // $0.002 / 1K tokens
|
"davinci-002": 1, // $0.002 / 1K tokens
|
||||||
"babbage-002": 0.2, // $0.0004 / 1K tokens
|
"babbage-002": 0.2, // $0.0004 / 1K tokens
|
||||||
"text-ada-001": 0.2,
|
"text-ada-001": 0.2,
|
||||||
@@ -69,6 +72,8 @@ var ModelRatio = map[string]float64{
|
|||||||
"text-davinci-edit-001": 10,
|
"text-davinci-edit-001": 10,
|
||||||
"code-davinci-edit-001": 10,
|
"code-davinci-edit-001": 10,
|
||||||
"whisper-1": 15, // $0.006 / minute -> $0.006 / 150 words -> $0.006 / 200 tokens -> $0.03 / 1k tokens
|
"whisper-1": 15, // $0.006 / minute -> $0.006 / 150 words -> $0.006 / 200 tokens -> $0.03 / 1k tokens
|
||||||
|
"gpt-4o-mini-transcribe": 15, // $0.006 / minute -> $0.006 / 150 words -> $0.006 / 200 tokens -> $0.03 / 1k tokens
|
||||||
|
"gpt-4o-transcribe": 15, // $0.006 / minute -> $0.006 / 150 words -> $0.006 / 200 tokens -> $0.03 / 1k tokens
|
||||||
"tts-1": 7.5, // $0.015 / 1K characters
|
"tts-1": 7.5, // $0.015 / 1K characters
|
||||||
"tts-1-1106": 7.5,
|
"tts-1-1106": 7.5,
|
||||||
"tts-1-hd": 15, // $0.030 / 1K characters
|
"tts-1-hd": 15, // $0.030 / 1K characters
|
||||||
@@ -115,15 +120,24 @@ var ModelRatio = map[string]float64{
|
|||||||
"bge-large-en": 0.002 * RMB,
|
"bge-large-en": 0.002 * RMB,
|
||||||
"tao-8k": 0.002 * RMB,
|
"tao-8k": 0.002 * RMB,
|
||||||
// https://ai.google.dev/pricing
|
// https://ai.google.dev/pricing
|
||||||
"gemini-pro": 1, // $0.00025 / 1k characters -> $0.001 / 1k tokens
|
// https://cloud.google.com/vertex-ai/generative-ai/pricing
|
||||||
"gemini-1.0-pro": 1,
|
// "gemma-2-2b-it": 0,
|
||||||
"gemini-1.5-pro": 1,
|
// "gemma-2-9b-it": 0,
|
||||||
"gemini-1.5-pro-001": 1,
|
// "gemma-2-27b-it": 0,
|
||||||
"gemini-1.5-flash": 1,
|
"gemini-pro": 0.25 * MILLI_USD, // $0.00025 / 1k characters -> $0.001 / 1k tokens
|
||||||
"gemini-1.5-flash-001": 1,
|
"gemini-1.0-pro": 0.125 * MILLI_USD,
|
||||||
"gemini-2.0-flash-exp": 1,
|
"gemini-1.5-pro": 1.25 * MILLI_USD,
|
||||||
"gemini-2.0-flash-thinking-exp": 1,
|
"gemini-1.5-pro-001": 1.25 * MILLI_USD,
|
||||||
"gemini-2.0-flash-thinking-exp-01-21": 1,
|
"gemini-1.5-pro-experimental": 1.25 * MILLI_USD,
|
||||||
|
"gemini-1.5-flash": 0.075 * MILLI_USD,
|
||||||
|
"gemini-1.5-flash-001": 0.075 * MILLI_USD,
|
||||||
|
"gemini-1.5-flash-8b": 0.0375 * MILLI_USD,
|
||||||
|
"gemini-2.0-flash-exp": 0.075 * MILLI_USD,
|
||||||
|
"gemini-2.0-flash": 0.15 * MILLI_USD,
|
||||||
|
"gemini-2.0-flash-001": 0.15 * MILLI_USD,
|
||||||
|
"gemini-2.0-flash-lite-preview-02-05": 0.075 * MILLI_USD,
|
||||||
|
"gemini-2.0-flash-thinking-exp-01-21": 0.075 * MILLI_USD,
|
||||||
|
"gemini-2.0-pro-exp-02-05": 1.25 * MILLI_USD,
|
||||||
"aqa": 1,
|
"aqa": 1,
|
||||||
// https://open.bigmodel.cn/pricing
|
// https://open.bigmodel.cn/pricing
|
||||||
"glm-zero-preview": 0.01 * RMB,
|
"glm-zero-preview": 0.01 * RMB,
|
||||||
@@ -150,91 +164,105 @@ var ModelRatio = map[string]float64{
|
|||||||
"embedding-2": 0.0005 * RMB,
|
"embedding-2": 0.0005 * RMB,
|
||||||
"embedding-3": 0.0005 * RMB,
|
"embedding-3": 0.0005 * RMB,
|
||||||
// https://help.aliyun.com/zh/dashscope/developer-reference/tongyi-thousand-questions-metering-and-billing
|
// https://help.aliyun.com/zh/dashscope/developer-reference/tongyi-thousand-questions-metering-and-billing
|
||||||
"qwen-turbo": 1.4286, // ¥0.02 / 1k tokens
|
"qwen-turbo": 0.0003 * RMB,
|
||||||
"qwen-turbo-latest": 1.4286,
|
"qwen-turbo-latest": 0.0003 * RMB,
|
||||||
"qwen-plus": 1.4286,
|
"qwen-plus": 0.0008 * RMB,
|
||||||
"qwen-plus-latest": 1.4286,
|
"qwen-plus-latest": 0.0008 * RMB,
|
||||||
"qwen-max": 1.4286,
|
"qwen-max": 0.0024 * RMB,
|
||||||
"qwen-max-latest": 1.4286,
|
"qwen-max-latest": 0.0024 * RMB,
|
||||||
"qwen-max-longcontext": 1.4286,
|
"qwen-max-longcontext": 0.0005 * RMB,
|
||||||
"qwen-vl-max": 1.4286,
|
"qwen-vl-max": 0.003 * RMB,
|
||||||
"qwen-vl-max-latest": 1.4286,
|
"qwen-vl-max-latest": 0.003 * RMB,
|
||||||
"qwen-vl-plus": 1.4286,
|
"qwen-vl-plus": 0.0015 * RMB,
|
||||||
"qwen-vl-plus-latest": 1.4286,
|
"qwen-vl-plus-latest": 0.0015 * RMB,
|
||||||
"qwen-vl-ocr": 1.4286,
|
"qwen-vl-ocr": 0.005 * RMB,
|
||||||
"qwen-vl-ocr-latest": 1.4286,
|
"qwen-vl-ocr-latest": 0.005 * RMB,
|
||||||
"qwen-audio-turbo": 1.4286,
|
"qwen-audio-turbo": 1.4286,
|
||||||
"qwen-math-plus": 1.4286,
|
"qwen-math-plus": 0.004 * RMB,
|
||||||
"qwen-math-plus-latest": 1.4286,
|
"qwen-math-plus-latest": 0.004 * RMB,
|
||||||
"qwen-math-turbo": 1.4286,
|
"qwen-math-turbo": 0.002 * RMB,
|
||||||
"qwen-math-turbo-latest": 1.4286,
|
"qwen-math-turbo-latest": 0.002 * RMB,
|
||||||
"qwen-coder-plus": 1.4286,
|
"qwen-coder-plus": 0.0035 * RMB,
|
||||||
"qwen-coder-plus-latest": 1.4286,
|
"qwen-coder-plus-latest": 0.0035 * RMB,
|
||||||
"qwen-coder-turbo": 1.4286,
|
"qwen-coder-turbo": 0.002 * RMB,
|
||||||
"qwen-coder-turbo-latest": 1.4286,
|
"qwen-coder-turbo-latest": 0.002 * RMB,
|
||||||
"qwq-32b-preview": 1.4286,
|
"qwen-mt-plus": 0.015 * RMB,
|
||||||
"qwen2.5-72b-instruct": 1.4286,
|
"qwen-mt-turbo": 0.001 * RMB,
|
||||||
"qwen2.5-32b-instruct": 1.4286,
|
"qwq-32b-preview": 0.002 * RMB,
|
||||||
"qwen2.5-14b-instruct": 1.4286,
|
"qwen2.5-72b-instruct": 0.004 * RMB,
|
||||||
"qwen2.5-7b-instruct": 1.4286,
|
"qwen2.5-32b-instruct": 0.03 * RMB,
|
||||||
"qwen2.5-3b-instruct": 1.4286,
|
"qwen2.5-14b-instruct": 0.001 * RMB,
|
||||||
"qwen2.5-1.5b-instruct": 1.4286,
|
"qwen2.5-7b-instruct": 0.0005 * RMB,
|
||||||
"qwen2.5-0.5b-instruct": 1.4286,
|
"qwen2.5-3b-instruct": 0.006 * RMB,
|
||||||
"qwen2-72b-instruct": 1.4286,
|
"qwen2.5-1.5b-instruct": 0.0003 * RMB,
|
||||||
"qwen2-57b-a14b-instruct": 1.4286,
|
"qwen2.5-0.5b-instruct": 0.0003 * RMB,
|
||||||
"qwen2-7b-instruct": 1.4286,
|
"qwen2-72b-instruct": 0.004 * RMB,
|
||||||
"qwen2-1.5b-instruct": 1.4286,
|
"qwen2-57b-a14b-instruct": 0.0035 * RMB,
|
||||||
"qwen2-0.5b-instruct": 1.4286,
|
"qwen2-7b-instruct": 0.001 * RMB,
|
||||||
"qwen1.5-110b-chat": 1.4286,
|
"qwen2-1.5b-instruct": 0.001 * RMB,
|
||||||
"qwen1.5-72b-chat": 1.4286,
|
"qwen2-0.5b-instruct": 0.001 * RMB,
|
||||||
"qwen1.5-32b-chat": 1.4286,
|
"qwen1.5-110b-chat": 0.007 * RMB,
|
||||||
"qwen1.5-14b-chat": 1.4286,
|
"qwen1.5-72b-chat": 0.005 * RMB,
|
||||||
"qwen1.5-7b-chat": 1.4286,
|
"qwen1.5-32b-chat": 0.0035 * RMB,
|
||||||
"qwen1.5-1.8b-chat": 1.4286,
|
"qwen1.5-14b-chat": 0.002 * RMB,
|
||||||
"qwen1.5-0.5b-chat": 1.4286,
|
"qwen1.5-7b-chat": 0.001 * RMB,
|
||||||
"qwen-72b-chat": 1.4286,
|
"qwen1.5-1.8b-chat": 0.001 * RMB,
|
||||||
"qwen-14b-chat": 1.4286,
|
"qwen1.5-0.5b-chat": 0.001 * RMB,
|
||||||
"qwen-7b-chat": 1.4286,
|
"qwen-72b-chat": 0.02 * RMB,
|
||||||
"qwen-1.8b-chat": 1.4286,
|
"qwen-14b-chat": 0.008 * RMB,
|
||||||
"qwen-1.8b-longcontext-chat": 1.4286,
|
"qwen-7b-chat": 0.006 * RMB,
|
||||||
"qwen2-vl-7b-instruct": 1.4286,
|
"qwen-1.8b-chat": 0.006 * RMB,
|
||||||
"qwen2-vl-2b-instruct": 1.4286,
|
"qwen-1.8b-longcontext-chat": 0.006 * RMB,
|
||||||
"qwen-vl-v1": 1.4286,
|
"qvq-72b-preview": 0.012 * RMB,
|
||||||
"qwen-vl-chat-v1": 1.4286,
|
"qwen2.5-vl-72b-instruct": 0.016 * RMB,
|
||||||
"qwen2-audio-instruct": 1.4286,
|
"qwen2.5-vl-7b-instruct": 0.002 * RMB,
|
||||||
"qwen-audio-chat": 1.4286,
|
"qwen2.5-vl-3b-instruct": 0.0012 * RMB,
|
||||||
"qwen2.5-math-72b-instruct": 1.4286,
|
"qwen2-vl-7b-instruct": 0.016 * RMB,
|
||||||
"qwen2.5-math-7b-instruct": 1.4286,
|
"qwen2-vl-2b-instruct": 0.002 * RMB,
|
||||||
"qwen2.5-math-1.5b-instruct": 1.4286,
|
"qwen-vl-v1": 0.002 * RMB,
|
||||||
"qwen2-math-72b-instruct": 1.4286,
|
"qwen-vl-chat-v1": 0.002 * RMB,
|
||||||
"qwen2-math-7b-instruct": 1.4286,
|
"qwen2-audio-instruct": 0.002 * RMB,
|
||||||
"qwen2-math-1.5b-instruct": 1.4286,
|
"qwen-audio-chat": 0.002 * RMB,
|
||||||
"qwen2.5-coder-32b-instruct": 1.4286,
|
"qwen2.5-math-72b-instruct": 0.004 * RMB,
|
||||||
"qwen2.5-coder-14b-instruct": 1.4286,
|
"qwen2.5-math-7b-instruct": 0.001 * RMB,
|
||||||
"qwen2.5-coder-7b-instruct": 1.4286,
|
"qwen2.5-math-1.5b-instruct": 0.001 * RMB,
|
||||||
"qwen2.5-coder-3b-instruct": 1.4286,
|
"qwen2-math-72b-instruct": 0.004 * RMB,
|
||||||
"qwen2.5-coder-1.5b-instruct": 1.4286,
|
"qwen2-math-7b-instruct": 0.001 * RMB,
|
||||||
"qwen2.5-coder-0.5b-instruct": 1.4286,
|
"qwen2-math-1.5b-instruct": 0.001 * RMB,
|
||||||
"text-embedding-v1": 0.05, // ¥0.0007 / 1k tokens
|
"qwen2.5-coder-32b-instruct": 0.002 * RMB,
|
||||||
"text-embedding-v3": 0.05,
|
"qwen2.5-coder-14b-instruct": 0.002 * RMB,
|
||||||
"text-embedding-v2": 0.05,
|
"qwen2.5-coder-7b-instruct": 0.001 * RMB,
|
||||||
"text-embedding-async-v2": 0.05,
|
"qwen2.5-coder-3b-instruct": 0.001 * RMB,
|
||||||
"text-embedding-async-v1": 0.05,
|
"qwen2.5-coder-1.5b-instruct": 0.001 * RMB,
|
||||||
"ali-stable-diffusion-xl": 8.00,
|
"qwen2.5-coder-0.5b-instruct": 0.001 * RMB,
|
||||||
"ali-stable-diffusion-v1.5": 8.00,
|
"text-embedding-v1": 0.0007 * RMB, // ¥0.0007 / 1k tokens
|
||||||
"wanx-v1": 8.00,
|
"text-embedding-v3": 0.0007 * RMB,
|
||||||
"SparkDesk": 1.2858, // ¥0.018 / 1k tokens
|
"text-embedding-v2": 0.0007 * RMB,
|
||||||
"SparkDesk-v1.1": 1.2858, // ¥0.018 / 1k tokens
|
"text-embedding-async-v2": 0.0007 * RMB,
|
||||||
"SparkDesk-v2.1": 1.2858, // ¥0.018 / 1k tokens
|
"text-embedding-async-v1": 0.0007 * RMB,
|
||||||
"SparkDesk-v3.1": 1.2858, // ¥0.018 / 1k tokens
|
"ali-stable-diffusion-xl": 8.00,
|
||||||
"SparkDesk-v3.1-128K": 1.2858, // ¥0.018 / 1k tokens
|
"ali-stable-diffusion-v1.5": 8.00,
|
||||||
"SparkDesk-v3.5": 1.2858, // ¥0.018 / 1k tokens
|
"wanx-v1": 8.00,
|
||||||
"SparkDesk-v3.5-32K": 1.2858, // ¥0.018 / 1k tokens
|
"deepseek-r1": 0.002 * RMB,
|
||||||
"SparkDesk-v4.0": 1.2858, // ¥0.018 / 1k tokens
|
"deepseek-v3": 0.001 * RMB,
|
||||||
"360GPT_S2_V9": 0.8572, // ¥0.012 / 1k tokens
|
"deepseek-r1-distill-qwen-1.5b": 0.001 * RMB,
|
||||||
"embedding-bert-512-v1": 0.0715, // ¥0.001 / 1k tokens
|
"deepseek-r1-distill-qwen-7b": 0.0005 * RMB,
|
||||||
"embedding_s1_v1": 0.0715, // ¥0.001 / 1k tokens
|
"deepseek-r1-distill-qwen-14b": 0.001 * RMB,
|
||||||
"semantic_similarity_s1_v1": 0.0715, // ¥0.001 / 1k tokens
|
"deepseek-r1-distill-qwen-32b": 0.002 * RMB,
|
||||||
|
"deepseek-r1-distill-llama-8b": 0.0005 * RMB,
|
||||||
|
"deepseek-r1-distill-llama-70b": 0.004 * RMB,
|
||||||
|
"SparkDesk": 1.2858, // ¥0.018 / 1k tokens
|
||||||
|
"SparkDesk-v1.1": 1.2858, // ¥0.018 / 1k tokens
|
||||||
|
"SparkDesk-v2.1": 1.2858, // ¥0.018 / 1k tokens
|
||||||
|
"SparkDesk-v3.1": 1.2858, // ¥0.018 / 1k tokens
|
||||||
|
"SparkDesk-v3.1-128K": 1.2858, // ¥0.018 / 1k tokens
|
||||||
|
"SparkDesk-v3.5": 1.2858, // ¥0.018 / 1k tokens
|
||||||
|
"SparkDesk-v3.5-32K": 1.2858, // ¥0.018 / 1k tokens
|
||||||
|
"SparkDesk-v4.0": 1.2858, // ¥0.018 / 1k tokens
|
||||||
|
"360GPT_S2_V9": 0.8572, // ¥0.012 / 1k tokens
|
||||||
|
"embedding-bert-512-v1": 0.0715, // ¥0.001 / 1k tokens
|
||||||
|
"embedding_s1_v1": 0.0715, // ¥0.001 / 1k tokens
|
||||||
|
"semantic_similarity_s1_v1": 0.0715, // ¥0.001 / 1k tokens
|
||||||
// https://cloud.tencent.com/document/product/1729/97731#e0e6be58-60c8-469f-bdeb-6c264ce3b4d0
|
// https://cloud.tencent.com/document/product/1729/97731#e0e6be58-60c8-469f-bdeb-6c264ce3b4d0
|
||||||
"hunyuan-turbo": 0.015 * RMB,
|
"hunyuan-turbo": 0.015 * RMB,
|
||||||
"hunyuan-large": 0.004 * RMB,
|
"hunyuan-large": 0.004 * RMB,
|
||||||
@@ -362,6 +390,238 @@ var ModelRatio = map[string]float64{
|
|||||||
"mistralai/mistral-7b-instruct-v0.2": 0.050 * USD,
|
"mistralai/mistral-7b-instruct-v0.2": 0.050 * USD,
|
||||||
"mistralai/mistral-7b-v0.1": 0.050 * USD,
|
"mistralai/mistral-7b-v0.1": 0.050 * USD,
|
||||||
"mistralai/mixtral-8x7b-instruct-v0.1": 0.300 * USD,
|
"mistralai/mixtral-8x7b-instruct-v0.1": 0.300 * USD,
|
||||||
|
//https://openrouter.ai/models
|
||||||
|
"01-ai/yi-large": 1.5,
|
||||||
|
"aetherwiing/mn-starcannon-12b": 0.6,
|
||||||
|
"ai21/jamba-1-5-large": 4.0,
|
||||||
|
"ai21/jamba-1-5-mini": 0.2,
|
||||||
|
"ai21/jamba-instruct": 0.35,
|
||||||
|
"aion-labs/aion-1.0": 6.0,
|
||||||
|
"aion-labs/aion-1.0-mini": 1.2,
|
||||||
|
"aion-labs/aion-rp-llama-3.1-8b": 0.1,
|
||||||
|
"allenai/llama-3.1-tulu-3-405b": 5.0,
|
||||||
|
"alpindale/goliath-120b": 4.6875,
|
||||||
|
"alpindale/magnum-72b": 1.125,
|
||||||
|
"amazon/nova-lite-v1": 0.12,
|
||||||
|
"amazon/nova-micro-v1": 0.07,
|
||||||
|
"amazon/nova-pro-v1": 1.6,
|
||||||
|
"anthracite-org/magnum-v2-72b": 1.5,
|
||||||
|
"anthracite-org/magnum-v4-72b": 1.125,
|
||||||
|
"anthropic/claude-2": 12.0,
|
||||||
|
"anthropic/claude-2.0": 12.0,
|
||||||
|
"anthropic/claude-2.0:beta": 12.0,
|
||||||
|
"anthropic/claude-2.1": 12.0,
|
||||||
|
"anthropic/claude-2.1:beta": 12.0,
|
||||||
|
"anthropic/claude-2:beta": 12.0,
|
||||||
|
"anthropic/claude-3-haiku": 0.625,
|
||||||
|
"anthropic/claude-3-haiku:beta": 0.625,
|
||||||
|
"anthropic/claude-3-opus": 37.5,
|
||||||
|
"anthropic/claude-3-opus:beta": 37.5,
|
||||||
|
"anthropic/claude-3-sonnet": 7.5,
|
||||||
|
"anthropic/claude-3-sonnet:beta": 7.5,
|
||||||
|
"anthropic/claude-3.5-haiku": 2.0,
|
||||||
|
"anthropic/claude-3.5-haiku-20241022": 2.0,
|
||||||
|
"anthropic/claude-3.5-haiku-20241022:beta": 2.0,
|
||||||
|
"anthropic/claude-3.5-haiku:beta": 2.0,
|
||||||
|
"anthropic/claude-3.5-sonnet": 7.5,
|
||||||
|
"anthropic/claude-3.5-sonnet-20240620": 7.5,
|
||||||
|
"anthropic/claude-3.5-sonnet-20240620:beta": 7.5,
|
||||||
|
"anthropic/claude-3.5-sonnet:beta": 7.5,
|
||||||
|
"cognitivecomputations/dolphin-mixtral-8x22b": 0.45,
|
||||||
|
"cognitivecomputations/dolphin-mixtral-8x7b": 0.25,
|
||||||
|
"cohere/command": 0.95,
|
||||||
|
"cohere/command-r": 0.7125,
|
||||||
|
"cohere/command-r-03-2024": 0.7125,
|
||||||
|
"cohere/command-r-08-2024": 0.285,
|
||||||
|
"cohere/command-r-plus": 7.125,
|
||||||
|
"cohere/command-r-plus-04-2024": 7.125,
|
||||||
|
"cohere/command-r-plus-08-2024": 4.75,
|
||||||
|
"cohere/command-r7b-12-2024": 0.075,
|
||||||
|
"databricks/dbrx-instruct": 0.6,
|
||||||
|
"deepseek/deepseek-chat": 0.445,
|
||||||
|
"deepseek/deepseek-chat-v2.5": 1.0,
|
||||||
|
"deepseek/deepseek-chat:free": 0.0,
|
||||||
|
"deepseek/deepseek-r1": 1.2,
|
||||||
|
"deepseek/deepseek-r1-distill-llama-70b": 0.345,
|
||||||
|
"deepseek/deepseek-r1-distill-llama-70b:free": 0.0,
|
||||||
|
"deepseek/deepseek-r1-distill-llama-8b": 0.02,
|
||||||
|
"deepseek/deepseek-r1-distill-qwen-1.5b": 0.09,
|
||||||
|
"deepseek/deepseek-r1-distill-qwen-14b": 0.075,
|
||||||
|
"deepseek/deepseek-r1-distill-qwen-32b": 0.09,
|
||||||
|
"deepseek/deepseek-r1:free": 0.0,
|
||||||
|
"eva-unit-01/eva-llama-3.33-70b": 3.0,
|
||||||
|
"eva-unit-01/eva-qwen-2.5-32b": 1.7,
|
||||||
|
"eva-unit-01/eva-qwen-2.5-72b": 3.0,
|
||||||
|
"google/gemini-2.0-flash-001": 0.2,
|
||||||
|
"google/gemini-2.0-flash-exp:free": 0.0,
|
||||||
|
"google/gemini-2.0-flash-lite-preview-02-05:free": 0.0,
|
||||||
|
"google/gemini-2.0-flash-thinking-exp-1219:free": 0.0,
|
||||||
|
"google/gemini-2.0-flash-thinking-exp:free": 0.0,
|
||||||
|
"google/gemini-2.0-pro-exp-02-05:free": 0.0,
|
||||||
|
"google/gemini-exp-1206:free": 0.0,
|
||||||
|
"google/gemini-flash-1.5": 0.15,
|
||||||
|
"google/gemini-flash-1.5-8b": 0.075,
|
||||||
|
"google/gemini-flash-1.5-8b-exp": 0.0,
|
||||||
|
"google/gemini-pro": 0.75,
|
||||||
|
"google/gemini-pro-1.5": 2.5,
|
||||||
|
"google/gemini-pro-vision": 0.75,
|
||||||
|
"google/gemma-2-27b-it": 0.135,
|
||||||
|
"google/gemma-2-9b-it": 0.03,
|
||||||
|
"google/gemma-2-9b-it:free": 0.0,
|
||||||
|
"google/gemma-7b-it": 0.075,
|
||||||
|
"google/learnlm-1.5-pro-experimental:free": 0.0,
|
||||||
|
"google/palm-2-chat-bison": 1.0,
|
||||||
|
"google/palm-2-chat-bison-32k": 1.0,
|
||||||
|
"google/palm-2-codechat-bison": 1.0,
|
||||||
|
"google/palm-2-codechat-bison-32k": 1.0,
|
||||||
|
"gryphe/mythomax-l2-13b": 0.0325,
|
||||||
|
"gryphe/mythomax-l2-13b:free": 0.0,
|
||||||
|
"huggingfaceh4/zephyr-7b-beta:free": 0.0,
|
||||||
|
"infermatic/mn-inferor-12b": 0.6,
|
||||||
|
"inflection/inflection-3-pi": 5.0,
|
||||||
|
"inflection/inflection-3-productivity": 5.0,
|
||||||
|
"jondurbin/airoboros-l2-70b": 0.25,
|
||||||
|
"liquid/lfm-3b": 0.01,
|
||||||
|
"liquid/lfm-40b": 0.075,
|
||||||
|
"liquid/lfm-7b": 0.005,
|
||||||
|
"mancer/weaver": 1.125,
|
||||||
|
"meta-llama/llama-2-13b-chat": 0.11,
|
||||||
|
"meta-llama/llama-2-70b-chat": 0.45,
|
||||||
|
"meta-llama/llama-3-70b-instruct": 0.2,
|
||||||
|
"meta-llama/llama-3-8b-instruct": 0.03,
|
||||||
|
"meta-llama/llama-3-8b-instruct:free": 0.0,
|
||||||
|
"meta-llama/llama-3.1-405b": 1.0,
|
||||||
|
"meta-llama/llama-3.1-405b-instruct": 0.4,
|
||||||
|
"meta-llama/llama-3.1-70b-instruct": 0.15,
|
||||||
|
"meta-llama/llama-3.1-8b-instruct": 0.025,
|
||||||
|
"meta-llama/llama-3.2-11b-vision-instruct": 0.0275,
|
||||||
|
"meta-llama/llama-3.2-11b-vision-instruct:free": 0.0,
|
||||||
|
"meta-llama/llama-3.2-1b-instruct": 0.005,
|
||||||
|
"meta-llama/llama-3.2-3b-instruct": 0.0125,
|
||||||
|
"meta-llama/llama-3.2-90b-vision-instruct": 0.8,
|
||||||
|
"meta-llama/llama-3.3-70b-instruct": 0.15,
|
||||||
|
"meta-llama/llama-3.3-70b-instruct:free": 0.0,
|
||||||
|
"meta-llama/llama-guard-2-8b": 0.1,
|
||||||
|
"microsoft/phi-3-medium-128k-instruct": 0.5,
|
||||||
|
"microsoft/phi-3-medium-128k-instruct:free": 0.0,
|
||||||
|
"microsoft/phi-3-mini-128k-instruct": 0.05,
|
||||||
|
"microsoft/phi-3-mini-128k-instruct:free": 0.0,
|
||||||
|
"microsoft/phi-3.5-mini-128k-instruct": 0.05,
|
||||||
|
"microsoft/phi-4": 0.07,
|
||||||
|
"microsoft/wizardlm-2-7b": 0.035,
|
||||||
|
"microsoft/wizardlm-2-8x22b": 0.25,
|
||||||
|
"minimax/minimax-01": 0.55,
|
||||||
|
"mistralai/codestral-2501": 0.45,
|
||||||
|
"mistralai/codestral-mamba": 0.125,
|
||||||
|
"mistralai/ministral-3b": 0.02,
|
||||||
|
"mistralai/ministral-8b": 0.05,
|
||||||
|
"mistralai/mistral-7b-instruct": 0.0275,
|
||||||
|
"mistralai/mistral-7b-instruct-v0.1": 0.1,
|
||||||
|
"mistralai/mistral-7b-instruct-v0.3": 0.0275,
|
||||||
|
"mistralai/mistral-7b-instruct:free": 0.0,
|
||||||
|
"mistralai/mistral-large": 3.0,
|
||||||
|
"mistralai/mistral-large-2407": 3.0,
|
||||||
|
"mistralai/mistral-large-2411": 3.0,
|
||||||
|
"mistralai/mistral-medium": 4.05,
|
||||||
|
"mistralai/mistral-nemo": 0.04,
|
||||||
|
"mistralai/mistral-nemo:free": 0.0,
|
||||||
|
"mistralai/mistral-small": 0.3,
|
||||||
|
"mistralai/mistral-small-24b-instruct-2501": 0.07,
|
||||||
|
"mistralai/mistral-small-24b-instruct-2501:free": 0.0,
|
||||||
|
"mistralai/mistral-tiny": 0.125,
|
||||||
|
"mistralai/mixtral-8x22b-instruct": 0.45,
|
||||||
|
"mistralai/mixtral-8x7b": 0.3,
|
||||||
|
"mistralai/mixtral-8x7b-instruct": 0.12,
|
||||||
|
"mistralai/pixtral-12b": 0.05,
|
||||||
|
"mistralai/pixtral-large-2411": 3.0,
|
||||||
|
"neversleep/llama-3-lumimaid-70b": 2.25,
|
||||||
|
"neversleep/llama-3-lumimaid-8b": 0.5625,
|
||||||
|
"neversleep/llama-3-lumimaid-8b:extended": 0.5625,
|
||||||
|
"neversleep/llama-3.1-lumimaid-70b": 2.25,
|
||||||
|
"neversleep/llama-3.1-lumimaid-8b": 0.5625,
|
||||||
|
"neversleep/noromaid-20b": 1.125,
|
||||||
|
"nothingiisreal/mn-celeste-12b": 0.6,
|
||||||
|
"nousresearch/hermes-2-pro-llama-3-8b": 0.02,
|
||||||
|
"nousresearch/hermes-3-llama-3.1-405b": 0.4,
|
||||||
|
"nousresearch/hermes-3-llama-3.1-70b": 0.15,
|
||||||
|
"nousresearch/nous-hermes-2-mixtral-8x7b-dpo": 0.3,
|
||||||
|
"nousresearch/nous-hermes-llama2-13b": 0.085,
|
||||||
|
"nvidia/llama-3.1-nemotron-70b-instruct": 0.15,
|
||||||
|
"nvidia/llama-3.1-nemotron-70b-instruct:free": 0.0,
|
||||||
|
"openai/chatgpt-4o-latest": 7.5,
|
||||||
|
"openai/gpt-3.5-turbo": 0.75,
|
||||||
|
"openai/gpt-3.5-turbo-0125": 0.75,
|
||||||
|
"openai/gpt-3.5-turbo-0613": 1.0,
|
||||||
|
"openai/gpt-3.5-turbo-1106": 1.0,
|
||||||
|
"openai/gpt-3.5-turbo-16k": 2.0,
|
||||||
|
"openai/gpt-3.5-turbo-instruct": 1.0,
|
||||||
|
"openai/gpt-4": 30.0,
|
||||||
|
"openai/gpt-4-0314": 30.0,
|
||||||
|
"openai/gpt-4-1106-preview": 15.0,
|
||||||
|
"openai/gpt-4-32k": 60.0,
|
||||||
|
"openai/gpt-4-32k-0314": 60.0,
|
||||||
|
"openai/gpt-4-turbo": 15.0,
|
||||||
|
"openai/gpt-4-turbo-preview": 15.0,
|
||||||
|
"openai/gpt-4o": 5.0,
|
||||||
|
"openai/gpt-4o-2024-05-13": 7.5,
|
||||||
|
"openai/gpt-4o-2024-08-06": 5.0,
|
||||||
|
"openai/gpt-4o-2024-11-20": 5.0,
|
||||||
|
"openai/gpt-4o-mini": 0.3,
|
||||||
|
"openai/gpt-4o-mini-2024-07-18": 0.3,
|
||||||
|
"openai/gpt-4o:extended": 9.0,
|
||||||
|
"openai/o1": 30.0,
|
||||||
|
"openai/o1-mini": 2.2,
|
||||||
|
"openai/o1-mini-2024-09-12": 2.2,
|
||||||
|
"openai/o1-preview": 30.0,
|
||||||
|
"openai/o1-preview-2024-09-12": 30.0,
|
||||||
|
"openai/o3-mini": 2.2,
|
||||||
|
"openai/o3-mini-high": 2.2,
|
||||||
|
"openchat/openchat-7b": 0.0275,
|
||||||
|
"openchat/openchat-7b:free": 0.0,
|
||||||
|
"openrouter/auto": -500000.0,
|
||||||
|
"perplexity/llama-3.1-sonar-huge-128k-online": 2.5,
|
||||||
|
"perplexity/llama-3.1-sonar-large-128k-chat": 0.5,
|
||||||
|
"perplexity/llama-3.1-sonar-large-128k-online": 0.5,
|
||||||
|
"perplexity/llama-3.1-sonar-small-128k-chat": 0.1,
|
||||||
|
"perplexity/llama-3.1-sonar-small-128k-online": 0.1,
|
||||||
|
"perplexity/sonar": 0.5,
|
||||||
|
"perplexity/sonar-reasoning": 2.5,
|
||||||
|
"pygmalionai/mythalion-13b": 0.6,
|
||||||
|
"qwen/qvq-72b-preview": 0.25,
|
||||||
|
"qwen/qwen-2-72b-instruct": 0.45,
|
||||||
|
"qwen/qwen-2-7b-instruct": 0.027,
|
||||||
|
"qwen/qwen-2-7b-instruct:free": 0.0,
|
||||||
|
"qwen/qwen-2-vl-72b-instruct": 0.2,
|
||||||
|
"qwen/qwen-2-vl-7b-instruct": 0.05,
|
||||||
|
"qwen/qwen-2.5-72b-instruct": 0.2,
|
||||||
|
"qwen/qwen-2.5-7b-instruct": 0.025,
|
||||||
|
"qwen/qwen-2.5-coder-32b-instruct": 0.08,
|
||||||
|
"qwen/qwen-max": 3.2,
|
||||||
|
"qwen/qwen-plus": 0.6,
|
||||||
|
"qwen/qwen-turbo": 0.1,
|
||||||
|
"qwen/qwen-vl-plus:free": 0.0,
|
||||||
|
"qwen/qwen2.5-vl-72b-instruct:free": 0.0,
|
||||||
|
"qwen/qwq-32b-preview": 0.09,
|
||||||
|
"raifle/sorcererlm-8x22b": 2.25,
|
||||||
|
"sao10k/fimbulvetr-11b-v2": 0.6,
|
||||||
|
"sao10k/l3-euryale-70b": 0.4,
|
||||||
|
"sao10k/l3-lunaris-8b": 0.03,
|
||||||
|
"sao10k/l3.1-70b-hanami-x1": 1.5,
|
||||||
|
"sao10k/l3.1-euryale-70b": 0.4,
|
||||||
|
"sao10k/l3.3-euryale-70b": 0.4,
|
||||||
|
"sophosympatheia/midnight-rose-70b": 0.4,
|
||||||
|
"sophosympatheia/rogue-rose-103b-v0.2:free": 0.0,
|
||||||
|
"teknium/openhermes-2.5-mistral-7b": 0.085,
|
||||||
|
"thedrummer/rocinante-12b": 0.25,
|
||||||
|
"thedrummer/unslopnemo-12b": 0.25,
|
||||||
|
"undi95/remm-slerp-l2-13b": 0.6,
|
||||||
|
"undi95/toppy-m-7b": 0.035,
|
||||||
|
"undi95/toppy-m-7b:free": 0.0,
|
||||||
|
"x-ai/grok-2-1212": 5.0,
|
||||||
|
"x-ai/grok-2-vision-1212": 5.0,
|
||||||
|
"x-ai/grok-beta": 7.5,
|
||||||
|
"x-ai/grok-vision-beta": 7.5,
|
||||||
|
"xwin-lm/xwin-lm-70b": 1.875,
|
||||||
}
|
}
|
||||||
|
|
||||||
var CompletionRatio = map[string]float64{
|
var CompletionRatio = map[string]float64{
|
||||||
@@ -369,7 +629,9 @@ var CompletionRatio = map[string]float64{
|
|||||||
"llama3-8b-8192(33)": 0.0006 / 0.0003,
|
"llama3-8b-8192(33)": 0.0006 / 0.0003,
|
||||||
"llama3-70b-8192(33)": 0.0035 / 0.00265,
|
"llama3-70b-8192(33)": 0.0035 / 0.00265,
|
||||||
// whisper
|
// whisper
|
||||||
"whisper-1": 0, // only count input tokens
|
"whisper-1": 0, // only count input tokens
|
||||||
|
"gpt-4o-mini-transcribe": 0,
|
||||||
|
"gpt-4o-transcribe": 0,
|
||||||
// deepseek
|
// deepseek
|
||||||
"deepseek-chat": 0.28 / 0.14,
|
"deepseek-chat": 0.28 / 0.14,
|
||||||
"deepseek-reasoner": 2.19 / 0.55,
|
"deepseek-reasoner": 2.19 / 0.55,
|
||||||
|
|||||||
@@ -50,5 +50,9 @@ const (
|
|||||||
Replicate
|
Replicate
|
||||||
BaiduV2
|
BaiduV2
|
||||||
XunfeiV2
|
XunfeiV2
|
||||||
|
AliBailian
|
||||||
|
OpenAICompatible
|
||||||
|
GeminiOpenAICompatible
|
||||||
|
CozeV3
|
||||||
Dummy
|
Dummy
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -23,12 +23,16 @@ func ToAPIType(channelType int) int {
|
|||||||
apiType = apitype.Tencent
|
apiType = apitype.Tencent
|
||||||
case Gemini:
|
case Gemini:
|
||||||
apiType = apitype.Gemini
|
apiType = apitype.Gemini
|
||||||
|
case GeminiOpenAICompatible:
|
||||||
|
apiType = apitype.Gemini
|
||||||
case Ollama:
|
case Ollama:
|
||||||
apiType = apitype.Ollama
|
apiType = apitype.Ollama
|
||||||
case AwsClaude:
|
case AwsClaude:
|
||||||
apiType = apitype.AwsClaude
|
apiType = apitype.AwsClaude
|
||||||
case Coze:
|
case Coze:
|
||||||
apiType = apitype.Coze
|
apiType = apitype.Coze
|
||||||
|
case CozeV3:
|
||||||
|
apiType = apitype.CozeV3
|
||||||
case Cohere:
|
case Cohere:
|
||||||
apiType = apitype.Cohere
|
apiType = apitype.Cohere
|
||||||
case Cloudflare:
|
case Cloudflare:
|
||||||
|
|||||||
@@ -50,6 +50,11 @@ var ChannelBaseURLs = []string{
|
|||||||
"https://api.replicate.com/v1/models/", // 46
|
"https://api.replicate.com/v1/models/", // 46
|
||||||
"https://qianfan.baidubce.com", // 47
|
"https://qianfan.baidubce.com", // 47
|
||||||
"https://spark-api-open.xf-yun.com", // 48
|
"https://spark-api-open.xf-yun.com", // 48
|
||||||
|
"https://dashscope.aliyuncs.com", // 49
|
||||||
|
"", // 50
|
||||||
|
|
||||||
|
"https://generativelanguage.googleapis.com/v1beta/openai/", // 51
|
||||||
|
"https://api.coze.cn", // 52
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"mime/multipart"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -30,8 +31,7 @@ import (
|
|||||||
func RelayAudioHelper(c *gin.Context, relayMode int) *relaymodel.ErrorWithStatusCode {
|
func RelayAudioHelper(c *gin.Context, relayMode int) *relaymodel.ErrorWithStatusCode {
|
||||||
ctx := c.Request.Context()
|
ctx := c.Request.Context()
|
||||||
meta := meta.GetByContext(c)
|
meta := meta.GetByContext(c)
|
||||||
audioModel := "whisper-1"
|
audioModel := "gpt-4o-transcribe"
|
||||||
|
|
||||||
tokenId := c.GetInt(ctxkey.TokenId)
|
tokenId := c.GetInt(ctxkey.TokenId)
|
||||||
channelType := c.GetInt(ctxkey.Channel)
|
channelType := c.GetInt(ctxkey.Channel)
|
||||||
channelId := c.GetInt(ctxkey.ChannelId)
|
channelId := c.GetInt(ctxkey.ChannelId)
|
||||||
@@ -124,12 +124,13 @@ func RelayAudioHelper(c *gin.Context, relayMode int) *relaymodel.ErrorWithStatus
|
|||||||
fullRequestURL := openai.GetFullRequestURL(baseURL, requestURL, channelType)
|
fullRequestURL := openai.GetFullRequestURL(baseURL, requestURL, channelType)
|
||||||
if channelType == channeltype.Azure {
|
if channelType == channeltype.Azure {
|
||||||
apiVersion := meta.Config.APIVersion
|
apiVersion := meta.Config.APIVersion
|
||||||
|
deploymentName := c.GetString(ctxkey.ChannelName)
|
||||||
if relayMode == relaymode.AudioTranscription {
|
if relayMode == relaymode.AudioTranscription {
|
||||||
// https://learn.microsoft.com/en-us/azure/ai-services/openai/whisper-quickstart?tabs=command-line#rest-api
|
// https://learn.microsoft.com/en-us/azure/ai-services/openai/whisper-quickstart?tabs=command-line#rest-api
|
||||||
fullRequestURL = fmt.Sprintf("%s/openai/deployments/%s/audio/transcriptions?api-version=%s", baseURL, audioModel, apiVersion)
|
fullRequestURL = fmt.Sprintf("%s/openai/deployments/%s/audio/transcriptions?api-version=%s", baseURL, deploymentName, apiVersion)
|
||||||
} else if relayMode == relaymode.AudioSpeech {
|
} else if relayMode == relaymode.AudioSpeech {
|
||||||
// https://learn.microsoft.com/en-us/azure/ai-services/openai/text-to-speech-quickstart?tabs=command-line#rest-api
|
// https://learn.microsoft.com/en-us/azure/ai-services/openai/text-to-speech-quickstart?tabs=command-line#rest-api
|
||||||
fullRequestURL = fmt.Sprintf("%s/openai/deployments/%s/audio/speech?api-version=%s", baseURL, audioModel, apiVersion)
|
fullRequestURL = fmt.Sprintf("%s/openai/deployments/%s/audio/speech?api-version=%s", baseURL, deploymentName, apiVersion)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,8 +139,73 @@ func RelayAudioHelper(c *gin.Context, relayMode int) *relaymodel.ErrorWithStatus
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return openai.ErrorWrapper(err, "new_request_body_failed", http.StatusInternalServerError)
|
return openai.ErrorWrapper(err, "new_request_body_failed", http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
c.Request.Body = io.NopCloser(bytes.NewBuffer(requestBody.Bytes()))
|
|
||||||
responseFormat := c.DefaultPostForm("response_format", "json")
|
// 处理表单数据
|
||||||
|
contentType := c.Request.Header.Get("Content-Type")
|
||||||
|
responseFormat := "json"
|
||||||
|
var contentTypeWithBoundary string
|
||||||
|
|
||||||
|
if strings.Contains(contentType, "multipart/form-data") {
|
||||||
|
originalBody := requestBody.Bytes()
|
||||||
|
c.Request.Body = io.NopCloser(bytes.NewBuffer(originalBody))
|
||||||
|
err = c.Request.ParseMultipartForm(32 << 20) // 32MB 最大内存
|
||||||
|
if err != nil {
|
||||||
|
return openai.ErrorWrapper(err, "parse_multipart_form_failed", http.StatusInternalServerError)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取响应格式
|
||||||
|
if format := c.Request.FormValue("response_format"); format != "" {
|
||||||
|
responseFormat = format
|
||||||
|
}
|
||||||
|
|
||||||
|
requestBody = &bytes.Buffer{}
|
||||||
|
writer := multipart.NewWriter(requestBody)
|
||||||
|
|
||||||
|
// 复制表单字段
|
||||||
|
for key, values := range c.Request.MultipartForm.Value {
|
||||||
|
for _, value := range values {
|
||||||
|
err = writer.WriteField(key, value)
|
||||||
|
if err != nil {
|
||||||
|
return openai.ErrorWrapper(err, "write_field_failed", http.StatusInternalServerError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 复制文件
|
||||||
|
for key, fileHeaders := range c.Request.MultipartForm.File {
|
||||||
|
for _, fileHeader := range fileHeaders {
|
||||||
|
file, err := fileHeader.Open()
|
||||||
|
if err != nil {
|
||||||
|
return openai.ErrorWrapper(err, "open_file_failed", http.StatusInternalServerError)
|
||||||
|
}
|
||||||
|
|
||||||
|
part, err := writer.CreateFormFile(key, fileHeader.Filename)
|
||||||
|
if err != nil {
|
||||||
|
file.Close()
|
||||||
|
return openai.ErrorWrapper(err, "create_form_file_failed", http.StatusInternalServerError)
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = io.Copy(part, file)
|
||||||
|
file.Close()
|
||||||
|
if err != nil {
|
||||||
|
return openai.ErrorWrapper(err, "copy_file_failed", http.StatusInternalServerError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 完成multipart写入
|
||||||
|
err = writer.Close()
|
||||||
|
if err != nil {
|
||||||
|
return openai.ErrorWrapper(err, "close_writer_failed", http.StatusInternalServerError)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新Content-Type
|
||||||
|
contentTypeWithBoundary = writer.FormDataContentType()
|
||||||
|
c.Request.Header.Set("Content-Type", contentTypeWithBoundary)
|
||||||
|
} else {
|
||||||
|
// 对于非表单请求,直接重置请求体
|
||||||
|
c.Request.Body = io.NopCloser(bytes.NewBuffer(requestBody.Bytes()))
|
||||||
|
}
|
||||||
|
|
||||||
req, err := http.NewRequest(c.Request.Method, fullRequestURL, requestBody)
|
req, err := http.NewRequest(c.Request.Method, fullRequestURL, requestBody)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -151,11 +217,26 @@ func RelayAudioHelper(c *gin.Context, relayMode int) *relaymodel.ErrorWithStatus
|
|||||||
apiKey := c.Request.Header.Get("Authorization")
|
apiKey := c.Request.Header.Get("Authorization")
|
||||||
apiKey = strings.TrimPrefix(apiKey, "Bearer ")
|
apiKey = strings.TrimPrefix(apiKey, "Bearer ")
|
||||||
req.Header.Set("api-key", apiKey)
|
req.Header.Set("api-key", apiKey)
|
||||||
req.ContentLength = c.Request.ContentLength
|
// 确保请求体大小与Content-Length一致
|
||||||
|
req.ContentLength = int64(requestBody.Len())
|
||||||
} else {
|
} else {
|
||||||
req.Header.Set("Authorization", c.Request.Header.Get("Authorization"))
|
req.Header.Set("Authorization", c.Request.Header.Get("Authorization"))
|
||||||
|
// 确保请求体大小与Content-Length一致
|
||||||
|
req.ContentLength = int64(requestBody.Len())
|
||||||
|
}
|
||||||
|
|
||||||
|
// 确保Content-Type正确传递
|
||||||
|
if strings.Contains(contentType, "multipart/form-data") && c.Request.MultipartForm != nil {
|
||||||
|
// 对于multipart请求,使用我们重建时生成的Content-Type
|
||||||
|
// 注意:此处必须使用writer生成的boundary
|
||||||
|
if contentTypeWithBoundary != "" {
|
||||||
|
req.Header.Set("Content-Type", contentTypeWithBoundary)
|
||||||
|
} else {
|
||||||
|
req.Header.Set("Content-Type", c.Request.Header.Get("Content-Type"))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
req.Header.Set("Content-Type", c.Request.Header.Get("Content-Type"))
|
||||||
}
|
}
|
||||||
req.Header.Set("Content-Type", c.Request.Header.Get("Content-Type"))
|
|
||||||
req.Header.Set("Accept", c.Request.Header.Get("Accept"))
|
req.Header.Set("Accept", c.Request.Header.Get("Accept"))
|
||||||
|
|
||||||
resp, err := client.HTTPClient.Do(req)
|
resp, err := client.HTTPClient.Do(req)
|
||||||
|
|||||||
@@ -4,4 +4,5 @@ const (
|
|||||||
ContentTypeText = "text"
|
ContentTypeText = "text"
|
||||||
ContentTypeImageURL = "image_url"
|
ContentTypeImageURL = "image_url"
|
||||||
ContentTypeInputAudio = "input_audio"
|
ContentTypeInputAudio = "input_audio"
|
||||||
|
ContentTypeInputFile = "file"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
|
import "encoding/json"
|
||||||
|
|
||||||
type Message struct {
|
type Message struct {
|
||||||
Role string `json:"role,omitempty"`
|
Role string `json:"role,omitempty"`
|
||||||
Content any `json:"content,omitempty"`
|
Content any `json:"content,omitempty"`
|
||||||
@@ -38,6 +40,53 @@ func (m Message) StringContent() string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m Message) CozeV3StringContent() string {
|
||||||
|
content, ok := m.Content.(string)
|
||||||
|
if ok {
|
||||||
|
return content
|
||||||
|
}
|
||||||
|
contentList, ok := m.Content.([]any)
|
||||||
|
if ok {
|
||||||
|
contents := make([]map[string]any, 0)
|
||||||
|
var contentStr string
|
||||||
|
for _, contentItem := range contentList {
|
||||||
|
contentMap, ok := contentItem.(map[string]any)
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
switch contentMap["type"] {
|
||||||
|
case "text":
|
||||||
|
if subStr, ok := contentMap["text"].(string); ok {
|
||||||
|
contents = append(contents, map[string]any{
|
||||||
|
"type": "text",
|
||||||
|
"text": subStr,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
case "image_url":
|
||||||
|
if subStr, ok := contentMap["image_url"].(string); ok {
|
||||||
|
contents = append(contents, map[string]any{
|
||||||
|
"type": "image",
|
||||||
|
"file_url": subStr,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
case "file":
|
||||||
|
if subStr, ok := contentMap["image_url"].(string); ok {
|
||||||
|
contents = append(contents, map[string]any{
|
||||||
|
"type": "file",
|
||||||
|
"file_url": subStr,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(contents) > 0 {
|
||||||
|
b, _ := json.Marshal(contents)
|
||||||
|
return string(b)
|
||||||
|
}
|
||||||
|
return contentStr
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
func (m Message) ParseContent() []MessageContent {
|
func (m Message) ParseContent() []MessageContent {
|
||||||
var contentList []MessageContent
|
var contentList []MessageContent
|
||||||
content, ok := m.Content.(string)
|
content, ok := m.Content.(string)
|
||||||
@@ -72,6 +121,15 @@ func (m Message) ParseContent() []MessageContent {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
case ContentTypeInputFile:
|
||||||
|
if subObj, ok := contentMap["file"].(map[string]any); ok {
|
||||||
|
contentList = append(contentList, MessageContent{
|
||||||
|
Type: ContentTypeInputFile,
|
||||||
|
File: &File{
|
||||||
|
FileData: subObj["file_data"].(string),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return contentList
|
return contentList
|
||||||
@@ -88,4 +146,10 @@ type MessageContent struct {
|
|||||||
Type string `json:"type,omitempty"`
|
Type string `json:"type,omitempty"`
|
||||||
Text string `json:"text"`
|
Text string `json:"text"`
|
||||||
ImageURL *ImageURL `json:"image_url,omitempty"`
|
ImageURL *ImageURL `json:"image_url,omitempty"`
|
||||||
|
File *File `json:"file,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type File struct {
|
||||||
|
FileData string `json:"file_data,omitempty"`
|
||||||
|
FileName string `json:"filename,omitempty"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ export const CHANNEL_OPTIONS = [
|
|||||||
{ key: 31, text: '零一万物', value: 31, color: 'green' },
|
{ key: 31, text: '零一万物', value: 31, color: 'green' },
|
||||||
{ key: 32, text: '阶跃星辰', value: 32, color: 'blue' },
|
{ key: 32, text: '阶跃星辰', value: 32, color: 'blue' },
|
||||||
{ key: 34, text: 'Coze', value: 34, color: 'blue' },
|
{ key: 34, text: 'Coze', value: 34, color: 'blue' },
|
||||||
|
{ key: 52, text: 'CozeV3', value: 52, color: 'blue' },
|
||||||
{ key: 35, text: 'Cohere', value: 35, color: 'blue' },
|
{ key: 35, text: 'Cohere', value: 35, color: 'blue' },
|
||||||
{ key: 36, text: 'DeepSeek', value: 36, color: 'black' },
|
{ key: 36, text: 'DeepSeek', value: 36, color: 'black' },
|
||||||
{ key: 37, text: 'Cloudflare', value: 37, color: 'orange' },
|
{ key: 37, text: 'Cloudflare', value: 37, color: 'orange' },
|
||||||
@@ -35,7 +36,7 @@ export const CHANNEL_OPTIONS = [
|
|||||||
{ key: 8, text: '自定义渠道', value: 8, color: 'pink' },
|
{ key: 8, text: '自定义渠道', value: 8, color: 'pink' },
|
||||||
{ key: 22, text: '知识库:FastGPT', value: 22, color: 'blue' },
|
{ key: 22, text: '知识库:FastGPT', value: 22, color: 'blue' },
|
||||||
{ key: 21, text: '知识库:AI Proxy', value: 21, color: 'purple' },
|
{ key: 21, text: '知识库:AI Proxy', value: 21, color: 'purple' },
|
||||||
{ key: 20, text: '代理:OpenRouter', value: 20, color: 'black' },
|
{key: 20, text: 'OpenRouter', value: 20, color: 'black'},
|
||||||
{ key: 2, text: '代理:API2D', value: 2, color: 'blue' },
|
{ key: 2, text: '代理:API2D', value: 2, color: 'blue' },
|
||||||
{ key: 5, text: '代理:OpenAI-SB', value: 5, color: 'brown' },
|
{ key: 5, text: '代理:OpenAI-SB', value: 5, color: 'brown' },
|
||||||
{ key: 7, text: '代理:OhMyGPT', value: 7, color: 'purple' },
|
{ key: 7, text: '代理:OhMyGPT', value: 7, color: 'purple' },
|
||||||
|
|||||||
@@ -137,6 +137,12 @@ export const CHANNEL_OPTIONS = {
|
|||||||
value: 34,
|
value: 34,
|
||||||
color: 'primary'
|
color: 'primary'
|
||||||
},
|
},
|
||||||
|
52: {
|
||||||
|
key: 52,
|
||||||
|
text: 'CozeV3',
|
||||||
|
value: 52,
|
||||||
|
color: 'primary'
|
||||||
|
},
|
||||||
35: {
|
35: {
|
||||||
key: 35,
|
key: 35,
|
||||||
text: 'Cohere',
|
text: 'Cohere',
|
||||||
@@ -185,7 +191,7 @@ export const CHANNEL_OPTIONS = {
|
|||||||
value: 45,
|
value: 45,
|
||||||
color: 'primary'
|
color: 'primary'
|
||||||
},
|
},
|
||||||
45: {
|
46: {
|
||||||
key: 46,
|
key: 46,
|
||||||
text: 'Replicate',
|
text: 'Replicate',
|
||||||
value: 46,
|
value: 46,
|
||||||
@@ -217,7 +223,7 @@ export const CHANNEL_OPTIONS = {
|
|||||||
},
|
},
|
||||||
20: {
|
20: {
|
||||||
key: 20,
|
key: 20,
|
||||||
text: '代理:OpenRouter',
|
text: 'OpenRouter',
|
||||||
value: 20,
|
value: 20,
|
||||||
color: 'success'
|
color: 'success'
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -206,6 +206,20 @@ const typeConfig = {
|
|||||||
},
|
},
|
||||||
modelGroup: 'Coze'
|
modelGroup: 'Coze'
|
||||||
},
|
},
|
||||||
|
52: {
|
||||||
|
inputLabel: {
|
||||||
|
config: {
|
||||||
|
user_id: 'User ID'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
prompt: {
|
||||||
|
models: '对于 CozeV3 而言,模型名称即 Bot ID,你可以添加一个前缀 `bot-`,例如:`bot-123456`',
|
||||||
|
config: {
|
||||||
|
user_id: '生成该密钥的用户 ID'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
modelGroup: 'CozeV3'
|
||||||
|
},
|
||||||
42: {
|
42: {
|
||||||
inputLabel: {
|
inputLabel: {
|
||||||
key: '',
|
key: '',
|
||||||
|
|||||||
@@ -44,6 +44,9 @@ function renderType(type, t) {
|
|||||||
function renderBalance(type, balance, t) {
|
function renderBalance(type, balance, t) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 1: // OpenAI
|
case 1: // OpenAI
|
||||||
|
if (balance === 0) {
|
||||||
|
return <span>{t('channel.table.balance_not_supported')}</span>;
|
||||||
|
}
|
||||||
return <span>${balance.toFixed(2)}</span>;
|
return <span>${balance.toFixed(2)}</span>;
|
||||||
case 4: // CloseAI
|
case 4: // CloseAI
|
||||||
return <span>¥{balance.toFixed(2)}</span>;
|
return <span>¥{balance.toFixed(2)}</span>;
|
||||||
@@ -57,6 +60,8 @@ function renderBalance(type, balance, t) {
|
|||||||
return <span>¥{balance.toFixed(2)}</span>;
|
return <span>¥{balance.toFixed(2)}</span>;
|
||||||
case 13: // AIGC2D
|
case 13: // AIGC2D
|
||||||
return <span>{renderNumber(balance)}</span>;
|
return <span>{renderNumber(balance)}</span>;
|
||||||
|
case 20: // OpenRouter
|
||||||
|
return <span>${balance.toFixed(2)}</span>;
|
||||||
case 36: // DeepSeek
|
case 36: // DeepSeek
|
||||||
return <span>¥{balance.toFixed(2)}</span>;
|
return <span>¥{balance.toFixed(2)}</span>;
|
||||||
case 44: // SiliconFlow
|
case 44: // SiliconFlow
|
||||||
@@ -106,7 +111,7 @@ const ChannelsTable = () => {
|
|||||||
|
|
||||||
const loadChannels = async (startIdx) => {
|
const loadChannels = async (startIdx) => {
|
||||||
const res = await API.get(`/api/channel/?p=${startIdx}`);
|
const res = await API.get(`/api/channel/?p=${startIdx}`);
|
||||||
const {success, message, data} = res.data;
|
const { success, message, data } = res.data;
|
||||||
if (success) {
|
if (success) {
|
||||||
let localChannels = data.map(processChannelData);
|
let localChannels = data.map(processChannelData);
|
||||||
if (startIdx === 0) {
|
if (startIdx === 0) {
|
||||||
@@ -488,7 +493,6 @@ const ChannelsTable = () => {
|
|||||||
onClick={() => {
|
onClick={() => {
|
||||||
sortChannel('balance');
|
sortChannel('balance');
|
||||||
}}
|
}}
|
||||||
hidden={!showDetail}
|
|
||||||
>
|
>
|
||||||
{t('channel.table.balance')}
|
{t('channel.table.balance')}
|
||||||
</Table.HeaderCell>
|
</Table.HeaderCell>
|
||||||
@@ -497,6 +501,7 @@ const ChannelsTable = () => {
|
|||||||
onClick={() => {
|
onClick={() => {
|
||||||
sortChannel('priority');
|
sortChannel('priority');
|
||||||
}}
|
}}
|
||||||
|
hidden={!showDetail}
|
||||||
>
|
>
|
||||||
{t('channel.table.priority')}
|
{t('channel.table.priority')}
|
||||||
</Table.HeaderCell>
|
</Table.HeaderCell>
|
||||||
@@ -536,7 +541,7 @@ const ChannelsTable = () => {
|
|||||||
basic
|
basic
|
||||||
/>
|
/>
|
||||||
</Table.Cell>
|
</Table.Cell>
|
||||||
<Table.Cell hidden={!showDetail}>
|
<Table.Cell>
|
||||||
<Popup
|
<Popup
|
||||||
trigger={
|
trigger={
|
||||||
<span
|
<span
|
||||||
@@ -552,7 +557,7 @@ const ChannelsTable = () => {
|
|||||||
basic
|
basic
|
||||||
/>
|
/>
|
||||||
</Table.Cell>
|
</Table.Cell>
|
||||||
<Table.Cell>
|
<Table.Cell hidden={!showDetail}>
|
||||||
<Popup
|
<Popup
|
||||||
trigger={
|
trigger={
|
||||||
<Input
|
<Input
|
||||||
@@ -586,7 +591,15 @@ const ChannelsTable = () => {
|
|||||||
/>
|
/>
|
||||||
</Table.Cell>
|
</Table.Cell>
|
||||||
<Table.Cell>
|
<Table.Cell>
|
||||||
<div>
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
flexWrap: 'wrap',
|
||||||
|
gap: '2px',
|
||||||
|
rowGap: '6px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
<Button
|
<Button
|
||||||
size={'tiny'}
|
size={'tiny'}
|
||||||
positive
|
positive
|
||||||
|
|||||||
@@ -1,80 +1,109 @@
|
|||||||
export const CHANNEL_OPTIONS = [
|
export const CHANNEL_OPTIONS = [
|
||||||
{key: 1, text: 'OpenAI', value: 1, color: 'green'},
|
{key: 1, text: 'OpenAI', value: 1, color: 'green'},
|
||||||
{key: 14, text: 'Anthropic Claude', value: 14, color: 'black'},
|
{
|
||||||
{key: 33, text: 'AWS', value: 33, color: 'black'},
|
key: 50,
|
||||||
{key: 3, text: 'Azure OpenAI', value: 3, color: 'olive'},
|
text: 'OpenAI 兼容',
|
||||||
{key: 11, text: 'Google PaLM2', value: 11, color: 'orange'},
|
value: 50,
|
||||||
{key: 24, text: 'Google Gemini', value: 24, color: 'orange'},
|
color: 'olive',
|
||||||
{key: 28, text: 'Mistral AI', value: 28, color: 'orange'},
|
description: 'OpenAI 兼容渠道,支持设置 Base URL',
|
||||||
{key: 41, text: 'Novita', value: 41, color: 'purple'},
|
},
|
||||||
{
|
{key: 14, text: 'Anthropic', value: 14, color: 'black'},
|
||||||
key: 40,
|
{key: 33, text: 'AWS', value: 33, color: 'black'},
|
||||||
text: '字节火山引擎',
|
{key: 3, text: 'Azure', value: 3, color: 'olive'},
|
||||||
value: 40,
|
{key: 11, text: 'PaLM2', value: 11, color: 'orange'},
|
||||||
color: 'blue',
|
{key: 24, text: 'Gemini', value: 24, color: 'orange'},
|
||||||
description: '原字节跳动豆包',
|
{
|
||||||
},
|
key: 51,
|
||||||
{
|
text: 'Gemini (OpenAI)',
|
||||||
key: 15,
|
value: 51,
|
||||||
text: '百度文心千帆',
|
color: 'orange',
|
||||||
value: 15,
|
description: 'Gemini OpenAI 兼容格式',
|
||||||
color: 'blue',
|
},
|
||||||
tip: '请前往<a href="https://console.bce.baidu.com/qianfan/ais/console/applicationConsole/application/v1" target="_blank">此处</a>获取 AK(API Key)以及 SK(Secret Key),注意,V2 版本接口请使用 <strong>百度文心千帆 V2 </strong>渠道类型',
|
{key: 28, text: 'Mistral AI', value: 28, color: 'orange'},
|
||||||
},
|
{key: 41, text: 'Novita', value: 41, color: 'purple'},
|
||||||
{
|
{
|
||||||
key: 47,
|
key: 40,
|
||||||
text: '百度文心千帆 V2',
|
text: '字节火山引擎',
|
||||||
value: 47,
|
value: 40,
|
||||||
color: 'blue',
|
color: 'blue',
|
||||||
tip: '请前往<a href="https://console.bce.baidu.com/iam/#/iam/apikey/list" target="_blank">此处</a>获取 API Key,注意本渠道仅支持<a target="_blank" href="https://cloud.baidu.com/doc/WENXINWORKSHOP/s/em4tsqo3v">推理服务 V2</a>相关模型',
|
description: '原字节跳动豆包',
|
||||||
},
|
},
|
||||||
{key: 17, text: '阿里通义千问', value: 17, color: 'orange'},
|
{
|
||||||
{
|
key: 15,
|
||||||
key: 18,
|
text: '百度文心千帆',
|
||||||
text: '讯飞星火认知',
|
value: 15,
|
||||||
value: 18,
|
color: 'blue',
|
||||||
color: 'blue',
|
tip: '请前往<a href="https://console.bce.baidu.com/qianfan/ais/console/applicationConsole/application/v1" target="_blank">此处</a>获取 AK(API Key)以及 SK(Secret Key),注意,V2 版本接口请使用 <strong>百度文心千帆 V2 </strong>渠道类型',
|
||||||
tip: '本渠道基于讯飞 WebSocket 版本 API,如需 HTTP 版本,请使用<strong>讯飞星火认知 V2</strong>渠道',
|
},
|
||||||
},
|
{
|
||||||
{
|
key: 47,
|
||||||
key: 48,
|
text: '百度文心千帆 V2',
|
||||||
text: '讯飞星火认知 V2',
|
value: 47,
|
||||||
value: 48,
|
color: 'blue',
|
||||||
color: 'blue',
|
tip: '请前往<a href="https://console.bce.baidu.com/iam/#/iam/apikey/list" target="_blank">此处</a>获取 API Key,注意本渠道仅支持<a target="_blank" href="https://cloud.baidu.com/doc/WENXINWORKSHOP/s/em4tsqo3v">推理服务 V2</a>相关模型',
|
||||||
tip: 'HTTP 版本的讯飞接口,前往<a href="https://console.xfyun.cn/services/cbm" target="_blank">此处</a>获取 HTTP 服务接口认证密钥',
|
},
|
||||||
},
|
{
|
||||||
{key: 16, text: '智谱 ChatGLM', value: 16, color: 'violet'},
|
key: 17,
|
||||||
{key: 19, text: '360 智脑', value: 19, color: 'blue'},
|
text: '阿里通义千问',
|
||||||
{key: 25, text: 'Moonshot AI', value: 25, color: 'black'},
|
value: 17,
|
||||||
{key: 23, text: '腾讯混元', value: 23, color: 'teal'},
|
color: 'orange',
|
||||||
{key: 26, text: '百川大模型', value: 26, color: 'orange'},
|
tip: '如需使用阿里云百炼,请使用<strong>阿里云百炼</strong>渠道',
|
||||||
{key: 27, text: 'MiniMax', value: 27, color: 'red'},
|
},
|
||||||
{key: 29, text: 'Groq', value: 29, color: 'orange'},
|
{key: 49, text: '阿里云百炼', value: 49, color: 'orange'},
|
||||||
{key: 30, text: 'Ollama', value: 30, color: 'black'},
|
{
|
||||||
{key: 31, text: '零一万物', value: 31, color: 'green'},
|
key: 18,
|
||||||
{key: 32, text: '阶跃星辰', value: 32, color: 'blue'},
|
text: '讯飞星火认知',
|
||||||
{key: 34, text: 'Coze', value: 34, color: 'blue'},
|
value: 18,
|
||||||
{key: 35, text: 'Cohere', value: 35, color: 'blue'},
|
color: 'blue',
|
||||||
{key: 36, text: 'DeepSeek', value: 36, color: 'black'},
|
tip: '本渠道基于讯飞 WebSocket 版本 API,如需 HTTP 版本,请使用<strong>讯飞星火认知 V2</strong>渠道',
|
||||||
{key: 37, text: 'Cloudflare', value: 37, color: 'orange'},
|
},
|
||||||
{key: 38, text: 'DeepL', value: 38, color: 'black'},
|
{
|
||||||
{key: 39, text: 'together.ai', value: 39, color: 'blue'},
|
key: 48,
|
||||||
{key: 42, text: 'VertexAI', value: 42, color: 'blue'},
|
text: '讯飞星火认知 V2',
|
||||||
{key: 43, text: 'Proxy', value: 43, color: 'blue'},
|
value: 48,
|
||||||
{key: 44, text: 'SiliconFlow', value: 44, color: 'blue'},
|
color: 'blue',
|
||||||
{key: 45, text: 'xAI', value: 45, color: 'blue'},
|
tip: 'HTTP 版本的讯飞接口,前往<a href="https://console.xfyun.cn/services/cbm" target="_blank">此处</a>获取 HTTP 服务接口认证密钥',
|
||||||
{key: 46, text: 'Replicate', value: 46, color: 'blue'},
|
},
|
||||||
{key: 8, text: '自定义渠道', value: 8, color: 'pink'},
|
{key: 16, text: '智谱 ChatGLM', value: 16, color: 'violet'},
|
||||||
{key: 22, text: '知识库:FastGPT', value: 22, color: 'blue'},
|
{key: 19, text: '360 智脑', value: 19, color: 'blue'},
|
||||||
{key: 21, text: '知识库:AI Proxy', value: 21, color: 'purple'},
|
{key: 25, text: 'Moonshot AI', value: 25, color: 'black'},
|
||||||
{key: 20, text: '代理:OpenRouter', value: 20, color: 'black'},
|
{key: 23, text: '腾讯混元', value: 23, color: 'teal'},
|
||||||
{key: 2, text: '代理:API2D', value: 2, color: 'blue'},
|
{key: 26, text: '百川大模型', value: 26, color: 'orange'},
|
||||||
{key: 5, text: '代理:OpenAI-SB', value: 5, color: 'brown'},
|
{key: 27, text: 'MiniMax', value: 27, color: 'red'},
|
||||||
{key: 7, text: '代理:OhMyGPT', value: 7, color: 'purple'},
|
{key: 29, text: 'Groq', value: 29, color: 'orange'},
|
||||||
{key: 10, text: '代理:AI Proxy', value: 10, color: 'purple'},
|
{key: 30, text: 'Ollama', value: 30, color: 'black'},
|
||||||
{key: 4, text: '代理:CloseAI', value: 4, color: 'teal'},
|
{key: 31, text: '零一万物', value: 31, color: 'green'},
|
||||||
{key: 6, text: '代理:OpenAI Max', value: 6, color: 'violet'},
|
{key: 32, text: '阶跃星辰', value: 32, color: 'blue'},
|
||||||
{key: 9, text: '代理:AI.LS', value: 9, color: 'yellow'},
|
{key: 34, text: 'Coze', value: 34, color: 'blue'},
|
||||||
{key: 12, text: '代理:API2GPT', value: 12, color: 'blue'},
|
{key: 52, text: 'CozeV3', value: 52, color: 'blue'},
|
||||||
{key: 13, text: '代理:AIGC2D', value: 13, color: 'purple'},
|
{key: 35, text: 'Cohere', value: 35, color: 'blue'},
|
||||||
|
{key: 36, text: 'DeepSeek', value: 36, color: 'black'},
|
||||||
|
{key: 37, text: 'Cloudflare', value: 37, color: 'orange'},
|
||||||
|
{key: 38, text: 'DeepL', value: 38, color: 'black'},
|
||||||
|
{key: 39, text: 'together.ai', value: 39, color: 'blue'},
|
||||||
|
{key: 42, text: 'VertexAI', value: 42, color: 'blue'},
|
||||||
|
{key: 43, text: 'Proxy', value: 43, color: 'blue'},
|
||||||
|
{key: 44, text: 'SiliconFlow', value: 44, color: 'blue'},
|
||||||
|
{key: 45, text: 'xAI', value: 45, color: 'blue'},
|
||||||
|
{key: 46, text: 'Replicate', value: 46, color: 'blue'},
|
||||||
|
{
|
||||||
|
key: 8,
|
||||||
|
text: '自定义渠道',
|
||||||
|
value: 8,
|
||||||
|
color: 'pink',
|
||||||
|
tip: '不推荐使用,请使用 <strong>OpenAI 兼容</strong>渠道类型。注意,这里所需要填入的代理地址仅会在实际请求时替换域名部分,如果你想填入 OpenAI SDK 中所要求的 Base URL,请使用 OpenAI 兼容渠道类型',
|
||||||
|
description: '不推荐使用,请使用 OpenAI 兼容渠道类型',
|
||||||
|
},
|
||||||
|
{key: 22, text: '知识库:FastGPT', value: 22, color: 'blue'},
|
||||||
|
{key: 21, text: '知识库:AI Proxy', value: 21, color: 'purple'},
|
||||||
|
{key: 20, text: 'OpenRouter', value: 20, color: 'black'},
|
||||||
|
{key: 2, text: '代理:API2D', value: 2, color: 'blue'},
|
||||||
|
{key: 5, text: '代理:OpenAI-SB', value: 5, color: 'brown'},
|
||||||
|
{key: 7, text: '代理:OhMyGPT', value: 7, color: 'purple'},
|
||||||
|
{key: 10, text: '代理:AI Proxy', value: 10, color: 'purple'},
|
||||||
|
{key: 4, text: '代理:CloseAI', value: 4, color: 'teal'},
|
||||||
|
{key: 6, text: '代理:OpenAI Max', value: 6, color: 'violet'},
|
||||||
|
{key: 9, text: '代理:AI.LS', value: 9, color: 'yellow'},
|
||||||
|
{key: 12, text: '代理:API2GPT', value: 12, color: 'blue'},
|
||||||
|
{key: 13, text: '代理:AIGC2D', value: 13, color: 'purple'},
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import {Label, Message} from 'semantic-ui-react';
|
import { Label, Message } from 'semantic-ui-react';
|
||||||
import {getChannelOption} from './helper';
|
import { getChannelOption } from './helper';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
export function renderText(text, limit) {
|
export function renderText(text, limit) {
|
||||||
@@ -16,7 +16,15 @@ export function renderGroup(group) {
|
|||||||
let groups = group.split(',');
|
let groups = group.split(',');
|
||||||
groups.sort();
|
groups.sort();
|
||||||
return (
|
return (
|
||||||
<>
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
flexWrap: 'wrap',
|
||||||
|
gap: '2px',
|
||||||
|
rowGap: '6px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
{groups.map((group) => {
|
{groups.map((group) => {
|
||||||
if (group === 'vip' || group === 'pro') {
|
if (group === 'vip' || group === 'pro') {
|
||||||
return <Label color='yellow'>{group}</Label>;
|
return <Label color='yellow'>{group}</Label>;
|
||||||
@@ -25,7 +33,7 @@ export function renderGroup(group) {
|
|||||||
}
|
}
|
||||||
return <Label>{group}</Label>;
|
return <Label>{group}</Label>;
|
||||||
})}
|
})}
|
||||||
</>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,8 +114,8 @@ export function renderChannelTip(channelId) {
|
|||||||
return <></>;
|
return <></>;
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<Message>
|
<Message>
|
||||||
<div dangerouslySetInnerHTML={{__html: channel.tip}}></div>
|
<div dangerouslySetInnerHTML={{ __html: channel.tip }}></div>
|
||||||
</Message>
|
</Message>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { toast } from 'react-toastify';
|
import {toast} from 'react-toastify';
|
||||||
import { toastConstants } from '../constants';
|
import {toastConstants} from '../constants';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { API } from './api';
|
import {API} from './api';
|
||||||
|
|
||||||
const HTMLToastContent = ({ htmlContent }) => {
|
const HTMLToastContent = ({ htmlContent }) => {
|
||||||
return <div dangerouslySetInnerHTML={{ __html: htmlContent }} />;
|
return <div dangerouslySetInnerHTML={{ __html: htmlContent }} />;
|
||||||
@@ -74,6 +74,7 @@ if (isMobile()) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function showError(error) {
|
export function showError(error) {
|
||||||
|
if (!error) return;
|
||||||
console.error(error);
|
console.error(error);
|
||||||
if (error.message) {
|
if (error.message) {
|
||||||
if (error.name === 'AxiosError') {
|
if (error.name === 'AxiosError') {
|
||||||
@@ -158,17 +159,7 @@ export function timestamp2string(timestamp) {
|
|||||||
second = '0' + second;
|
second = '0' + second;
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
year +
|
year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second
|
||||||
'-' +
|
|
||||||
month +
|
|
||||||
'-' +
|
|
||||||
day +
|
|
||||||
' ' +
|
|
||||||
hour +
|
|
||||||
':' +
|
|
||||||
minute +
|
|
||||||
':' +
|
|
||||||
second
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -193,7 +184,6 @@ export const verifyJSON = (str) => {
|
|||||||
export function shouldShowPrompt(id) {
|
export function shouldShowPrompt(id) {
|
||||||
let prompt = localStorage.getItem(`prompt-${id}`);
|
let prompt = localStorage.getItem(`prompt-${id}`);
|
||||||
return !prompt;
|
return !prompt;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setPromptShown(id) {
|
export function setPromptShown(id) {
|
||||||
|
|||||||
@@ -104,8 +104,10 @@
|
|||||||
"model_mapping_placeholder": "Optional, used to modify model names in request body. A JSON string where keys are request model names and values are target model names",
|
"model_mapping_placeholder": "Optional, used to modify model names in request body. A JSON string where keys are request model names and values are target model names",
|
||||||
"system_prompt": "System Prompt",
|
"system_prompt": "System Prompt",
|
||||||
"system_prompt_placeholder": "Optional, used to force set system prompt. Use with custom model & model mapping. First create a unique custom model name above, then map it to a natively supported model",
|
"system_prompt_placeholder": "Optional, used to force set system prompt. Use with custom model & model mapping. First create a unique custom model name above, then map it to a natively supported model",
|
||||||
"base_url": "Proxy",
|
"proxy_url": "Proxy",
|
||||||
"base_url_placeholder": "Optional, used for API calls through proxy. Enter proxy address in format: https://domain.com",
|
"proxy_url_placeholder": "This is optional and used for API calls via a proxy. Please enter the proxy URL, formatted as: https://domain.com",
|
||||||
|
"base_url": "Base URL",
|
||||||
|
"base_url_placeholder": "The Base URL required by the OpenAPI SDK",
|
||||||
"key": "Key",
|
"key": "Key",
|
||||||
"key_placeholder": "Please enter key",
|
"key_placeholder": "Please enter key",
|
||||||
"batch": "Batch Create",
|
"batch": "Batch Create",
|
||||||
|
|||||||
@@ -104,8 +104,10 @@
|
|||||||
"model_mapping_placeholder": "此项可选,用于修改请求体中的模型名称,为一个 JSON 字符串,键为请求中模型名称,值为要替换的模型名称",
|
"model_mapping_placeholder": "此项可选,用于修改请求体中的模型名称,为一个 JSON 字符串,键为请求中模型名称,值为要替换的模型名称",
|
||||||
"system_prompt": "系统提示词",
|
"system_prompt": "系统提示词",
|
||||||
"system_prompt_placeholder": "此项可选,用于强制设置给定的系统提示词,请配合自定义模型 & 模型重定向使用,首先创建一个唯一的自定义模型名称并在上面填入,之后将该自定义模型重定向映射到该渠道一个原生支持的模型",
|
"system_prompt_placeholder": "此项可选,用于强制设置给定的系统提示词,请配合自定义模型 & 模型重定向使用,首先创建一个唯一的自定义模型名称并在上面填入,之后将该自定义模型重定向映射到该渠道一个原生支持的模型",
|
||||||
"base_url": "代理",
|
"proxy_url": "代理",
|
||||||
"base_url_placeholder": "此项可选,用于通过代理站来进行 API 调用,请输入代理站地址,格式为:https://domain.com",
|
"proxy_url_placeholder": "此项可选,用于通过代理站来进行 API 调用,请输入代理站地址,格式为:https://domain.com。注意,这里所需要填入的代理地址仅会在实际请求时替换域名部分,如果你想填入 OpenAI SDK 中所要求的 Base URL,请使用 OpenAI 兼容渠道类型",
|
||||||
|
"base_url": "Base URL",
|
||||||
|
"base_url_placeholder": "OpenAPI SDK 中所要求的 Base URL",
|
||||||
"key": "密钥",
|
"key": "密钥",
|
||||||
"key_placeholder": "请输入密钥",
|
"key_placeholder": "请输入密钥",
|
||||||
"batch": "批量创建",
|
"batch": "批量创建",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import React, {useEffect, useState} from 'react';
|
import React, {useEffect, useState} from 'react';
|
||||||
import {useTranslation} from 'react-i18next';
|
import {useTranslation} from 'react-i18next';
|
||||||
import {Button, Card, Form, Input, Message,} from 'semantic-ui-react';
|
import {Button, Card, Form, Input, Message} from 'semantic-ui-react';
|
||||||
import {useNavigate, useParams} from 'react-router-dom';
|
import {useNavigate, useParams} from 'react-router-dom';
|
||||||
import {API, copy, getChannelModels, showError, showInfo, showSuccess, verifyJSON,} from '../../helpers';
|
import {API, copy, getChannelModels, showError, showInfo, showSuccess, verifyJSON,} from '../../helpers';
|
||||||
import {CHANNEL_OPTIONS} from '../../constants';
|
import {CHANNEL_OPTIONS} from '../../constants';
|
||||||
@@ -339,6 +339,20 @@ const EditChannel = () => {
|
|||||||
{inputs.type === 8 && (
|
{inputs.type === 8 && (
|
||||||
<Form.Field>
|
<Form.Field>
|
||||||
<Form.Input
|
<Form.Input
|
||||||
|
required
|
||||||
|
label={t('channel.edit.proxy_url')}
|
||||||
|
name='base_url'
|
||||||
|
placeholder={t('channel.edit.proxy_url_placeholder')}
|
||||||
|
onChange={handleInputChange}
|
||||||
|
value={inputs.base_url}
|
||||||
|
autoComplete='new-password'
|
||||||
|
/>
|
||||||
|
</Form.Field>
|
||||||
|
)}
|
||||||
|
{inputs.type === 50 && (
|
||||||
|
<Form.Field>
|
||||||
|
<Form.Input
|
||||||
|
required
|
||||||
label={t('channel.edit.base_url')}
|
label={t('channel.edit.base_url')}
|
||||||
name='base_url'
|
name='base_url'
|
||||||
placeholder={t('channel.edit.base_url_placeholder')}
|
placeholder={t('channel.edit.base_url_placeholder')}
|
||||||
@@ -637,12 +651,13 @@ const EditChannel = () => {
|
|||||||
{inputs.type !== 3 &&
|
{inputs.type !== 3 &&
|
||||||
inputs.type !== 33 &&
|
inputs.type !== 33 &&
|
||||||
inputs.type !== 8 &&
|
inputs.type !== 8 &&
|
||||||
|
inputs.type !== 50 &&
|
||||||
inputs.type !== 22 && (
|
inputs.type !== 22 && (
|
||||||
<Form.Field>
|
<Form.Field>
|
||||||
<Form.Input
|
<Form.Input
|
||||||
label={t('channel.edit.base_url')}
|
label={t('channel.edit.proxy_url')}
|
||||||
name='base_url'
|
name='base_url'
|
||||||
placeholder={t('channel.edit.base_url_placeholder')}
|
placeholder={t('channel.edit.proxy_url_placeholder')}
|
||||||
onChange={handleInputChange}
|
onChange={handleInputChange}
|
||||||
value={inputs.base_url}
|
value={inputs.base_url}
|
||||||
autoComplete='new-password'
|
autoComplete='new-password'
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import React, { useEffect, useState } from 'react';
|
import React, {useEffect, useState} from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import {useTranslation} from 'react-i18next';
|
||||||
import { Card, Grid } from 'semantic-ui-react';
|
import {Card, Grid} from 'semantic-ui-react';
|
||||||
import {
|
import {
|
||||||
Bar,
|
Bar,
|
||||||
BarChart,
|
BarChart,
|
||||||
@@ -122,11 +122,11 @@ const Dashboard = () => {
|
|||||||
? new Date(Math.min(...dates.map((d) => new Date(d))))
|
? new Date(Math.min(...dates.map((d) => new Date(d))))
|
||||||
: new Date();
|
: new Date();
|
||||||
|
|
||||||
// 确保至少显示5天的数据
|
// 确保至少显示7天的数据
|
||||||
const fiveDaysAgo = new Date();
|
const sevenDaysAgo = new Date();
|
||||||
fiveDaysAgo.setDate(fiveDaysAgo.getDate() - 4); // -4是因为包含今天
|
sevenDaysAgo.setDate(sevenDaysAgo.getDate() - 6); // -6是因为包含今天
|
||||||
if (minDate > fiveDaysAgo) {
|
if (minDate > sevenDaysAgo) {
|
||||||
minDate = fiveDaysAgo;
|
minDate = sevenDaysAgo;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 生成所有日期
|
// 生成所有日期
|
||||||
@@ -164,11 +164,11 @@ const Dashboard = () => {
|
|||||||
? new Date(Math.min(...dates.map((d) => new Date(d))))
|
? new Date(Math.min(...dates.map((d) => new Date(d))))
|
||||||
: new Date();
|
: new Date();
|
||||||
|
|
||||||
// 确保至少显示5天的数据
|
// 确保至少显示7天的数据
|
||||||
const fiveDaysAgo = new Date();
|
const sevenDaysAgo = new Date();
|
||||||
fiveDaysAgo.setDate(fiveDaysAgo.getDate() - 4); // -4是因为包含今天
|
sevenDaysAgo.setDate(sevenDaysAgo.getDate() - 6); // -6是因为包含今天
|
||||||
if (minDate > fiveDaysAgo) {
|
if (minDate > sevenDaysAgo) {
|
||||||
minDate = fiveDaysAgo;
|
minDate = sevenDaysAgo;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 生成所有日期
|
// 生成所有日期
|
||||||
|
|||||||
Reference in New Issue
Block a user