Merge pull request #853 from trheyi/main
Enhance message processing and user identification
This commit is contained in:
commit
b77a0d31b7
2 changed files with 10 additions and 4 deletions
|
|
@ -202,6 +202,10 @@ func (next *NextAction) Execute(c *gin.Context, ctx chatctx.Context, contents *c
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
messages, err := assistant.withHistory(ctx, input)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("with history error: %s", err.Error())
|
return fmt.Errorf("with history error: %s", err.Error())
|
||||||
|
|
@ -338,6 +342,7 @@ func (ast *Assistant) streamChat(
|
||||||
end.Write(c.Writer)
|
end.Write(c.Writer)
|
||||||
end.ID = currentMessageID
|
end.ID = currentMessageID
|
||||||
end.AppendTo(contents)
|
end.AppendTo(contents)
|
||||||
|
contents.UpdateType("think", map[string]interface{}{"text": contents.Text()}, currentMessageID)
|
||||||
isThinking = false
|
isThinking = false
|
||||||
|
|
||||||
// Clear the token and make a new line
|
// 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 := []chatMessage.Message{}
|
||||||
messages = ast.withPrompts(messages)
|
|
||||||
if storage != nil {
|
if storage != nil {
|
||||||
history, err := storage.GetHistory(ctx.Sid, ctx.ChatID)
|
history, err := storage.GetHistory(ctx.Sid, ctx.ChatID)
|
||||||
if err != nil {
|
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
|
// Add user message
|
||||||
messages = append(messages, *userMessage)
|
messages = append(messages, *userMessage)
|
||||||
return messages, nil
|
return messages, nil
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package message
|
package message
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
|
|
@ -256,7 +255,6 @@ func (data *Data) Map() (map[string]interface{}, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if data.Arguments != nil && len(data.Arguments) > 0 {
|
if data.Arguments != nil && len(data.Arguments) > 0 {
|
||||||
fmt.Println("data.Arguments", string(data.Arguments))
|
|
||||||
var vv interface{} = nil
|
var vv interface{} = nil
|
||||||
err := jsoniter.Unmarshal(data.Arguments, &vv)
|
err := jsoniter.Unmarshal(data.Arguments, &vv)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue