Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
ab5f17d0
authored
Jul 05, 2024
by
CalciumIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: update baidu
parent
43f073d7
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
102 additions
and
52 deletions
+102
-52
common/model-ratio.go
+16
-12
relay/channel/baidu/adaptor.go
+48
-22
relay/channel/baidu/constants.go
+11
-9
relay/channel/baidu/dto.go
+8
-1
relay/channel/baidu/relay-baidu.go
+15
-5
relay/channel/tencent/constants.go
+4
-3
No files found.
common/model-ratio.go
View file @
ab5f17d0
...
...
@@ -79,18 +79,22 @@ var defaultModelRatio = map[string]float64{
"claude-3-sonnet-20240229"
:
1.5
,
// $3 / 1M tokens
"claude-3-5-sonnet-20240620"
:
1.5
,
"claude-3-opus-20240229"
:
7.5
,
// $15 / 1M tokens
"ERNIE-Bot"
:
0.8572
,
// ¥0.012 / 1k tokens //renamed to ERNIE-3.5-8K
"ERNIE-Bot-turbo"
:
0.5715
,
// ¥0.008 / 1k tokens //renamed to ERNIE-Lite-8K
"ERNIE-Bot-4"
:
8.572
,
// ¥0.12 / 1k tokens //renamed to ERNIE-4.0-8K
"ERNIE-4.0-8K"
:
8.572
,
// ¥0.12 / 1k tokens
"ERNIE-3.5-8K"
:
0.8572
,
// ¥0.012 / 1k tokens
"ERNIE-Speed-8K"
:
0.2858
,
// ¥0.004 / 1k tokens
"ERNIE-Speed-128K"
:
0.2858
,
// ¥0.004 / 1k tokens
"ERNIE-Lite-8K"
:
0.2143
,
// ¥0.003 / 1k tokens
"ERNIE-Tiny-8K"
:
0.0715
,
// ¥0.001 / 1k tokens
"ERNIE-Character-8K"
:
0.2858
,
// ¥0.004 / 1k tokens
"ERNIE-Functions-8K"
:
0.2858
,
// ¥0.004 / 1k tokens
"Embedding-V1"
:
0.1429
,
// ¥0.002 / 1k tokens
"ERNIE-4.0-8K"
:
0.120
*
RMB
,
"ERNIE-3.5-8K"
:
0.012
*
RMB
,
"ERNIE-3.5-8K-0205"
:
0.024
*
RMB
,
"ERNIE-3.5-8K-1222"
:
0.012
*
RMB
,
"ERNIE-Bot-8K"
:
0.024
*
RMB
,
"ERNIE-3.5-4K-0205"
:
0.012
*
RMB
,
"ERNIE-Speed-8K"
:
0.004
*
RMB
,
"ERNIE-Speed-128K"
:
0.004
*
RMB
,
"ERNIE-Lite-8K-0922"
:
0.008
*
RMB
,
"ERNIE-Lite-8K-0308"
:
0.003
*
RMB
,
"ERNIE-Tiny-8K"
:
0.001
*
RMB
,
"BLOOMZ-7B"
:
0.004
*
RMB
,
"Embedding-V1"
:
0.002
*
RMB
,
"bge-large-zh"
:
0.002
*
RMB
,
"bge-large-en"
:
0.002
*
RMB
,
"tao-8k"
:
0.002
*
RMB
,
"PaLM-2"
:
1
,
"gemini-pro"
:
1
,
// $0.00025 / 1k characters -> $0.001 / 1k tokens
"gemini-pro-vision"
:
1
,
// $0.00025 / 1k characters -> $0.001 / 1k tokens
...
...
relay/channel/baidu/adaptor.go
View file @
ab5f17d0
...
...
@@ -2,6 +2,7 @@ package baidu
import
(
"errors"
"fmt"
"github.com/gin-gonic/gin"
"io"
"net/http"
...
...
@@ -20,39 +21,64 @@ func (a *Adaptor) Init(info *relaycommon.RelayInfo, request dto.GeneralOpenAIReq
}
func
(
a
*
Adaptor
)
GetRequestURL
(
info
*
relaycommon
.
RelayInfo
)
(
string
,
error
)
{
var
fullRequestURL
string
// https://cloud.baidu.com/doc/WENXINWORKSHOP/s/clntwmv7t
suffix
:=
"chat/"
if
strings
.
HasPrefix
(
info
.
UpstreamModelName
,
"Embedding"
)
{
suffix
=
"embeddings/"
}
if
strings
.
HasPrefix
(
info
.
UpstreamModelName
,
"bge-large"
)
{
suffix
=
"embeddings/"
}
if
strings
.
HasPrefix
(
info
.
UpstreamModelName
,
"tao-8k"
)
{
suffix
=
"embeddings/"
}
switch
info
.
UpstreamModelName
{
case
"ERNIE-4.0"
:
suffix
+=
"completions_pro"
case
"ERNIE-Bot-4"
:
fullRequestURL
=
"https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/completions_pro"
case
"ERNIE-Bot-8K"
:
fullRequestURL
=
"https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/ernie_bot_8k"
suffix
+=
"completions_pro"
case
"ERNIE-Bot"
:
fullRequestURL
=
"https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/completions"
case
"ERNIE-Speed"
:
fullRequestURL
=
"https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/ernie_speed"
suffix
+=
"completions"
case
"ERNIE-Bot-turbo"
:
fullRequestURL
=
"https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/
eb-instant"
case
"
BLOOMZ-7B
"
:
fullRequestURL
=
"https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/bloomz_7b1
"
suffix
+=
"
eb-instant"
case
"
ERNIE-Speed
"
:
suffix
+=
"ernie_speed
"
case
"ERNIE-4.0-8K"
:
fullRequestURL
=
"https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/
completions_pro"
suffix
+=
"
completions_pro"
case
"ERNIE-3.5-8K"
:
fullRequestURL
=
"https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/completions"
suffix
+=
"completions"
case
"ERNIE-3.5-8K-0205"
:
suffix
+=
"ernie-3.5-8k-0205"
case
"ERNIE-3.5-8K-1222"
:
suffix
+=
"ernie-3.5-8k-1222"
case
"ERNIE-Bot-8K"
:
suffix
+=
"ernie_bot_8k"
case
"ERNIE-3.5-4K-0205"
:
suffix
+=
"ernie-3.5-4k-0205"
case
"ERNIE-Speed-8K"
:
fullRequestURL
=
"https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/ernie_speed"
case
"ERNIE-Character-8K"
:
fullRequestURL
=
"https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/ernie-char-8k"
case
"ERNIE-Functions-8K"
:
fullRequestURL
=
"https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/ernie-func-8k"
suffix
+=
"ernie_speed"
case
"ERNIE-Speed-128K"
:
suffix
+=
"ernie-speed-128k"
case
"ERNIE-Lite-8K-0922"
:
fullRequestURL
=
"https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/eb-instant"
case
"Yi-34B-Chat"
:
fullRequestURL
=
"https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/yi_34b_chat"
suffix
+=
"eb-instant"
case
"ERNIE-Lite-8K-0308"
:
suffix
+=
"ernie-lite-8k"
case
"ERNIE-Tiny-8K"
:
suffix
+=
"ernie-tiny-8k"
case
"BLOOMZ-7B"
:
suffix
+=
"bloomz_7b1"
case
"Embedding-V1"
:
fullRequestURL
=
"https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/embeddings/embedding-v1"
suffix
+=
"embedding-v1"
case
"bge-large-zh"
:
suffix
+=
"bge_large_zh"
case
"bge-large-en"
:
suffix
+=
"bge_large_en"
case
"tao-8k"
:
suffix
+=
"tao_8k"
default
:
fullRequestURL
=
"https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/"
+
strings
.
ToLower
(
info
.
UpstreamModelName
)
suffix
+=
strings
.
ToLower
(
info
.
UpstreamModelName
)
}
fullRequestURL
:=
fmt
.
Sprintf
(
"%s/rpc/2.0/ai_custom/v1/wenxinworkshop/%s"
,
info
.
BaseUrl
,
suffix
)
var
accessToken
string
var
err
error
if
accessToken
,
err
=
getBaiduAccessToken
(
info
.
ApiKey
);
err
!=
nil
{
...
...
relay/channel/baidu/constants.go
View file @
ab5f17d0
package
baidu
var
ModelList
=
[]
string
{
"ERNIE-3.5-8K"
,
"ERNIE-4.0-8K"
,
"ERNIE-3.5-8K"
,
"ERNIE-3.5-8K-0205"
,
"ERNIE-3.5-8K-1222"
,
"ERNIE-Bot-8K"
,
"ERNIE-3.5-4K-0205"
,
"ERNIE-Speed-8K"
,
"ERNIE-Speed-128K"
,
"ERNIE-Lite-8K"
,
"ERNIE-Lite-8K-0922"
,
"ERNIE-Lite-8K-0308"
,
"ERNIE-Tiny-8K"
,
"ERNIE-Character-8K"
,
"ERNIE-Functions-8K"
,
//"ERNIE-Bot-4",
//"ERNIE-Bot-8K",
//"ERNIE-Bot",
//"ERNIE-Speed",
//"ERNIE-Bot-turbo",
"BLOOMZ-7B"
,
"Embedding-V1"
,
"bge-large-zh"
,
"bge-large-en"
,
"tao-8k"
,
}
var
ChannelName
=
"baidu"
relay/channel/baidu/dto.go
View file @
ab5f17d0
...
...
@@ -12,7 +12,14 @@ type BaiduMessage struct {
type
BaiduChatRequest
struct
{
Messages
[]
BaiduMessage
`json:"messages"`
Stream
bool
`json:"stream"`
Temperature
float64
`json:"temperature,omitempty"`
TopP
float64
`json:"top_p,omitempty"`
PenaltyScore
float64
`json:"penalty_score,omitempty"`
Stream
bool
`json:"stream,omitempty"`
System
string
`json:"system,omitempty"`
DisableSearch
bool
`json:"disable_search,omitempty"`
EnableCitation
bool
`json:"enable_citation,omitempty"`
MaxOutputTokens
int
`json:"max_output_tokens,omitempty"`
UserId
string
`json:"user_id,omitempty"`
}
...
...
relay/channel/baidu/relay-baidu.go
View file @
ab5f17d0
...
...
@@ -22,17 +22,27 @@ import (
var
baiduTokenStore
sync
.
Map
func
requestOpenAI2Baidu
(
request
dto
.
GeneralOpenAIRequest
)
*
BaiduChatRequest
{
messages
:=
make
([]
BaiduMessage
,
0
,
len
(
request
.
Messages
))
baiduRequest
:=
BaiduChatRequest
{
Temperature
:
request
.
Temperature
,
TopP
:
request
.
TopP
,
PenaltyScore
:
request
.
FrequencyPenalty
,
Stream
:
request
.
Stream
,
DisableSearch
:
false
,
EnableCitation
:
false
,
MaxOutputTokens
:
int
(
request
.
MaxTokens
),
UserId
:
request
.
User
,
}
for
_
,
message
:=
range
request
.
Messages
{
messages
=
append
(
messages
,
BaiduMessage
{
if
message
.
Role
==
"system"
{
baiduRequest
.
System
=
message
.
StringContent
()
}
else
{
baiduRequest
.
Messages
=
append
(
baiduRequest
.
Messages
,
BaiduMessage
{
Role
:
message
.
Role
,
Content
:
message
.
StringContent
(),
})
}
return
&
BaiduChatRequest
{
Messages
:
messages
,
Stream
:
request
.
Stream
,
}
return
&
baiduRequest
}
func
responseBaidu2OpenAI
(
response
*
BaiduChatResponse
)
*
dto
.
OpenAITextResponse
{
...
...
relay/channel/tencent/constants.go
View file @
ab5f17d0
package
tencent
var
ModelList
=
[]
string
{
"ChatPro"
,
"ChatStd"
,
"hunyuan"
,
"hunyuan-lite"
,
"hunyuan-standard"
,
"hunyuan-standard-256K"
,
"hunyuan-pro"
,
}
var
ChannelName
=
"tencent"
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment