兼容讯飞v2接口
This commit is contained in:
parent
86c2627c24
commit
21f05d1294
@ -501,11 +501,14 @@ func relayTextHelper(c *gin.Context, relayMode int) *OpenAIErrorWithStatusCode {
|
||||
auth := c.Request.Header.Get("Authorization")
|
||||
auth = strings.TrimPrefix(auth, "Bearer ")
|
||||
splits := strings.Split(auth, "|")
|
||||
if len(splits) != 3 {
|
||||
if len(splits) < 3 || len(splits) > 4 {
|
||||
return errorWrapper(errors.New("invalid auth"), "invalid_auth", http.StatusBadRequest)
|
||||
}
|
||||
err, usage := xunfeiStreamHandler(c, textRequest, splits[0], splits[1], splits[2])
|
||||
if err != nil {
|
||||
if len(splits) == 3 {
|
||||
splits[3] = ""
|
||||
}
|
||||
err, usage := xunfeiStreamHandler(c, textRequest, splits[0], splits[1], splits[2], splits[3])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if usage != nil {
|
||||
|
@ -176,12 +176,15 @@ func buildXunfeiAuthUrl(hostUrl string, apiKey, apiSecret string) string {
|
||||
return callUrl
|
||||
}
|
||||
|
||||
func xunfeiStreamHandler(c *gin.Context, textRequest GeneralOpenAIRequest, appId string, apiSecret string, apiKey string) (*OpenAIErrorWithStatusCode, *Usage) {
|
||||
func xunfeiStreamHandler(c *gin.Context, textRequest GeneralOpenAIRequest, appId string, apiSecret string, apiKey string, version string) (*OpenAIErrorWithStatusCode, *Usage) {
|
||||
var usage Usage
|
||||
d := websocket.Dialer{
|
||||
HandshakeTimeout: 5 * time.Second,
|
||||
}
|
||||
hostUrl := "wss://aichat.xf-yun.com/v1/chat"
|
||||
if version != "" { //换成新版的,支持v2
|
||||
hostUrl = "wss://spark-api.xf-yun.com/" + version + "/chat"
|
||||
}
|
||||
conn, resp, err := d.Dial(buildXunfeiAuthUrl(hostUrl, apiKey, apiSecret), nil)
|
||||
if err != nil || resp.StatusCode != 101 {
|
||||
return errorWrapper(err, "dial_failed", http.StatusInternalServerError), nil
|
||||
|
@ -355,7 +355,7 @@ const EditChannel = () => {
|
||||
label='密钥'
|
||||
name='key'
|
||||
required
|
||||
placeholder={inputs.type === 15 ? '按照如下格式输入:APIKey|SecretKey' : (inputs.type === 18 ? '按照如下格式输入:APPID|APISecret|APIKey' : '请输入渠道对应的鉴权密钥')}
|
||||
placeholder={inputs.type === 15 ? '按照如下格式输入:APIKey|SecretKey' : (inputs.type === 18 ? '按照如下格式输入:APPID|APISecret|APIKey|v1.1或v2.1' : '请输入渠道对应的鉴权密钥')}
|
||||
onChange={handleInputChange}
|
||||
value={inputs.key}
|
||||
autoComplete='new-password'
|
||||
|
Loading…
Reference in New Issue
Block a user