feat: AI分析加入前日报告上下文 + 隐藏模型名 + Docker上海时区

This commit is contained in:
Sakurasan
2026-09-01 16:11:08 +08:00
parent 64c6ed92b0
commit a005118aa4
3 changed files with 37 additions and 2 deletions
+4
View File
@@ -20,6 +20,10 @@ RUN find /usr/local/lib/python3.11 -type d -name "__pycache__" -exec rm -rf {} +
FROM python:3.11-slim
WORKDIR /app
# 设置上海时区
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
# 仅复制已编译好的包,无需 gcc
COPY --from=python-deps /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages
+33 -1
View File
@@ -39,6 +39,8 @@ SYSTEM_PROMPT = """你是一位专业的A股市场分析师,擅长从数据中
DAILY_ANALYSIS_PROMPT = """请对 {trade_date} 的A股市场进行收盘分析,生成一份完整的分析报告。
{prev_report_section}
请先调用以下工具获取数据:
1. get_market_dashboard - 获取市场整体数据
2. get_theme_history(date="{trade_date}") - 获取今日题材涨幅
@@ -107,9 +109,13 @@ async def collect_ai_analysis(trade_date: str) -> dict:
Returns:
{"id": int, "tokens_used": int, "tools_used": list}
"""
prev_report_section = _get_prev_report_section(trade_date)
messages = [
{"role": "system", "content": SYSTEM_PROMPT},
{"role": "user", "content": DAILY_ANALYSIS_PROMPT.format(trade_date=trade_date)}
{"role": "user", "content": DAILY_ANALYSIS_PROMPT.format(
trade_date=trade_date,
prev_report_section=prev_report_section
)}
]
tools_used = []
@@ -185,3 +191,29 @@ def _save_report(trade_date: str, content: str, summary: str, tools_used: list,
return cursor.lastrowid
finally:
conn.close()
def _get_prev_report_section(trade_date: str) -> str:
"""获取前一个交易日的报告摘要,用于上下文参考"""
conn = get_connection()
try:
row = conn.execute(
"SELECT trade_date, content FROM ai_reports WHERE trade_date < ? AND report_type = 'daily' ORDER BY trade_date DESC LIMIT 1",
(trade_date,)
).fetchone()
if not row:
return ""
prev_date = row["trade_date"]
prev_content = row["content"] or ""
# 取报告的前1500字符作为参考上下文
truncated = prev_content[:1500]
if len(prev_content) > 1500:
truncated += "\n...(已截断)"
return f"""以下是前一个交易日({prev_date})的分析报告,请参考其中的分析逻辑和关注方向,结合今日数据进行对比分析:
{truncated}
---
"""
finally:
conn.close()
-1
View File
@@ -86,7 +86,6 @@ function AiAnalysisPage() {
<Clock className="h-3.5 w-3.5 shrink-0" />
<span className="truncate">{report.created_at}</span>
</span>
<span className="truncate">{report.model}</span>
<span>{report.tokens_used?.toLocaleString()} tokens</span>
{report.toolsUsed && report.toolsUsed.length > 0 && (
<span className="flex items-center gap-1.5">