feat: add doubao channel

This commit is contained in:
linzhaoming 2024-06-15 20:08:27 +08:00
parent 318a086e10
commit 023d141e4a
7 changed files with 1308 additions and 1272 deletions

View File

@ -232,6 +232,7 @@ const (
ChannelTypeCohere = 34
ChannelTypeMiniMax = 35
ChannelTypeScholarAI = 36
ChannelTypeDoubao = 37
ChannelTypeDummy // this one is only for count, do not add any channel after this
)
@ -274,4 +275,5 @@ var ChannelBaseURLs = []string{
"https://api.cohere.ai", //34
"https://api.minimax.chat", //35
"https://api.scholarai.io", //36
"https://ark.cn-beijing.volces.com", //37
}

View File

@ -125,8 +125,8 @@ func init() {
}
channelId2Models = make(map[int][]string)
for i := 1; i <= common.ChannelTypeDummy; i++ {
apiType, success := relayconstant.ChannelType2APIType(i)
if !success || apiType == relayconstant.APITypeAIProxyLibrary {
apiType, _ := relayconstant.ChannelType2APIType(i)
if apiType == relayconstant.APITypeAIProxyLibrary {
continue
}
meta := &relaycommon.RelayInfo{ChannelType: i}

View File

@ -0,0 +1,15 @@
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",
}
var ChannelName = "doubao"

View File

@ -0,0 +1,10 @@
package doubao
import (
"fmt"
relaycommon "one-api/relay/common"
)
func GetRequestURL(info *relaycommon.RelayInfo) (string, error) {
return fmt.Sprintf("%s/api/v3/chat/completions", info.BaseUrl), nil
}

View File

@ -3,19 +3,21 @@ package openai
import (
"errors"
"fmt"
"github.com/gin-gonic/gin"
"io"
"net/http"
"one-api/common"
"one-api/dto"
"one-api/relay/channel"
"one-api/relay/channel/ai360"
"one-api/relay/channel/doubao"
"one-api/relay/channel/lingyiwanwu"
"one-api/relay/channel/minimax"
"one-api/relay/channel/moonshot"
relaycommon "one-api/relay/common"
"one-api/service"
"strings"
"github.com/gin-gonic/gin"
)
type Adaptor struct {
@ -41,6 +43,8 @@ func (a *Adaptor) GetRequestURL(info *relaycommon.RelayInfo) (string, error) {
return relaycommon.GetFullRequestURL(info.BaseUrl, requestURL, info.ChannelType), nil
case common.ChannelTypeMiniMax:
return minimax.GetRequestURL(info)
case common.ChannelTypeDoubao:
return doubao.GetRequestURL(info)
case common.ChannelTypeCustom:
url := info.BaseUrl
url = strings.Replace(url, "{model}", info.UpstreamModelName, -1)
@ -101,6 +105,8 @@ func (a *Adaptor) GetModelList() []string {
return lingyiwanwu.ModelList
case common.ChannelTypeMiniMax:
return minimax.ModelList
case common.ChannelTypeDoubao:
return doubao.ModelList
default:
return ModelList
}
@ -116,6 +122,8 @@ func (a *Adaptor) GetChannelName() string {
return lingyiwanwu.ChannelName
case common.ChannelTypeMiniMax:
return minimax.ChannelName
case common.ChannelTypeDoubao:
return doubao.ChannelName
default:
return ChannelName
}

View File

@ -98,6 +98,7 @@ export const CHANNEL_OPTIONS = [
{ key: 31, text: '零一万物', value: 31, color: 'green', label: '零一万物' },
{ key: 35, text: 'MiniMax', value: 35, color: 'green', label: 'MiniMax' },
{ key: 36, text: 'ScholarAI', value: 36, color: 'green', label: 'ScholarAI' },
{ key: 37, text: '豆包', value: 37, color: 'green', label: '豆包' },
{ key: 8, text: '自定义渠道', value: 8, color: 'pink', label: '自定义渠道' },
{
key: 22,

File diff suppressed because it is too large Load Diff