update
This commit is contained in:
@@ -15,6 +15,10 @@ DEEPSEEK_API_KEY=your_actual_deepseek_api_key_here
|
||||
# DeepSeek API基础URL(可选,使用默认值即可)
|
||||
DEEPSEEK_BASE_URL=https://api.deepseek.com/v1
|
||||
|
||||
# AI模型名称(可选,支持OpenAI兼容的任意模型)
|
||||
# 常用模型:deepseek-chat, deepseek-reasoner, qwen-plus, gpt-4o 等
|
||||
DEFAULT_MODEL_NAME=deepseek-chat
|
||||
|
||||
|
||||
# ========== Tushare数据接口(可选)==========
|
||||
# Tushare Token(可选,用于获取更多金融数据)
|
||||
|
||||
@@ -5,7 +5,29 @@
|
||||
## B站本地部署教程1:https://www.bilibili.com/video/BV1qHFPz9EXY/
|
||||
## docker部署教程2:https://www.bilibili.com/video/BV1j2FNz4EAi/
|
||||
|
||||
## ⭐20261.25第一更 - 新闻流量监测 📈
|
||||
## ⭐ 2026.2.27更新 - AI模型自由切换 🤖
|
||||
|
||||
**重大改进:AI模型全局可配置化**
|
||||
|
||||
将所有硬编码的模型名称统一改为从 `.env` 文件动态读取,一键切换任意 OpenAI 兼容大模型,无需修改代码!
|
||||
|
||||
**核心变化:**
|
||||
- ✅ **新增 `DEFAULT_MODEL_NAME`** — 在 `.env` 中配置默认 AI 模型
|
||||
- ✅ **移除所有模型选择下拉框** — 龙虎榜、主力选股、智策板块等页面不再需要手动选模型
|
||||
- ✅ **环境配置 UI 新增模型输入** — 在「环境配置」中可直接输入模型名称,附常用模型参考
|
||||
- ✅ **支持任意 OpenAI 兼容模型** — DeepSeek、通义千问、GPT-4o 等一键切换
|
||||
|
||||
**切换模型只需一步:**
|
||||
```env
|
||||
# .env 文件
|
||||
DEFAULT_MODEL_NAME="qwen-plus" # 或 deepseek-chat, gpt-4o 等
|
||||
```
|
||||
|
||||
> 💡 修改后重启应用即可生效,侧边栏会显示当前使用的模型名称。
|
||||
|
||||
---
|
||||
|
||||
## ⭐ 2026.1.25第一更 - 新闻流量监测 📈
|
||||
|
||||
实时监测百度、微博、东财、财联社、抖音、B站等20个平台热点新闻,调用ai分析对A股板块及股票的影响,生成分析报告。也可使用https://stock-news.ws4.cn
|
||||
|
||||
@@ -378,7 +400,7 @@ StockAPI龙虎榜接口(每日更新,免费1000次)
|
||||
- 灵活设置运行时间(盘前/盘后/晚间)
|
||||
- 手动触发和状态监控
|
||||
- **数据来源**:AKShare免费数据(行情、资金、新闻)
|
||||
- **AI模型**:DeepSeek Chat / Reasoner双模型
|
||||
- **AI模型**:支持任意 OpenAI 兼容模型(通过 `.env` 配置切换)
|
||||
- **报告导出**:支持PDF格式完整报告
|
||||
- **使用场景**:盘前策略、板块轮动、风险规避
|
||||
|
||||
@@ -576,6 +598,11 @@ cp .env.example .env
|
||||
```env
|
||||
# DeepSeek API配置(必需)
|
||||
DEEPSEEK_API_KEY=your_actual_deepseek_api_key_here
|
||||
DEEPSEEK_BASE_URL=https://api.deepseek.com/v1
|
||||
|
||||
# AI模型名称(可选,支持OpenAI兼容模型)
|
||||
# 常用:deepseek-chat, deepseek-reasoner, qwen-plus, gpt-4o
|
||||
DEFAULT_MODEL_NAME=deepseek-chat
|
||||
|
||||
# Tushare配置(可选)- 作为降级数据源
|
||||
TUSHARE_TOKEN=your_tushare_token # 在 https://tushare.pro 注册获取
|
||||
@@ -588,7 +615,7 @@ EMAIL_FROM=your_email@qq.com
|
||||
EMAIL_PASSWORD=your_authorization_code
|
||||
EMAIL_TO=receiver@example.com
|
||||
|
||||
# Webhook通知配置(可选)⭐️ 新增 - 用于实时监测和智策定时分析
|
||||
# Webhook通知配置(可选)- 用于实时监测和智策定时分析
|
||||
WEBHOOK_ENABLED=false
|
||||
WEBHOOK_TYPE=dingtalk # 或 feishu
|
||||
WEBHOOK_URL=your_webhook_url_here
|
||||
@@ -704,9 +731,7 @@ streamlit run app.py
|
||||
2. **设置分析参数**
|
||||
- **分析模式**:选择"指定日期"或"最近N天"
|
||||
- **日期选择**:建议选择昨天的日期(龙虎榜数据T日更新)
|
||||
- **AI模型**:
|
||||
- **deepseek-chat**:速度快,8-12分钟完成
|
||||
- **deepseek-reasoner**:推理深入,12-18分钟完成
|
||||
- **AI模型**:自动使用 `.env` 中配置的默认模型
|
||||
|
||||
3. **开始分析**
|
||||
- 点击"🚀 开始分析"按钮
|
||||
@@ -780,12 +805,9 @@ streamlit run app.py
|
||||
### 智策板块分析使用流程 ⭐️ 全新功能
|
||||
1. **进入智策板块**
|
||||
- 点击侧边栏"🎯 智策板块"按钮
|
||||
- AI模型自动使用 `.env` 中配置的默认模型
|
||||
|
||||
2. **选择AI模型**
|
||||
- **deepseek-chat**:标准模型,速度快(2-3分钟)
|
||||
- **deepseek-reasoner**:推理增强模型,分析深度更高(3-5分钟)
|
||||
|
||||
3. **开始分析**
|
||||
2. **开始分析**
|
||||
- 点击"🚀 开始智策分析"按钮
|
||||
- 系统自动执行:
|
||||
- 获取市场数据(30秒)
|
||||
@@ -793,7 +815,7 @@ streamlit run app.py
|
||||
- 综合研判(30秒)
|
||||
- 生成预测报告
|
||||
|
||||
4. **查看分析结果**
|
||||
3. **查看分析结果**
|
||||
分析完成后,查看四个标签页:
|
||||
|
||||
- **📋 核心预测**:
|
||||
@@ -816,12 +838,12 @@ streamlit run app.py
|
||||
- 板块多空信心度对比图
|
||||
- 板块热度分布图
|
||||
|
||||
5. **导出PDF报告**
|
||||
4. **导出PDF报告**
|
||||
- 点击"📥 生成PDF报告"按钮
|
||||
- 等待生成(3-5秒)
|
||||
- 点击"💾 下载PDF"保存
|
||||
|
||||
6. **配置定时分析** ⭐️
|
||||
5. **配置定时分析** ⭐️
|
||||
展开"⏰ 定时分析设置":
|
||||
|
||||
**步骤1:配置邮件/Webhook**
|
||||
@@ -848,14 +870,14 @@ streamlit run app.py
|
||||
- 查看运行状态和上次运行时间
|
||||
- 需要时可点击"⏹️ 停止定时任务"
|
||||
|
||||
7. **使用技巧**
|
||||
6. **使用技巧**
|
||||
- **最佳使用时间**:盘前8:30-9:30或盘后15:30-20:00
|
||||
- **关注信心度**:≥8分为高信心,可重点关注
|
||||
- **结合轮动**:重点关注"潜力接力板块",最佳布局时机
|
||||
- **热度判断**:升温板块有机会,降温板块注意风险
|
||||
- **四维共振**:宏观、基本面、资金、情绪共振时信号更强
|
||||
|
||||
8. **通知内容示例**
|
||||
7. **通知内容示例**
|
||||
|
||||
**邮件/Webhook推送内容**:
|
||||
```
|
||||
@@ -1199,7 +1221,7 @@ AI股票分析系统
|
||||
|
||||
**longhubang_ui.py**
|
||||
- 智瞰龙虎主界面
|
||||
- 分析参数设置(日期/模型)
|
||||
- 分析参数设置
|
||||
- 实时进度显示
|
||||
- 四个结果标签页(推荐/报告/数据/图表)
|
||||
- 历史报告查询
|
||||
@@ -1244,7 +1266,6 @@ AI股票分析系统
|
||||
|
||||
**sector_strategy_ui.py**
|
||||
- 智策板块主界面
|
||||
- AI模型选择
|
||||
- 分析进度显示
|
||||
- 四个结果标签页展示
|
||||
- 定时分析设置面板
|
||||
@@ -1318,7 +1339,8 @@ AI股票分析系统
|
||||
- **降级机制**:TDX → Tushare → AKShare 多层数据源保障
|
||||
|
||||
### AI模型
|
||||
- **语言模型**:DeepSeek Chat API
|
||||
- **语言模型**:支持任意 OpenAI 兼容模型(DeepSeek、通义千问、GPT-4o 等)
|
||||
- **模型配置**:通过 `.env` 文件中的 `DEFAULT_MODEL_NAME` 一键切换
|
||||
- **分析框架**:多智能体协作
|
||||
- **决策逻辑**:综合评分机制
|
||||
|
||||
@@ -1339,6 +1361,7 @@ AI股票分析系统
|
||||
# .env 文件
|
||||
DEEPSEEK_API_KEY=your_api_key
|
||||
DEEPSEEK_BASE_URL=https://api.deepseek.com/v1
|
||||
DEFAULT_MODEL_NAME=deepseek-chat # 支持任意OpenAI兼容模型
|
||||
```
|
||||
|
||||
**重要提示**:
|
||||
|
||||
+4
-3
@@ -1,13 +1,14 @@
|
||||
from deepseek_client import DeepSeekClient
|
||||
from typing import Dict, Any
|
||||
import time
|
||||
import config
|
||||
|
||||
class StockAnalysisAgents:
|
||||
"""股票分析AI智能体集合"""
|
||||
|
||||
def __init__(self, model="deepseek-chat"):
|
||||
self.model = model
|
||||
self.deepseek_client = DeepSeekClient(model=model)
|
||||
def __init__(self, model=None):
|
||||
self.model = model or config.DEFAULT_MODEL_NAME
|
||||
self.deepseek_client = DeepSeekClient(model=self.model)
|
||||
|
||||
def technical_analyst_agent(self, stock_info: Dict, stock_data: Any, indicators: Dict) -> Dict[str, Any]:
|
||||
"""技术面分析智能体"""
|
||||
|
||||
@@ -7,8 +7,7 @@ from datetime import datetime
|
||||
import time
|
||||
import base64
|
||||
import os
|
||||
# 从新的配置文件导入model_options
|
||||
from model_config import model_options
|
||||
import config
|
||||
|
||||
from stock_data import StockDataFetcher
|
||||
from ai_agents import StockAnalysisAgents
|
||||
@@ -32,22 +31,13 @@ st.set_page_config(
|
||||
initial_sidebar_state="expanded"
|
||||
)
|
||||
|
||||
# 模型选择器
|
||||
def model_selector():
|
||||
"""模型选择器"""
|
||||
# 在侧边栏显示当前模型信息(统一使用.env配置)
|
||||
def show_current_model_info():
|
||||
"""显示当前使用的AI模型信息"""
|
||||
st.sidebar.markdown("---")
|
||||
st.sidebar.subheader("🤖 AI模型选择")
|
||||
|
||||
|
||||
|
||||
selected_model = st.sidebar.selectbox(
|
||||
"选择AI模型",
|
||||
options=list(model_options.keys()),
|
||||
format_func=lambda x: model_options[x],
|
||||
help="DeepSeek Reasoner提供更强的推理能力,但响应时间可能更长"
|
||||
)
|
||||
|
||||
return selected_model
|
||||
st.sidebar.subheader("🤖 AI模型")
|
||||
st.sidebar.info(f"当前模型: **{config.DEFAULT_MODEL_NAME}**")
|
||||
st.sidebar.caption("可在「环境配置」中修改模型名称")
|
||||
|
||||
# 自定义CSS样式 - 专业版
|
||||
st.markdown("""
|
||||
@@ -416,9 +406,9 @@ def main():
|
||||
|
||||
st.markdown("---")
|
||||
|
||||
# 模型选择器
|
||||
selected_model = model_selector()
|
||||
st.session_state.selected_model = selected_model
|
||||
# 显示当前模型信息
|
||||
show_current_model_info()
|
||||
st.session_state.selected_model = config.DEFAULT_MODEL_NAME
|
||||
|
||||
st.markdown("---")
|
||||
|
||||
@@ -825,18 +815,22 @@ def parse_stock_list(stock_input):
|
||||
|
||||
return unique_list
|
||||
|
||||
def analyze_single_stock_for_batch(symbol, period, enabled_analysts_config=None, selected_model='deepseek-chat'):
|
||||
def analyze_single_stock_for_batch(symbol, period, enabled_analysts_config=None, selected_model=None):
|
||||
"""单个股票分析(用于批量分析)
|
||||
|
||||
Args:
|
||||
symbol: 股票代码
|
||||
period: 数据周期
|
||||
enabled_analysts_config: 分析师配置字典
|
||||
selected_model: 选择的AI模型
|
||||
selected_model: 选择的AI模型,默认从 .env 的 DEFAULT_MODEL_NAME 读取
|
||||
|
||||
返回分析结果或错误信息
|
||||
"""
|
||||
try:
|
||||
# 使用默认模型
|
||||
if selected_model is None:
|
||||
selected_model = config.DEFAULT_MODEL_NAME
|
||||
|
||||
# 使用默认配置
|
||||
if enabled_analysts_config is None:
|
||||
enabled_analysts_config = {
|
||||
@@ -983,7 +977,7 @@ def run_batch_analysis(stock_list, period, batch_mode="顺序分析"):
|
||||
'sentiment': st.session_state.get('enable_sentiment', False),
|
||||
'news': st.session_state.get('enable_news', False)
|
||||
}
|
||||
selected_model = st.session_state.get('selected_model', 'deepseek-chat')
|
||||
selected_model = st.session_state.get('selected_model', config.DEFAULT_MODEL_NAME)
|
||||
|
||||
# 创建进度显示
|
||||
st.subheader(f"📊 批量分析进行中 ({batch_mode})")
|
||||
@@ -1256,7 +1250,7 @@ def run_stock_analysis(symbol, period):
|
||||
# 6. 初始化AI分析系统
|
||||
status_text.text("🤖 正在初始化AI分析系统...")
|
||||
# 使用选择的模型
|
||||
selected_model = st.session_state.get('selected_model', 'deepseek-chat')
|
||||
selected_model = st.session_state.get('selected_model', config.DEFAULT_MODEL_NAME)
|
||||
agents = StockAnalysisAgents(model=selected_model)
|
||||
progress_bar.progress(55)
|
||||
|
||||
@@ -2154,6 +2148,37 @@ def display_config_manager():
|
||||
)
|
||||
st.session_state.temp_config["DEEPSEEK_BASE_URL"] = new_base_url
|
||||
|
||||
st.markdown("---")
|
||||
|
||||
# AI模型名称
|
||||
model_name_info = config_info["DEFAULT_MODEL_NAME"]
|
||||
current_model_name = st.session_state.temp_config.get("DEFAULT_MODEL_NAME", "deepseek-chat")
|
||||
|
||||
new_model_name = st.text_input(
|
||||
f"🤖 {model_name_info['description']}",
|
||||
value=current_model_name,
|
||||
help="输入OpenAI兼容的模型名称,修改后重启生效",
|
||||
key="input_default_model_name"
|
||||
)
|
||||
st.session_state.temp_config["DEFAULT_MODEL_NAME"] = new_model_name
|
||||
|
||||
if new_model_name:
|
||||
st.success(f"✅ 当前模型: **{new_model_name}**")
|
||||
else:
|
||||
st.warning("⚠️ 未设置模型名称,将使用默认值 deepseek-chat")
|
||||
|
||||
st.markdown("""
|
||||
**常用模型名称参考:**
|
||||
- `deepseek-chat` — DeepSeek Chat(默认)
|
||||
- `deepseek-reasoner` — DeepSeek Reasoner(推理增强)
|
||||
- `qwen-plus` — 通义千问 Plus
|
||||
- `qwen-turbo` — 通义千问 Turbo
|
||||
- `gpt-4o` — OpenAI GPT-4o
|
||||
- `gpt-4o-mini` — OpenAI GPT-4o Mini
|
||||
|
||||
> 💡 使用非 DeepSeek 模型时,请同时修改上方的 API地址 和 API密钥
|
||||
""")
|
||||
|
||||
st.info("💡 如何获取DeepSeek API密钥?\n\n1. 访问 https://platform.deepseek.com\n2. 注册/登录账号\n3. 进入API密钥管理页面\n4. 创建新的API密钥\n5. 复制密钥并粘贴到上方输入框")
|
||||
|
||||
with tab2:
|
||||
|
||||
@@ -8,6 +8,9 @@ load_dotenv(override=True)
|
||||
DEEPSEEK_API_KEY = os.getenv("DEEPSEEK_API_KEY", "")
|
||||
DEEPSEEK_BASE_URL = os.getenv("DEEPSEEK_BASE_URL", "https://api.deepseek.com/v1")
|
||||
|
||||
# 默认AI模型名称(支持任何OpenAI兼容的模型)
|
||||
DEFAULT_MODEL_NAME = os.getenv("DEFAULT_MODEL_NAME", "deepseek-chat")
|
||||
|
||||
# 其他配置
|
||||
TUSHARE_TOKEN = os.getenv("TUSHARE_TOKEN", "")
|
||||
|
||||
|
||||
@@ -26,6 +26,12 @@ class ConfigManager:
|
||||
"required": False,
|
||||
"type": "text"
|
||||
},
|
||||
"DEFAULT_MODEL_NAME": {
|
||||
"value": "deepseek-chat",
|
||||
"description": "AI模型名称(支持OpenAI兼容模型)",
|
||||
"required": False,
|
||||
"type": "text"
|
||||
},
|
||||
"TUSHARE_TOKEN": {
|
||||
"value": "",
|
||||
"description": "Tushare数据接口Token(可选)",
|
||||
|
||||
+2
-2
@@ -6,8 +6,8 @@ import config
|
||||
class DeepSeekClient:
|
||||
"""DeepSeek API客户端"""
|
||||
|
||||
def __init__(self, model="deepseek-chat"):
|
||||
self.model = model
|
||||
def __init__(self, model=None):
|
||||
self.model = model or config.DEFAULT_MODEL_NAME
|
||||
self.client = openai.OpenAI(
|
||||
api_key=config.DEEPSEEK_API_KEY,
|
||||
base_url=config.DEEPSEEK_BASE_URL
|
||||
|
||||
Binary file not shown.
@@ -6,15 +6,16 @@
|
||||
from deepseek_client import DeepSeekClient
|
||||
from typing import Dict, Any, List
|
||||
import time
|
||||
import config
|
||||
|
||||
|
||||
class LonghubangAgents:
|
||||
"""龙虎榜AI分析师集合"""
|
||||
|
||||
def __init__(self, model="deepseek-chat"):
|
||||
self.model = model
|
||||
self.deepseek_client = DeepSeekClient(model=model)
|
||||
print(f"[智瞰龙虎] AI分析师系统初始化 (模型: {model})")
|
||||
def __init__(self, model=None):
|
||||
self.model = model or config.DEFAULT_MODEL_NAME
|
||||
self.deepseek_client = DeepSeekClient(model=self.model)
|
||||
print(f"[智瞰龙虎] AI分析师系统初始化 (模型: {self.model})")
|
||||
|
||||
def youzi_behavior_analyst(self, longhubang_data: str, summary: Dict) -> Dict[str, Any]:
|
||||
"""
|
||||
|
||||
@@ -11,12 +11,13 @@ from typing import Dict, Any, List
|
||||
from datetime import datetime, timedelta
|
||||
import time
|
||||
import logging
|
||||
import config
|
||||
|
||||
|
||||
class LonghubangEngine:
|
||||
"""龙虎榜综合分析引擎"""
|
||||
|
||||
def __init__(self, model="deepseek-chat", db_path='longhubang.db'):
|
||||
def __init__(self, model=None, db_path='longhubang.db'):
|
||||
"""
|
||||
初始化分析引擎
|
||||
|
||||
|
||||
+11
-18
@@ -13,6 +13,7 @@ import base64
|
||||
|
||||
from longhubang_engine import LonghubangEngine
|
||||
from longhubang_pdf import LonghubangPDFGenerator
|
||||
import config
|
||||
|
||||
|
||||
def display_longhubang():
|
||||
@@ -110,7 +111,7 @@ def display_analysis_tab():
|
||||
st.subheader("🔍 龙虎榜综合分析")
|
||||
|
||||
# 参数设置
|
||||
col1, col2, col3 = st.columns([2, 2, 2])
|
||||
col1, col2 = st.columns([2, 2])
|
||||
|
||||
with col1:
|
||||
analysis_mode = st.selectbox(
|
||||
@@ -135,18 +136,8 @@ def display_analysis_tab():
|
||||
help="分析最近N天的龙虎榜数据"
|
||||
)
|
||||
|
||||
with col3:
|
||||
# 导入model_config.py中定义的model_options
|
||||
from model_config import model_options as app_model_options
|
||||
selected_model = st.selectbox(
|
||||
"AI模型",
|
||||
list(app_model_options.keys()),
|
||||
format_func=lambda x: app_model_options[x],
|
||||
help="Reasoner模型提供更强的推理能力"
|
||||
)
|
||||
|
||||
# 分析按钮
|
||||
col1, col2, col3 = st.columns([2, 2, 2])
|
||||
col1, col2 = st.columns([2, 2])
|
||||
|
||||
with col1:
|
||||
analyze_button = st.button("🚀 开始分析", type="primary", width='stretch')
|
||||
@@ -166,12 +157,12 @@ def display_analysis_tab():
|
||||
if 'longhubang_result' in st.session_state:
|
||||
del st.session_state.longhubang_result
|
||||
|
||||
# 准备参数
|
||||
# 准备参数(使用.env中配置的默认模型)
|
||||
if analysis_mode == "指定日期":
|
||||
date_str = selected_date.strftime('%Y-%m-%d')
|
||||
run_longhubang_analysis(model=selected_model, date=date_str)
|
||||
run_longhubang_analysis(date=date_str)
|
||||
else:
|
||||
run_longhubang_analysis(model=selected_model, days=days)
|
||||
run_longhubang_analysis(days=days)
|
||||
|
||||
# 显示分析结果
|
||||
if 'longhubang_result' in st.session_state:
|
||||
@@ -183,8 +174,10 @@ def display_analysis_tab():
|
||||
st.error(f"❌ 分析失败: {result.get('error', '未知错误')}")
|
||||
|
||||
|
||||
def run_longhubang_analysis(model="deepseek-chat", date=None, days=1):
|
||||
def run_longhubang_analysis(model=None, date=None, days=1):
|
||||
"""运行龙虎榜分析"""
|
||||
import config
|
||||
model = model or config.DEFAULT_MODEL_NAME
|
||||
|
||||
# 进度显示
|
||||
progress_bar = st.progress(0)
|
||||
@@ -1397,7 +1390,7 @@ def run_longhubang_batch_analysis():
|
||||
'sentiment': False,
|
||||
'news': False
|
||||
},
|
||||
selected_model='deepseek-chat'
|
||||
selected_model=config.DEFAULT_MODEL_NAME
|
||||
)
|
||||
|
||||
results.append({
|
||||
@@ -1428,7 +1421,7 @@ def run_longhubang_batch_analysis():
|
||||
'sentiment': False,
|
||||
'news': False
|
||||
},
|
||||
selected_model='deepseek-chat'
|
||||
selected_model=config.DEFAULT_MODEL_NAME
|
||||
)
|
||||
return {"code": code, "result": result}
|
||||
except Exception as e:
|
||||
|
||||
@@ -13,15 +13,16 @@ from ai_agents import StockAnalysisAgents
|
||||
from deepseek_client import DeepSeekClient
|
||||
import time
|
||||
import json
|
||||
import config
|
||||
|
||||
class MainForceAnalyzer:
|
||||
"""主力选股分析器 - 批量整体分析"""
|
||||
|
||||
def __init__(self, model='deepseek-chat'):
|
||||
def __init__(self, model=None):
|
||||
self.selector = main_force_selector
|
||||
self.fetcher = StockDataFetcher()
|
||||
self.model = model
|
||||
self.agents = StockAnalysisAgents(model=model)
|
||||
self.model = model or config.DEFAULT_MODEL_NAME
|
||||
self.agents = StockAnalysisAgents(model=self.model)
|
||||
self.deepseek_client = self.agents.deepseek_client
|
||||
self.raw_stocks = None
|
||||
self.final_recommendations = []
|
||||
|
||||
+5
-14
@@ -127,25 +127,15 @@ def display_main_force_selector():
|
||||
step=100.0
|
||||
)
|
||||
|
||||
# 模型选择
|
||||
# 导入model_config.py中定义的model_options
|
||||
from model_config import model_options as app_model_options
|
||||
model = st.selectbox(
|
||||
"选择AI模型",
|
||||
list(app_model_options.keys()),
|
||||
format_func=lambda x: app_model_options[x],
|
||||
help="deepseek-chat速度快,deepseek-reasoner推理能力强"
|
||||
)
|
||||
|
||||
st.markdown("---")
|
||||
|
||||
# 开始分析按钮
|
||||
# 开始分析按钮(使用.env中配置的默认模型)
|
||||
if st.button("🚀 开始主力选股", type="primary", width='content'):
|
||||
|
||||
with st.spinner("正在获取数据并分析,这可能需要几分钟..."):
|
||||
|
||||
# 创建分析器
|
||||
analyzer = MainForceAnalyzer(model=model)
|
||||
# 创建分析器(使用默认模型)
|
||||
analyzer = MainForceAnalyzer()
|
||||
|
||||
# 运行分析
|
||||
result = analyzer.run_full_analysis(
|
||||
@@ -613,7 +603,8 @@ def run_main_force_batch_analysis():
|
||||
'sentiment': False, # 禁用以提升速度
|
||||
'news': False # 禁用以提升速度
|
||||
}
|
||||
selected_model = 'deepseek-chat'
|
||||
import config
|
||||
selected_model = config.DEFAULT_MODEL_NAME
|
||||
period = '1y'
|
||||
|
||||
# 创建进度显示
|
||||
|
||||
+31
-4
@@ -1,10 +1,13 @@
|
||||
"""
|
||||
模型配置文件
|
||||
包含所有可用的AI模型选项
|
||||
支持通过 .env 中的 DEFAULT_MODEL_NAME 自定义默认模型
|
||||
"""
|
||||
import config
|
||||
|
||||
model_options = {
|
||||
"deepseek-chat": "DeepSeek Chat (默认)",
|
||||
# 预置模型列表(用户可以在UI中选择)
|
||||
_preset_models = {
|
||||
"deepseek-chat": "DeepSeek Chat",
|
||||
"deepseek-reasoner": "DeepSeek Reasoner (推理增强)",
|
||||
"qwen-plus": "qwen-plus (阿里百炼)",
|
||||
"qwen-plus-latest": "qwen-plus-latest (阿里百炼)",
|
||||
@@ -20,5 +23,29 @@ model_options = {
|
||||
"zai-org/GLM-4.6": "智谱(硅基流动)",
|
||||
"moonshotai/Kimi-K2-Instruct-0905": "Kimi (硅基流动)",
|
||||
"Ring-1T": "蚂蚁百灵 (硅基流动)",
|
||||
"step3": "阶跃星辰(硅基流动)"
|
||||
}
|
||||
"step3": "阶跃星辰(硅基流动)",
|
||||
}
|
||||
|
||||
# 获取 .env 中配置的默认模型名称
|
||||
_default_model = config.DEFAULT_MODEL_NAME
|
||||
|
||||
# 如果 .env 中配置的默认模型不在预置列表中,自动将其加入列表首位
|
||||
if _default_model and _default_model not in _preset_models:
|
||||
_preset_models = {_default_model: f"{_default_model} (自定义默认)"} | _preset_models
|
||||
|
||||
# 确保默认模型的显示名称带有 "(默认)" 标记
|
||||
if _default_model in _preset_models:
|
||||
original_label = _preset_models[_default_model]
|
||||
if "(默认)" not in original_label:
|
||||
_preset_models[_default_model] = f"{original_label} (默认)"
|
||||
|
||||
# 导出模型选项字典,确保默认模型排在第一位
|
||||
model_options = {}
|
||||
if _default_model in _preset_models:
|
||||
model_options[_default_model] = _preset_models[_default_model]
|
||||
for k, v in _preset_models.items():
|
||||
if k not in model_options:
|
||||
model_options[k] = v
|
||||
|
||||
# 导出默认模型名称,供其他模块使用
|
||||
default_model_name = _default_model
|
||||
Binary file not shown.
+4
-3
@@ -16,14 +16,15 @@ logger = logging.getLogger(__name__)
|
||||
class NewsFlowAgents:
|
||||
"""新闻流量智能分析代理"""
|
||||
|
||||
def __init__(self, model: str = "deepseek-chat"):
|
||||
def __init__(self, model: str = None):
|
||||
"""
|
||||
初始化代理
|
||||
|
||||
Args:
|
||||
model: 使用的模型,默认 deepseek-chat
|
||||
model: 使用的模型,默认从 .env 的 DEFAULT_MODEL_NAME 读取
|
||||
"""
|
||||
self.model = model
|
||||
import config
|
||||
self.model = model or config.DEFAULT_MODEL_NAME
|
||||
self.deepseek_client = None
|
||||
self._init_client()
|
||||
|
||||
|
||||
+1
-1
@@ -766,7 +766,7 @@ class NewsFlowDatabase:
|
||||
analysis_data.get('confidence', 50),
|
||||
analysis_data.get('summary', ''),
|
||||
analysis_data.get('raw_response', ''),
|
||||
analysis_data.get('model_used', 'deepseek-chat'),
|
||||
analysis_data.get('model_used', 'unknown'),
|
||||
analysis_data.get('analysis_time', 0)
|
||||
))
|
||||
|
||||
|
||||
+1
-1
@@ -250,7 +250,7 @@ class NewsFlowEngine:
|
||||
'advice': ai_analysis.get('investment_advice', {}).get('advice', '观望'),
|
||||
'confidence': ai_analysis.get('investment_advice', {}).get('confidence', 50),
|
||||
'summary': ai_analysis.get('investment_advice', {}).get('summary', ''),
|
||||
'model_used': 'deepseek-chat',
|
||||
'model_used': getattr(self, 'model', 'unknown'),
|
||||
'analysis_time': ai_analysis.get('analysis_time', 0),
|
||||
}
|
||||
self.db.save_ai_analysis(quick_result['snapshot_id'], ai_record)
|
||||
|
||||
@@ -11,19 +11,20 @@ from datetime import datetime
|
||||
|
||||
# 导入必要的模块
|
||||
from portfolio_db import portfolio_db
|
||||
import config
|
||||
|
||||
|
||||
class PortfolioManager:
|
||||
"""持仓管理器类"""
|
||||
|
||||
def __init__(self, model="deepseek-chat"):
|
||||
def __init__(self, model=None):
|
||||
"""
|
||||
初始化持仓管理器
|
||||
|
||||
Args:
|
||||
model: AI模型(deepseek-chat 或 deepseek-reasoner)
|
||||
model: AI模型名称,默认从 .env 的 DEFAULT_MODEL_NAME 读取
|
||||
"""
|
||||
self.model = model
|
||||
self.model = model or config.DEFAULT_MODEL_NAME
|
||||
self.db = portfolio_db
|
||||
|
||||
# ==================== 持仓股票管理 ====================
|
||||
|
||||
@@ -6,15 +6,16 @@
|
||||
from deepseek_client import DeepSeekClient
|
||||
from typing import Dict, Any
|
||||
import time
|
||||
import config
|
||||
|
||||
|
||||
class SectorStrategyAgents:
|
||||
"""板块策略AI智能体集合"""
|
||||
|
||||
def __init__(self, model="deepseek-chat"):
|
||||
self.model = model
|
||||
self.deepseek_client = DeepSeekClient(model=model)
|
||||
print(f"[智策] AI智能体系统初始化 (模型: {model})")
|
||||
def __init__(self, model=None):
|
||||
self.model = model or config.DEFAULT_MODEL_NAME
|
||||
self.deepseek_client = DeepSeekClient(model=self.model)
|
||||
print(f"[智策] AI智能体系统初始化 (模型: {self.model})")
|
||||
|
||||
def macro_strategist_agent(self, market_data: Dict, news_data: list) -> Dict[str, Any]:
|
||||
"""
|
||||
|
||||
@@ -11,20 +11,21 @@ import time
|
||||
import json
|
||||
import pandas as pd
|
||||
import logging
|
||||
import config
|
||||
|
||||
|
||||
class SectorStrategyEngine:
|
||||
"""板块策略综合研判引擎"""
|
||||
|
||||
def __init__(self, model="deepseek-chat"):
|
||||
self.model = model
|
||||
self.agents = SectorStrategyAgents(model=model)
|
||||
self.deepseek_client = DeepSeekClient(model=model)
|
||||
def __init__(self, model=None):
|
||||
self.model = model or config.DEFAULT_MODEL_NAME
|
||||
self.agents = SectorStrategyAgents(model=self.model)
|
||||
self.deepseek_client = DeepSeekClient(model=self.model)
|
||||
self.database = SectorStrategyDatabase()
|
||||
self.logger = logging.getLogger(__name__)
|
||||
if not self.logger.handlers:
|
||||
logging.basicConfig(level=logging.INFO, format='[%(asctime)s] %(levelname)s %(name)s: %(message)s')
|
||||
print(f"[智策引擎] 初始化完成 (模型: {model})")
|
||||
print(f"[智策引擎] 初始化完成 (模型: {self.model})")
|
||||
|
||||
def save_raw_data_with_fallback(self, data_type, data_df, data_date=None):
|
||||
"""
|
||||
|
||||
@@ -128,7 +128,7 @@ class SectorStrategyScheduler:
|
||||
|
||||
# 2. 运行AI分析
|
||||
print("[智策定时] [2/3] AI智能体分析中...")
|
||||
engine = SectorStrategyEngine(model="deepseek-chat")
|
||||
engine = SectorStrategyEngine()
|
||||
result = engine.run_comprehensive_analysis(data)
|
||||
|
||||
if not result.get("success"):
|
||||
|
||||
+8
-20
@@ -112,27 +112,13 @@ def display_analysis_tab():
|
||||
|
||||
st.markdown("---")
|
||||
|
||||
# 模型选择
|
||||
col1, col2, col3 = st.columns([2, 2, 2])
|
||||
# 操作按钮
|
||||
col1, col2 = st.columns([2, 2])
|
||||
|
||||
with col1:
|
||||
# 导入model_config.py中定义的model_options
|
||||
from model_config import model_options as app_model_options
|
||||
selected_model = st.selectbox(
|
||||
"AI模型",
|
||||
list(app_model_options.keys()),
|
||||
format_func=lambda x: app_model_options[x],
|
||||
help="Reasoner模型提供更强的推理能力"
|
||||
)
|
||||
|
||||
with col2:
|
||||
st.write("")
|
||||
st.write("")
|
||||
analyze_button = st.button("🚀 开始智策分析", type="primary", width='content')
|
||||
|
||||
with col3:
|
||||
st.write("")
|
||||
st.write("")
|
||||
with col2:
|
||||
if st.button("🔄 清除结果", width='content'):
|
||||
if 'sector_strategy_result' in st.session_state:
|
||||
del st.session_state.sector_strategy_result
|
||||
@@ -141,13 +127,13 @@ def display_analysis_tab():
|
||||
|
||||
st.markdown("---")
|
||||
|
||||
# 开始分析
|
||||
# 开始分析(使用.env中配置的默认模型)
|
||||
if analyze_button:
|
||||
# 清除之前的结果
|
||||
if 'sector_strategy_result' in st.session_state:
|
||||
del st.session_state.sector_strategy_result
|
||||
|
||||
run_sector_strategy_analysis(selected_model)
|
||||
run_sector_strategy_analysis()
|
||||
|
||||
# 显示分析结果
|
||||
if 'sector_strategy_result' in st.session_state:
|
||||
@@ -261,8 +247,10 @@ def display_report_detail(report_id):
|
||||
st.info("当前版本仅提供报告摘要,详细页面已移除。")
|
||||
|
||||
|
||||
def run_sector_strategy_analysis(model="deepseek-chat"):
|
||||
def run_sector_strategy_analysis(model=None):
|
||||
"""运行智策分析"""
|
||||
import config
|
||||
model = model or config.DEFAULT_MODEL_NAME
|
||||
|
||||
# 进度显示
|
||||
progress_bar = st.progress(0)
|
||||
|
||||
@@ -7,6 +7,7 @@ import logging
|
||||
from typing import Dict, List, Optional
|
||||
from datetime import datetime, time
|
||||
import pytz
|
||||
import config
|
||||
|
||||
|
||||
class SmartMonitorDeepSeek:
|
||||
@@ -20,7 +21,7 @@ class SmartMonitorDeepSeek:
|
||||
api_key: DeepSeek API密钥
|
||||
"""
|
||||
self.api_key = api_key
|
||||
self.base_url = "https://api.deepseek.com/v1"
|
||||
self.base_url = config.DEEPSEEK_BASE_URL
|
||||
self.headers = {
|
||||
"Authorization": f"Bearer {api_key}",
|
||||
"Content-Type": "application/json"
|
||||
@@ -138,7 +139,7 @@ class SmartMonitorDeepSeek:
|
||||
'can_trade': False
|
||||
}
|
||||
|
||||
def chat_completion(self, messages: List[Dict], model: str = "deepseek-chat",
|
||||
def chat_completion(self, messages: List[Dict], model: str = None,
|
||||
temperature: float = 0.7, max_tokens: int = 2000) -> Dict:
|
||||
"""
|
||||
调用DeepSeek API
|
||||
@@ -154,6 +155,8 @@ class SmartMonitorDeepSeek:
|
||||
"""
|
||||
import requests
|
||||
|
||||
model = model or config.DEFAULT_MODEL_NAME
|
||||
|
||||
payload = {
|
||||
"model": model,
|
||||
"messages": messages,
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user