fix: market_screener小果离线降级+2秒快速探测

This commit is contained in:
知微
2026-07-08 20:04:32 +08:00
parent db5ce2b305
commit b13259df5f
+27 -1
View File
@@ -47,9 +47,22 @@ def call_xiaoguo(messages, timeout=API_TIMEOUT):
resp = urllib.request.build_opener(urllib.request.ProxyHandler({})).open(req, timeout=timeout)
return json.loads(resp.read())["choices"][0]["message"]["content"]
except Exception as e:
print(f"API失败: {e}", flush=True)
print(f"⚠️ 小果API不可用: {e}", flush=True)
return None
def xiaoguo_available():
"""快速探测小果是否在线(2秒超时)"""
try:
req = urllib.request.Request(_get_xiaoguo_url(),
data=b'{"model":"Qwen3.6-27B-OptiQ-4bit","messages":[{"role":"user","content":"ok"}],"max_tokens":1}',
headers={"Content-Type": "application/json",
"Authorization": "Bearer hermes123"}, method="POST")
urllib.request.build_opener(urllib.request.ProxyHandler({})).open(req, timeout=2)
return True
except Exception:
return False
def extract_json(text):
"""从回复中提取第一个完整JSON,跳过思考过程"""
@@ -242,6 +255,19 @@ def main():
sectors = market["sectors"]
source = market.get("source", "db")
print(f"板块: {len(sectors)}, 来源: {source}", flush=True)
# 快速探测小果是否在线,不在线就降级
if not xiaoguo_available():
print("⚠️ 小果不在线,跳过LLM分析,仅保存板块数据", flush=True)
save_json(DATA_DIR / "market_scan_summary.json", {
"timestamp": datetime.now().strftime("%Y-%m-%d %H:%M"),
"source": source,
"sector_count": len(sectors),
"xiaoguo_status": "offline",
"note": "小果不在线,未做LLM全市场筛选",
})
return
pool = load_pool()
existing = {c["code"] for c in pool.get("candidates", []) if not c.get("dropped")}