if no therads or no messages then no ai
This commit is contained in:
13
main.go
13
main.go
@@ -121,23 +121,32 @@ func newHandlerGetAPIV1RPCAIEvent(cfg Config) http.HandlerFunc {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(threads) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
prompt := fmt.Sprintf("Summarize the Slack thread in 1 sentence. List any suggested follow ups.\n\n---\n\n")
|
||||
for _, thread := range threads {
|
||||
prompt := fmt.Sprintf("Summarize the Slack thread in 1 sentence. List any suggested follow ups.\n\n---\n\n")
|
||||
|
||||
messages, err := cfg.storage.GetThreadMessages(ctx, thread.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(messages) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, message := range messages {
|
||||
prompt += fmt.Sprintf("%s\n%s\n\n", message.Author, message.Plaintext)
|
||||
}
|
||||
}
|
||||
|
||||
summary, err := cfg.ai.Do(ctx, prompt)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
threadSummaries = append(threadSummaries, summary)
|
||||
}
|
||||
|
||||
return nil
|
||||
}(r.Context()); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
|
||||
Reference in New Issue
Block a user