Fixed the Issue Where Search History was not Displayed in Media Engine
This commit is contained in:
+12
-2
@@ -263,7 +263,12 @@ class DeepSearchAgent:
|
|||||||
logger.info(" - 未找到搜索结果")
|
logger.info(" - 未找到搜索结果")
|
||||||
|
|
||||||
# 更新状态中的搜索历史
|
# 更新状态中的搜索历史
|
||||||
paragraph.research.add_search_results(search_query, search_results)
|
paragraph.research.add_search_results(
|
||||||
|
search_query,
|
||||||
|
search_results,
|
||||||
|
search_tool=search_tool,
|
||||||
|
paragraph_title=paragraph.title,
|
||||||
|
)
|
||||||
|
|
||||||
# 生成初始总结
|
# 生成初始总结
|
||||||
logger.info(" - 生成初始总结...")
|
logger.info(" - 生成初始总结...")
|
||||||
@@ -341,7 +346,12 @@ class DeepSearchAgent:
|
|||||||
logger.info(" 未找到反思搜索结果")
|
logger.info(" 未找到反思搜索结果")
|
||||||
|
|
||||||
# 更新搜索历史
|
# 更新搜索历史
|
||||||
paragraph.research.add_search_results(search_query, search_results)
|
paragraph.research.add_search_results(
|
||||||
|
search_query,
|
||||||
|
search_results,
|
||||||
|
search_tool=search_tool,
|
||||||
|
paragraph_title=paragraph.title,
|
||||||
|
)
|
||||||
|
|
||||||
# 生成反思总结
|
# 生成反思总结
|
||||||
reflection_summary_input = {
|
reflection_summary_input = {
|
||||||
|
|||||||
+38
-10
@@ -17,6 +17,9 @@ class Search:
|
|||||||
title: str = "" # 搜索结果标题
|
title: str = "" # 搜索结果标题
|
||||||
content: str = "" # 搜索返回的内容
|
content: str = "" # 搜索返回的内容
|
||||||
score: Optional[float] = None # 相关度评分
|
score: Optional[float] = None # 相关度评分
|
||||||
|
paragraph_title: str = "" # 段落标题,便于展示归属
|
||||||
|
search_tool: str = "" # 使用的搜索工具
|
||||||
|
has_result: bool = True # 是否有返回结果
|
||||||
timestamp: str = field(default_factory=lambda: datetime.now().isoformat())
|
timestamp: str = field(default_factory=lambda: datetime.now().isoformat())
|
||||||
|
|
||||||
def to_dict(self) -> Dict[str, Any]:
|
def to_dict(self) -> Dict[str, Any]:
|
||||||
@@ -27,6 +30,9 @@ class Search:
|
|||||||
"title": self.title,
|
"title": self.title,
|
||||||
"content": self.content,
|
"content": self.content,
|
||||||
"score": self.score,
|
"score": self.score,
|
||||||
|
"paragraph_title": self.paragraph_title,
|
||||||
|
"search_tool": self.search_tool,
|
||||||
|
"has_result": self.has_result,
|
||||||
"timestamp": self.timestamp
|
"timestamp": self.timestamp
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,6 +45,9 @@ class Search:
|
|||||||
title=data.get("title", ""),
|
title=data.get("title", ""),
|
||||||
content=data.get("content", ""),
|
content=data.get("content", ""),
|
||||||
score=data.get("score"),
|
score=data.get("score"),
|
||||||
|
paragraph_title=data.get("paragraph_title", ""),
|
||||||
|
search_tool=data.get("search_tool", ""),
|
||||||
|
has_result=data.get("has_result", True),
|
||||||
timestamp=data.get("timestamp", datetime.now().isoformat())
|
timestamp=data.get("timestamp", datetime.now().isoformat())
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -55,23 +64,42 @@ class Research:
|
|||||||
"""添加搜索记录"""
|
"""添加搜索记录"""
|
||||||
self.search_history.append(search)
|
self.search_history.append(search)
|
||||||
|
|
||||||
def add_search_results(self, query: str, results: List[Dict[str, Any]]):
|
def add_search_results(self, query: str, results: List[Dict[str, Any]], search_tool: str = "", paragraph_title: str = ""):
|
||||||
"""批量添加搜索结果"""
|
"""批量添加搜索结果"""
|
||||||
|
if not results:
|
||||||
|
# 记录一次“无结果”搜索,方便前端显示搜索轨迹
|
||||||
|
self.add_search(
|
||||||
|
Search(
|
||||||
|
query=query or "",
|
||||||
|
title="未找到结果",
|
||||||
|
content="本次搜索未返回结果或调用失败",
|
||||||
|
url="",
|
||||||
|
score=None,
|
||||||
|
paragraph_title=paragraph_title,
|
||||||
|
search_tool=search_tool,
|
||||||
|
has_result=False,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
for result in results:
|
for result in results:
|
||||||
# 防御空值,避免下游展示时报错
|
|
||||||
url = result.get("url") or ""
|
url = result.get("url") or ""
|
||||||
title = result.get("title") or ""
|
title = result.get("title") or ""
|
||||||
content = result.get("content") or ""
|
content = result.get("content") or result.get("raw_content") or ""
|
||||||
if not isinstance(content, str):
|
if not isinstance(content, str):
|
||||||
content = str(content)
|
content = str(content)
|
||||||
search = Search(
|
self.add_search(
|
||||||
query=query or "",
|
Search(
|
||||||
url=url,
|
query=query or "",
|
||||||
title=title,
|
url=url,
|
||||||
content=content,
|
title=title,
|
||||||
score=result.get("score")
|
content=content,
|
||||||
|
score=result.get("score"),
|
||||||
|
paragraph_title=paragraph_title or result.get("paragraph_title", ""),
|
||||||
|
search_tool=search_tool or result.get("search_tool", ""),
|
||||||
|
has_result=True,
|
||||||
|
)
|
||||||
)
|
)
|
||||||
self.add_search(search)
|
|
||||||
|
|
||||||
def get_search_count(self) -> int:
|
def get_search_count(self) -> int:
|
||||||
"""获取搜索次数"""
|
"""获取搜索次数"""
|
||||||
|
|||||||
@@ -222,14 +222,21 @@ def display_results(agent: DeepSearchAgent, final_report: str):
|
|||||||
for i, search in enumerate(all_searches):
|
for i, search in enumerate(all_searches):
|
||||||
query_label = search.query if search.query else "未记录查询"
|
query_label = search.query if search.query else "未记录查询"
|
||||||
with st.expander(f"搜索 {i + 1}: {query_label}"):
|
with st.expander(f"搜索 {i + 1}: {query_label}"):
|
||||||
|
paragraph_title = getattr(search, "paragraph_title", "") or "未标注段落"
|
||||||
|
search_tool = getattr(search, "search_tool", "") or "未标注工具"
|
||||||
|
has_result = getattr(search, "has_result", True)
|
||||||
|
st.write("**段落:**", paragraph_title)
|
||||||
|
st.write("**使用的工具:**", search_tool)
|
||||||
preview = search.content or ""
|
preview = search.content or ""
|
||||||
if not isinstance(preview, str):
|
if not isinstance(preview, str):
|
||||||
preview = str(preview)
|
preview = str(preview)
|
||||||
if len(preview) > 200:
|
if len(preview) > 200:
|
||||||
preview = preview[:200] + "..."
|
preview = preview[:200] + "..."
|
||||||
st.write("**URL:**", search.url)
|
st.write("**URL:**", search.url or "无")
|
||||||
st.write("**标题:**", search.title)
|
st.write("**标题:**", search.title or "无")
|
||||||
st.write("**内容预览:**", preview if preview else "无可用内容")
|
st.write("**内容预览:**", preview if preview else "无可用内容")
|
||||||
|
if not has_result:
|
||||||
|
st.info("本次搜索未返回结果")
|
||||||
if search.score:
|
if search.score:
|
||||||
st.write("**相关度评分:**", search.score)
|
st.write("**相关度评分:**", search.score)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user