From 27738aa3c771593c9f0fd70f3382a2393f84df8b Mon Sep 17 00:00:00 2001 From: Buer <42402987+MartialBE@users.noreply.github.com> Date: Mon, 11 Mar 2024 11:53:04 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20complete=20some=20issues=20?= =?UTF-8?q?(#98)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 🎨 improve: SparkDesk support system roles * 🎨 feat: Update Baidu model name * ✨ feat: claude support cloudflare gateway --- common/model-ratio.go | 8 +++++++- providers/baidu/base.go | 10 +++++++++- providers/claude/base.go | 11 +++++++++++ providers/xunfei/chat.go | 11 +---------- web/src/views/Channel/type/Config.js | 4 ++-- 5 files changed, 30 insertions(+), 14 deletions(-) diff --git a/common/model-ratio.go b/common/model-ratio.go index 07916eef..ac532180 100644 --- a/common/model-ratio.go +++ b/common/model-ratio.go @@ -94,16 +94,22 @@ func init() { "claude-3-opus-20240229": {[]float64{7.5, 22.5}, ChannelTypeAnthropic}, "claude-3-sonnet-20240229": {[]float64{1.3, 3.9}, ChannelTypeAnthropic}, + // ¥0.004 / 1k tokens ¥0.008 / 1k tokens + "ERNIE-Speed": {[]float64{0.2857, 0.5714}, ChannelTypeBaidu}, // ¥0.012 / 1k tokens ¥0.012 / 1k tokens - "ERNIE-Bot": {[]float64{0.8572, 0.8572}, ChannelTypeBaidu}, + "ERNIE-Bot": {[]float64{0.8572, 0.8572}, ChannelTypeBaidu}, + "ERNIE-3.5-8K": {[]float64{0.8572, 0.8572}, ChannelTypeBaidu}, // 0.024元/千tokens 0.048元/千tokens "ERNIE-Bot-8k": {[]float64{1.7143, 3.4286}, ChannelTypeBaidu}, // ¥0.008 / 1k tokens ¥0.008 / 1k tokens "ERNIE-Bot-turbo": {[]float64{0.5715, 0.5715}, ChannelTypeBaidu}, // ¥0.12 / 1k tokens ¥0.12 / 1k tokens "ERNIE-Bot-4": {[]float64{8.572, 8.572}, ChannelTypeBaidu}, + "ERNIE-4.0": {[]float64{8.572, 8.572}, ChannelTypeBaidu}, // ¥0.002 / 1k tokens "Embedding-V1": {[]float64{0.1429, 0.1429}, ChannelTypeBaidu}, + // ¥0.004 / 1k tokens + "BLOOMZ-7B": {[]float64{0.2857, 0.2857}, ChannelTypeBaidu}, "PaLM-2": {[]float64{1, 1}, ChannelTypePaLM}, "gemini-pro": {[]float64{1, 1}, ChannelTypeGemini}, diff --git a/providers/baidu/base.go b/providers/baidu/base.go index ee82ebf5..2117dd27 100644 --- a/providers/baidu/base.go +++ b/providers/baidu/base.go @@ -73,6 +73,14 @@ func (p *BaiduProvider) GetFullRequestURL(requestURL string, modelName string) s "ERNIE-Bot-4": "completions_pro", "BLOOMZ-7B": "bloomz_7b1", "Embedding-V1": "embedding-v1", + "ERNIE-4.0": "completions_pro", + "ERNIE-3.5-8K": "completions", + "ERNIE-Bot-8K": "ernie_bot_8k", + "ERNIE-Speed": "ernie_speed", + } + + if modelNameConvert, ok := modelNameMap[modelName]; ok { + modelName = modelNameConvert } baseURL := strings.TrimSuffix(p.GetBaseURL(), "/") @@ -81,7 +89,7 @@ func (p *BaiduProvider) GetFullRequestURL(requestURL string, modelName string) s return "" } - return fmt.Sprintf("%s%s/%s?access_token=%s", baseURL, requestURL, modelNameMap[modelName], apiKey) + return fmt.Sprintf("%s%s/%s?access_token=%s", baseURL, requestURL, modelName, apiKey) } // 获取请求头 diff --git a/providers/claude/base.go b/providers/claude/base.go index 58f9120c..ce3a7d88 100644 --- a/providers/claude/base.go +++ b/providers/claude/base.go @@ -2,11 +2,13 @@ package claude import ( "encoding/json" + "fmt" "net/http" "one-api/common/requester" "one-api/model" "one-api/providers/base" "one-api/types" + "strings" ) type ClaudeProviderFactory struct{} @@ -71,6 +73,15 @@ func (p *ClaudeProvider) GetRequestHeaders() (headers map[string]string) { return headers } +func (p *ClaudeProvider) GetFullRequestURL(requestURL string, modelName string) string { + baseURL := strings.TrimSuffix(p.GetBaseURL(), "/") + if strings.HasPrefix(baseURL, "https://gateway.ai.cloudflare.com") { + requestURL = strings.TrimPrefix(requestURL, "/v1") + } + + return fmt.Sprintf("%s%s", baseURL, requestURL) +} + func stopReasonClaude2OpenAI(reason string) string { switch reason { case "end_turn": diff --git a/providers/xunfei/chat.go b/providers/xunfei/chat.go index d031fd61..9b89e614 100644 --- a/providers/xunfei/chat.go +++ b/providers/xunfei/chat.go @@ -75,16 +75,7 @@ func (p *XunfeiProvider) getChatRequest(request *types.ChatCompletionRequest) (* func (p *XunfeiProvider) convertFromChatOpenai(request *types.ChatCompletionRequest) *XunfeiChatRequest { messages := make([]XunfeiMessage, 0, len(request.Messages)) for _, message := range request.Messages { - if message.Role == "system" { - messages = append(messages, XunfeiMessage{ - Role: types.ChatMessageRoleUser, - Content: message.StringContent(), - }) - messages = append(messages, XunfeiMessage{ - Role: types.ChatMessageRoleAssistant, - Content: "Okay", - }) - } else if message.Role == types.ChatMessageRoleFunction { + if message.Role == types.ChatMessageRoleFunction { messages = append(messages, XunfeiMessage{ Role: types.ChatMessageRoleUser, Content: "这是函数调用返回的内容,请回答之前的问题:\n" + message.StringContent(), diff --git a/web/src/views/Channel/type/Config.js b/web/src/views/Channel/type/Config.js index 0454db72..63296f98 100644 --- a/web/src/views/Channel/type/Config.js +++ b/web/src/views/Channel/type/Config.js @@ -67,8 +67,8 @@ const typeConfig = { }, 15: { input: { - models: ['ERNIE-Bot', 'ERNIE-Bot-turbo', 'ERNIE-Bot-4', 'Embedding-V1'], - test_model: 'ERNIE-Bot' + models: ['ERNIE-4.0', 'ERNIE-3.5-8K', 'ERNIE-Bot-8K', 'Embedding-V1'], + test_model: 'ERNIE-3.5-8K' }, prompt: { key: '按照如下格式输入:APIKey|SecretKey'