From 2ad8a074acf0f9f9fe17aedb4425637580dad019 Mon Sep 17 00:00:00 2001 From: Michael Yang Date: Wed, 18 Oct 2023 16:04:32 -0700 Subject: [PATCH] generate: set created_at move the empty response so it's more visible --- server/routes.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/server/routes.go b/server/routes.go index ec8f4bde..9bac6708 100644 --- a/server/routes.go +++ b/server/routes.go @@ -182,6 +182,12 @@ func GenerateHandler(c *gin.Context) { ch := make(chan any) go func() { defer close(ch) + // an empty request loads the model + if req.Prompt == "" && req.Template == "" && req.System == "" { + ch <- api.GenerateResponse{CreatedAt: time.Now().UTC(), Model: req.Model, Done: true} + return + } + fn := func(r api.GenerateResponse) { loaded.expireAt = time.Now().Add(sessionDuration) loaded.expireTimer.Reset(sessionDuration) @@ -196,13 +202,8 @@ func GenerateHandler(c *gin.Context) { ch <- r } - // an empty request loads the model - if req.Prompt == "" && req.Template == "" && req.System == "" { - ch <- api.GenerateResponse{Model: req.Model, Done: true} - } else { - if err := loaded.runner.Predict(c.Request.Context(), req.Context, prompt, fn); err != nil { - ch <- gin.H{"error": err.Error()} - } + if err := loaded.runner.Predict(c.Request.Context(), req.Context, prompt, fn); err != nil { + ch <- gin.H{"error": err.Error()} } }()