Showing
2 changed files
with
18 additions
and
7 deletions
| @@ -58,11 +58,17 @@ class Research: | @@ -58,11 +58,17 @@ class Research: | ||
| 58 | def add_search_results(self, query: str, results: List[Dict[str, Any]]): | 58 | def add_search_results(self, query: str, results: List[Dict[str, Any]]): |
| 59 | """批量添加搜索结果""" | 59 | """批量添加搜索结果""" |
| 60 | for result in results: | 60 | for result in results: |
| 61 | + # 防御空值,避免下游展示时报错 | ||
| 62 | + url = result.get("url") or "" | ||
| 63 | + title = result.get("title") or "" | ||
| 64 | + content = result.get("content") or "" | ||
| 65 | + if not isinstance(content, str): | ||
| 66 | + content = str(content) | ||
| 61 | search = Search( | 67 | search = Search( |
| 62 | - query=query, | ||
| 63 | - url=result.get("url", ""), | ||
| 64 | - title=result.get("title", ""), | ||
| 65 | - content=result.get("content", ""), | 68 | + query=query or "", |
| 69 | + url=url, | ||
| 70 | + title=title, | ||
| 71 | + content=content, | ||
| 66 | score=result.get("score") | 72 | score=result.get("score") |
| 67 | ) | 73 | ) |
| 68 | self.add_search(search) | 74 | self.add_search(search) |
| @@ -220,11 +220,16 @@ def display_results(agent: DeepSearchAgent, final_report: str): | @@ -220,11 +220,16 @@ def display_results(agent: DeepSearchAgent, final_report: str): | ||
| 220 | 220 | ||
| 221 | if all_searches: | 221 | if all_searches: |
| 222 | for i, search in enumerate(all_searches): | 222 | for i, search in enumerate(all_searches): |
| 223 | - with st.expander(f"搜索 {i + 1}: {search.query}"): | 223 | + query_label = search.query if search.query else "未记录查询" |
| 224 | + with st.expander(f"搜索 {i + 1}: {query_label}"): | ||
| 225 | + preview = search.content or "" | ||
| 226 | + if not isinstance(preview, str): | ||
| 227 | + preview = str(preview) | ||
| 228 | + if len(preview) > 200: | ||
| 229 | + preview = preview[:200] + "..." | ||
| 224 | st.write("**URL:**", search.url) | 230 | st.write("**URL:**", search.url) |
| 225 | st.write("**标题:**", search.title) | 231 | st.write("**标题:**", search.title) |
| 226 | - st.write("**内容预览:**", | ||
| 227 | - search.content[:200] + "..." if len(search.content) > 200 else search.content) | 232 | + st.write("**内容预览:**", preview if preview else "无可用内容") |
| 228 | if search.score: | 233 | if search.score: |
| 229 | st.write("**相关度评分:**", search.score) | 234 | st.write("**相关度评分:**", search.score) |
| 230 | 235 |
-
Please register or login to post a comment