diff --git a/.gitignore b/.gitignore index 4ec4ccc..5724d8b 100644 --- a/.gitignore +++ b/.gitignore @@ -35,4 +35,6 @@ ENV/ config.json *.log .env -.DS_Store \ No newline at end of file +.DS_Store +stock_cache.json +watchlist.json \ No newline at end of file diff --git a/app/__init__.py b/app/__init__.py index c8e2d15..fb76ee6 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -11,7 +11,7 @@ Config.ensure_directories() app = FastAPI() # 设置tushare token -ts.set_token(Config.TUSHARE_TOKEN) +ts.set_token(Config.get_tushare_token()) pro = ts.pro_api() # Mount static files diff --git a/app/config.py b/app/config.py index 7ea0fc3..2ef8fa0 100644 --- a/app/config.py +++ b/app/config.py @@ -1,13 +1,11 @@ import os +import json # 基础配置 class Config: # 项目根目录 BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) - # Tushare API配置 - TUSHARE_TOKEN = '90f8a141125e1decb952cd49032b7b8409a2d7fa370745f6c9f45c96' - # 配置文件路径 CONFIG_FILE = os.path.join(BASE_DIR, "config.json") @@ -17,6 +15,29 @@ class Config: # 静态文件目录 STATIC_DIR = os.path.join(BASE_DIR, "app", "static") + # API配置 + @classmethod + def load_config(cls): + if os.path.exists(cls.CONFIG_FILE): + with open(cls.CONFIG_FILE, 'r', encoding='utf-8') as f: + return json.load(f) + return {"watchlist": {}} + + @classmethod + def get_tushare_token(cls): + config = cls.load_config() + return config.get('tushare_token') + + @classmethod + def get_ai_api_key(cls): + config = cls.load_config() + return config.get('ai_api_key') + + @classmethod + def get_ai_model_id(cls): + config = cls.load_config() + return config.get('ai_model_id') + # 确保目录存在 @classmethod def ensure_directories(cls): diff --git a/app/services/ai_analysis_service.py b/app/services/ai_analysis_service.py index a44e68e..b6fa63f 100644 --- a/app/services/ai_analysis_service.py +++ b/app/services/ai_analysis_service.py @@ -2,12 +2,13 @@ import json import os import re from openai import OpenAI +from app.config import Config class AIAnalysisService: def __init__(self): - self.model = "ep-20250111143839-vn8l8" # endpoint ID + self.model = Config.get_ai_model_id() # 从配置获取 model ID self.client = OpenAI( - api_key = "cf4edd4d-55cd-4e0f-82f6-49072660bdaf", # 直接使用API Key + api_key = Config.get_ai_api_key(), # 从配置获取 API Key base_url = "https://ark.cn-beijing.volces.com/api/v3" ) diff --git a/config.json.example b/config.json.example index 0ff06d7..53ceb1c 100644 --- a/config.json.example +++ b/config.json.example @@ -1,4 +1,6 @@ { "watchlist": {}, - "tushare_token": "your_tushare_token_here" + "tushare_token": "your_tushare_token_here", + "ai_api_key": "your_ai_api_key_here", + "ai_model_id": "your_ai_model_id_here" } \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 4768a4e..3740e72 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,54 +1,11 @@ -aiofiles==23.2.1 -akshare==1.11.22 -annotated-types==0.7.0 -anyio==3.7.1 -baostock==0.8.9 -beautifulsoup4==4.12.3 -bs4==0.0.2 -certifi==2024.12.14 -charset-normalizer==3.4.1 -click==8.1.8 -decorator==5.1.1 -efinance==0.4.8 -et_xmlfile==2.0.0 fastapi==0.104.1 -h11==0.14.0 -html5lib==1.1 -idna==3.10 -Jinja2==3.1.2 -jsonpath==0.82.2 -lxml==5.3.0 -markdown-it-py==3.0.0 -MarkupSafe==3.0.2 -mdurl==0.1.2 -multitasking==0.0.11 -numpy==2.2.1 -openpyxl==3.1.5 -pandas==2.2.3 -py==1.11.0 -py_mini_racer==0.6.0 -pydantic==2.10.4 -pydantic_core==2.27.2 -Pygments==2.19.1 -pypinyin==0.53.0 -python-dateutil==2.9.0.post0 -python-multipart==0.0.6 -pytz==2024.2 -requests==2.32.3 -retry==0.9.2 -rich==13.9.4 -simplejson==3.19.3 -six==1.17.0 -sniffio==1.3.1 -soupsieve==2.6 -starlette==0.27.0 -tabulate==0.9.0 -tqdm==4.67.1 -tushare==1.4.16 -typing_extensions==4.12.2 -tzdata==2024.2 -urllib3==2.3.0 uvicorn==0.24.0 -webencodings==0.5.1 -websocket-client==1.8.0 -xlrd==2.0.1 +python-multipart==0.0.6 +pydantic==2.10.4 +requests==2.32.3 +pandas==2.2.3 +numpy==2.2.1 +tushare==1.4.16 +Jinja2==3.1.2 +python-dateutil==2.9.0.post0 +simplejson==3.19.3