Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DALL-E longer timeout to upload #504

Merged
merged 1 commit into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion command/openai/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package openai
import (
"bytes"
"net/http"
"time"

"github.com/pkg/errors"
)
Expand All @@ -20,7 +21,9 @@ const (
)

// we don't use our default clients.HttpClient as we need longer timeouts...
var client http.Client
var client = http.Client{
Timeout: 25 * time.Second,
}

func doRequest(cfg Config, apiEndpoint string, data []byte) (*http.Response, error) {
req, err := http.NewRequest("POST", cfg.APIHost+apiEndpoint, bytes.NewBuffer(data))
Expand Down
1 change: 1 addition & 0 deletions command/openai/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ func (c *openaiCommand) GetHelp() []bot.Help {
Category: category,
Examples: []string{
"dalle high resolution image of a sunset, painted by a robot",
"dall-e high resolution image of a sunset, painted by a robot",
},
},
}
Expand Down
9 changes: 7 additions & 2 deletions command/openai/dalle.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,19 @@ func (c *openaiCommand) dalleGenerateImage(match matcher.Result, message msg.Mes
c.AddReaction(":coffee:", message)

go func() {
defer c.RemoveReaction(":coffee:", message)

prompt := match.GetString(util.FullMatch)
images, err := generateImages(c.cfg, prompt)
c.RemoveReaction(":coffee:", message)
if err != nil {
c.ReplyError(message, err)
return
}

// add 📤 emoji to indicate that the image is being uploaded which can take some time via slack
c.AddReaction(":outbox_tray:", message)
defer c.RemoveReaction(":outbox_tray:", message)

startTime := time.Now()
for _, image := range images {
err := c.sendImageInSlack(image, message)
if err != nil {
Expand All @@ -37,6 +41,7 @@ func (c *openaiCommand) dalleGenerateImage(match matcher.Result, message msg.Mes
)
}
}
log.Infof("Uploading %d images took %s", len(images), time.Since(startTime))
}()
}

Expand Down
2 changes: 2 additions & 0 deletions command/openai/dalle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ func TestDalle(t *testing.T) {

mocks.AssertReaction(slackClient, ":coffee:", message)
mocks.AssertRemoveReaction(slackClient, ":coffee:", message)
mocks.AssertReaction(slackClient, ":outbox_tray:", message)
mocks.AssertRemoveReaction(slackClient, ":outbox_tray:", message)

slackClient.On(
"UploadFile",
Expand Down
Loading