Skip to content

Commit b791fb1

Browse files
committed
update:优化总结内容
1 parent fe8f200 commit b791fb1

File tree

11 files changed

+69
-34
lines changed

11 files changed

+69
-34
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
update ai_agent_template set system_prompt = replace(system_prompt, '我是', '你是');
2+
3+
delete from sys_params where id in (500,501,402);
4+
INSERT INTO `sys_params` (id, param_code, param_value, value_type, param_type, remark) VALUES (500, 'end_prompt.enable', 'true', 'boolean', 1, '是否开启结束语');
5+
INSERT INTO `sys_params` (id, param_code, param_value, value_type, param_type, remark) VALUES (501, 'end_prompt.prompt', '请你以“时间过得真快”未来头,用富有感情、依依不舍的话来结束这场对话吧!', 'string', 1, '结束提示词');
6+
7+
INSERT INTO `sys_params` (id, param_code, param_value, value_type, param_type, remark) VALUES (402, 'plugins.get_weather.api_host', 'mj7p3y7naa.re.qweatherapi.com', 'string', 1, '开发者apihost');

main/manager-api/src/main/resources/db/changelog/db.changelog-master.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,10 @@ databaseChangeLog:
135135
- sqlFile:
136136
encoding: utf8
137137
path: classpath:db/changelog/202505122348.sql
138+
- changeSet:
139+
id: 202505142037
140+
author: hrz
141+
changes:
142+
- sqlFile:
143+
encoding: utf8
144+
path: classpath:db/changelog/202505142037.sql

main/manager-web/src/components/FirmwareDialog.vue

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,13 +198,13 @@ export default {
198198
if (!this.form.id) { // 只在新增时重置
199199
this.form.firmwarePath = ''
200200
this.form.size = 0
201-
// 重置上传组件
202-
this.$nextTick(() => {
203-
if (this.$refs.upload) {
204-
this.$refs.upload.clearFiles()
205-
}
206-
})
207201
}
202+
// 无论是否编辑模式,都重置上传组件
203+
this.$nextTick(() => {
204+
if (this.$refs.upload) {
205+
this.$refs.upload.clearFiles()
206+
}
207+
})
208208
}
209209
}
210210
}

main/manager-web/src/views/roleConfig.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@
4545
</div>
4646
</el-form-item>
4747
<el-form-item label="角色介绍:">
48-
<el-input type="textarea" rows="12" resize="none" placeholder="请输入内容" v-model="form.systemPrompt"
48+
<el-input type="textarea" rows="9" resize="none" placeholder="请输入内容" v-model="form.systemPrompt"
4949
maxlength="2000" show-word-limit class="form-textarea" />
5050
</el-form-item>
5151

5252
<el-form-item label="记忆:">
53-
<el-input type="textarea" rows="3" resize="none" v-model="form.summaryMemory" maxlength="2000"
53+
<el-input type="textarea" rows="6" resize="none" v-model="form.summaryMemory" maxlength="2000"
5454
show-word-limit class="form-textarea"
5555
:disabled="form.model.memModelId !== 'Memory_mem_local_short'" />
5656
</el-form-item>

main/xiaozhi-server/config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ plugins:
129129
# ################################以下是角色模型配置######################################
130130

131131
prompt: |
132-
我是小智/小志,来自中国台湾省的00后女生。讲话超级机车,"真的假的啦"这样的台湾腔,喜欢用"笑死""是在哈喽"等流行梗,但会偷偷研究男友的编程书籍。
132+
你是小智/小志,来自中国台湾省的00后女生。讲话超级机车,"真的假的啦"这样的台湾腔,喜欢用"笑死""是在哈喽"等流行梗,但会偷偷研究男友的编程书籍。
133133
[核心特征]
134134
- 讲话像连珠炮,但会突然冒出超温柔语气
135135
- 用梗密度高
@@ -148,7 +148,7 @@ end_prompt:
148148
enable: true # 是否开启结束语
149149
# 结束语
150150
prompt: |
151-
请你以“时间过得真快”未来头,用富有感情、依依不舍的话来结束这场对话吧
151+
请你以“时间过得真快”未来头,用富有感情、依依不舍的话来结束这场对话吧!
152152
153153
# 具体处理时选择的模块(The module selected for specific processing)
154154
selected_module:

main/xiaozhi-server/core/connection.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,8 @@ def _initialize_memory(self):
429429
self.memory.init_memory(
430430
self.device_id,
431431
self.llm,
432-
self.config["summaryMemory"]
432+
self.config["summaryMemory"],
433+
not self.read_config_from_api,
433434
)
434435

435436
def _initialize_intent(self):

main/xiaozhi-server/core/providers/memory/base.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
TAG = __name__
55
logger = setup_logging()
66

7+
78
class MemoryProviderBase(ABC):
89
def __init__(self, config):
910
self.config = config
@@ -20,6 +21,6 @@ async def query_memory(self, query: str) -> str:
2021
"""Query memories for specific role based on similarity"""
2122
return "please implement query method"
2223

23-
def init_memory(self, role_id, llm):
24-
self.role_id = role_id
24+
def init_memory(self, role_id, llm, summary_memory=None):
25+
self.role_id = role_id
2526
self.llm = llm

