feat: per_stock_reassess调LLM写九维分析(gateway API)
This commit is contained in:
@@ -342,11 +342,45 @@ def main():
|
||||
if _fa and _fa[0]: print(f" ✅ full_analysis已写入({len(_fa[0])}字)")
|
||||
else: print(f" ⚠️ full_analysis为空")
|
||||
_v.close()
|
||||
__import__('sys').stdout.write(" >>> FLAG: LLM code reached\n")
|
||||
__import__('sys').stdout.flush()
|
||||
# 用代码生成九维分析(LLM调用通过报告cron实现)
|
||||
_full_analysis_text = _build_full_analysis(code, entry, result)
|
||||
print(f" 九维分析完成({len(_full_analysis_text)}字)")
|
||||
# LLM生成完整九维分析
|
||||
_macro_desc = ""
|
||||
_pe_val = ""
|
||||
_pb_val = ""
|
||||
try:
|
||||
_mdb = __import__('sqlite3').connect("/home/hmo/MoFin/data/mofin.db")
|
||||
_mr = _mdb.execute("SELECT structure FROM macro_context_log ORDER BY id DESC LIMIT 1").fetchone()
|
||||
if _mr and _mr[0]:
|
||||
_st = __import__('json').loads(_mr[0])
|
||||
_macro_desc = _st.get("description", "")
|
||||
_mood = _mr[1] if len(_mr) > 1 else ""
|
||||
if _mood: _macro_desc += f" 情绪={_mood}"
|
||||
# 基本面从腾讯API
|
||||
_p = "sh" if str(code).startswith(("6","9")) else "sz"
|
||||
_cr = __import__('subprocess').run(["curl","-s",f"http://qt.gtimg.cn/q={_p}{code}"], capture_output=True, timeout=10)
|
||||
_ct = _cr.stdout.decode("gbk", errors="ignore").split("~")
|
||||
if len(_ct) > 39 and _ct[39]: _pe_val = f"PE={_ct[39]}"
|
||||
if len(_ct) > 44 and _ct[44]: _pb_val = f"PB≈{float(_ct[44])/10000:.1f}亿"
|
||||
_mdb.close()
|
||||
except:
|
||||
pass
|
||||
|
||||
_prompt = f"""你是一个资深股票分析师。请对股票{code}做一个完整的9维矩阵分析。
|
||||
当前数据:大盘={_macro_desc or "震荡"} | PE/市值={_pe_val} {_pb_val} | 价格={price} 区间={entry.get("entry_low",0)}~{entry.get("entry_high",0)} 止损={entry.get("stop_loss",0)} 止盈={entry.get("take_profit",0)} RR={result.get("rr_ratio",entry.get("rr_ratio",0))} | 信号={result.get("timing_signal") or entry.get("timing_signal","")} | 行业={(result.get("sector_context") or entry.get("sector_context",""))[:50]}
|
||||
策略={(result.get("action") or entry.get("action",""))[:200]}
|
||||
技术={(result.get("tech_snapshot") or entry.get("tech_snapshot",""))[:200]}
|
||||
格式:①大盘×基本面 ②大盘×消息面 ③大盘×技术面 ④大盘×资金流 ⑤行业×基本面 ⑥行业×消息面 ⑦行业×技术面 ⑧个股×基本面 ⑨个股×消息面 然后综合结论和操作建议。"""
|
||||
try:
|
||||
_ur = __import__('urllib.request', fromlist=['Request'])
|
||||
_req = _ur.Request("http://127.0.0.1:8643/v1/chat/completions",
|
||||
data=__import__('json').dumps({"model":"deepseek-v4-flash","messages":[{"role":"user","content":_prompt}],"max_tokens":1024}).encode(),
|
||||
headers={"Content-Type":"application/json","Authorization":"Bearer hermes123"})
|
||||
_resp = _ur.build_opener(_ur.ProxyHandler({})).open(_req, timeout=120)
|
||||
_llm_out = __import__('json').loads(_resp.read().decode())["choices"][0]["message"]["content"]
|
||||
_full_analysis_text = _llm_out
|
||||
print(f" ✅ LLM九维分析完成({len(_full_analysis_text)}字)", flush=True)
|
||||
except Exception as _e:
|
||||
print(f" LLM调用失败: {_e},使用代码降级", file=__import__('sys').stderr)
|
||||
_full_analysis_text = _build_full_analysis(code, entry, result)
|
||||
|
||||
# 保存到DB
|
||||
_fa_conn = __import__('sqlite3').connect("/home/hmo/MoFin/data/mofin.db")
|
||||
|
||||
Reference in New Issue
Block a user