if no therads or no messages then no ai
parent
9d7f69bd8a
commit
782b9ec3cf
21
main.go
21
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)
|
||||
}
|
||||
|
||||
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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue