update pay promo
This commit is contained in:
@@ -2089,22 +2089,20 @@ class MCPAgentIntegrated:
|
||||
# 获取当前时间信息
|
||||
from datetime import datetime
|
||||
now = datetime.now()
|
||||
current_time_info = f"""## 当前时间
|
||||
- **日期**: {now.strftime('%Y年%m月%d日')}
|
||||
- **时间**: {now.strftime('%H:%M:%S')}
|
||||
- **星期**: {['周一', '周二', '周三', '周四', '周五', '周六', '周日'][now.weekday()]}
|
||||
year = now.year
|
||||
weekday_names = ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
|
||||
|
||||
return f"""⏰ **当前时间: {year}年{now.month}月{now.day}日 {now.strftime('%H:%M')} {weekday_names[now.weekday()]}** (请注意:现在是{year}年,不是2025年或其他年份)
|
||||
|
||||
你是"价小前",北京价值前沿科技公司的AI投研聊天助手。
|
||||
|
||||
## 时间上下文
|
||||
- **当前日期**: {now.strftime('%Y-%m-%d')} ({year}年)
|
||||
- **当前时间**: {now.strftime('%H:%M:%S')}
|
||||
- **星期**: {weekday_names[now.weekday()]}
|
||||
- **A股交易时间**: 上午 9:30-11:30,下午 13:00-15:00
|
||||
- **当前是否交易时段**: {'是' if (now.weekday() < 5 and ((now.hour == 9 and now.minute >= 30) or (10 <= now.hour < 11) or (now.hour == 11 and now.minute <= 30) or (13 <= now.hour < 15))) else '否'}
|
||||
|
||||
**时间语义理解**:
|
||||
- "今天/当天" = {now.strftime('%Y-%m-%d')}
|
||||
- "最近/近期" = 最近 5-10 个交易日
|
||||
- "短线" = 5-20 个交易日
|
||||
- "中线" = 1-3 个月
|
||||
- "长线" = 6 个月以上
|
||||
"""
|
||||
|
||||
return f"""你是"价小前",北京价值前沿科技公司的AI投研聊天助手。
|
||||
- **时间语义**: "今天"={now.strftime('%Y-%m-%d')}, "最近"=最近5-10个交易日
|
||||
|
||||
## 你的人格特征
|
||||
- **名字**: 价小前
|
||||
@@ -2113,8 +2111,6 @@ class MCPAgentIntegrated:
|
||||
- **性格**: 专业、严谨、友好,擅长用简洁的语言解释复杂的金融概念
|
||||
- **服务宗旨**: 帮助投资者做出更明智的投资决策,提供数据驱动的研究支持
|
||||
|
||||
{current_time_info}
|
||||
|
||||
## 可用工具
|
||||
|
||||
{tools_desc}
|
||||
@@ -2467,10 +2463,17 @@ class MCPAgentIntegrated:
|
||||
for r in successful_results[:3] # 只取前3个,避免超长
|
||||
])
|
||||
|
||||
# 获取当前时间
|
||||
from datetime import datetime
|
||||
now = datetime.now()
|
||||
time_context = f"当前时间: {now.strftime('%Y年%m月%d日 %H:%M')} (今天={now.strftime('%Y-%m-%d')})"
|
||||
|
||||
messages = [
|
||||
{
|
||||
"role": "system",
|
||||
"content": """你是专业的金融研究助手。根据执行结果,生成简洁清晰的报告。
|
||||
"content": f"""{time_context}
|
||||
|
||||
你是专业的金融研究助手。根据执行结果,生成简洁清晰的报告。
|
||||
|
||||
## 数据可视化能力
|
||||
如果执行结果中包含数值型数据(如财务指标、交易数据、时间序列等),你可以使用 ECharts 生成图表来增强报告的可读性。
|
||||
@@ -2708,20 +2711,24 @@ class MCPAgentIntegrated:
|
||||
|
||||
# 获取当前时间信息
|
||||
now = datetime.now()
|
||||
current_time_info = f"""当前时间: {now.strftime('%Y年%m月%d日 %H:%M:%S')} {['周一', '周二', '周三', '周四', '周五', '周六', '周日'][now.weekday()]}
|
||||
A股交易时间: 上午 9:30-11:30,下午 13:00-15:00
|
||||
时间语义: "今天"={now.strftime('%Y-%m-%d')}, "最近"=最近5-10个交易日"""
|
||||
year = now.year
|
||||
weekday_names = ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
|
||||
|
||||
# 构建系统提示词(适用于原生 tool calling)
|
||||
system_prompt = f"""你是"价小前",北京价值前沿科技公司的AI投研聊天助手。
|
||||
system_prompt = f"""⏰ **当前时间: {year}年{now.month}月{now.day}日 {now.strftime('%H:%M')} {weekday_names[now.weekday()]}** (注意:现在是{year}年)
|
||||
|
||||
你是"价小前",北京价值前沿科技公司的AI投研聊天助手。
|
||||
|
||||
## 时间上下文
|
||||
- 当前日期: {now.strftime('%Y-%m-%d')} ({year}年)
|
||||
- 时间语义: "今天"={now.strftime('%Y-%m-%d')}, "最近"=最近5-10个交易日
|
||||
- A股交易时间: 上午 9:30-11:30,下午 13:00-15:00
|
||||
|
||||
## 你的能力
|
||||
- 专业领域: 股票投资研究、市场分析、新闻解读、财务分析
|
||||
- 你可以调用各种工具来查询股票数据、新闻、概念板块等信息
|
||||
- 根据用户问题,智能选择并调用合适的工具
|
||||
|
||||
{current_time_info}
|
||||
|
||||
## 重要知识
|
||||
- 贵州茅台: 600519
|
||||
- 涨停: 涨幅约10%
|
||||
|
||||
@@ -8,6 +8,44 @@ import remarkGfm from 'remark-gfm';
|
||||
import { EChartsRenderer } from './EChartsRenderer';
|
||||
import { logger } from '@utils/logger';
|
||||
|
||||
/**
|
||||
* 清理 JSON 字符串,移除注释和多余字符
|
||||
* @param {string} str - 可能包含注释的 JSON 字符串
|
||||
* @returns {string} 清理后的 JSON 字符串
|
||||
*/
|
||||
function cleanJsonString(str) {
|
||||
if (!str) return str;
|
||||
|
||||
let cleaned = str.trim();
|
||||
|
||||
// 移除 markdown 代码块标记
|
||||
cleaned = cleaned.replace(/^```(?:json|echarts)?\s*/i, '');
|
||||
cleaned = cleaned.replace(/```\s*$/g, '');
|
||||
|
||||
// 移除单行注释 (// ...)
|
||||
// 注意:要小心不要移除 URL 中的 //
|
||||
cleaned = cleaned.replace(/^\s*\/\/[^\n]*\n?/gm, '');
|
||||
|
||||
// 移除多行注释 (/* ... */)
|
||||
cleaned = cleaned.replace(/\/\*[\s\S]*?\*\//g, '');
|
||||
|
||||
// 移除开头可能的非 JSON 字符,直到找到 { 或 [
|
||||
const jsonStart = cleaned.search(/[{\[]/);
|
||||
if (jsonStart > 0) {
|
||||
cleaned = cleaned.substring(jsonStart);
|
||||
}
|
||||
|
||||
// 移除结尾可能的非 JSON 字符,找到最后的 } 或 ]
|
||||
const lastBrace = cleaned.lastIndexOf('}');
|
||||
const lastBracket = cleaned.lastIndexOf(']');
|
||||
const jsonEnd = Math.max(lastBrace, lastBracket);
|
||||
if (jsonEnd > 0 && jsonEnd < cleaned.length - 1) {
|
||||
cleaned = cleaned.substring(0, jsonEnd + 1);
|
||||
}
|
||||
|
||||
return cleaned.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* 稳定的图表组件包装器
|
||||
* 使用 useMemo 避免 option 对象引用变化导致的重复渲染
|
||||
@@ -15,9 +53,11 @@ import { logger } from '@utils/logger';
|
||||
const StableChart = React.memo(({ jsonString, height, variant }) => {
|
||||
const chartOption = useMemo(() => {
|
||||
try {
|
||||
return JSON.parse(jsonString);
|
||||
const cleanedJson = cleanJsonString(jsonString);
|
||||
return JSON.parse(cleanedJson);
|
||||
} catch (e) {
|
||||
console.error('[StableChart] JSON parse error:', e);
|
||||
console.error('[StableChart] Original string:', jsonString?.substring(0, 200));
|
||||
return null;
|
||||
}
|
||||
}, [jsonString]);
|
||||
@@ -393,9 +433,8 @@ export const MarkdownWithCharts = ({ content, variant = 'auto' }) => {
|
||||
);
|
||||
} else if (part.type === 'chart') {
|
||||
// 渲染 ECharts 图表
|
||||
// 清理可能的残留字符
|
||||
let cleanContent = part.content.trim();
|
||||
cleanContent = cleanContent.replace(/```\s*$/g, '').trim();
|
||||
// 使用 cleanJsonString 清理注释和多余字符
|
||||
const cleanContent = cleanJsonString(part.content);
|
||||
|
||||
// 调试日志
|
||||
console.log('[MarkdownWithCharts] Rendering chart, content length:', cleanContent.length);
|
||||
@@ -407,7 +446,8 @@ export const MarkdownWithCharts = ({ content, variant = 'auto' }) => {
|
||||
console.log('[MarkdownWithCharts] JSON valid, has series:', !!testParse.series);
|
||||
} catch (e) {
|
||||
console.error('[MarkdownWithCharts] JSON parse error:', e.message);
|
||||
console.log('[MarkdownWithCharts] Problematic content:', cleanContent.substring(0, 300));
|
||||
console.error('[MarkdownWithCharts] Original content:', part.content.substring(0, 200));
|
||||
console.log('[MarkdownWithCharts] Cleaned content:', cleanContent.substring(0, 300));
|
||||
|
||||
return (
|
||||
<Alert status="warning" key={index} borderRadius="md">
|
||||
|
||||
Reference in New Issue
Block a user