xiaoguo_scanner: 每只1次LLM,合审3篇,5分钟窗口无压力
This commit is contained in:
+29
-23
@@ -133,12 +133,20 @@ def search_news(code, max_results=3):
|
|||||||
return articles
|
return articles
|
||||||
|
|
||||||
|
|
||||||
def has_substance(title, content):
|
def check_stock(code, name, articles):
|
||||||
"""小果LLM判断是否有料(返回 True/False + 情感)"""
|
"""小果LLM判断这只股票是否有料(一次调用判断所有文章)"""
|
||||||
text = title + (content or '')[:100]
|
if not articles:
|
||||||
prompt = f"""新闻:{text}
|
return None, None
|
||||||
问:这条新闻跟该股今日上榜有关吗?
|
|
||||||
回答格式:{"有关":"利好|利空|中性"} 或 "无关"
|
lines = [f"{i+1}. {a['title']}" for i, a in enumerate(articles[:3])]
|
||||||
|
prompt = f"""以下是最新关于{name}({code})的新闻标题。
|
||||||
|
该股今日上了人气热榜/技术榜单。
|
||||||
|
|
||||||
|
新闻:
|
||||||
|
{chr(10).join(lines)}
|
||||||
|
|
||||||
|
这只股上榜是否跟这些新闻有关?有关的话是利好还是利空?
|
||||||
|
回答格式:有关(利好|利空|中性) 或 无关
|
||||||
回答:"""
|
回答:"""
|
||||||
|
|
||||||
payload = json.dumps({
|
payload = json.dumps({
|
||||||
@@ -153,14 +161,14 @@ def has_substance(title, content):
|
|||||||
try:
|
try:
|
||||||
resp = opener.open(req, timeout=30)
|
resp = opener.open(req, timeout=30)
|
||||||
reply = json.loads(resp.read())["choices"][0]["message"]["content"]
|
reply = json.loads(resp.read())["choices"][0]["message"]["content"]
|
||||||
if "有关" in reply:
|
if "有关" in reply or "利好" in reply or "利空" in reply:
|
||||||
for s in ["利好", "利空", "中性"]:
|
for s in ["利好", "利空", "中性"]:
|
||||||
if s in reply:
|
if s in reply:
|
||||||
return True, s
|
return True, s
|
||||||
return True, "中性"
|
return True, "中性"
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
return False, None
|
return None, None
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@@ -209,21 +217,19 @@ def main():
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
has_found = False
|
has_found = False
|
||||||
for art in articles:
|
ok, sentiment = check_stock(code, name, articles)
|
||||||
ok, sentiment = has_substance(art["title"], art.get("content", ""))
|
if ok:
|
||||||
if ok:
|
has_found = True
|
||||||
# 有料 → 写入signal_news
|
found_any = True
|
||||||
conn.execute(
|
sources = "|".join(stock["sources"])
|
||||||
"INSERT INTO signal_news (signal_id, sector, overall_sentiment, summary, key_articles, searched_stocks, source) "
|
conn.execute(
|
||||||
"VALUES (NULL, ?, ?, ?, ?, ?, 'xiaoguo')",
|
"INSERT INTO signal_news (signal_id, sector, overall_sentiment, summary, key_articles, searched_stocks, source) "
|
||||||
(f"扫描-{name}", sentiment, f"[{sources}] {art['title'][:80]}",
|
"VALUES (NULL, ?, ?, ?, ?, ?, 'xiaoguo')",
|
||||||
json.dumps([{"title": art["title"], "sentiment": sentiment, "summary": art.get("content","")[:100]}], ensure_ascii=False),
|
(f"扫描-{name}", sentiment, f"[{sources}] {articles[0]['title'][:80]}",
|
||||||
json.dumps([name], ensure_ascii=False))
|
json.dumps([{"title": a["title"], "sentiment": sentiment, "summary": (a.get("content") or "")[:100]} for a in articles[:3]], ensure_ascii=False),
|
||||||
)
|
json.dumps([name], ensure_ascii=False))
|
||||||
has_found = True
|
)
|
||||||
found_any = True
|
print(f" ✅ {name}({code}) [{sources}] {sentiment}: {articles[0]['title'][:50]}", flush=True)
|
||||||
print(f" ✅ {name}({code}) [{sources}] {sentiment}: {art['title'][:50]}", flush=True)
|
|
||||||
break # 一只股有一条有料就够了
|
|
||||||
|
|
||||||
mark_scanned(conn, code, name, has_found)
|
mark_scanned(conn, code, name, has_found)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user