Merge remote-tracking branch 'origin/upstream/main'

This commit is contained in:
Laisky.Cai 2024-06-09 13:39:05 +00:00
commit 91ec8b92f0
10 changed files with 57 additions and 3 deletions

View File

@ -17,10 +17,15 @@ import (
) )
func ConvertRequest(textRequest model.GeneralOpenAIRequest) *Request { func ConvertRequest(textRequest model.GeneralOpenAIRequest) *Request {
lastMessage := textRequest.Messages[len(textRequest.Messages)-1] var promptBuilder strings.Builder
for _, message := range textRequest.Messages {
promptBuilder.WriteString(message.StringContent())
promptBuilder.WriteString("\n") // 添加换行符来分隔每个消息
}
return &Request{ return &Request{
MaxTokens: textRequest.MaxTokens, MaxTokens: textRequest.MaxTokens,
Prompt: lastMessage.StringContent(), Prompt: promptBuilder.String(),
Stream: textRequest.Stream, Stream: textRequest.Stream,
Temperature: textRequest.Temperature, Temperature: textRequest.Temperature,
} }

View File

@ -0,0 +1,13 @@
package doubao
// https://console.volcengine.com/ark/region:ark+cn-beijing/model
var ModelList = []string{
"Doubao-pro-128k",
"Doubao-pro-32k",
"Doubao-pro-4k",
"Doubao-lite-128k",
"Doubao-lite-32k",
"Doubao-lite-4k",
"Doubao-embedding",
}

View File

@ -0,0 +1,14 @@
package doubao
import (
"fmt"
"github.com/songquanpeng/one-api/relay/meta"
"github.com/songquanpeng/one-api/relay/relaymode"
)
func GetRequestURL(meta *meta.Meta) (string, error) {
if meta.Mode == relaymode.ChatCompletions {
return fmt.Sprintf("%s/api/v3/chat/completions", meta.BaseURL), nil
}
return "", fmt.Errorf("unsupported relay mode %d for doubao", meta.Mode)
}

View File

@ -5,6 +5,7 @@ import (
"github.com/Laisky/errors/v2" "github.com/Laisky/errors/v2"
"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/doubao"
"github.com/songquanpeng/one-api/relay/adaptor/minimax" "github.com/songquanpeng/one-api/relay/adaptor/minimax"
"github.com/songquanpeng/one-api/relay/channeltype" "github.com/songquanpeng/one-api/relay/channeltype"
"github.com/songquanpeng/one-api/relay/meta" "github.com/songquanpeng/one-api/relay/meta"
@ -45,6 +46,8 @@ func (a *Adaptor) GetRequestURL(meta *meta.Meta) (string, error) {
return GetFullRequestURL(meta.BaseURL, requestURL, meta.ChannelType), nil return GetFullRequestURL(meta.BaseURL, requestURL, meta.ChannelType), nil
case channeltype.Minimax: case channeltype.Minimax:
return minimax.GetRequestURL(meta) return minimax.GetRequestURL(meta)
case channeltype.Doubao:
return doubao.GetRequestURL(meta)
default: default:
return GetFullRequestURL(meta.BaseURL, meta.RequestURLPath, meta.ChannelType), nil return GetFullRequestURL(meta.BaseURL, meta.RequestURLPath, meta.ChannelType), nil
} }

View File

@ -4,6 +4,7 @@ import (
"github.com/songquanpeng/one-api/relay/adaptor/ai360" "github.com/songquanpeng/one-api/relay/adaptor/ai360"
"github.com/songquanpeng/one-api/relay/adaptor/baichuan" "github.com/songquanpeng/one-api/relay/adaptor/baichuan"
"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/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"
@ -20,6 +21,7 @@ var CompatibleChannels = []int{
channeltype.Moonshot, channeltype.Moonshot,
channeltype.Baichuan, channeltype.Baichuan,
channeltype.Minimax, channeltype.Minimax,
channeltype.Doubao,
channeltype.Mistral, channeltype.Mistral,
channeltype.Groq, channeltype.Groq,
channeltype.LingYiWanWu, channeltype.LingYiWanWu,
@ -52,6 +54,8 @@ func GetCompatibleChannelMeta(channelType int) (string, []string) {
return "deepseek", deepseek.ModelList return "deepseek", deepseek.ModelList
case channeltype.TogetherAI: case channeltype.TogetherAI:
return "together.ai", togetherai.ModelList return "together.ai", togetherai.ModelList
case channeltype.Doubao:
return "doubao", doubao.ModelList
default: default:
return "openai", ModelList return "openai", ModelList
} }

View File

@ -41,6 +41,6 @@ const (
Cloudflare Cloudflare
DeepL DeepL
TogetherAI TogetherAI
Doubao
Dummy Dummy
) )

View File

@ -41,6 +41,7 @@ var ChannelBaseURLs = []string{
"https://api.cloudflare.com", // 37 "https://api.cloudflare.com", // 37
"https://api-free.deepl.com", // 38 "https://api-free.deepl.com", // 38
"https://api.together.xyz", // 39 "https://api.together.xyz", // 39
"https://ark.cn-beijing.volces.com", // 40
} }
func init() { func init() {

View File

@ -47,6 +47,12 @@ export const CHANNEL_OPTIONS = {
value: 28, value: 28,
color: 'warning' color: 'warning'
}, },
40: {
key: 40,
text: '字节跳动豆包',
value: 40,
color: 'primary'
},
15: { 15: {
key: 15, key: 15,
text: '百度文心千帆', text: '百度文心千帆',

View File

@ -6,6 +6,7 @@ export const CHANNEL_OPTIONS = [
{key: 11, text: 'Google PaLM2', value: 11, color: 'orange'}, {key: 11, text: 'Google PaLM2', value: 11, color: 'orange'},
{key: 24, text: 'Google Gemini', value: 24, color: 'orange'}, {key: 24, text: 'Google Gemini', value: 24, color: 'orange'},
{key: 28, text: 'Mistral AI', value: 28, color: 'orange'}, {key: 28, text: 'Mistral AI', value: 28, color: 'orange'},
{key: 40, text: '字节跳动豆包', value: 40, color: 'blue'},
{key: 15, text: '百度文心千帆', value: 15, color: 'blue'}, {key: 15, text: '百度文心千帆', value: 15, color: 'blue'},
{key: 17, text: '阿里通义千问', value: 17, color: 'orange'}, {key: 17, text: '阿里通义千问', value: 17, color: 'orange'},
{key: 18, text: '讯飞星火认知', value: 18, color: 'blue'}, {key: 18, text: '讯飞星火认知', value: 18, color: 'blue'},

View File

@ -362,6 +362,13 @@ const EditChannel = () => {
</Message> </Message>
) )
} }
{
inputs.type === 40 && (
<Message>
对于豆包而言需要手动去 <a target="_blank" href="https://console.volcengine.com/ark/region:ark+cn-beijing/endpoint">模型推理页面</a> `ep-20240608051426-tkxvl`
</Message>
)
}
<Form.Field> <Form.Field>
<Form.Dropdown <Form.Dropdown
label='模型' label='模型'