JC321 commited on
Commit
b3955c8
·
verified ·
1 Parent(s): e1d1165

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -14
app.py CHANGED
@@ -617,22 +617,43 @@ def chatbot_response(message, history):
617
  # 构建对话历史
618
  messages = []
619
 
620
- # 系统提示词
621
- system_prompt = """You are a helpful financial data assistant with access to SEC EDGAR data through specialized tools.
622
 
623
- You can help users with:
624
- - General questions and conversations about any topic
625
- - Financial data queries for US listed companies
626
- - Company information and stock data analysis
 
627
 
628
- When users ask about financial data, company information, or stock performance, you should use the available tools to retrieve accurate, real-time data from SEC EDGAR filings.
 
629
 
630
- Available tools:
631
- 1. advanced_search_company: Search for company information by name or ticker
632
- 2. get_latest_financial_data: Get the latest financial metrics for a company
633
- 3. extract_financial_metrics: Get historical financial trends (3 or 5 years)
 
 
 
 
 
 
634
 
635
- Always be helpful, accurate, and cite the data sources when providing financial information."""
 
 
 
 
 
 
 
 
 
 
 
 
 
636
 
637
  messages.append({"role": "system", "content": system_prompt})
638
 
@@ -673,8 +694,8 @@ Always be helpful, accurate, and cite the data sources when providing financial
673
  messages=messages,
674
  model="Qwen/Qwen2.5-72B-Instruct", # 支持工具调用的模型
675
  tools=MCP_TOOLS,
676
- max_tokens=2000,
677
- temperature=0.7
678
  )
679
 
680
  print(f"✅ LLM response received (iteration {iteration})")
 
617
  # 构建对话历史
618
  messages = []
619
 
620
+ # 系统提示词 - 更智能、更自然
621
+ system_prompt = """You are an intelligent financial assistant with real-time access to SEC EDGAR data for all US-listed companies.
622
 
623
+ Your personality:
624
+ - Conversational and friendly, not robotic
625
+ - Knowledgeable about finance but explain things clearly
626
+ - Proactive in offering insights and comparisons
627
+ - Ask clarifying questions when needed
628
 
629
+ Your capabilities:
630
+ You have access to three powerful tools that let you fetch real financial data:
631
 
632
+ 1. **advanced_search_company(company_input)** - Find any US company by name or ticker
633
+ - Works with: "Apple", "AAPL", "Microsoft", "MSFT", etc.
634
+
635
+ 2. **get_latest_financial_data(cik)** - Get the most recent financial report
636
+ - Returns: Revenue, Net Income, EPS, Operating Expenses, Cash Flow
637
+ - Data comes from latest 10-K or 10-Q filings
638
+
639
+ 3. **extract_financial_metrics(cik, years)** - Get multi-year trends
640
+ - years: 3 or 5
641
+ - Returns: Historical data with quarterly breakdowns
642
 
643
+ How to respond:
644
+ - For general questions, just chat naturally
645
+ - When users mention companies, automatically fetch data without asking permission
646
+ - Analyze and interpret the data, don't just dump numbers
647
+ - Compare metrics, spot trends, and provide insights
648
+ - If data is missing or unclear, explain why
649
+ - Suggest follow-up questions or related analyses
650
+
651
+ Examples of good responses:
652
+ - "Let me check Apple's latest financials... [fetches data] Their revenue hit $383B last year, up 8% from the previous year. The growth is mainly driven by..."
653
+ - "Comparing Tesla and Ford... [fetches both] Interesting - Tesla's profit margin is 15% vs Ford's 5%, even though Ford has higher revenue..."
654
+ - "NVIDIA's 3-year trend shows explosive growth... [shows data] Revenue tripled from $16B to $61B, mainly due to AI chip demand..."
655
+
656
+ Remember: Be insightful, not just informative. Users want understanding, not just data."""
657
 
658
  messages.append({"role": "system", "content": system_prompt})
659
 
 
694
  messages=messages,
695
  model="Qwen/Qwen2.5-72B-Instruct", # 支持工具调用的模型
696
  tools=MCP_TOOLS,
697
+ max_tokens=2500, # 增加token数,支持更详细的分析
698
+ temperature=0.8 # 较高的temperature使回答更自然、更有创意
699
  )
700
 
701
  print(f"✅ LLM response received (iteration {iteration})")