Files
new-api/relay/channel/baidu/adaptor.go

164 lines
4.4 KiB
Go
Raw Normal View History

2024-02-29 01:08:18 +08:00
package baidu
import (
"errors"
2024-07-05 20:22:30 +08:00
"fmt"
2024-02-29 01:08:18 +08:00
"io"
"net/http"
"one-api/dto"
2024-02-29 16:21:25 +08:00
"one-api/relay/channel"
2024-02-29 01:08:18 +08:00
relaycommon "one-api/relay/common"
"one-api/relay/constant"
Squashed commit of the following: commit 5a6a0df45dee3dfbf2f65591a79fe5f2b74a49e6 Author: Akarin <jimmyshjj@gmail.com> Date: Thu May 16 14:05:28 2024 +0800 Revert "Update docker-image-amd64.yml" This reverts commit 581343a78783bbd779e65b476e125af0e2b64ce5. commit a0aec1bd030da2c6b25d9541199d598f16813a60 Merge: 5b46c7d 58abb38 Author: Jiayun Shen <jimmyshjj@gmail.com> Date: Thu May 16 06:46:51 2024 +0800 Merge branch 'main' of https://github.com/jimmyshjj/new-api commit 58abb3864a89294d82f812cda9fe49ccf7e2dd91 Merge: 7d2c026 93858c3 Author: Akarin <jimmyshjj@gmail.com> Date: Thu May 16 06:46:00 2024 +0800 Merge branch 'Calcium-Ion:main' into main commit 5b46c7dd8e6132d2be3b59c7b2ed6a4b84b93cef Author: Jiayun Shen <jimmyshjj@gmail.com> Date: Thu May 16 06:45:00 2024 +0800 Update constants.go Remove replaced Baidu models commit 7d2c02679cd90b8b53f4145f83969b980a8c2095 Author: Akarin <jimmyshjj@gmail.com> Date: Wed May 15 23:40:50 2024 +0800 Update adaptor.go - Normalize model name to lowercase Baidu's official model names may include mixed case letters, but their model APIs are case-sensitive and accept only lowercase. To ensure compatibility, the default behavior has been updated to convert model names to lowercase before constructing API requests. commit 6bc168a39d9a6194d66f2f32b175e56de9295b2e Merge: bb9fecd 910e76a Author: Jiayun Shen <jimmyshjj@gmail.com> Date: Wed May 15 21:51:52 2024 +0800 Merge branch 'main' of https://github.com/jimmyshjj/new-api commit 910e76ac94d7f5dca6254abb4d0669cbb762e724 Merge: 581343a ff044de Author: Akarin <jimmyshjj@gmail.com> Date: Wed May 15 21:51:13 2024 +0800 Merge branch 'Calcium-Ion:main' into main commit bb9fecd5bf2bd9f1859a4017e7e68f80bdb6685a Author: Jiayun Shen <jimmyshjj@gmail.com> Date: Wed May 15 21:50:08 2024 +0800 update Baidu and 360 models Add Baidu and 360 new models. Add Baidu completion ratio commit 581343a78783bbd779e65b476e125af0e2b64ce5 Author: Akarin <jimmyshjj@gmail.com> Date: Wed May 15 19:41:34 2024 +0800 Update docker-image-amd64.yml commit de17e2d95eec80f1eeae66e82dec4e9601cdee43 Merge: 046f653 a3b3e6c Author: Akarin <jimmyshjj@gmail.com> Date: Wed May 15 19:22:09 2024 +0800 Merge branch 'Calcium-Ion:main' into main commit 046f6537913ae8ad8ecf21019b64c0379331b3fd Merge: 4164d51 7b58305 Author: Akarin <jimmyshjj@gmail.com> Date: Wed May 15 15:32:38 2024 +0800 Merge branch 'Calcium-Ion:main' into main commit 4164d51207808283a18ca2728241fd5cddc4855f Merge: ef35b07 c222bc8 Author: Akarin <jimmyshjj@gmail.com> Date: Wed May 15 11:19:13 2024 +0800 Merge branch 'Calcium-Ion:main' into main commit ef35b072824b5095ecd2d1ed7ca9fa11673da2c4 Author: Jiayun Shen <jimmyshjj@gmail.com> Date: Tue May 14 19:17:32 2024 +0800 Update adaptor.go Update frequently used model names from Baidu official docs and support custom models
2024-05-16 14:05:44 +08:00
"strings"
2025-05-02 13:59:46 +08:00
"github.com/gin-gonic/gin"
2024-02-29 01:08:18 +08:00
)
type Adaptor struct {
}
2025-03-12 21:31:46 +08:00
func (a *Adaptor) ConvertClaudeRequest(*gin.Context, *relaycommon.RelayInfo, *dto.ClaudeRequest) (any, error) {
//TODO implement me
panic("implement me")
return nil, nil
}
2024-07-16 22:07:10 +08:00
func (a *Adaptor) ConvertAudioRequest(c *gin.Context, info *relaycommon.RelayInfo, request dto.AudioRequest) (io.Reader, error) {
2024-07-06 17:09:22 +08:00
//TODO implement me
2024-07-16 22:07:10 +08:00
return nil, errors.New("not implemented")
}
2024-07-06 17:09:22 +08:00
2024-07-16 22:07:10 +08:00
func (a *Adaptor) ConvertImageRequest(c *gin.Context, info *relaycommon.RelayInfo, request dto.ImageRequest) (any, error) {
//TODO implement me
return nil, errors.New("not implemented")
2024-07-06 17:09:22 +08:00
}
2024-07-16 22:07:10 +08:00
func (a *Adaptor) Init(info *relaycommon.RelayInfo) {
2024-02-29 01:08:18 +08:00
}
func (a *Adaptor) GetRequestURL(info *relaycommon.RelayInfo) (string, error) {
2024-07-05 20:22:30 +08:00
// 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/"
}
2024-02-29 01:08:18 +08:00
switch info.UpstreamModelName {
2024-07-05 20:22:30 +08:00
case "ERNIE-4.0":
suffix += "completions_pro"
2024-02-29 01:08:18 +08:00
case "ERNIE-Bot-4":
2024-07-05 20:22:30 +08:00
suffix += "completions_pro"
2024-02-29 01:08:18 +08:00
case "ERNIE-Bot":
2024-07-05 20:22:30 +08:00
suffix += "completions"
2024-02-29 01:08:18 +08:00
case "ERNIE-Bot-turbo":
2024-07-05 20:22:30 +08:00
suffix += "eb-instant"
case "ERNIE-Speed":
suffix += "ernie_speed"
Squashed commit of the following: commit 5a6a0df45dee3dfbf2f65591a79fe5f2b74a49e6 Author: Akarin <jimmyshjj@gmail.com> Date: Thu May 16 14:05:28 2024 +0800 Revert "Update docker-image-amd64.yml" This reverts commit 581343a78783bbd779e65b476e125af0e2b64ce5. commit a0aec1bd030da2c6b25d9541199d598f16813a60 Merge: 5b46c7d 58abb38 Author: Jiayun Shen <jimmyshjj@gmail.com> Date: Thu May 16 06:46:51 2024 +0800 Merge branch 'main' of https://github.com/jimmyshjj/new-api commit 58abb3864a89294d82f812cda9fe49ccf7e2dd91 Merge: 7d2c026 93858c3 Author: Akarin <jimmyshjj@gmail.com> Date: Thu May 16 06:46:00 2024 +0800 Merge branch 'Calcium-Ion:main' into main commit 5b46c7dd8e6132d2be3b59c7b2ed6a4b84b93cef Author: Jiayun Shen <jimmyshjj@gmail.com> Date: Thu May 16 06:45:00 2024 +0800 Update constants.go Remove replaced Baidu models commit 7d2c02679cd90b8b53f4145f83969b980a8c2095 Author: Akarin <jimmyshjj@gmail.com> Date: Wed May 15 23:40:50 2024 +0800 Update adaptor.go - Normalize model name to lowercase Baidu's official model names may include mixed case letters, but their model APIs are case-sensitive and accept only lowercase. To ensure compatibility, the default behavior has been updated to convert model names to lowercase before constructing API requests. commit 6bc168a39d9a6194d66f2f32b175e56de9295b2e Merge: bb9fecd 910e76a Author: Jiayun Shen <jimmyshjj@gmail.com> Date: Wed May 15 21:51:52 2024 +0800 Merge branch 'main' of https://github.com/jimmyshjj/new-api commit 910e76ac94d7f5dca6254abb4d0669cbb762e724 Merge: 581343a ff044de Author: Akarin <jimmyshjj@gmail.com> Date: Wed May 15 21:51:13 2024 +0800 Merge branch 'Calcium-Ion:main' into main commit bb9fecd5bf2bd9f1859a4017e7e68f80bdb6685a Author: Jiayun Shen <jimmyshjj@gmail.com> Date: Wed May 15 21:50:08 2024 +0800 update Baidu and 360 models Add Baidu and 360 new models. Add Baidu completion ratio commit 581343a78783bbd779e65b476e125af0e2b64ce5 Author: Akarin <jimmyshjj@gmail.com> Date: Wed May 15 19:41:34 2024 +0800 Update docker-image-amd64.yml commit de17e2d95eec80f1eeae66e82dec4e9601cdee43 Merge: 046f653 a3b3e6c Author: Akarin <jimmyshjj@gmail.com> Date: Wed May 15 19:22:09 2024 +0800 Merge branch 'Calcium-Ion:main' into main commit 046f6537913ae8ad8ecf21019b64c0379331b3fd Merge: 4164d51 7b58305 Author: Akarin <jimmyshjj@gmail.com> Date: Wed May 15 15:32:38 2024 +0800 Merge branch 'Calcium-Ion:main' into main commit 4164d51207808283a18ca2728241fd5cddc4855f Merge: ef35b07 c222bc8 Author: Akarin <jimmyshjj@gmail.com> Date: Wed May 15 11:19:13 2024 +0800 Merge branch 'Calcium-Ion:main' into main commit ef35b072824b5095ecd2d1ed7ca9fa11673da2c4 Author: Jiayun Shen <jimmyshjj@gmail.com> Date: Tue May 14 19:17:32 2024 +0800 Update adaptor.go Update frequently used model names from Baidu official docs and support custom models
2024-05-16 14:05:44 +08:00
case "ERNIE-4.0-8K":
2024-07-05 20:22:30 +08:00
suffix += "completions_pro"
Squashed commit of the following: commit 5a6a0df45dee3dfbf2f65591a79fe5f2b74a49e6 Author: Akarin <jimmyshjj@gmail.com> Date: Thu May 16 14:05:28 2024 +0800 Revert "Update docker-image-amd64.yml" This reverts commit 581343a78783bbd779e65b476e125af0e2b64ce5. commit a0aec1bd030da2c6b25d9541199d598f16813a60 Merge: 5b46c7d 58abb38 Author: Jiayun Shen <jimmyshjj@gmail.com> Date: Thu May 16 06:46:51 2024 +0800 Merge branch 'main' of https://github.com/jimmyshjj/new-api commit 58abb3864a89294d82f812cda9fe49ccf7e2dd91 Merge: 7d2c026 93858c3 Author: Akarin <jimmyshjj@gmail.com> Date: Thu May 16 06:46:00 2024 +0800 Merge branch 'Calcium-Ion:main' into main commit 5b46c7dd8e6132d2be3b59c7b2ed6a4b84b93cef Author: Jiayun Shen <jimmyshjj@gmail.com> Date: Thu May 16 06:45:00 2024 +0800 Update constants.go Remove replaced Baidu models commit 7d2c02679cd90b8b53f4145f83969b980a8c2095 Author: Akarin <jimmyshjj@gmail.com> Date: Wed May 15 23:40:50 2024 +0800 Update adaptor.go - Normalize model name to lowercase Baidu's official model names may include mixed case letters, but their model APIs are case-sensitive and accept only lowercase. To ensure compatibility, the default behavior has been updated to convert model names to lowercase before constructing API requests. commit 6bc168a39d9a6194d66f2f32b175e56de9295b2e Merge: bb9fecd 910e76a Author: Jiayun Shen <jimmyshjj@gmail.com> Date: Wed May 15 21:51:52 2024 +0800 Merge branch 'main' of https://github.com/jimmyshjj/new-api commit 910e76ac94d7f5dca6254abb4d0669cbb762e724 Merge: 581343a ff044de Author: Akarin <jimmyshjj@gmail.com> Date: Wed May 15 21:51:13 2024 +0800 Merge branch 'Calcium-Ion:main' into main commit bb9fecd5bf2bd9f1859a4017e7e68f80bdb6685a Author: Jiayun Shen <jimmyshjj@gmail.com> Date: Wed May 15 21:50:08 2024 +0800 update Baidu and 360 models Add Baidu and 360 new models. Add Baidu completion ratio commit 581343a78783bbd779e65b476e125af0e2b64ce5 Author: Akarin <jimmyshjj@gmail.com> Date: Wed May 15 19:41:34 2024 +0800 Update docker-image-amd64.yml commit de17e2d95eec80f1eeae66e82dec4e9601cdee43 Merge: 046f653 a3b3e6c Author: Akarin <jimmyshjj@gmail.com> Date: Wed May 15 19:22:09 2024 +0800 Merge branch 'Calcium-Ion:main' into main commit 046f6537913ae8ad8ecf21019b64c0379331b3fd Merge: 4164d51 7b58305 Author: Akarin <jimmyshjj@gmail.com> Date: Wed May 15 15:32:38 2024 +0800 Merge branch 'Calcium-Ion:main' into main commit 4164d51207808283a18ca2728241fd5cddc4855f Merge: ef35b07 c222bc8 Author: Akarin <jimmyshjj@gmail.com> Date: Wed May 15 11:19:13 2024 +0800 Merge branch 'Calcium-Ion:main' into main commit ef35b072824b5095ecd2d1ed7ca9fa11673da2c4 Author: Jiayun Shen <jimmyshjj@gmail.com> Date: Tue May 14 19:17:32 2024 +0800 Update adaptor.go Update frequently used model names from Baidu official docs and support custom models
2024-05-16 14:05:44 +08:00
case "ERNIE-3.5-8K":
2024-07-05 20:22:30 +08:00
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"
Squashed commit of the following: commit 5a6a0df45dee3dfbf2f65591a79fe5f2b74a49e6 Author: Akarin <jimmyshjj@gmail.com> Date: Thu May 16 14:05:28 2024 +0800 Revert "Update docker-image-amd64.yml" This reverts commit 581343a78783bbd779e65b476e125af0e2b64ce5. commit a0aec1bd030da2c6b25d9541199d598f16813a60 Merge: 5b46c7d 58abb38 Author: Jiayun Shen <jimmyshjj@gmail.com> Date: Thu May 16 06:46:51 2024 +0800 Merge branch 'main' of https://github.com/jimmyshjj/new-api commit 58abb3864a89294d82f812cda9fe49ccf7e2dd91 Merge: 7d2c026 93858c3 Author: Akarin <jimmyshjj@gmail.com> Date: Thu May 16 06:46:00 2024 +0800 Merge branch 'Calcium-Ion:main' into main commit 5b46c7dd8e6132d2be3b59c7b2ed6a4b84b93cef Author: Jiayun Shen <jimmyshjj@gmail.com> Date: Thu May 16 06:45:00 2024 +0800 Update constants.go Remove replaced Baidu models commit 7d2c02679cd90b8b53f4145f83969b980a8c2095 Author: Akarin <jimmyshjj@gmail.com> Date: Wed May 15 23:40:50 2024 +0800 Update adaptor.go - Normalize model name to lowercase Baidu's official model names may include mixed case letters, but their model APIs are case-sensitive and accept only lowercase. To ensure compatibility, the default behavior has been updated to convert model names to lowercase before constructing API requests. commit 6bc168a39d9a6194d66f2f32b175e56de9295b2e Merge: bb9fecd 910e76a Author: Jiayun Shen <jimmyshjj@gmail.com> Date: Wed May 15 21:51:52 2024 +0800 Merge branch 'main' of https://github.com/jimmyshjj/new-api commit 910e76ac94d7f5dca6254abb4d0669cbb762e724 Merge: 581343a ff044de Author: Akarin <jimmyshjj@gmail.com> Date: Wed May 15 21:51:13 2024 +0800 Merge branch 'Calcium-Ion:main' into main commit bb9fecd5bf2bd9f1859a4017e7e68f80bdb6685a Author: Jiayun Shen <jimmyshjj@gmail.com> Date: Wed May 15 21:50:08 2024 +0800 update Baidu and 360 models Add Baidu and 360 new models. Add Baidu completion ratio commit 581343a78783bbd779e65b476e125af0e2b64ce5 Author: Akarin <jimmyshjj@gmail.com> Date: Wed May 15 19:41:34 2024 +0800 Update docker-image-amd64.yml commit de17e2d95eec80f1eeae66e82dec4e9601cdee43 Merge: 046f653 a3b3e6c Author: Akarin <jimmyshjj@gmail.com> Date: Wed May 15 19:22:09 2024 +0800 Merge branch 'Calcium-Ion:main' into main commit 046f6537913ae8ad8ecf21019b64c0379331b3fd Merge: 4164d51 7b58305 Author: Akarin <jimmyshjj@gmail.com> Date: Wed May 15 15:32:38 2024 +0800 Merge branch 'Calcium-Ion:main' into main commit 4164d51207808283a18ca2728241fd5cddc4855f Merge: ef35b07 c222bc8 Author: Akarin <jimmyshjj@gmail.com> Date: Wed May 15 11:19:13 2024 +0800 Merge branch 'Calcium-Ion:main' into main commit ef35b072824b5095ecd2d1ed7ca9fa11673da2c4 Author: Jiayun Shen <jimmyshjj@gmail.com> Date: Tue May 14 19:17:32 2024 +0800 Update adaptor.go Update frequently used model names from Baidu official docs and support custom models
2024-05-16 14:05:44 +08:00
case "ERNIE-Speed-8K":
2024-07-05 20:22:30 +08:00
suffix += "ernie_speed"
case "ERNIE-Speed-128K":
suffix += "ernie-speed-128k"
Squashed commit of the following: commit 5a6a0df45dee3dfbf2f65591a79fe5f2b74a49e6 Author: Akarin <jimmyshjj@gmail.com> Date: Thu May 16 14:05:28 2024 +0800 Revert "Update docker-image-amd64.yml" This reverts commit 581343a78783bbd779e65b476e125af0e2b64ce5. commit a0aec1bd030da2c6b25d9541199d598f16813a60 Merge: 5b46c7d 58abb38 Author: Jiayun Shen <jimmyshjj@gmail.com> Date: Thu May 16 06:46:51 2024 +0800 Merge branch 'main' of https://github.com/jimmyshjj/new-api commit 58abb3864a89294d82f812cda9fe49ccf7e2dd91 Merge: 7d2c026 93858c3 Author: Akarin <jimmyshjj@gmail.com> Date: Thu May 16 06:46:00 2024 +0800 Merge branch 'Calcium-Ion:main' into main commit 5b46c7dd8e6132d2be3b59c7b2ed6a4b84b93cef Author: Jiayun Shen <jimmyshjj@gmail.com> Date: Thu May 16 06:45:00 2024 +0800 Update constants.go Remove replaced Baidu models commit 7d2c02679cd90b8b53f4145f83969b980a8c2095 Author: Akarin <jimmyshjj@gmail.com> Date: Wed May 15 23:40:50 2024 +0800 Update adaptor.go - Normalize model name to lowercase Baidu's official model names may include mixed case letters, but their model APIs are case-sensitive and accept only lowercase. To ensure compatibility, the default behavior has been updated to convert model names to lowercase before constructing API requests. commit 6bc168a39d9a6194d66f2f32b175e56de9295b2e Merge: bb9fecd 910e76a Author: Jiayun Shen <jimmyshjj@gmail.com> Date: Wed May 15 21:51:52 2024 +0800 Merge branch 'main' of https://github.com/jimmyshjj/new-api commit 910e76ac94d7f5dca6254abb4d0669cbb762e724 Merge: 581343a ff044de Author: Akarin <jimmyshjj@gmail.com> Date: Wed May 15 21:51:13 2024 +0800 Merge branch 'Calcium-Ion:main' into main commit bb9fecd5bf2bd9f1859a4017e7e68f80bdb6685a Author: Jiayun Shen <jimmyshjj@gmail.com> Date: Wed May 15 21:50:08 2024 +0800 update Baidu and 360 models Add Baidu and 360 new models. Add Baidu completion ratio commit 581343a78783bbd779e65b476e125af0e2b64ce5 Author: Akarin <jimmyshjj@gmail.com> Date: Wed May 15 19:41:34 2024 +0800 Update docker-image-amd64.yml commit de17e2d95eec80f1eeae66e82dec4e9601cdee43 Merge: 046f653 a3b3e6c Author: Akarin <jimmyshjj@gmail.com> Date: Wed May 15 19:22:09 2024 +0800 Merge branch 'Calcium-Ion:main' into main commit 046f6537913ae8ad8ecf21019b64c0379331b3fd Merge: 4164d51 7b58305 Author: Akarin <jimmyshjj@gmail.com> Date: Wed May 15 15:32:38 2024 +0800 Merge branch 'Calcium-Ion:main' into main commit 4164d51207808283a18ca2728241fd5cddc4855f Merge: ef35b07 c222bc8 Author: Akarin <jimmyshjj@gmail.com> Date: Wed May 15 11:19:13 2024 +0800 Merge branch 'Calcium-Ion:main' into main commit ef35b072824b5095ecd2d1ed7ca9fa11673da2c4 Author: Jiayun Shen <jimmyshjj@gmail.com> Date: Tue May 14 19:17:32 2024 +0800 Update adaptor.go Update frequently used model names from Baidu official docs and support custom models
2024-05-16 14:05:44 +08:00
case "ERNIE-Lite-8K-0922":
2024-07-05 20:22:30 +08:00
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"
2024-02-29 01:08:18 +08:00
case "Embedding-V1":
2024-07-05 20:22:30 +08:00
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"
Squashed commit of the following: commit 5a6a0df45dee3dfbf2f65591a79fe5f2b74a49e6 Author: Akarin <jimmyshjj@gmail.com> Date: Thu May 16 14:05:28 2024 +0800 Revert "Update docker-image-amd64.yml" This reverts commit 581343a78783bbd779e65b476e125af0e2b64ce5. commit a0aec1bd030da2c6b25d9541199d598f16813a60 Merge: 5b46c7d 58abb38 Author: Jiayun Shen <jimmyshjj@gmail.com> Date: Thu May 16 06:46:51 2024 +0800 Merge branch 'main' of https://github.com/jimmyshjj/new-api commit 58abb3864a89294d82f812cda9fe49ccf7e2dd91 Merge: 7d2c026 93858c3 Author: Akarin <jimmyshjj@gmail.com> Date: Thu May 16 06:46:00 2024 +0800 Merge branch 'Calcium-Ion:main' into main commit 5b46c7dd8e6132d2be3b59c7b2ed6a4b84b93cef Author: Jiayun Shen <jimmyshjj@gmail.com> Date: Thu May 16 06:45:00 2024 +0800 Update constants.go Remove replaced Baidu models commit 7d2c02679cd90b8b53f4145f83969b980a8c2095 Author: Akarin <jimmyshjj@gmail.com> Date: Wed May 15 23:40:50 2024 +0800 Update adaptor.go - Normalize model name to lowercase Baidu's official model names may include mixed case letters, but their model APIs are case-sensitive and accept only lowercase. To ensure compatibility, the default behavior has been updated to convert model names to lowercase before constructing API requests. commit 6bc168a39d9a6194d66f2f32b175e56de9295b2e Merge: bb9fecd 910e76a Author: Jiayun Shen <jimmyshjj@gmail.com> Date: Wed May 15 21:51:52 2024 +0800 Merge branch 'main' of https://github.com/jimmyshjj/new-api commit 910e76ac94d7f5dca6254abb4d0669cbb762e724 Merge: 581343a ff044de Author: Akarin <jimmyshjj@gmail.com> Date: Wed May 15 21:51:13 2024 +0800 Merge branch 'Calcium-Ion:main' into main commit bb9fecd5bf2bd9f1859a4017e7e68f80bdb6685a Author: Jiayun Shen <jimmyshjj@gmail.com> Date: Wed May 15 21:50:08 2024 +0800 update Baidu and 360 models Add Baidu and 360 new models. Add Baidu completion ratio commit 581343a78783bbd779e65b476e125af0e2b64ce5 Author: Akarin <jimmyshjj@gmail.com> Date: Wed May 15 19:41:34 2024 +0800 Update docker-image-amd64.yml commit de17e2d95eec80f1eeae66e82dec4e9601cdee43 Merge: 046f653 a3b3e6c Author: Akarin <jimmyshjj@gmail.com> Date: Wed May 15 19:22:09 2024 +0800 Merge branch 'Calcium-Ion:main' into main commit 046f6537913ae8ad8ecf21019b64c0379331b3fd Merge: 4164d51 7b58305 Author: Akarin <jimmyshjj@gmail.com> Date: Wed May 15 15:32:38 2024 +0800 Merge branch 'Calcium-Ion:main' into main commit 4164d51207808283a18ca2728241fd5cddc4855f Merge: ef35b07 c222bc8 Author: Akarin <jimmyshjj@gmail.com> Date: Wed May 15 11:19:13 2024 +0800 Merge branch 'Calcium-Ion:main' into main commit ef35b072824b5095ecd2d1ed7ca9fa11673da2c4 Author: Jiayun Shen <jimmyshjj@gmail.com> Date: Tue May 14 19:17:32 2024 +0800 Update adaptor.go Update frequently used model names from Baidu official docs and support custom models
2024-05-16 14:05:44 +08:00
default:
2024-07-05 20:22:30 +08:00
suffix += strings.ToLower(info.UpstreamModelName)
2024-02-29 01:08:18 +08:00
}
2024-07-05 20:22:30 +08:00
fullRequestURL := fmt.Sprintf("%s/rpc/2.0/ai_custom/v1/wenxinworkshop/%s", info.BaseUrl, suffix)
2024-02-29 01:08:18 +08:00
var accessToken string
var err error
if accessToken, err = getBaiduAccessToken(info.ApiKey); err != nil {
return "", err
}
fullRequestURL += "?access_token=" + accessToken
return fullRequestURL, nil
}
func (a *Adaptor) SetupRequestHeader(c *gin.Context, req *http.Header, info *relaycommon.RelayInfo) error {
2024-02-29 16:21:25 +08:00
channel.SetupApiRequestHeader(info, c, req)
req.Set("Authorization", "Bearer "+info.ApiKey)
2024-02-29 01:08:18 +08:00
return nil
}
func (a *Adaptor) ConvertOpenAIRequest(c *gin.Context, info *relaycommon.RelayInfo, request *dto.GeneralOpenAIRequest) (any, error) {
2024-02-29 01:08:18 +08:00
if request == nil {
return nil, errors.New("request is nil")
}
2024-07-15 16:05:30 +08:00
switch info.RelayMode {
2024-02-29 01:08:18 +08:00
default:
baiduRequest := requestOpenAI2Baidu(*request)
return baiduRequest, nil
}
}
2024-07-06 17:09:22 +08:00
func (a *Adaptor) ConvertRerankRequest(c *gin.Context, relayMode int, request dto.RerankRequest) (any, error) {
return nil, nil
}
2025-01-23 05:54:39 +08:00
func (a *Adaptor) ConvertEmbeddingRequest(c *gin.Context, info *relaycommon.RelayInfo, request dto.EmbeddingRequest) (any, error) {
baiduEmbeddingRequest := embeddingRequestOpenAI2Baidu(request)
return baiduEmbeddingRequest, nil
2025-01-23 05:54:39 +08:00
}
2025-05-02 13:59:46 +08:00
func (a *Adaptor) ConvertOpenAIResponsesRequest(c *gin.Context, info *relaycommon.RelayInfo, request dto.OpenAIResponsesRequest) (any, error) {
// TODO implement me
return nil, errors.New("not implemented")
}
func (a *Adaptor) DoRequest(c *gin.Context, info *relaycommon.RelayInfo, requestBody io.Reader) (any, error) {
2024-02-29 16:21:25 +08:00
return channel.DoApiRequest(a, c, info, requestBody)
2024-02-29 01:08:18 +08:00
}
func (a *Adaptor) DoResponse(c *gin.Context, resp *http.Response, info *relaycommon.RelayInfo) (usage any, err *dto.OpenAIErrorWithStatusCode) {
2024-02-29 01:08:18 +08:00
if info.IsStream {
err, usage = baiduStreamHandler(c, resp)
} else {
switch info.RelayMode {
case constant.RelayModeEmbeddings:
err, usage = baiduEmbeddingHandler(c, resp)
default:
err, usage = baiduHandler(c, resp)
}
}
return
}
func (a *Adaptor) GetModelList() []string {
return ModelList
}
func (a *Adaptor) GetChannelName() string {
return ChannelName
}