update
This commit is contained in:
parent
d3f35f2c53
commit
8a49b21ace
@ -16,7 +16,7 @@ func StartTelegramBot() {
|
||||
log.Info("Start Telegram Bot")
|
||||
telegramKey := config.GetTelegram()
|
||||
if telegramKey == nil {
|
||||
log.Info("未找到tg token,不启动tg tot")
|
||||
log.Error("未找到tg token,不启动tg tot")
|
||||
return
|
||||
}
|
||||
|
||||
@ -79,9 +79,10 @@ func StartTelegramBot() {
|
||||
}
|
||||
|
||||
requestText := strings.TrimSpace(splitItems[1])
|
||||
log.Println("问题:", requestText)
|
||||
log.Info("问题:", requestText)
|
||||
reply = telegram.Handle(requestText)
|
||||
} else {
|
||||
log.Info("问题:", text)
|
||||
reply = telegram.Handle(text)
|
||||
}
|
||||
|
||||
@ -96,7 +97,7 @@ func StartTelegramBot() {
|
||||
continue
|
||||
}
|
||||
|
||||
log.Println(send.Text)
|
||||
log.Info("回答:", send.Text)
|
||||
}
|
||||
|
||||
select {}
|
||||
|
@ -12,7 +12,7 @@ func Handle(msg string) *string {
|
||||
requestText := strings.TrimSpace(msg)
|
||||
reply, err := openai.Completions(requestText)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
log.Error(err)
|
||||
}
|
||||
return reply
|
||||
}
|
||||
|
4
main.go
4
main.go
@ -8,6 +8,9 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
log.SetLevel(log.DebugLevel)
|
||||
//log.SetLevel(log.InfoLevel)
|
||||
|
||||
log.SetReportCaller(true)
|
||||
log.SetFormatter(&log.TextFormatter{
|
||||
DisableColors: false,
|
||||
@ -27,5 +30,6 @@ func main() {
|
||||
} else if telegramEnv != nil {
|
||||
bootstrap.StartTelegramBot()
|
||||
}
|
||||
|
||||
log.Info("程序退出")
|
||||
}
|
||||
|
@ -79,14 +79,14 @@ func Completions(msg string) (*string, error) {
|
||||
requestData, err := json.Marshal(requestBody)
|
||||
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
log.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
log.Printf("request openai json string : %v", string(requestData))
|
||||
log.Debugf("request openai json string : %v", string(requestData))
|
||||
req, err := http.NewRequest("POST", "https://api.openai.com/v1/completions", bytes.NewBuffer(requestData))
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
log.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -111,10 +111,10 @@ func Completions(msg string) (*string, error) {
|
||||
}
|
||||
|
||||
gptResponseBody := &ChatGPTResponseBody{}
|
||||
log.Println(string(body))
|
||||
log.Debug(string(body))
|
||||
err = json.Unmarshal(body, gptResponseBody)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
log.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -130,13 +130,13 @@ func Completions(msg string) (*string, error) {
|
||||
gptErrorBody := &ChatGPTErrorBody{}
|
||||
err = json.Unmarshal(body, gptErrorBody)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
log.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
reply = gptErrorBody.Error["message"].(string)
|
||||
}
|
||||
|
||||
log.Printf("gpt response full text: %s \n", reply)
|
||||
log.Debugf("gpt response full text: %s \n", reply)
|
||||
result := strings.TrimSpace(reply)
|
||||
return &result, nil
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user