|
@@ -226,6 +226,7 @@ async def hot_topic_search(
|
|
|
cursor: int = 1,
|
|
cursor: int = 1,
|
|
|
feature_keywords: Optional[List[str]] = None,
|
|
feature_keywords: Optional[List[str]] = None,
|
|
|
timeout: Optional[float] = None,
|
|
timeout: Optional[float] = None,
|
|
|
|
|
+ include_raw_data: bool = False,
|
|
|
) -> ToolResult:
|
|
) -> ToolResult:
|
|
|
"""
|
|
"""
|
|
|
检索每日热点话题(今日热榜)
|
|
检索每日热点话题(今日热榜)
|
|
@@ -236,6 +237,7 @@ async def hot_topic_search(
|
|
|
feature_keywords: 词语列表(list[str])。传入时对每条话题标题逐词判断规范化后的包含关系,
|
|
feature_keywords: 词语列表(list[str])。传入时对每条话题标题逐词判断规范化后的包含关系,
|
|
|
至少命中一词则保留;不传入则不做过滤(返回全部话题)。
|
|
至少命中一词则保留;不传入则不做过滤(返回全部话题)。
|
|
|
timeout: 超时时间(秒),默认 60
|
|
timeout: 超时时间(秒),默认 60
|
|
|
|
|
+ include_raw_data: 是否在 metadata 中包含原始 API 返回。默认 False 以减少 token 消耗。
|
|
|
|
|
|
|
|
Returns:
|
|
Returns:
|
|
|
ToolResult:
|
|
ToolResult:
|
|
@@ -247,7 +249,7 @@ async def hot_topic_search(
|
|
|
- metadata.top_topics: Top3 话题明细(含 score、matched_keywords)
|
|
- metadata.top_topics: Top3 话题明细(含 score、matched_keywords)
|
|
|
- metadata.matched_total: 实际返回的命中话题总数(<=3)
|
|
- metadata.matched_total: 实际返回的命中话题总数(<=3)
|
|
|
- metadata.feature_keywords: 本次参与匹配的词语(清洗/去重后)
|
|
- metadata.feature_keywords: 本次参与匹配的词语(清洗/去重后)
|
|
|
- - metadata.raw_data: 原始 API 返回
|
|
|
|
|
|
|
+ - metadata.raw_data: 原始 API 返回(仅 include_raw_data=True 时提供)
|
|
|
"""
|
|
"""
|
|
|
start_time = time.time()
|
|
start_time = time.time()
|
|
|
request_timeout = timeout if timeout is not None else DEFAULT_TIMEOUT
|
|
request_timeout = timeout if timeout is not None else DEFAULT_TIMEOUT
|
|
@@ -257,6 +259,7 @@ async def hot_topic_search(
|
|
|
"cursor": cursor,
|
|
"cursor": cursor,
|
|
|
"feature_keywords": cleaned_keywords,
|
|
"feature_keywords": cleaned_keywords,
|
|
|
"timeout": request_timeout,
|
|
"timeout": request_timeout,
|
|
|
|
|
+ "include_raw_data": include_raw_data,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if not isinstance(sort_type, str) or not sort_type.strip():
|
|
if not isinstance(sort_type, str) or not sort_type.strip():
|
|
@@ -330,20 +333,23 @@ async def hot_topic_search(
|
|
|
},
|
|
},
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
+ metadata: Dict[str, Any] = {
|
|
|
|
|
+ "has_more": has_more,
|
|
|
|
|
+ "next_cursor": next_cursor,
|
|
|
|
|
+ "blocks": blocks,
|
|
|
|
|
+ "topics_by_source": parsed.get("topics_by_source", {}),
|
|
|
|
|
+ "top_topics": parsed.get("top_topics", []),
|
|
|
|
|
+ "matched_total": matched_total,
|
|
|
|
|
+ "feature_keywords": cleaned_keywords,
|
|
|
|
|
+ }
|
|
|
|
|
+ if include_raw_data:
|
|
|
|
|
+ metadata["raw_data"] = raw
|
|
|
|
|
+
|
|
|
out = ToolResult(
|
|
out = ToolResult(
|
|
|
title=f"今日热榜热点话题({sort_type},cursor={cursor})",
|
|
title=f"今日热榜热点话题({sort_type},cursor={cursor})",
|
|
|
output=summary,
|
|
output=summary,
|
|
|
long_term_memory=f"Fetched hot topics sort_type='{sort_type}' cursor={cursor}",
|
|
long_term_memory=f"Fetched hot topics sort_type='{sort_type}' cursor={cursor}",
|
|
|
- metadata={
|
|
|
|
|
- "raw_data": raw,
|
|
|
|
|
- "has_more": has_more,
|
|
|
|
|
- "next_cursor": next_cursor,
|
|
|
|
|
- "blocks": blocks,
|
|
|
|
|
- "topics_by_source": parsed.get("topics_by_source", {}),
|
|
|
|
|
- "top_topics": parsed.get("top_topics", []),
|
|
|
|
|
- "matched_total": matched_total,
|
|
|
|
|
- "feature_keywords": cleaned_keywords,
|
|
|
|
|
- },
|
|
|
|
|
|
|
+ metadata=metadata,
|
|
|
include_metadata_in_llm=True,
|
|
include_metadata_in_llm=True,
|
|
|
)
|
|
)
|
|
|
log_tool_call(_LOG_LABEL, call_params, json.dumps(out.metadata.get("topics_by_source", {}), ensure_ascii=False))
|
|
log_tool_call(_LOG_LABEL, call_params, json.dumps(out.metadata.get("topics_by_source", {}), ensure_ascii=False))
|