mirror of
https://github.com/yangjian102621/geekai.git
synced 2025-09-18 01:06:39 +08:00
fix: fix bug with missing chat context
This commit is contained in:
parent
64d6bff6d9
commit
4fcbd511c0
@ -258,17 +258,15 @@ func (h *ChatHandler) sendMessage(ctx context.Context, session *types.ChatSessio
|
||||
|
||||
// loading the role context
|
||||
var messages []types.Message
|
||||
if len(messages) > 0 {
|
||||
err := utils.JsonDecode(role.Context, &messages)
|
||||
if err == nil {
|
||||
for _, v := range messages {
|
||||
tks, _ := utils.CalcTokens(v.Content, req.Model)
|
||||
if tokens+tks >= types.ModelToTokens[req.Model] {
|
||||
break
|
||||
}
|
||||
tokens += tks
|
||||
chatCtx = append(chatCtx, v)
|
||||
err := utils.JsonDecode(role.Context, &messages)
|
||||
if err == nil {
|
||||
for _, v := range messages {
|
||||
tks, _ := utils.CalcTokens(v.Content, req.Model)
|
||||
if tokens+tks >= types.ModelToTokens[req.Model] {
|
||||
break
|
||||
}
|
||||
tokens += tks
|
||||
chatCtx = append(chatCtx, v)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user