Skip to content

Commit

Permalink
✨ feat: complete some issues (lobehub#98)
Browse files Browse the repository at this point in the history
* 🎨 improve: SparkDesk support system roles

* 🎨 feat: Update Baidu model name

* ✨ feat: claude support cloudflare gateway
  • Loading branch information
MartialBE authored Mar 11, 2024
1 parent fa89a3d commit 27738aa
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 14 deletions.
8 changes: 7 additions & 1 deletion common/model-ratio.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
10 changes: 9 additions & 1 deletion providers/baidu/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(), "/")
Expand All @@ -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)
}

// 获取请求头
Expand Down
11 changes: 11 additions & 0 deletions providers/claude/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -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":
Expand Down
11 changes: 1 addition & 10 deletions providers/xunfei/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
4 changes: 2 additions & 2 deletions web/src/views/Channel/type/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 27738aa

Please sign in to comment.