From 7e33eaa6e06b94ee6fb0455fe91b7fa73f415662 Mon Sep 17 00:00:00 2001 From: fruitbars Date: Mon, 24 Jun 2024 00:29:44 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/adapter/qianfan_openai.go | 14 +++++++------- pkg/adapter/xinghuo_openai.go | 5 +++-- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/pkg/adapter/qianfan_openai.go b/pkg/adapter/qianfan_openai.go index b84f7b3..67f1fe6 100644 --- a/pkg/adapter/qianfan_openai.go +++ b/pkg/adapter/qianfan_openai.go @@ -2,9 +2,10 @@ package adapter import ( "github.com/sashabaranov/go-openai" - "log" + "go.uber.org/zap" "simple-one-api/pkg/common" baiduqianfan "simple-one-api/pkg/llm/baidu-qianfan" + "simple-one-api/pkg/mylog" myopenai "simple-one-api/pkg/openai" "strings" ) @@ -54,7 +55,7 @@ func qianFanCheckMaxTokens(model string, maxtokens int) int { return validateMaxTokens(maxtokens, config.Min, config.Max, config.DefaultMax) } } - log.Println("Unknown model prefix") + mylog.Logger.Warn("Unknown model prefix") return 0 } @@ -152,7 +153,7 @@ func QianFanResponseToOpenAIResponse(qfResp *baiduqianfan.QianFanResponse) *myop oaResp := myopenai.OpenAIResponse{ ID: qfResp.ID, Object: qfResp.Object, - Created: int64(qfResp.Created), + Created: qfResp.Created, Model: "", // 假定使用的模型 SystemFingerprint: "", // 假定一个系统指纹 Usage: &myopenai.Usage{ @@ -180,7 +181,7 @@ func QianFanResponseToOpenAIResponse(qfResp *baiduqianfan.QianFanResponse) *myop // 将 Choice 添加到 Choices 数组 oaResp.Choices = append(oaResp.Choices, choice) - log.Println(oaResp) + mylog.Logger.Info("resp", zap.Any("oaResp", oaResp)) return &oaResp } @@ -188,8 +189,7 @@ func QianFanResponseToOpenAIResponse(qfResp *baiduqianfan.QianFanResponse) *myop func QianFanResponseToOpenAIStreamResponse(qfResp *baiduqianfan.QianFanResponse) *myopenai.OpenAIStreamResponse { // 创建一个 OpenAIResponse 实例 if qfResp.ErrorCode != 0 && len(qfResp.ErrorMsg) > 0 { - - log.Println("something error") + mylog.Logger.Error("something error") return &myopenai.OpenAIStreamResponse{ //ID: qfResp.ID, Error: &myopenai.ErrorDetail{ @@ -236,7 +236,7 @@ func QianFanResponseToOpenAIStreamResponse(qfResp *baiduqianfan.QianFanResponse) oaResp.Choices = append(oaResp.Choices, choice) - log.Println(oaResp) + mylog.Logger.Info("resp", zap.Any("resp", oaResp)) return &oaResp } diff --git a/pkg/adapter/xinghuo_openai.go b/pkg/adapter/xinghuo_openai.go index 721d5ba..1bc0c61 100644 --- a/pkg/adapter/xinghuo_openai.go +++ b/pkg/adapter/xinghuo_openai.go @@ -5,6 +5,7 @@ import ( "github.com/fruitbars/gosparkclient" "github.com/sashabaranov/go-openai" "log" + "simple-one-api/pkg/mylog" myopenai "simple-one-api/pkg/openai" "time" ) @@ -58,9 +59,9 @@ func OpenAIRequestToXingHuoRequest(openAIReq openai.ChatCompletionRequest) *gosp } case map[string]interface{}: - log.Println("ToolChoice is an object, ignore") + mylog.Logger.Warn("ToolChoice is an object, ignore") default: - log.Println("Unhandled type, ignore") + mylog.Logger.Warn("Unhandled type, ignore") } return &sparkChatReq