fix: 消息面不限情绪标签(分类器已死,原始新闻直接喂LLM自行判断)——batch+per_stock两路
This commit is contained in:
@@ -179,13 +179,14 @@ def build_prompt(data):
|
||||
except:
|
||||
pass
|
||||
|
||||
# 拉取近期消息面(stock 关联走 searched_stocks,失败不拖累大盘兜底)
|
||||
# 拉取近期消息面(不再要求情绪标签——原始新闻直接喂给12维LLM,由LLM自行判断情绪。
|
||||
# 2026-07-22:情绪分类器已退役,利好/利空标签停在07-09,强制过滤=自断新闻源)
|
||||
_news_note = "暂无近期消息"
|
||||
_news_items = []
|
||||
try:
|
||||
import sqlite3 as _sq
|
||||
_db = _sq.connect("/home/hmo/MoFin/data/mofin.db")
|
||||
# ① 个股直接相关(searched_stocks 含本代码 或 行业名匹配)
|
||||
# ① 个股直接相关(searched_stocks 含本代码 或 行业名匹配),不限情绪标签
|
||||
_sector_name = ""
|
||||
try:
|
||||
_sr = _db.execute(
|
||||
@@ -195,21 +196,24 @@ def build_prompt(data):
|
||||
pass
|
||||
_nr = _db.execute(
|
||||
"SELECT summary, overall_sentiment, created_at FROM signal_news "
|
||||
"WHERE (searched_stocks LIKE ? OR sector LIKE ?) AND overall_sentiment IN ('利好','利空') "
|
||||
"WHERE searched_stocks LIKE ? OR sector LIKE ? "
|
||||
"ORDER BY id DESC LIMIT 3",
|
||||
(f'%{data["code"]}%', f'%{_sector_name}%')).fetchall()
|
||||
_news_items.extend(_nr)
|
||||
# ② 大盘兜底(独立 try,不被①的失败拖累)
|
||||
# ② 大盘兜底(独立 try,不被①的失败拖累;取最新3条,不限标签)
|
||||
if not _news_items:
|
||||
_nr2 = _db.execute(
|
||||
"SELECT summary, overall_sentiment, created_at FROM signal_news "
|
||||
"WHERE overall_sentiment IN ('利好','利空') ORDER BY id DESC LIMIT 2").fetchall()
|
||||
"ORDER BY id DESC LIMIT 3").fetchall()
|
||||
_news_items.extend(_nr2)
|
||||
_db.close()
|
||||
except:
|
||||
pass
|
||||
if _news_items:
|
||||
_news_note = " | ".join([f"{r[2][:10]} {r[1]} {r[0][:40]}" for r in _news_items])
|
||||
def _fmt(r):
|
||||
senti = r[1] if r[1] and r[1] != 'unknown' else '未标注'
|
||||
return f"{r[2][:10]} [{senti}] {r[0][:40]}"
|
||||
_news_note = " | ".join([_fmt(r) for r in _news_items])
|
||||
|
||||
# ── 构建【原策略全文】section ──
|
||||
_params_parts = []
|
||||
|
||||
@@ -179,19 +179,28 @@ def _build_full_analysis(code, entry, result):
|
||||
except:
|
||||
pass
|
||||
|
||||
# 消息面:从signal_news读最新信号
|
||||
# 消息面:从signal_news读最新信号(不限情绪标签,LLM自行判断)
|
||||
news_lines = []
|
||||
try:
|
||||
_n_db = __import__('sqlite3').connect("/home/hmo/MoFin/data/mofin.db")
|
||||
_nr = _n_db.execute(
|
||||
"SELECT summary, overall_sentiment, created_at FROM signal_news "
|
||||
"WHERE (sector LIKE ? OR sector LIKE ?) AND overall_sentiment IN ('利好','利空') "
|
||||
"WHERE sector LIKE ? OR sector LIKE ? "
|
||||
"ORDER BY id DESC LIMIT 2",
|
||||
(f'%{code}%', f'%{name[:4]}%')
|
||||
).fetchall()
|
||||
if not _nr:
|
||||
_nr = _n_db.execute(
|
||||
"SELECT summary, overall_sentiment, created_at FROM signal_news "
|
||||
"ORDER BY id DESC LIMIT 2").fetchall()
|
||||
for _ns in _nr:
|
||||
_sent = _ns[1]
|
||||
_icon = '📈' if '利好' in str(_sent) else '📉'
|
||||
_sent = str(_ns[1])
|
||||
if '利好' in _sent:
|
||||
_icon = '📈'
|
||||
elif '利空' in _sent:
|
||||
_icon = '📉'
|
||||
else:
|
||||
_icon = '📰'
|
||||
news_lines.append(f"{_icon} {_ns[0][:60]} ({str(_ns[2])[:10]})")
|
||||
_n_db.close()
|
||||
except:
|
||||
@@ -418,18 +427,22 @@ def main():
|
||||
except:
|
||||
pass
|
||||
|
||||
# 拉取近期消息面
|
||||
# 拉取近期消息面(不限情绪标签)
|
||||
_news_note = "暂无近期消息"
|
||||
try:
|
||||
_ndb = __import__('sqlite3').connect("/home/hmo/MoFin/data/mofin.db")
|
||||
_nr2 = _ndb.execute(
|
||||
"SELECT summary, overall_sentiment, created_at FROM signal_news "
|
||||
"WHERE (code=? OR sector LIKE ?) AND overall_sentiment IN ('利好','利空') "
|
||||
"WHERE searched_stocks LIKE ? OR sector LIKE ? "
|
||||
"ORDER BY id DESC LIMIT 3",
|
||||
(code, f'%{entry.get("name","")[:4]}%')
|
||||
(f'%{code}%', f'%{entry.get("name","")[:4]}%')
|
||||
).fetchall()
|
||||
if not _nr2:
|
||||
_nr2 = _ndb.execute(
|
||||
"SELECT summary, overall_sentiment, created_at FROM signal_news "
|
||||
"ORDER BY id DESC LIMIT 3").fetchall()
|
||||
if _nr2:
|
||||
_news_note = " | ".join([f"{r[2][:10]} {r[1]} {r[0][:40]}" for r in _nr2])
|
||||
_news_note = " | ".join([f"{r[2][:10]} [{r[1] or '未标注'}] {r[0][:40]}" for r in _nr2])
|
||||
_ndb.close()
|
||||
except:
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user