Skip to content
This repository has been archived by the owner on Nov 7, 2023. It is now read-only.

Commit

Permalink
πŸ› fix(image.go): change action from "image" to "generate"
Browse files Browse the repository at this point in the history
✨ feat(http): add goroutines to handle requests asynchronously in commands.go

🎨 refactor(image): rename action from "image" to "generate" in Slack and Telegram interfaces
  • Loading branch information
kamushadenes committed Mar 31, 2023
1 parent 0aacd08 commit 4ae76f8
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 19 deletions.
2 changes: 1 addition & 1 deletion interfaces/discord/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

func generate(ctx context.Context, msg *memory.Message) error {
req := structs.NewActionRequest()
req.Action = "image"
req.Action = "generate"
req.Params = promptFromMessage(msg)
req.Message = msg
req.Context = ctx
Expand Down
49 changes: 33 additions & 16 deletions interfaces/http/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,12 @@ func complete(w http.ResponseWriter, r *http.Request) {

request.Writer = utils.NewHTTPResponseWriteCloser(w)

if err := channels.RunCompletion(request); err != nil {
_ = render.Render(w, r, ErrInvalidRequest(err))
return
}
go func() {
if err := channels.RunCompletion(request); err != nil {
_ = render.Render(w, r, ErrInvalidRequest(err))
return
}
}()

for {
select {
Expand Down Expand Up @@ -118,15 +120,17 @@ func generate(w http.ResponseWriter, r *http.Request) {
req := structs.NewActionRequest()
req.ID = msg.ExternalID
req.Context = ctx
req.Action = "image"
req.Action = "generate"
req.Params = params.Prompt
req.Message = msg
req.Writers = []io.WriteCloser{utils.NewHTTPResponseWriteCloser(w)}

if err := channels.RunAction(req); err != nil {
_ = render.Render(w, r, ErrInvalidRequest(err))
return
}
go func() {
if err := channels.RunAction(req); err != nil {
_ = render.Render(w, r, ErrInvalidRequest(err))
return
}
}()

for {
select {
Expand Down Expand Up @@ -169,10 +173,12 @@ func tts(w http.ResponseWriter, r *http.Request) {
req.Message = msg
req.Writers = []io.WriteCloser{utils.NewHTTPResponseWriteCloser(w)}

if err := channels.RunAction(req); err != nil {
_ = render.Render(w, r, ErrInvalidRequest(err))
return
}
go func() {
if err := channels.RunAction(req); err != nil {
_ = render.Render(w, r, ErrInvalidRequest(err))
return
}
}()

for {
select {
Expand Down Expand Up @@ -234,8 +240,19 @@ func action(w http.ResponseWriter, r *http.Request) {
req.Thought = fmt.Sprintf("User wants to run action %s", params.Action)
req.Writers = []io.WriteCloser{&utils.HTTPResponseWriteCloser{Writer: w}}

if err := channels.RunAction(req); err != nil {
_ = render.Render(w, r, ErrInvalidRequest(err))
return
go func() {
if err := channels.RunAction(req); err != nil {
_ = render.Render(w, r, ErrInvalidRequest(err))
return
}
}()

for {
select {
case <-ctx.Done():
return
case <-req.Writers[0].(*utils.HTTPResponseWriteCloser).CloseCh:
return
}
}
}
2 changes: 1 addition & 1 deletion interfaces/slack/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

func generate(ctx context.Context, msg *memory.Message) error {
req := structs.NewActionRequest()
req.Action = "image"
req.Action = "generate"
req.Params = promptFromMessage(msg)
req.Message = msg
req.Context = ctx
Expand Down
2 changes: 1 addition & 1 deletion interfaces/telegram/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func aiAction(ctx context.Context, msg *memory.Message) error {
func aiGenerate(ctx context.Context, msg *memory.Message) error {
req := structs.NewActionRequest()
req.Context = ctx
req.Action = "image"
req.Action = "generate"
req.Params = promptFromMessage(msg)
req.Writers = append(req.Writers, NewImageWriter(ctx, req, false))

Expand Down

0 comments on commit 4ae76f8

Please sign in to comment.