✨ 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:
parent
fa89a3d60b
commit
27738aa3c7
@ -94,16 +94,22 @@ func init() {
|
|||||||
"claude-3-opus-20240229": {[]float64{7.5, 22.5}, ChannelTypeAnthropic},
|
"claude-3-opus-20240229": {[]float64{7.5, 22.5}, ChannelTypeAnthropic},
|
||||||
"claude-3-sonnet-20240229": {[]float64{1.3, 3.9}, 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
|
// ¥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
|
// 0.024元/千tokens 0.048元/千tokens
|
||||||
"ERNIE-Bot-8k": {[]float64{1.7143, 3.4286}, ChannelTypeBaidu},
|
"ERNIE-Bot-8k": {[]float64{1.7143, 3.4286}, ChannelTypeBaidu},
|
||||||
// ¥0.008 / 1k tokens ¥0.008 / 1k tokens
|
// ¥0.008 / 1k tokens ¥0.008 / 1k tokens
|
||||||
"ERNIE-Bot-turbo": {[]float64{0.5715, 0.5715}, ChannelTypeBaidu},
|
"ERNIE-Bot-turbo": {[]float64{0.5715, 0.5715}, ChannelTypeBaidu},
|
||||||
// ¥0.12 / 1k tokens ¥0.12 / 1k tokens
|
// ¥0.12 / 1k tokens ¥0.12 / 1k tokens
|
||||||
"ERNIE-Bot-4": {[]float64{8.572, 8.572}, ChannelTypeBaidu},
|
"ERNIE-Bot-4": {[]float64{8.572, 8.572}, ChannelTypeBaidu},
|
||||||
|
"ERNIE-4.0": {[]float64{8.572, 8.572}, ChannelTypeBaidu},
|
||||||
// ¥0.002 / 1k tokens
|
// ¥0.002 / 1k tokens
|
||||||
"Embedding-V1": {[]float64{0.1429, 0.1429}, ChannelTypeBaidu},
|
"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},
|
"PaLM-2": {[]float64{1, 1}, ChannelTypePaLM},
|
||||||
"gemini-pro": {[]float64{1, 1}, ChannelTypeGemini},
|
"gemini-pro": {[]float64{1, 1}, ChannelTypeGemini},
|
||||||
|
@ -73,6 +73,14 @@ func (p *BaiduProvider) GetFullRequestURL(requestURL string, modelName string) s
|
|||||||
"ERNIE-Bot-4": "completions_pro",
|
"ERNIE-Bot-4": "completions_pro",
|
||||||
"BLOOMZ-7B": "bloomz_7b1",
|
"BLOOMZ-7B": "bloomz_7b1",
|
||||||
"Embedding-V1": "embedding-v1",
|
"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(), "/")
|
baseURL := strings.TrimSuffix(p.GetBaseURL(), "/")
|
||||||
@ -81,7 +89,7 @@ func (p *BaiduProvider) GetFullRequestURL(requestURL string, modelName string) s
|
|||||||
return ""
|
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取请求头
|
// 获取请求头
|
||||||
|
@ -2,11 +2,13 @@ package claude
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"one-api/common/requester"
|
"one-api/common/requester"
|
||||||
"one-api/model"
|
"one-api/model"
|
||||||
"one-api/providers/base"
|
"one-api/providers/base"
|
||||||
"one-api/types"
|
"one-api/types"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ClaudeProviderFactory struct{}
|
type ClaudeProviderFactory struct{}
|
||||||
@ -71,6 +73,15 @@ func (p *ClaudeProvider) GetRequestHeaders() (headers map[string]string) {
|
|||||||
return headers
|
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 {
|
func stopReasonClaude2OpenAI(reason string) string {
|
||||||
switch reason {
|
switch reason {
|
||||||
case "end_turn":
|
case "end_turn":
|
||||||
|
@ -75,16 +75,7 @@ func (p *XunfeiProvider) getChatRequest(request *types.ChatCompletionRequest) (*
|
|||||||
func (p *XunfeiProvider) convertFromChatOpenai(request *types.ChatCompletionRequest) *XunfeiChatRequest {
|
func (p *XunfeiProvider) convertFromChatOpenai(request *types.ChatCompletionRequest) *XunfeiChatRequest {
|
||||||
messages := make([]XunfeiMessage, 0, len(request.Messages))
|
messages := make([]XunfeiMessage, 0, len(request.Messages))
|
||||||
for _, message := range request.Messages {
|
for _, message := range request.Messages {
|
||||||
if message.Role == "system" {
|
if message.Role == types.ChatMessageRoleFunction {
|
||||||
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 {
|
|
||||||
messages = append(messages, XunfeiMessage{
|
messages = append(messages, XunfeiMessage{
|
||||||
Role: types.ChatMessageRoleUser,
|
Role: types.ChatMessageRoleUser,
|
||||||
Content: "这是函数调用返回的内容,请回答之前的问题:\n" + message.StringContent(),
|
Content: "这是函数调用返回的内容,请回答之前的问题:\n" + message.StringContent(),
|
||||||
|
@ -67,8 +67,8 @@ const typeConfig = {
|
|||||||
},
|
},
|
||||||
15: {
|
15: {
|
||||||
input: {
|
input: {
|
||||||
models: ['ERNIE-Bot', 'ERNIE-Bot-turbo', 'ERNIE-Bot-4', 'Embedding-V1'],
|
models: ['ERNIE-4.0', 'ERNIE-3.5-8K', 'ERNIE-Bot-8K', 'Embedding-V1'],
|
||||||
test_model: 'ERNIE-Bot'
|
test_model: 'ERNIE-3.5-8K'
|
||||||
},
|
},
|
||||||
prompt: {
|
prompt: {
|
||||||
key: '按照如下格式输入:APIKey|SecretKey'
|
key: '按照如下格式输入:APIKey|SecretKey'
|
||||||
|
Loading…
Reference in New Issue
Block a user