aigroup-econ-mcp 0.4.1__py3-none-any.whl → 0.5.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of aigroup-econ-mcp might be problematic. Click here for more details.
- aigroup_econ_mcp/__init__.py +2 -2
- aigroup_econ_mcp/server.py +451 -451
- aigroup_econ_mcp/tools/__init__.py +8 -7
- aigroup_econ_mcp/tools/base.py +204 -5
- aigroup_econ_mcp/tools/file_parser.py +273 -4
- aigroup_econ_mcp/tools/machine_learning.py +56 -669
- aigroup_econ_mcp/tools/ml_ensemble.py +210 -0
- aigroup_econ_mcp/tools/ml_evaluation.py +272 -0
- aigroup_econ_mcp/tools/ml_models.py +54 -0
- aigroup_econ_mcp/tools/ml_regularization.py +172 -0
- aigroup_econ_mcp/tools/tool_descriptions.py +416 -0
- aigroup_econ_mcp/tools/tool_registry.py +1 -1
- {aigroup_econ_mcp-0.4.1.dist-info → aigroup_econ_mcp-0.5.0.dist-info}/METADATA +2 -2
- aigroup_econ_mcp-0.5.0.dist-info/RECORD +30 -0
- aigroup_econ_mcp/tools/decorators.py +0 -178
- aigroup_econ_mcp/tools/file_input_handler.py +0 -268
- aigroup_econ_mcp-0.4.1.dist-info/RECORD +0 -27
- {aigroup_econ_mcp-0.4.1.dist-info → aigroup_econ_mcp-0.5.0.dist-info}/WHEEL +0 -0
- {aigroup_econ_mcp-0.4.1.dist-info → aigroup_econ_mcp-0.5.0.dist-info}/entry_points.txt +0 -0
- {aigroup_econ_mcp-0.4.1.dist-info → aigroup_econ_mcp-0.5.0.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,268 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
文件输入处理组件
|
|
3
|
-
提供统一的文件输入处理接口,支持所有工具
|
|
4
|
-
"""
|
|
5
|
-
|
|
6
|
-
from typing import Dict, List, Any, Optional, Callable
|
|
7
|
-
from functools import wraps
|
|
8
|
-
from .file_parser import FileParser
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
class FileInputHandler:
|
|
12
|
-
"""
|
|
13
|
-
文件输入处理组件
|
|
14
|
-
|
|
15
|
-
使用组件模式,为任何工具函数添加文件输入支持
|
|
16
|
-
"""
|
|
17
|
-
|
|
18
|
-
@staticmethod
|
|
19
|
-
def process_input(
|
|
20
|
-
file_content: Optional[str],
|
|
21
|
-
file_format: str,
|
|
22
|
-
tool_type: str,
|
|
23
|
-
data_params: Dict[str, Any]
|
|
24
|
-
) -> Dict[str, Any]:
|
|
25
|
-
"""
|
|
26
|
-
处理文件输入并转换为工具参数
|
|
27
|
-
|
|
28
|
-
Args:
|
|
29
|
-
file_content: 文件内容
|
|
30
|
-
file_format: 文件格式
|
|
31
|
-
tool_type: 工具类型
|
|
32
|
-
data_params: 当前数据参数
|
|
33
|
-
|
|
34
|
-
Returns:
|
|
35
|
-
更新后的参数字典
|
|
36
|
-
"""
|
|
37
|
-
# 如果没有文件输入,直接返回原参数
|
|
38
|
-
if file_content is None:
|
|
39
|
-
return data_params
|
|
40
|
-
|
|
41
|
-
# 解析文件
|
|
42
|
-
parsed = FileParser.parse_file_content(file_content, file_format)
|
|
43
|
-
|
|
44
|
-
# 转换为工具格式
|
|
45
|
-
converted = FileParser.convert_to_tool_format(parsed, tool_type)
|
|
46
|
-
|
|
47
|
-
# 合并参数(文件数据优先)
|
|
48
|
-
result = {**data_params, **converted}
|
|
49
|
-
|
|
50
|
-
return result
|
|
51
|
-
|
|
52
|
-
@staticmethod
|
|
53
|
-
def with_file_support(tool_type: str):
|
|
54
|
-
"""
|
|
55
|
-
装饰器:为工具函数添加文件输入支持
|
|
56
|
-
|
|
57
|
-
Args:
|
|
58
|
-
tool_type: 工具类型(single_var, multi_var_dict, regression, panel等)
|
|
59
|
-
|
|
60
|
-
Returns:
|
|
61
|
-
装饰后的函数
|
|
62
|
-
|
|
63
|
-
使用示例:
|
|
64
|
-
@FileInputHandler.with_file_support('regression')
|
|
65
|
-
async def my_regression_tool(y_data, x_data, file_content=None, file_format='auto'):
|
|
66
|
-
# 函数会自动处理file_content并填充y_data和x_data
|
|
67
|
-
pass
|
|
68
|
-
"""
|
|
69
|
-
def decorator(func: Callable) -> Callable:
|
|
70
|
-
@wraps(func)
|
|
71
|
-
async def wrapper(*args, **kwargs):
|
|
72
|
-
# 提取文件相关参数
|
|
73
|
-
file_content = kwargs.get('file_content')
|
|
74
|
-
file_format = kwargs.get('file_format', 'auto')
|
|
75
|
-
|
|
76
|
-
if file_content is not None:
|
|
77
|
-
# 处理文件输入
|
|
78
|
-
processed = FileInputHandler.process_input(
|
|
79
|
-
file_content=file_content,
|
|
80
|
-
file_format=file_format,
|
|
81
|
-
tool_type=tool_type,
|
|
82
|
-
data_params=kwargs
|
|
83
|
-
)
|
|
84
|
-
|
|
85
|
-
# 更新kwargs
|
|
86
|
-
kwargs.update(processed)
|
|
87
|
-
|
|
88
|
-
# 调用原函数
|
|
89
|
-
return await func(*args, **kwargs)
|
|
90
|
-
|
|
91
|
-
return wrapper
|
|
92
|
-
return decorator
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
class FileInputMixin:
|
|
96
|
-
"""
|
|
97
|
-
文件输入混入类
|
|
98
|
-
|
|
99
|
-
为类提供文件输入处理能力
|
|
100
|
-
"""
|
|
101
|
-
|
|
102
|
-
def parse_file_input(
|
|
103
|
-
self,
|
|
104
|
-
file_content: Optional[str],
|
|
105
|
-
file_format: str = "auto"
|
|
106
|
-
) -> Optional[Dict[str, Any]]:
|
|
107
|
-
"""解析文件输入"""
|
|
108
|
-
if file_content is None:
|
|
109
|
-
return None
|
|
110
|
-
return FileParser.parse_file_content(file_content, file_format)
|
|
111
|
-
|
|
112
|
-
def convert_for_tool(
|
|
113
|
-
self,
|
|
114
|
-
parsed_data: Dict[str, Any],
|
|
115
|
-
tool_type: str
|
|
116
|
-
) -> Dict[str, Any]:
|
|
117
|
-
"""转换为工具格式"""
|
|
118
|
-
return FileParser.convert_to_tool_format(parsed_data, tool_type)
|
|
119
|
-
|
|
120
|
-
def get_recommendations(
|
|
121
|
-
self,
|
|
122
|
-
parsed_data: Dict[str, Any]
|
|
123
|
-
) -> Dict[str, Any]:
|
|
124
|
-
"""获取工具推荐"""
|
|
125
|
-
return FileParser.auto_detect_tool_params(parsed_data)
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
def create_file_params(
|
|
129
|
-
description: str = "CSV或JSON文件内容"
|
|
130
|
-
) -> Dict[str, Any]:
|
|
131
|
-
"""
|
|
132
|
-
创建标准的文件输入参数定义
|
|
133
|
-
|
|
134
|
-
Args:
|
|
135
|
-
description: 参数描述
|
|
136
|
-
|
|
137
|
-
Returns:
|
|
138
|
-
参数定义字典,可直接用于Field()
|
|
139
|
-
"""
|
|
140
|
-
return {
|
|
141
|
-
"file_content": {
|
|
142
|
-
"default": None,
|
|
143
|
-
"description": f"""{description}
|
|
144
|
-
|
|
145
|
-
📁 支持格式:
|
|
146
|
-
- CSV: 带表头的列数据,自动检测分隔符
|
|
147
|
-
- JSON: {{"变量名": [数据], ...}} 或 [{{"变量1": 值, ...}}, ...]
|
|
148
|
-
|
|
149
|
-
💡 使用方式:
|
|
150
|
-
- 提供文件内容字符串(可以是base64编码)
|
|
151
|
-
- 系统会自动解析并识别变量
|
|
152
|
-
- 优先使用file_content,如果提供则忽略其他数据参数"""
|
|
153
|
-
},
|
|
154
|
-
"file_format": {
|
|
155
|
-
"default": "auto",
|
|
156
|
-
"description": """文件格式
|
|
157
|
-
|
|
158
|
-
可选值:
|
|
159
|
-
- "auto": 自动检测(默认)
|
|
160
|
-
- "csv": CSV格式
|
|
161
|
-
- "json": JSON格式"""
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
class UnifiedFileInput:
|
|
167
|
-
"""
|
|
168
|
-
统一文件输入接口
|
|
169
|
-
|
|
170
|
-
所有工具通过此类统一处理文件输入
|
|
171
|
-
"""
|
|
172
|
-
|
|
173
|
-
@staticmethod
|
|
174
|
-
async def handle(
|
|
175
|
-
ctx: Any,
|
|
176
|
-
file_content: Optional[str],
|
|
177
|
-
file_format: str,
|
|
178
|
-
tool_type: str,
|
|
179
|
-
original_params: Dict[str, Any]
|
|
180
|
-
) -> Dict[str, Any]:
|
|
181
|
-
"""
|
|
182
|
-
统一处理文件输入
|
|
183
|
-
|
|
184
|
-
Args:
|
|
185
|
-
ctx: MCP上下文
|
|
186
|
-
file_content: 文件内容
|
|
187
|
-
file_format: 文件格式
|
|
188
|
-
tool_type: 工具类型
|
|
189
|
-
original_params: 原始参数
|
|
190
|
-
|
|
191
|
-
Returns:
|
|
192
|
-
处理后的参数
|
|
193
|
-
"""
|
|
194
|
-
if file_content is None:
|
|
195
|
-
return original_params
|
|
196
|
-
|
|
197
|
-
try:
|
|
198
|
-
# 记录日志
|
|
199
|
-
await ctx.info("检测到文件输入,开始解析...")
|
|
200
|
-
|
|
201
|
-
# 解析文件
|
|
202
|
-
parsed = FileParser.parse_file_content(file_content, file_format)
|
|
203
|
-
|
|
204
|
-
# 记录解析结果
|
|
205
|
-
await ctx.info(
|
|
206
|
-
f"文件解析成功:{parsed['n_variables']}个变量,"
|
|
207
|
-
f"{parsed['n_observations']}个观测,"
|
|
208
|
-
f"数据类型={parsed['data_type']}"
|
|
209
|
-
)
|
|
210
|
-
|
|
211
|
-
# 转换为工具格式
|
|
212
|
-
converted = FileParser.convert_to_tool_format(parsed, tool_type)
|
|
213
|
-
|
|
214
|
-
# 合并参数
|
|
215
|
-
result = {**original_params}
|
|
216
|
-
result.update(converted)
|
|
217
|
-
|
|
218
|
-
# 记录转换结果
|
|
219
|
-
if tool_type == 'regression':
|
|
220
|
-
await ctx.info(
|
|
221
|
-
f"数据已转换:因变量={converted.get('y_variable')},"
|
|
222
|
-
f"自变量={converted.get('feature_names')}"
|
|
223
|
-
)
|
|
224
|
-
elif tool_type == 'panel':
|
|
225
|
-
await ctx.info(
|
|
226
|
-
f"面板数据已识别:{len(set(converted.get('entity_ids', [])))}个实体,"
|
|
227
|
-
f"{len(set(converted.get('time_periods', [])))}个时间点"
|
|
228
|
-
)
|
|
229
|
-
else:
|
|
230
|
-
await ctx.info(f"数据已转换为{tool_type}格式")
|
|
231
|
-
|
|
232
|
-
return result
|
|
233
|
-
|
|
234
|
-
except Exception as e:
|
|
235
|
-
await ctx.error(f"文件解析失败: {str(e)}")
|
|
236
|
-
raise ValueError(f"文件解析失败: {str(e)}")
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
# 便捷函数
|
|
240
|
-
async def process_file_for_tool(
|
|
241
|
-
ctx: Any,
|
|
242
|
-
file_content: Optional[str],
|
|
243
|
-
file_format: str,
|
|
244
|
-
tool_type: str,
|
|
245
|
-
**kwargs
|
|
246
|
-
) -> Dict[str, Any]:
|
|
247
|
-
"""
|
|
248
|
-
为工具处理文件输入的便捷函数
|
|
249
|
-
|
|
250
|
-
使用示例:
|
|
251
|
-
params = await process_file_for_tool(
|
|
252
|
-
ctx=ctx,
|
|
253
|
-
file_content=file_content,
|
|
254
|
-
file_format=file_format,
|
|
255
|
-
tool_type='regression',
|
|
256
|
-
y_data=y_data,
|
|
257
|
-
x_data=x_data,
|
|
258
|
-
feature_names=feature_names
|
|
259
|
-
)
|
|
260
|
-
# params 现在包含处理后的所有参数
|
|
261
|
-
"""
|
|
262
|
-
return await UnifiedFileInput.handle(
|
|
263
|
-
ctx=ctx,
|
|
264
|
-
file_content=file_content,
|
|
265
|
-
file_format=file_format,
|
|
266
|
-
tool_type=tool_type,
|
|
267
|
-
original_params=kwargs
|
|
268
|
-
)
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
aigroup_econ_mcp/__init__.py,sha256=2GgJrD8MTHFgaiXrWYsOou0034taAT1zTRyJx_NZKkg,472
|
|
2
|
-
aigroup_econ_mcp/cli.py,sha256=7yeNXWNwMdpUswAO4LsqAvb0EmCO3S6Bs6sl483uSXI,3363
|
|
3
|
-
aigroup_econ_mcp/config.py,sha256=ab5X4-H8isIe2nma0c0AOqlyYgwhf5kfe9Zx5XRrzIo,18876
|
|
4
|
-
aigroup_econ_mcp/server.py,sha256=-FIO4rnJrRQJpT1UESB4-hN5SYMQlTdj94veFOn8cxw,21690
|
|
5
|
-
aigroup_econ_mcp/tools/__init__.py,sha256=6C9seG5y9BKDl_cRpvMOT8WqSkBSGRPS_9P7-uRRTEc,357
|
|
6
|
-
aigroup_econ_mcp/tools/base.py,sha256=CwZFtvagcv732OAyCecEfwj8vekrOHSKjPXwrWamW2g,8163
|
|
7
|
-
aigroup_econ_mcp/tools/cache.py,sha256=Urv2zuycp5dS7Qh-XQWEMrwszq9RZ-il8cz_-WniGgc,15311
|
|
8
|
-
aigroup_econ_mcp/tools/data_loader.py,sha256=BVYvP04bQpsk3dZVFy-Y8EK3dnY4Pm0JSBYrthnHf74,5619
|
|
9
|
-
aigroup_econ_mcp/tools/decorators.py,sha256=Xn0P6sNWkJay4UWM5iRqKrs55O1clfrhRM18MpQ36Ko,6142
|
|
10
|
-
aigroup_econ_mcp/tools/file_input_handler.py,sha256=uRju239j3U4DvNPIXnXtAzZFO7v9M2ca9bTi4JezYyQ,7866
|
|
11
|
-
aigroup_econ_mcp/tools/file_parser.py,sha256=pzzsnxUnJQfYIX8rjvb9or3pAWU8zV9wG7s78ePlbko,20137
|
|
12
|
-
aigroup_econ_mcp/tools/machine_learning.py,sha256=09RJAdqOl7Xxiv2E8PyhztYAyzt-cWffpSMh7_9GRbk,21472
|
|
13
|
-
aigroup_econ_mcp/tools/monitoring.py,sha256=-hcw5nu5Q91FmDz39mRBsKavrTmEqXsKfGzlXr_5f0c,16708
|
|
14
|
-
aigroup_econ_mcp/tools/optimized_example.py,sha256=tZVQ2jTzHY_zixTynm4Sq8gj5hz6eWg7MKqNwsxrPoQ,6784
|
|
15
|
-
aigroup_econ_mcp/tools/panel_data.py,sha256=uzbgcDLXACfdi9KaMRmZdRTkhMtEyWb7p3vS3mUJ-co,19254
|
|
16
|
-
aigroup_econ_mcp/tools/regression.py,sha256=uMGRGUQo4mU1sb8fwpP2FpkCqt_e9AtqEtUpInACtJo,6443
|
|
17
|
-
aigroup_econ_mcp/tools/statistics.py,sha256=2cHgNSUXwPYPLxntVOEOL8yF-x92mrgjK-R8kkxDihg,4239
|
|
18
|
-
aigroup_econ_mcp/tools/time_series.py,sha256=LNCO0bYXLPilQ2kSVXA3woNp8ERVq7n3jaoQhWgTCJQ,21763
|
|
19
|
-
aigroup_econ_mcp/tools/timeout.py,sha256=vNnGsR0sXW1xvIbKCF-qPUU3QNDAn_MaQgSxbGxkfW4,8404
|
|
20
|
-
aigroup_econ_mcp/tools/tool_handlers.py,sha256=cqv7FU95b_kjEJcZSAIGuGjUqbcCCKT0MXrmflnnelo,15028
|
|
21
|
-
aigroup_econ_mcp/tools/tool_registry.py,sha256=yoA00XBiIQ0ly45huW4x9TNHSEJqu7veGOwSyZF-qko,4388
|
|
22
|
-
aigroup_econ_mcp/tools/validation.py,sha256=F7LHwog5xtFIMjD9D48kd8jAF5MsZb7wjdrgaOg8EKo,16657
|
|
23
|
-
aigroup_econ_mcp-0.4.1.dist-info/METADATA,sha256=ipzSXbSHPdZCgxmYgGvjDf7PLckgtAvpjbxYbQMUr-k,10800
|
|
24
|
-
aigroup_econ_mcp-0.4.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
25
|
-
aigroup_econ_mcp-0.4.1.dist-info/entry_points.txt,sha256=j5ZJYOc4lAZV-X3XkAuGhzHtIRcJtZ6Gz8ZKPY_QTrM,62
|
|
26
|
-
aigroup_econ_mcp-0.4.1.dist-info/licenses/LICENSE,sha256=DoyCJUWlDzKbqc5KRbFpsGYLwLh-XJRHKQDoITjb1yc,1083
|
|
27
|
-
aigroup_econ_mcp-0.4.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|