Version: 0.4.1.dev.260304
feat: 💬 新增对话创建与上下文记忆机制 * 新增对话的创建与使用功能,实现会话级上下文隔离 * 实现上下文保存与传递机制,使模型具备持续对话记忆能力 * 引入滑动窗口策略控制上下文规模 * 当前窗口大小限制为 20 条消息,超过后自动丢弃最早消息以控制上下文长度 docs: 📝 更新示例配置文件 * 更新示例配置文件,新增 `agent` 相关配置信息 * 明确 Agent 模块运行所需参数,方便本地部署与环境初始化 undo: ⚠️ Agent 上下文读取性能待优化 * 当前测试中模型响应速度偏慢 * 计划后续将上下文暂存至缓存层,以减少读取与拼接开销并提升响应速度
This commit is contained in:
27
backend/conv/agent.go
Normal file
27
backend/conv/agent.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package conv
|
||||
|
||||
import (
|
||||
"github.com/LoveLosita/smartflow/backend/model"
|
||||
"github.com/cloudwego/eino/schema"
|
||||
)
|
||||
|
||||
// ToEinoMessages 将数据库模型转换为 Eino 模型
|
||||
func ToEinoMessages(dbMsgs []model.ChatHistory) []*schema.Message {
|
||||
res := make([]*schema.Message, 0)
|
||||
for _, m := range dbMsgs {
|
||||
var role schema.RoleType
|
||||
switch *m.Role {
|
||||
case "user":
|
||||
role = schema.User
|
||||
case "assistant":
|
||||
role = schema.Assistant
|
||||
default:
|
||||
role = schema.System
|
||||
}
|
||||
res = append(res, &schema.Message{
|
||||
Role: role,
|
||||
Content: *m.MessageContent,
|
||||
})
|
||||
}
|
||||
return res
|
||||
}
|
||||
Reference in New Issue
Block a user