改用Grok联网搜索并保留每轮信号

This commit is contained in:
Codex
2026-07-09 00:14:20 +08:00
parent 4f50de8def
commit e02d5db495
14 changed files with 465 additions and 110 deletions
+37 -13
View File
@@ -2,26 +2,50 @@ from app.core.config import Settings
from app.integrations.news_search_client import NewsSearchClient
def test_news_search_client_maps_article_to_candidate() -> None:
# 新闻搜索结果会先转为候选信号,再交给模型筛选成最终情报
def test_news_search_client_maps_grok_article_to_candidate() -> None:
# Grok Web Search结果会先转为候选信号,再进入入库和日报总结流程
client = NewsSearchClient(Settings())
signal = client._story_to_signal(
signal = client._article_to_signal(
{
"title": "Show HN: AI agent platform launches",
"url": "https://example.com/ai-agent-platform",
"author": "builder",
"points": 128,
"num_comments": 24,
"created_at": "2026-07-08T12:00:00Z",
"objectID": "123",
"title": "国内大模型公司发布新一代Agent平台",
"summary": "中文AI新闻候选。",
"url": "https://example.cn/ai-agent-platform",
"source": "示例中文媒体",
"published_at": "2026-07-08T12:00:00Z",
"language": "zh",
"importance": 4,
"entities": ["Agent平台"],
}
)
assert signal is not None
assert signal.topic == "AI 新闻候选"
assert signal.topic == "中文 AI 新闻"
assert signal.source_type == "news"
assert signal.source_name == "Hacker News"
assert signal.source_name == "示例中文媒体"
assert signal.published_at is not None
assert signal.published_at.year == 2026
assert signal.published_at.hour == 20
assert "128 points" in signal.summary
assert signal.importance == 4
def test_news_search_client_parses_responses_output_text() -> None:
# Responses API会返回多段output,业务JSON只来自最终output_text。
client = NewsSearchClient(Settings())
payload = client._parse_response_json(
{
"output": [
{"type": "web_search_call", "status": "completed"},
{
"type": "message",
"content": [
{
"type": "output_text",
"text": '{"items":[{"title":"AI news","url":"https://example.com","source":"Example"}]}',
}
],
},
]
}
)
assert payload["items"][0]["title"] == "AI news"