feat: complete some issues (#98)

* 🎨 improve: SparkDesk support system roles

* 🎨 feat: Update Baidu model name

*  feat: claude support cloudflare gateway
This commit is contained in:
Buer 2024-03-11 11:53:04 +08:00 committed by GitHub
parent fa89a3d60b
commit 27738aa3c7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 30 additions and 14 deletions

View File

@ -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},

View File

@ -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)
}
// 获取请求头

View File

@ -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":

View File

@ -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(),

View File

@ -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'