diff --git a/code/handlers/event_msg_action.go b/code/handlers/event_msg_action.go index f9e10f71..8c06ea7c 100644 --- a/code/handlers/event_msg_action.go +++ b/code/handlers/event_msg_action.go @@ -49,7 +49,7 @@ func (*MessageAction) Execute(a *ActionInfo) bool { } msg := a.handler.sessionCache.GetMsg(*a.info.sessionId) // 如果没有提示词,默认模拟ChatGPT - msg = setDefaultPrompt(msg) + // msg = setDefaultPrompt(msg) msg = append(msg, openai.Messages{ Role: "user", Content: a.info.qParsed, }) @@ -58,7 +58,7 @@ func (*MessageAction) Execute(a *ActionInfo) bool { aiMode := a.handler.sessionCache.GetAIMode(*a.info.sessionId) fmt.Println("msg: ", msg) fmt.Println("aiMode: ", aiMode) - completions, err := a.handler.gpt.Completions(msg, aiMode) + completions, err := a.handler.gpt.Completions(msg, aiMode, *a.info.sessionId) if err != nil { replyMsg(*a.ctx, fmt.Sprintf( "🤖️:消息机器人摆烂了,请稍后再试~\n错误信息: %v", err), a.info.msgId) @@ -87,7 +87,7 @@ func (*MessageAction) Execute(a *ActionInfo) bool { return true } -//判断msg中的是否包含system role +// 判断msg中的是否包含system role func hasSystemRole(msg []openai.Messages) bool { for _, m := range msg { if m.Role == "system" { diff --git a/code/logger/logger.go b/code/logger/logger.go index 75442471..df9aadc8 100644 --- a/code/logger/logger.go +++ b/code/logger/logger.go @@ -24,7 +24,7 @@ func init() { //WarnLevel //InfoLevel //DebugLevel - logger.Level = logrus.InfoLevel + logger.Level = logrus.DebugLevel } diff --git a/code/services/openai/common.go b/code/services/openai/common.go index 85f6341e..ec48535d 100644 --- a/code/services/openai/common.go +++ b/code/services/openai/common.go @@ -141,7 +141,7 @@ func (gpt *ChatGPT) doAPIRequestWithRetry(url, method string, if err != nil || response.StatusCode < 200 || response.StatusCode >= 300 { body, _ := ioutil.ReadAll(response.Body) - fmt.Println("body", string(body)) + logger.Debug("response body", string(body)) gpt.Lb.SetAvailability(api.Key, false) if retry == maxRetries { diff --git a/code/services/openai/gpt3.go b/code/services/openai/gpt3.go index 0ecc7397..613eb441 100644 --- a/code/services/openai/gpt3.go +++ b/code/services/openai/gpt3.go @@ -54,6 +54,9 @@ type ChatGPTChoiceItem struct { // ChatGPTRequestBody 响应体 type ChatGPTRequestBody struct { + ChatId string `json:"chatId"` + Stream bool `json:"stream"` + Detail bool `json:"detail"` Model string `json:"model"` Messages []Messages `json:"messages"` MaxTokens int `json:"max_tokens"` @@ -68,9 +71,10 @@ func (msg *Messages) CalculateTokenLength() int { return tokenizer.MustCalToken(text) } -func (gpt *ChatGPT) Completions(msg []Messages, aiMode AIMode) (resp Messages, +func (gpt *ChatGPT) Completions(msg []Messages, aiMode AIMode, chatid string) (resp Messages, err error) { requestBody := ChatGPTRequestBody{ + ChatId: chatid, Model: gpt.Model, Messages: msg, MaxTokens: gpt.MaxTokens, @@ -81,13 +85,13 @@ func (gpt *ChatGPT) Completions(msg []Messages, aiMode AIMode) (resp Messages, } gptResponseBody := &ChatGPTResponseBody{} url := gpt.FullUrl("chat/completions") - //fmt.Println(url) - logger.Debug(url) + logger.Debug("request url ", url) logger.Debug("request body ", requestBody) if url == "" { return resp, errors.New("无法获取openai请求地址") } err = gpt.sendRequestWithBodyType(url, "POST", jsonBody, requestBody, gptResponseBody) + logger.Debugf("gptresponse %v", gptResponseBody) if err == nil && len(gptResponseBody.Choices) > 0 { resp = gptResponseBody.Choices[0].Message } else {