diff --git a/controller/relay-text.go b/controller/relay-text.go index 761ca86f..8ee707af 100644 --- a/controller/relay-text.go +++ b/controller/relay-text.go @@ -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 { diff --git a/controller/relay-xunfei.go b/controller/relay-xunfei.go index 87037e34..2aba2e88 100644 --- a/controller/relay-xunfei.go +++ b/controller/relay-xunfei.go @@ -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 diff --git a/web/src/pages/Channel/EditChannel.js b/web/src/pages/Channel/EditChannel.js index b5fb524e..2912c5ed 100644 --- a/web/src/pages/Channel/EditChannel.js +++ b/web/src/pages/Channel/EditChannel.js @@ -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'