From b19c5d63ff52f976f2ee0c9fe40ae0b48e6304f1 Mon Sep 17 00:00:00 2001 From: Max Date: Fri, 7 Feb 2025 10:30:12 +0800 Subject: [PATCH] Enhance message processing and user identification - Add user ID to input name when not explicitly set - Update stream chat to mark final message as "think" type - Modify history retrieval to add system prompts after fetching chat history - Remove debug print statement in message data mapping --- neo/assistant/api.go | 12 ++++++++++-- neo/message/contents.go | 2 -- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/neo/assistant/api.go b/neo/assistant/api.go index 8b86d0ba93..80d84bce70 100644 --- a/neo/assistant/api.go +++ b/neo/assistant/api.go @@ -201,7 +201,11 @@ func (next *NextAction) Execute(c *gin.Context, ctx chatctx.Context, contents *c options = v } - input.Hidden = true // not show in the history + input.Hidden = true // not show in the history + if input.Name == "" && ctx.Sid != "" { // add user id to the input + input.Name = ctx.Sid + } + messages, err := assistant.withHistory(ctx, input) if err != nil { return fmt.Errorf("with history error: %s", err.Error()) @@ -338,6 +342,7 @@ func (ast *Assistant) streamChat( end.Write(c.Writer) end.ID = currentMessageID end.AppendTo(contents) + contents.UpdateType("think", map[string]interface{}{"text": contents.Text()}, currentMessageID) isThinking = false // Clear the token and make a new line @@ -614,7 +619,7 @@ func (ast *Assistant) withHistory(ctx chatctx.Context, input interface{}) ([]cha } messages := []chatMessage.Message{} - messages = ast.withPrompts(messages) + if storage != nil { history, err := storage.GetHistory(ctx.Sid, ctx.ChatID) if err != nil { @@ -631,6 +636,9 @@ func (ast *Assistant) withHistory(ctx chatctx.Context, input interface{}) ([]cha } } + // Add system prompts + messages = ast.withPrompts(messages) + // Add user message messages = append(messages, *userMessage) return messages, nil diff --git a/neo/message/contents.go b/neo/message/contents.go index f8b8c97ad7..054168574a 100644 --- a/neo/message/contents.go +++ b/neo/message/contents.go @@ -1,7 +1,6 @@ package message import ( - "fmt" "strings" "github.com/google/uuid" @@ -256,7 +255,6 @@ func (data *Data) Map() (map[string]interface{}, error) { } if data.Arguments != nil && len(data.Arguments) > 0 { - fmt.Println("data.Arguments", string(data.Arguments)) var vv interface{} = nil err := jsoniter.Unmarshal(data.Arguments, &vv) if err != nil {