Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
|
@@ -28,6 +28,19 @@ def format_value(value, value_type="money"):
|
|
| 28 |
else: # number
|
| 29 |
return f"{value:.2f}"
|
| 30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
# MCP 工具定义
|
| 32 |
def create_mcp_tools():
|
| 33 |
"""创建 MCP 工具列表"""
|
|
@@ -128,7 +141,10 @@ def query_financial_data(company_name, query_type):
|
|
| 128 |
result += f"**Stock Symbol**: {company.get('tickers', ['N/A'])[0] if company.get('tickers') else 'N/A'}\n"
|
| 129 |
result += f"**Industry**: {company.get('sic_description', 'N/A')}\n\n---\n\n"
|
| 130 |
|
| 131 |
-
|
|
|
|
|
|
|
|
|
|
| 132 |
|
| 133 |
# 根据查询类型获取数据
|
| 134 |
if internal_query_type == "最新财务数据":
|
|
|
|
| 28 |
else: # number
|
| 29 |
return f"{value:.2f}"
|
| 30 |
|
| 31 |
+
def normalize_cik(cik):
|
| 32 |
+
"""
|
| 33 |
+
格式化 CIK 为标准的 10 位格式
|
| 34 |
+
"""
|
| 35 |
+
if not cik:
|
| 36 |
+
return None
|
| 37 |
+
# 转换为字符串并移除非数字字符
|
| 38 |
+
cik_str = str(cik).replace('-', '').replace(' ', '')
|
| 39 |
+
# 仅保留数字
|
| 40 |
+
cik_str = ''.join(c for c in cik_str if c.isdigit())
|
| 41 |
+
# 填充前导 0 至 10 位
|
| 42 |
+
return cik_str.zfill(10) if cik_str else None
|
| 43 |
+
|
| 44 |
# MCP 工具定义
|
| 45 |
def create_mcp_tools():
|
| 46 |
"""创建 MCP 工具列表"""
|
|
|
|
| 141 |
result += f"**Stock Symbol**: {company.get('tickers', ['N/A'])[0] if company.get('tickers') else 'N/A'}\n"
|
| 142 |
result += f"**Industry**: {company.get('sic_description', 'N/A')}\n\n---\n\n"
|
| 143 |
|
| 144 |
+
# 获取并格式化 CIK 为 10 位标准格式
|
| 145 |
+
cik = normalize_cik(company.get('cik'))
|
| 146 |
+
if not cik:
|
| 147 |
+
return result + "❌ Error: Invalid CIK from company search"
|
| 148 |
|
| 149 |
# 根据查询类型获取数据
|
| 150 |
if internal_query_type == "最新财务数据":
|