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