From e78a070fbd0a4eb1733c741cc53729ea56aa7c56 Mon Sep 17 00:00:00 2001 From: SengokuCola <1026294844@qq.com> Date: Thu, 13 Nov 2025 00:00:17 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8D=E4=B8=80=E4=BA=9B?= =?UTF-8?q?=E6=BD=9C=E5=9C=A8=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/jargon/jargon_miner.py | 39 ++++++++------------------- src/memory_system/memory_retrieval.py | 11 +++++--- 2 files changed, 18 insertions(+), 32 deletions(-) diff --git a/src/jargon/jargon_miner.py b/src/jargon/jargon_miner.py index 554d886c..3d983521 100644 --- a/src/jargon/jargon_miner.py +++ b/src/jargon/jargon_miner.py @@ -56,18 +56,15 @@ def _init_inference_prompts() -> None: prompt1_str = """ **词条内容** {content} - -**词条出现的上下文(raw_content)其中的SELF是你自己的发言** -{raw_content_list} + 请根据以上词条内容和上下文,推断这个词条的含义。 -- 如果这是一个黑话、俚语或网络用语,请推断其含义和翻译 +- 如果这是一个黑话、俚语或网络用语,请推断其含义 - 如果含义明确(常规词汇),也请说明 以 JSON 格式输出: {{ - "meaning": "详细含义说明(包含使用场景、来源、具体解释等)", - "translation": "原文(用一个词语写明这个词的实际含义)" + "meaning": "详细含义说明(包含使用场景、来源、具体解释等)" }} """ Prompt(prompt1_str, "jargon_inference_with_context_prompt") @@ -78,13 +75,12 @@ def _init_inference_prompts() -> None: {content} 请仅根据这个词条本身,推断其含义。 -- 如果这是一个黑话、俚语或网络用语,请推断其含义和翻译 +- 如果这是一个黑话、俚语或网络用语,请推断其含义 - 如果含义明确(常规词汇),也请说明 以 JSON 格式输出: {{ - "meaning": "详细含义说明(包含使用场景、来源、具体解释等)", - "translation": "原文(用一个词语写明这个词的实际含义)" + "meaning": "详细含义说明(包含使用场景、来源、具体解释等)" }} """ Prompt(prompt2_str, "jargon_inference_content_only_prompt") @@ -309,11 +305,9 @@ class JargonMiner: if is_jargon: # 是黑话,使用推断1的结果(基于上下文,更准确) jargon_obj.meaning = inference1.get("meaning", "") - jargon_obj.translation = inference1.get("translation", "") else: # 不是黑话,也记录含义(使用推断2的结果,因为含义明确) jargon_obj.meaning = inference2.get("meaning", "") - jargon_obj.translation = inference2.get("translation", "") # 更新最后一次判定的count值,避免重启后重复判定 jargon_obj.last_inference_count = jargon_obj.count or 0 @@ -327,14 +321,13 @@ class JargonMiner: # 固定输出推断结果,格式化为可读形式 if is_jargon: - # 是黑话,输出格式:[聊天名]xxx (translation)的含义是 xxxxxxxxxxx - translation = jargon_obj.translation or "未知" + # 是黑话,输出格式:[聊天名]xxx的含义是 xxxxxxxxxxx meaning = jargon_obj.meaning or "无详细说明" is_global = jargon_obj.is_global if is_global: - logger.info(f"[通用黑话]{content} ({translation})的含义是 {meaning}") + logger.info(f"[通用黑话]{content}的含义是 {meaning}") else: - logger.info(f"[{self.stream_name}]{content} ({translation})的含义是 {meaning}") + logger.info(f"[{self.stream_name}]{content}的含义是 {meaning}") else: # 不是黑话,输出格式:[聊天名]xxx 不是黑话 logger.info(f"[{self.stream_name}]{content} 不是黑话") @@ -558,7 +551,6 @@ class JargonMiner: # 合并其他字段:优先使用已有值 merged_meaning = None - merged_translation = None merged_is_jargon = None merged_last_inference_count = None merged_is_complete = False @@ -566,8 +558,6 @@ class JargonMiner: for obj in all_matching: if obj.meaning and not merged_meaning: merged_meaning = obj.meaning - if obj.translation and not merged_translation: - merged_translation = obj.translation if obj.is_jargon is not None and merged_is_jargon is None: merged_is_jargon = obj.is_jargon if obj.last_inference_count is not None and merged_last_inference_count is None: @@ -588,7 +578,6 @@ class JargonMiner: is_global=True, count=total_count, meaning=merged_meaning, - translation=merged_translation, is_jargon=merged_is_jargon, last_inference_count=merged_last_inference_count, is_complete=merged_is_complete @@ -664,7 +653,7 @@ def search_jargon( fuzzy: 是否模糊搜索,默认True(使用LIKE匹配) Returns: - List[Dict[str, str]]: 包含content, translation, meaning的字典列表 + List[Dict[str, str]]: 包含content, meaning的字典列表 """ if not keyword or not keyword.strip(): return [] @@ -674,7 +663,6 @@ def search_jargon( # 构建查询 query = Jargon.select( Jargon.content, - Jargon.translation, Jargon.meaning ) @@ -704,13 +692,9 @@ def search_jargon( (Jargon.chat_id == chat_id) | Jargon.is_global ) - # 只返回有translation或meaning的记录 + # 只返回有meaning的记录 query = query.where( - ( - (Jargon.translation.is_null(False)) & (Jargon.translation != "") - ) | ( - (Jargon.meaning.is_null(False)) & (Jargon.meaning != "") - ) + (Jargon.meaning.is_null(False)) & (Jargon.meaning != "") ) # 按count降序排序,优先返回出现频率高的 @@ -724,7 +708,6 @@ def search_jargon( for jargon in query: results.append({ "content": jargon.content or "", - "translation": jargon.translation or "", "meaning": jargon.meaning or "" }) diff --git a/src/memory_system/memory_retrieval.py b/src/memory_system/memory_retrieval.py index 025aba37..7e9c8ee0 100644 --- a/src/memory_system/memory_retrieval.py +++ b/src/memory_system/memory_retrieval.py @@ -94,8 +94,8 @@ def init_memory_retrieval_prompt(): 重要说明: - 你可以在一次迭代中执行多个查询,将多个action放在actions数组中 - 如果只需要执行一个查询,actions数组中只包含一个action即可 -- 如果已经收集到足够的信息可以回答问题,请设置actions为包含一个action_type为"final_answer"的数组,并在thought中说明答案。除非明确找到答案,否则不要设置为final_answer。 -- 如果经过多次查询后,确认无法找到相关信息或答案,请设置actions为包含一个action_type为"no_answer"的数组,并在thought中说明原因。 +- 如果已经收集到足够的信息可以回答问题,请设置actions为包含一个action_type为"final_answer"的数组,并在action_params中提供答案(例如:{{"answer": "你的答案内容"}})。除非明确找到答案,否则不要设置为final_answer。 +- 如果经过多次查询后,确认无法找到相关信息或答案,请设置actions为包含一个action_type为"no_answer"的数组,并在action_params中说明原因(例如:{{"reason": "无法找到的原因"}})。 请只输出JSON,不要输出其他内容: """, @@ -248,16 +248,19 @@ async def _react_agent_solve_question( # 检查是否有final_answer或no_answer for action in actions: action_type = action.get("action_type", "") + action_params = action.get("action_params", {}) if action_type == "final_answer": # Agent认为已经找到答案 - answer = thought # 使用thought作为答案 + # 从action_params中获取答案,如果没有则使用thought作为后备 + answer = action_params.get("answer", thought) if isinstance(action_params, dict) else thought step["observations"] = ["找到答案"] thinking_steps.append(step) logger.info(f"ReAct Agent 第 {iteration + 1} 次迭代 找到最终答案: {answer}") return True, answer, thinking_steps, False elif action_type == "no_answer": # Agent确认无法找到答案 - answer = thought # 使用thought说明无法找到答案的原因 + # 从action_params中获取原因,如果没有则使用thought作为后备 + answer = action_params.get("reason", thought) if isinstance(action_params, dict) else thought step["observations"] = ["确认无法找到答案"] thinking_steps.append(step) logger.info(f"ReAct Agent 第 {iteration + 1} 次迭代 确认无法找到答案: {answer}")