diff --git a/command/openai/api.go b/command/openai/api.go index c04e84cc..47a9cef9 100644 --- a/command/openai/api.go +++ b/command/openai/api.go @@ -3,6 +3,7 @@ package openai import ( "bytes" "net/http" + "time" "github.com/pkg/errors" ) @@ -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)) diff --git a/command/openai/command.go b/command/openai/command.go index 7d705c65..5937d078 100644 --- a/command/openai/command.go +++ b/command/openai/command.go @@ -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", }, }, } diff --git a/command/openai/dalle.go b/command/openai/dalle.go index f9687a9f..727c829c 100644 --- a/command/openai/dalle.go +++ b/command/openai/dalle.go @@ -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 { @@ -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)) }() } diff --git a/command/openai/dalle_test.go b/command/openai/dalle_test.go index 78eb00b7..116b8d18 100644 --- a/command/openai/dalle_test.go +++ b/command/openai/dalle_test.go @@ -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",