log
This commit is contained in:
@@ -10,22 +10,23 @@ import (
|
||||
)
|
||||
|
||||
func OnMessageCreated(s *discordgo.Session, m *discordgo.MessageCreate) {
|
||||
log.Printf("new message posted: [%s], par [%s], authorID [%s], state user id [%s]", m.Content, m.Author.Username, m.Author.ID, s.State.User.ID)
|
||||
|
||||
log.Printf("author [%+v], state user [%+v]", m.Author, s.State.User)
|
||||
if m.Author.ID == s.State.User.ID {
|
||||
return
|
||||
}
|
||||
|
||||
if containUser(m.Mentions, s.State.User.ID) {
|
||||
fmt.Println("going through openai stuff")
|
||||
fmt.Println("create ai client")
|
||||
aiclient := openai.NewClient(env.GetEnvVariables().OpenaiHalToken)
|
||||
|
||||
fmt.Println("ai client created")
|
||||
|
||||
res, err := aiclient.ChatCompletions(m.Content)
|
||||
if err != nil {
|
||||
log.Panicf("failed to query open ai with the following prompt [%s]. Error: %s", m.Content, err.Error())
|
||||
}
|
||||
|
||||
fmt.Println("ai client replied")
|
||||
|
||||
if len(res.Choices) > 0 {
|
||||
aiResponse := res.Choices[0].Message.Content
|
||||
if _, err = s.ChannelMessageSend(m.ChannelID, aiResponse); err != nil {
|
||||
@@ -33,13 +34,14 @@ func OnMessageCreated(s *discordgo.Session, m *discordgo.MessageCreate) {
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Println("### ai did not return any response ###", res.Usage, res.Choices)
|
||||
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func containUser(users []*discordgo.User, userID string) bool {
|
||||
for _, u := range users {
|
||||
fmt.Println("## mentions ##", u.ID, u.Username, "-----", userID)
|
||||
if u.ID == userID {
|
||||
return true
|
||||
}
|
||||
|
||||
+1
-5
@@ -8,7 +8,6 @@ import (
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
Token string
|
||||
HttpClient *resty.Client
|
||||
}
|
||||
|
||||
@@ -16,10 +15,7 @@ func NewClient(token string) *Client {
|
||||
httpclient := resty.New()
|
||||
httpclient.SetAuthToken(token)
|
||||
|
||||
return &Client{
|
||||
Token: token,
|
||||
HttpClient: httpclient,
|
||||
}
|
||||
return &Client{HttpClient: httpclient}
|
||||
}
|
||||
|
||||
func (c Client) ChatCompletions(prompt string) (*CompletionResponse, error) {
|
||||
|
||||
Reference in New Issue
Block a user