From a005118aa46e6d153f4c2ac62302af679c146e24 Mon Sep 17 00:00:00 2001 From: Sakurasan <26715255+Sakurasan@users.noreply.github.com> Date: Tue, 1 Sep 2026 16:11:08 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20AI=E5=88=86=E6=9E=90=E5=8A=A0=E5=85=A5?= =?UTF-8?q?=E5=89=8D=E6=97=A5=E6=8A=A5=E5=91=8A=E4=B8=8A=E4=B8=8B=E6=96=87?= =?UTF-8?q?=20+=20=E9=9A=90=E8=97=8F=E6=A8=A1=E5=9E=8B=E5=90=8D=20+=20Dock?= =?UTF-8?q?er=E4=B8=8A=E6=B5=B7=E6=97=B6=E5=8C=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 4 ++++ backend/services/ai_service.py | 34 +++++++++++++++++++++++++++++++++- src/routes/ai-analysis.tsx | 1 - 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 7a22b51..00c78cb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 diff --git a/backend/services/ai_service.py b/backend/services/ai_service.py index 26eb81e..a7097c7 100644 --- a/backend/services/ai_service.py +++ b/backend/services/ai_service.py @@ -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() diff --git a/src/routes/ai-analysis.tsx b/src/routes/ai-analysis.tsx index 1acd9af..acce930 100644 --- a/src/routes/ai-analysis.tsx +++ b/src/routes/ai-analysis.tsx @@ -86,7 +86,6 @@ function AiAnalysisPage() { {report.created_at} - {report.model} {report.tokens_used?.toLocaleString()} tokens {report.toolsUsed && report.toolsUsed.length > 0 && (