Skip to content

Commit

Permalink
Merge pull request #853 from trheyi/main
Browse files Browse the repository at this point in the history
Enhance message processing and user identification
  • Loading branch information
trheyi authored Feb 7, 2025
2 parents c338086 + b19c5d6 commit b77a0d3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 10 additions & 2 deletions neo/assistant/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down
2 changes: 0 additions & 2 deletions neo/message/contents.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package message

import (
"fmt"
"strings"

"github.com/google/uuid"
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit b77a0d3

Please sign in to comment.