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