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
This commit is contained in:
parent
dabba1a744
commit
b19c5d63ff
2 changed files with 10 additions and 4 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue