From 0847e557fb85db61790c302bcceb872032966790 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=85=B0=E5=BF=97=E5=AE=8F?= Date: Tue, 4 Mar 2025 18:24:37 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=BB=9F=E4=B8=80=E5=89=8D=E5=90=8E?= =?UTF-8?q?=E7=AB=AFAPI=5FURL=E5=A4=84=E7=90=86=E8=A7=84=E5=88=99=EF=BC=9A?= =?UTF-8?q?=20/=E7=BB=93=E5=B0=BE=E5=BF=BD=E7=95=A5v1=E7=89=88=E6=9C=AC?= =?UTF-8?q?=EF=BC=8C#=E7=BB=93=E5=B0=BE=E5=BC=BA=E5=88=B6=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E8=BE=93=E5=85=A5=E5=9C=B0=E5=9D=80=E3=80=82=20?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=85=AC=E5=91=8A=E5=8C=BA=E5=9F=9F=E4=BD=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + stock_analyzer.py | 9 +- templates/index.html | 270 +++++++++++++++++++++++++++++++++++++++---- tests/test_stream.py | 8 +- utils/api_utils.py | 23 ++++ web_server.py | 13 +-- 6 files changed, 282 insertions(+), 42 deletions(-) create mode 100644 utils/api_utils.py diff --git a/README.md b/README.md index 27f877f..c3fc193 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ 2. 增加港股、美股支持。 3. 完善Dockerfile、GitHub Actions 支持docker一键部署使用。 4. 支持x86_64 和 ARM64架构镜像 +5. 支持流式输出,支持前端传入Key(仅作为本地用户使用,日志等内容不会输出) 感谢@Cassianvale ## docker一键部署 ``` diff --git a/stock_analyzer.py b/stock_analyzer.py index 43d92e2..bcf9375 100644 --- a/stock_analyzer.py +++ b/stock_analyzer.py @@ -7,6 +7,7 @@ from typing import Dict, List, Optional, Tuple, Generator from dotenv import load_dotenv import json from logger import get_logger +from utils.api_utils import APIUtils # 获取日志器 logger = get_logger() @@ -259,12 +260,8 @@ class StockAnalyzer: logger.error(error_msg) return error_msg if not stream else (yield json.dumps({"error": error_msg})) - # 标准化API URL 使用Cherry Studio相同逻辑处理 - if self.API_URL.endswith('/'): - api_url = f"{self.API_URL}chat/completions" - else: - api_url = f"{self.API_URL}/v1/chat/completions" - + # 标准化API URL + api_url = APIUtils.format_api_url(self.API_URL) logger.debug(f"标准化后的API URL: {api_url}") diff --git a/templates/index.html b/templates/index.html index 979f6bc..eeeeb61 100644 --- a/templates/index.html +++ b/templates/index.html @@ -7,28 +7,202 @@ + + + {% if announcement %} +
+
+
+
+ + + +
+
+

+

+
+ +
+
+
+ + + {% endif %} +

股票分析系统

- - - {% if announcement %} + +
-
-
-
- - - +
+
+ +
+

当前时间

+

-
-

- {{ announcement }} -

+ + +
+

A股市场

+

+

+
+ + +
+

港股市场

+

+

+
+ + +
+

美股市场

+

+

- {% endif %} + +
@@ -54,7 +228,9 @@ + value="{{ default_api_url }}" + oninput="updateFormattedUrl(this.value)"> +

@@ -115,10 +291,10 @@