d
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"hal/env"
|
||||
"hal/openai"
|
||||
"log"
|
||||
@@ -20,10 +21,13 @@ func OnMessageCreated(s *discordgo.Session, m *discordgo.MessageCreate) {
|
||||
log.Panicf("failed to query open ai with the following prompt [%s]. Error: %s", m.Content, err.Error())
|
||||
}
|
||||
|
||||
aiResponse := res.Choices[0].Text
|
||||
if len(res.Choices) > 0 {
|
||||
if _, err = s.ChannelMessageSend(m.ChannelID, aiResponse); err != nil {
|
||||
log.Panicf("failed to send the response [%s] to the discord channel [%s]", aiResponse, err.Error())
|
||||
}
|
||||
} else {
|
||||
fmt.Println("### no response ##")
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -41,6 +41,12 @@ func (c Client) Completions(prompt string) (*CompletionResponse, error) {
|
||||
return nil, fmt.Errorf("failed to query openai. Error: %s", err.Error())
|
||||
}
|
||||
|
||||
var test interface{}
|
||||
if err := json.Unmarshal(res.Body(), &test); err != nil {
|
||||
return nil, fmt.Errorf("failed to parse the openai response. Error: %s", err.Error())
|
||||
}
|
||||
fmt.Println("### RESPONSE INTERFCE ###", test)
|
||||
|
||||
var r CompletionResponse
|
||||
if err := json.Unmarshal(res.Body(), &r); err != nil {
|
||||
return nil, fmt.Errorf("failed to parse the openai response. Error: %s", err.Error())
|
||||
|
||||
Reference in New Issue
Block a user