From 5e3042752e174a9bb97c8a285320f91133705627 Mon Sep 17 00:00:00 2001 From: haochun <759869747@qq.com> Date: Tue, 8 Oct 2024 10:51:44 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E9=98=BF=E9=87=8C?= =?UTF-8?q?=E4=BA=91=E5=AE=98=E6=96=B9=E7=9A=84=E7=BB=BF=E7=BD=91=E5=93=8D?= =?UTF-8?q?=E5=BA=94=E6=9C=AA=E6=AD=A3=E5=B8=B8=E5=A4=84=E7=90=86=EF=BC=8C?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E4=B8=9A=E5=8A=A1=E5=88=99=E4=B8=AD=E6=96=AD?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=8C=E5=81=9A=E4=BA=86=E5=85=BC?= =?UTF-8?q?=E5=AE=B9=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- relay/adaptor/ali/main.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/relay/adaptor/ali/main.go b/relay/adaptor/ali/main.go index f9039dbe..bd0d3344 100644 --- a/relay/adaptor/ali/main.go +++ b/relay/adaptor/ali/main.go @@ -199,6 +199,20 @@ func StreamHandler(c *gin.Context, resp *http.Response) (*model.ErrorWithStatusC logger.SysError("error unmarshalling stream response: " + err.Error()) continue } + + // Check for known error codes and handle accordingly + if aliResponse.Code != "" { + return &model.ErrorWithStatusCode{ + Error: model.Error{ + Message: aliResponse.Message, + Type: aliResponse.Code, + Param: aliResponse.RequestId, + Code: aliResponse.Code, + }, + StatusCode: resp.StatusCode, + }, nil + } + if aliResponse.Usage.OutputTokens != 0 { usage.PromptTokens = aliResponse.Usage.InputTokens usage.CompletionTokens = aliResponse.Usage.OutputTokens @@ -243,6 +257,8 @@ func Handler(c *gin.Context, resp *http.Response) (*model.ErrorWithStatusCode, * if err != nil { return openai.ErrorWrapper(err, "unmarshal_response_body_failed", http.StatusInternalServerError), nil } + + // Check for known error codes and handle accordingly if aliResponse.Code != "" { return &model.ErrorWithStatusCode{ Error: model.Error{ @@ -254,6 +270,7 @@ func Handler(c *gin.Context, resp *http.Response) (*model.ErrorWithStatusCode, * StatusCode: resp.StatusCode, }, nil } + fullTextResponse := responseAli2OpenAI(&aliResponse) fullTextResponse.Model = "qwen" jsonResponse, err := json.Marshal(fullTextResponse)