fix: check response type when expect stream response
This commit is contained in:
parent
f05b403ca5
commit
2346bf70af
@ -2,6 +2,7 @@ package baidu
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/songquanpeng/one-api/relay/channel"
|
"github.com/songquanpeng/one-api/relay/channel"
|
||||||
"github.com/songquanpeng/one-api/relay/constant"
|
"github.com/songquanpeng/one-api/relay/constant"
|
||||||
@ -9,6 +10,7 @@ import (
|
|||||||
"github.com/songquanpeng/one-api/relay/util"
|
"github.com/songquanpeng/one-api/relay/util"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Adaptor struct {
|
type Adaptor struct {
|
||||||
@ -20,25 +22,33 @@ func (a *Adaptor) Init(meta *util.RelayMeta) {
|
|||||||
|
|
||||||
func (a *Adaptor) GetRequestURL(meta *util.RelayMeta) (string, error) {
|
func (a *Adaptor) GetRequestURL(meta *util.RelayMeta) (string, error) {
|
||||||
// https://cloud.baidu.com/doc/WENXINWORKSHOP/s/clntwmv7t
|
// https://cloud.baidu.com/doc/WENXINWORKSHOP/s/clntwmv7t
|
||||||
var fullRequestURL string
|
suffix := "chat/"
|
||||||
switch meta.ActualModelName {
|
if strings.HasPrefix("Embedding", meta.ActualModelName) {
|
||||||
case "ERNIE-Bot-4":
|
suffix = "embeddings/"
|
||||||
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"
|
|
||||||
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"
|
|
||||||
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"
|
|
||||||
case "Embedding-V1":
|
|
||||||
fullRequestURL = "https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/embeddings/embedding-v1"
|
|
||||||
default:
|
|
||||||
fullRequestURL = "https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/" + meta.ActualModelName
|
|
||||||
}
|
}
|
||||||
|
switch meta.ActualModelName {
|
||||||
|
case "ERNIE-4.0":
|
||||||
|
suffix += "completions_pro"
|
||||||
|
case "ERNIE-Bot-4":
|
||||||
|
suffix += "completions_pro"
|
||||||
|
case "ERNIE-3.5-8K":
|
||||||
|
suffix += "completions"
|
||||||
|
case "ERNIE-Bot-8K":
|
||||||
|
suffix += "ernie_bot_8k"
|
||||||
|
case "ERNIE-Bot":
|
||||||
|
suffix += "completions"
|
||||||
|
case "ERNIE-Speed":
|
||||||
|
suffix += "ernie_speed"
|
||||||
|
case "ERNIE-Bot-turbo":
|
||||||
|
suffix += "eb-instant"
|
||||||
|
case "BLOOMZ-7B":
|
||||||
|
suffix += "bloomz_7b1"
|
||||||
|
case "Embedding-V1":
|
||||||
|
suffix += "embedding-v1"
|
||||||
|
default:
|
||||||
|
suffix += meta.ActualModelName
|
||||||
|
}
|
||||||
|
fullRequestURL := fmt.Sprintf("%s/rpc/2.0/ai_custom/v1/wenxinworkshop/%s", meta.BaseURL, suffix)
|
||||||
var accessToken string
|
var accessToken string
|
||||||
var err error
|
var err error
|
||||||
if accessToken, err = GetAccessToken(meta.APIKey); err != nil {
|
if accessToken, err = GetAccessToken(meta.APIKey); err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user