From 661741e25daa9e7ca368d4980925dad0220827de 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 17:08:51 +0800 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20API=20URL=20=E5=A4=84=E7=90=86?= =?UTF-8?q?=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- requirements.txt | 3 ++- tests/test_stream.py | 12 ++++-------- web_server.py | 14 ++++++-------- 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/requirements.txt b/requirements.txt index 7799faf..c77a82b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ ---index-url https://pypi.tuna.tsinghua.edu.cn/simple +# 本地打包使用国内镜像源加速下载, 默认不使用,影响github actions +# --index-url https://pypi.tuna.tsinghua.edu.cn/simple # 基础科学计算和数据处理库 numpy==2.1.2 diff --git a/tests/test_stream.py b/tests/test_stream.py index 7d01ada..defe173 100644 --- a/tests/test_stream.py +++ b/tests/test_stream.py @@ -50,14 +50,10 @@ def test_api_stream(): logger.error("API Key未配置,无法进行测试") return - # 标准化API URL - if not (api_url.endswith('/chat/completions') or api_url.endswith('/v1/chat/completions')): - if api_url.endswith('/v1'): - api_url = f"{api_url}/chat/completions" - elif api_url.endswith('/'): - api_url = f"{api_url}v1/chat/completions" - else: - api_url = f"{api_url}/v1/chat/completions" + if api_url.endswith('/'): + api_url = f"{api_url}chat/completions" + else: + api_url = f"{api_url}/v1/chat/completions" logger.debug(f"标准化后的API URL: {api_url}") diff --git a/web_server.py b/web_server.py index b30aaf2..46796ee 100644 --- a/web_server.py +++ b/web_server.py @@ -138,14 +138,12 @@ def test_api_connection(): return jsonify({'error': '请提供API Key'}), 400 # 构建API URL - test_url = api_url - if not (api_url.endswith('/chat/completions') or api_url.endswith('/v1/chat/completions')): - if api_url.endswith('/v1'): - test_url = f"{api_url}/chat/completions" - elif api_url.endswith('/'): - test_url = f"{api_url}chat/completions" - else: - test_url = f"{api_url}/v1/chat/completions" + if api_url.endswith('/'): + test_url = f"{api_url}chat/completions" + else: + test_url = f"{api_url}/v1/chat/completions" + + logger.debug(f"完整API测试URL: {test_url}") 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 2/3] =?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 @@