统一所有 <thinking></thinking>
标签的处理逻辑,避免重复代码,确保 DISPLAY_RESULT_THINKING
参数在整个系统中的一致性控制。
在多个文件中都有 _remove_thinking_content()
函数的重复实现:
agent/tools/sql_generation.py
agent/tools/summary_generation.py
citu_app.py
customllm/base_llm_chat.py
某些场景下thinking内容被多次处理:
customllm/base_llm_chat.py:generate_summary()
已经处理,但 citu_app.py
又重复处理agent/tools/summary_generation.py
处理后,customllm/base_llm_chat.py:generate_summary()
又处理一次agent/tools/sql_generation.py
中的解释性文本可能包含thinking内容,但没有被处理。
统一在最底层处理 - 只在 customllm/base_llm_chat.py
中处理thinking内容,其他地方不再重复处理。
customllm/base_llm_chat.py
是所有LLM响应的统一出口ask()
API 还是 ask_agent()
API,最终都会调用到这里customllm/base_llm_chat.py
- 统一处理中心:
# generate_sql() 方法中处理解释性文本
if not DISPLAY_RESULT_THINKING:
explanation = self._remove_thinking_content(explanation)
# generate_summary() 方法中处理摘要内容
if not display_thinking:
summary = self._remove_thinking_content(summary)
# chat_with_llm() 方法中处理聊天对话内容
if not DISPLAY_RESULT_THINKING:
response = self._remove_thinking_content(response)
# generate_question() 方法中处理问题生成内容
if not DISPLAY_RESULT_THINKING:
response = self._remove_thinking_content(response)
# generate_rewritten_question() 方法中处理问题合并内容
if not DISPLAY_RESULT_THINKING:
rewritten_question = self._remove_thinking_content(rewritten_question)
# generate_plotly_code() 方法中处理图表代码生成内容
if not DISPLAY_RESULT_THINKING:
plotly_code = self._remove_thinking_content(plotly_code)
agent/tools/sql_generation.py
_remove_thinking_content()
函数定义from app_config import DISPLAY_RESULT_THINKING
导入customllm/base_llm_chat.py
中的统一处理agent/tools/summary_generation.py
_process_thinking_content()
函数import app_config
导入customllm/base_llm_chat.py:generate_summary()
中的统一处理citu_app.py
_remove_thinking_content()
函数定义DISPLAY_RESULT_THINKING
导入citu_app.py:ask_full()
→ vn.ask()
→ customllm/base_llm_chat.py:ask()
→ customllm/base_llm_chat.py:generate_summary() # ✅ 在这里统一处理thinking
→ 返回到 citu_app.py # ✅ 使用已处理的结果
citu_app.py:ask_agent()
→ agent/citu_agent.py:process_question()
→ agent/tools/summary_generation.py:generate_summary() # ✅ 不再处理thinking
→ 内部调用 vn.generate_summary()
→ customllm/base_llm_chat.py:generate_summary() # ✅ 在这里统一处理thinking
→ 返回到 agent 层 # ✅ 使用已处理的结果
→ 最终返回到 citu_app.py
agent/tools/sql_generation.py:generate_sql()
→ vn.generate_sql()
→ customllm/base_llm_chat.py:generate_sql() # ✅ 在这里统一处理thinking
→ 保存到 vn.last_llm_explanation # ✅ 已处理的解释性文本
→ 返回到 agent 层 # ✅ 使用已处理的结果
当 DISPLAY_RESULT_THINKING = False
时,以下所有内容的thinking标签都会被自动移除:
customllm/base_llm_chat.py:generate_summary()
customllm/base_llm_chat.py:generate_sql()
customllm/base_llm_chat.py:chat_with_llm()
customllm/base_llm_chat.py:generate_question()
customllm/base_llm_chat.py:generate_rewritten_question()
customllm/base_llm_chat.py:generate_plotly_code()
创建了测试脚本 test_thinking_control.py
来验证:
customllm/base_llm_chat.py
中添加thinking处理customllm/base_llm_chat.py
中的 _remove_thinking_content()
方法app_config.py
中的 DISPLAY_RESULT_THINKING
值