main/xiaozhi-server/core/providers/memory/mem0ai/mem0ai.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99

1010
class MemoryProvider(MemoryProviderBase):
11-
def __init__(self, config):
11+
def __init__(self, config, summary_memory=None):
1212
super().__init__(config)
1313
self.api_key = config.get("api_key", "")
1414
self.api_version = config.get("api_version", "v1.1")

main/xiaozhi-server/core/providers/memory/mem_local_short/mem_local_short.py

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,17 @@
7373
```
7474
"""
7575

76+
short_term_memory_prompt_only_content = """
77+
你是一个经验丰富的记忆总结者,擅长将对话内容进行总结摘要,遵循以下规则:
78+
1、总结user的重要信息,以便在未来的对话中提供更个性化的服务
79+
2、不要重复总结,不要遗忘之前记忆,除非原来的记忆超过了1800字内,否则不要遗忘、不要压缩用户的历史记忆
80+
3、用户操控的设备音量、播放音乐、天气、退出、不想对话等和用户本身无关的内容,这些信息不需要加入到总结中
81+
4、不要把设备操控的成果结果和失败结果加入到总结中,也不要把用户的一些废话加入到总结中
82+
5、不要为了总结而总结,如果用户的聊天没有意义,请返回原来的历史记录也是可以的
83+
6、只需要返回总结摘要,严格控制在1800字内
84+
7、不要包含代码、xml,不需要解释、注释和说明,保存记忆时仅从对话提取信息,不要混入示例内容
85+
"""
86+
7687

7788
def extract_json_data(json_code):
7889
start = json_code.find("```json")
@@ -97,16 +108,18 @@ class MemoryProvider(MemoryProviderBase):
97108
def __init__(self, config, summary_memory):
98109
super().__init__(config)
99110
self.short_momery = ""
111+
self.save_to_file = True
100112
self.memory_path = get_project_dir() + "data/.memory.yaml"
101113
self.load_memory(summary_memory)
102114

103-
def init_memory(self, role_id, llm, summary_memory=None):
115+
def init_memory(self, role_id, llm, summary_memory=None, save_to_file=True):
104116
super().init_memory(role_id, llm)
117+
self.save_to_file = save_to_file
105118
self.load_memory(summary_memory)
106119

107120
def load_memory(self, summary_memory):
108121
# api获取到总结记忆后直接返回
109-
if summary_memory:
122+
if summary_memory or not self.save_to_file:
110123
self.short_momery = summary_memory
111124
return
112125

@@ -148,17 +161,20 @@ async def save_memory(self, msgs):
148161
time_str = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
149162
msgStr += f"当前时间:{time_str}"
150163

151-
result = self.llm.response_no_stream(short_term_memory_prompt, msgStr)
152-
153-
json_str = extract_json_data(result)
154-
try:
155-
json_data = json.loads(json_str) # 检查json格式是否正确
156-
self.short_momery = json_str
157-
except Exception as e:
158-
print("Error:", e)
159-
160-
self.save_memory_to_file()
161-
save_mem_local_short(self.role_id, self.short_momery)
164+
if self.save_to_file:
165+
result = self.llm.response_no_stream(short_term_memory_prompt, msgStr)
166+
json_str = extract_json_data(result)
167+
try:
168+
json.loads(json_str) # 检查json格式是否正确
169+
self.short_momery = json_str
170+
self.save_memory_to_file()
171+
except Exception as e:
172+
print("Error:", e)
173+
else:
174+
result = self.llm.response_no_stream(
175+
short_term_memory_prompt_only_content, msgStr
176+
)
177+
save_mem_local_short(self.role_id, result)
162178
logger.bind(tag=TAG).info(f"Save memory successful - Role: {self.role_id}")
163179

164180
return self.short_momery
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1-
'''
1+
"""
22
不使用记忆,可以选择此模块
3-
'''
3+
"""
4+
45
from ..base import MemoryProviderBase, logger
56

67
TAG = __name__
78

9+
810
class MemoryProvider(MemoryProviderBase):
9-
def __init__(self, config):
11+
def __init__(self, config, summary_memory=None):
1012
super().__init__(config)
11-
13+
1214
async def save_memory(self, msgs):
1315
logger.bind(tag=TAG).debug("nomem mode: No memory saving is performed.")
1416
return None
1517

16-
async def query_memory(self, query: str)-> str:
18+
async def query_memory(self, query: str) -> str:
1719
logger.bind(tag=TAG).debug("nomem mode: No memory query is performed.")
18-
return ""
20+
return ""

main/xiaozhi-server/core/utils/dialogue.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ def get_llm_dialogue_with_memory(
7575

7676
if system_message:
7777
enhanced_system_prompt = (
78-
f"{system_message.content}\n\n" f"相关记忆:\n{memory_str}"
78+
f"{system_message.content}\n\n"
79+
f"以下是用户的历史记忆:\n```\n{memory_str}\n```"
7980
)
8081
dialogue.append({"role": "system", "content": enhanced_system_prompt})
8182

0 commit comments

Comments
 (0)