This commit is contained in:
unintendedfraud
2023-11-07 09:30:03 +01:00
parent a20ee7c581
commit e4df28272a
2 changed files with 11 additions and 0 deletions
+2
View File
@@ -45,6 +45,8 @@ 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())
}
fmt.Println("Choices: ", res.Choices)
if len(res.Choices) > 0 {
aiResponse := res.Choices[0].Message.Content
sendResponse(s, m.ChannelID, aiResponse)
+9
View File
@@ -41,6 +41,15 @@ func (c Client) Chat(messages []*ChatMessage) (*ChatResponse, 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 {
fmt.Println("ERROR: ", err.Error())
}
fmt.Println("Parsing response in interface:")
indent, _ := json.MarshalIndent(test, "\n", " ")
fmt.Printf("\n%+v\n", indent)
var r ChatResponse
if err := json.Unmarshal(res.Body(), &r); err != nil {
return nil, fmt.Errorf("failed to parse the openai response. Error: %s", err.Error())