From fbaae8528d2e47c924f223940a09715c5177df74 Mon Sep 17 00:00:00 2001 From: Ettore Di Giacinto Date: Thu, 22 Aug 2024 10:56:05 +0200 Subject: [PATCH] fix(chat): re-generated uuid, created, and text on each request (#3359) This was noticed by models returning content besides function calls. Sadly we can't test that easily in the CI so it got unnoticed. Signed-off-by: Ettore Di Giacinto --- core/http/endpoints/openai/chat.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/core/http/endpoints/openai/chat.go b/core/http/endpoints/openai/chat.go index 12a14eace4f..a979b7bca33 100644 --- a/core/http/endpoints/openai/chat.go +++ b/core/http/endpoints/openai/chat.go @@ -25,9 +25,8 @@ import ( // @Success 200 {object} schema.OpenAIResponse "Response" // @Router /v1/chat/completions [post] func ChatEndpoint(cl *config.BackendConfigLoader, ml *model.ModelLoader, startupOptions *config.ApplicationConfig) func(c *fiber.Ctx) error { - textContentToReturn := "" - id := uuid.New().String() - created := int(time.Now().Unix()) + var id, textContentToReturn string + var created int process := func(s string, req *schema.OpenAIRequest, config *config.BackendConfig, loader *model.ModelLoader, responses chan schema.OpenAIResponse) { initialMessage := schema.OpenAIResponse{ @@ -159,6 +158,10 @@ func ChatEndpoint(cl *config.BackendConfigLoader, ml *model.ModelLoader, startup } return func(c *fiber.Ctx) error { + textContentToReturn = "" + id = uuid.New().String() + created = int(time.Now().Unix()) + modelFile, input, err := readRequest(c, cl, ml, startupOptions, true) if err != nil { return fmt.Errorf("failed reading parameters from request:%w", err)