aiecs 1.0.8__py3-none-any.whl → 1.2.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 aiecs might be problematic. Click here for more details.
- aiecs/__init__.py +1 -1
- aiecs/aiecs_client.py +159 -1
- aiecs/config/config.py +6 -0
- aiecs/domain/__init__.py +95 -0
- aiecs/domain/community/__init__.py +159 -0
- aiecs/domain/community/agent_adapter.py +516 -0
- aiecs/domain/community/analytics.py +465 -0
- aiecs/domain/community/collaborative_workflow.py +99 -7
- aiecs/domain/community/communication_hub.py +649 -0
- aiecs/domain/community/community_builder.py +322 -0
- aiecs/domain/community/community_integration.py +365 -12
- aiecs/domain/community/community_manager.py +481 -5
- aiecs/domain/community/decision_engine.py +459 -13
- aiecs/domain/community/exceptions.py +238 -0
- aiecs/domain/community/models/__init__.py +36 -0
- aiecs/domain/community/resource_manager.py +1 -1
- aiecs/domain/community/shared_context_manager.py +621 -0
- aiecs/domain/context/__init__.py +24 -0
- aiecs/domain/context/context_engine.py +37 -33
- aiecs/main.py +20 -2
- aiecs/scripts/aid/VERSION_MANAGEMENT.md +97 -0
- aiecs/scripts/aid/__init__.py +15 -0
- aiecs/scripts/aid/version_manager.py +224 -0
- aiecs/scripts/dependance_check/__init__.py +18 -0
- aiecs/scripts/{download_nlp_data.py → dependance_check/download_nlp_data.py} +51 -8
- aiecs/scripts/dependance_patch/__init__.py +8 -0
- aiecs/scripts/dependance_patch/fix_weasel/__init__.py +12 -0
- aiecs/scripts/tools_develop/README.md +340 -0
- aiecs/scripts/tools_develop/__init__.py +16 -0
- aiecs/scripts/tools_develop/check_type_annotations.py +263 -0
- aiecs/scripts/tools_develop/validate_tool_schemas.py +346 -0
- aiecs/tools/__init__.py +53 -34
- aiecs/tools/docs/__init__.py +106 -0
- aiecs/tools/docs/ai_document_orchestrator.py +556 -0
- aiecs/tools/docs/ai_document_writer_orchestrator.py +2222 -0
- aiecs/tools/docs/content_insertion_tool.py +1234 -0
- aiecs/tools/docs/document_creator_tool.py +1179 -0
- aiecs/tools/docs/document_layout_tool.py +1105 -0
- aiecs/tools/docs/document_parser_tool.py +924 -0
- aiecs/tools/docs/document_writer_tool.py +1636 -0
- aiecs/tools/langchain_adapter.py +102 -51
- aiecs/tools/schema_generator.py +265 -0
- aiecs/tools/statistics/__init__.py +82 -0
- aiecs/tools/statistics/ai_data_analysis_orchestrator.py +581 -0
- aiecs/tools/statistics/ai_insight_generator_tool.py +473 -0
- aiecs/tools/statistics/ai_report_orchestrator_tool.py +629 -0
- aiecs/tools/statistics/data_loader_tool.py +518 -0
- aiecs/tools/statistics/data_profiler_tool.py +599 -0
- aiecs/tools/statistics/data_transformer_tool.py +531 -0
- aiecs/tools/statistics/data_visualizer_tool.py +460 -0
- aiecs/tools/statistics/model_trainer_tool.py +470 -0
- aiecs/tools/statistics/statistical_analyzer_tool.py +426 -0
- aiecs/tools/task_tools/chart_tool.py +2 -1
- aiecs/tools/task_tools/image_tool.py +43 -43
- aiecs/tools/task_tools/office_tool.py +48 -36
- aiecs/tools/task_tools/pandas_tool.py +37 -33
- aiecs/tools/task_tools/report_tool.py +67 -56
- aiecs/tools/task_tools/research_tool.py +32 -31
- aiecs/tools/task_tools/scraper_tool.py +53 -46
- aiecs/tools/task_tools/search_tool.py +1123 -0
- aiecs/tools/task_tools/stats_tool.py +20 -15
- {aiecs-1.0.8.dist-info → aiecs-1.2.0.dist-info}/METADATA +5 -1
- aiecs-1.2.0.dist-info/RECORD +135 -0
- aiecs-1.2.0.dist-info/entry_points.txt +10 -0
- aiecs/tools/task_tools/search_api.py +0 -7
- aiecs-1.0.8.dist-info/RECORD +0 -98
- aiecs-1.0.8.dist-info/entry_points.txt +0 -7
- /aiecs/scripts/{DEPENDENCY_SYSTEM_SUMMARY.md → dependance_check/DEPENDENCY_SYSTEM_SUMMARY.md} +0 -0
- /aiecs/scripts/{README_DEPENDENCY_CHECKER.md → dependance_check/README_DEPENDENCY_CHECKER.md} +0 -0
- /aiecs/scripts/{dependency_checker.py → dependance_check/dependency_checker.py} +0 -0
- /aiecs/scripts/{dependency_fixer.py → dependance_check/dependency_fixer.py} +0 -0
- /aiecs/scripts/{quick_dependency_check.py → dependance_check/quick_dependency_check.py} +0 -0
- /aiecs/scripts/{setup_nlp_data.sh → dependance_check/setup_nlp_data.sh} +0 -0
- /aiecs/scripts/{README_WEASEL_PATCH.md → dependance_patch/fix_weasel/README_WEASEL_PATCH.md} +0 -0
- /aiecs/scripts/{fix_weasel_validator.py → dependance_patch/fix_weasel/fix_weasel_validator.py} +0 -0
- /aiecs/scripts/{fix_weasel_validator.sh → dependance_patch/fix_weasel/fix_weasel_validator.sh} +0 -0
- /aiecs/scripts/{patch_weasel_library.sh → dependance_patch/fix_weasel/patch_weasel_library.sh} +0 -0
- /aiecs/scripts/{run_weasel_patch.sh → dependance_patch/fix_weasel/run_weasel_patch.sh} +0 -0
- {aiecs-1.0.8.dist-info → aiecs-1.2.0.dist-info}/WHEEL +0 -0
- {aiecs-1.0.8.dist-info → aiecs-1.2.0.dist-info}/licenses/LICENSE +0 -0
- {aiecs-1.0.8.dist-info → aiecs-1.2.0.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
# 工具开发辅助脚本
|
|
2
|
+
|
|
3
|
+
本目录包含用于 AIECS 工具开发和维护的验证脚本,帮助开发者确保工具质量和 Schema 自动生成的有效性。
|
|
4
|
+
|
|
5
|
+
## 📋 脚本列表
|
|
6
|
+
|
|
7
|
+
### 1. 类型注解检查器 (`check_type_annotations.py`)
|
|
8
|
+
|
|
9
|
+
检查工具方法的类型注解完整性,确保所有方法都有完整的类型注解(参数类型 + 返回类型)。
|
|
10
|
+
|
|
11
|
+
**用途**:
|
|
12
|
+
- 验证新开发的工具是否有完整的类型注解
|
|
13
|
+
- 检查现有工具的类型注解覆盖率
|
|
14
|
+
- 为自动 Schema 生成提供基础保障
|
|
15
|
+
|
|
16
|
+
**命令**:
|
|
17
|
+
```bash
|
|
18
|
+
# 检查所有工具
|
|
19
|
+
aiecs-tools-check-annotations
|
|
20
|
+
|
|
21
|
+
# 检查特定工具
|
|
22
|
+
aiecs-tools-check-annotations pandas
|
|
23
|
+
|
|
24
|
+
# 检查多个工具
|
|
25
|
+
aiecs-tools-check-annotations pandas chart image
|
|
26
|
+
|
|
27
|
+
# 显示详细的改进建议
|
|
28
|
+
aiecs-tools-check-annotations pandas --verbose
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
**输出示例**:
|
|
32
|
+
```
|
|
33
|
+
====================================================================================================
|
|
34
|
+
工具类型注解检查器
|
|
35
|
+
====================================================================================================
|
|
36
|
+
|
|
37
|
+
✅ pandas: 38/38 方法有完整类型注解 (100.0%)
|
|
38
|
+
|
|
39
|
+
⚠️ my_tool: 5/10 方法有完整类型注解 (50.0%)
|
|
40
|
+
|
|
41
|
+
需要改进的方法:
|
|
42
|
+
✗ process_data: 无类型注解
|
|
43
|
+
⚠ filter_records: 部分类型注解
|
|
44
|
+
→ 为参数 'condition' 添加类型注解
|
|
45
|
+
→ 添加返回类型注解
|
|
46
|
+
|
|
47
|
+
====================================================================================================
|
|
48
|
+
总体统计: 43/48 方法有完整类型注解 (89.6%)
|
|
49
|
+
====================================================================================================
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### 2. Schema 质量验证器 (`validate_tool_schemas.py`)
|
|
53
|
+
|
|
54
|
+
验证自动生成的 Schema 质量,识别需要改进的文档字符串。
|
|
55
|
+
|
|
56
|
+
**用途**:
|
|
57
|
+
- 验证 Schema 自动生成是否成功
|
|
58
|
+
- 评估生成的 Schema 描述质量
|
|
59
|
+
- 指导开发者改进文档字符串
|
|
60
|
+
|
|
61
|
+
**命令**:
|
|
62
|
+
```bash
|
|
63
|
+
# 验证所有工具
|
|
64
|
+
aiecs-tools-validate-schemas
|
|
65
|
+
|
|
66
|
+
# 验证特定工具
|
|
67
|
+
aiecs-tools-validate-schemas pandas
|
|
68
|
+
|
|
69
|
+
# 显示详细的改进建议
|
|
70
|
+
aiecs-tools-validate-schemas pandas --verbose
|
|
71
|
+
|
|
72
|
+
# 显示示例 Schema
|
|
73
|
+
aiecs-tools-validate-schemas pandas --show-examples
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
**输出示例**:
|
|
77
|
+
```
|
|
78
|
+
====================================================================================================
|
|
79
|
+
工具 Schema 质量验证器
|
|
80
|
+
====================================================================================================
|
|
81
|
+
|
|
82
|
+
✅ chart
|
|
83
|
+
方法数: 3
|
|
84
|
+
成功生成 Schema: 3 (100.0%)
|
|
85
|
+
描述质量: 100.0%
|
|
86
|
+
综合评分: 100.0% (A (优秀))
|
|
87
|
+
|
|
88
|
+
❌ pandas
|
|
89
|
+
方法数: 38
|
|
90
|
+
成功生成 Schema: 38 (100.0%)
|
|
91
|
+
描述质量: 0.0%
|
|
92
|
+
综合评分: 66.7% (D (需改进))
|
|
93
|
+
|
|
94
|
+
需要改进的方法 (38 个):
|
|
95
|
+
|
|
96
|
+
filter:
|
|
97
|
+
💡 在文档字符串的 Args 部分为参数 'records' 添加描述
|
|
98
|
+
💡 在文档字符串的 Args 部分为参数 'condition' 添加描述
|
|
99
|
+
|
|
100
|
+
====================================================================================================
|
|
101
|
+
总体统计:
|
|
102
|
+
方法数: 41
|
|
103
|
+
Schema 生成率: 41/41 (100.0%)
|
|
104
|
+
描述质量: 7.3%
|
|
105
|
+
====================================================================================================
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## 🚀 工具开发工作流
|
|
109
|
+
|
|
110
|
+
### 新工具开发流程
|
|
111
|
+
|
|
112
|
+
1. **编写工具类**
|
|
113
|
+
```python
|
|
114
|
+
from aiecs.tools.base_tool import BaseTool
|
|
115
|
+
from typing import List, Dict
|
|
116
|
+
|
|
117
|
+
class MyTool(BaseTool):
|
|
118
|
+
"""My custom tool"""
|
|
119
|
+
|
|
120
|
+
def process(self, data: List[Dict], threshold: float = 0.5) -> Dict:
|
|
121
|
+
"""
|
|
122
|
+
Process data with threshold.
|
|
123
|
+
|
|
124
|
+
Args:
|
|
125
|
+
data: Input data to process
|
|
126
|
+
threshold: Processing threshold (0.0 to 1.0)
|
|
127
|
+
|
|
128
|
+
Returns:
|
|
129
|
+
Processing results
|
|
130
|
+
"""
|
|
131
|
+
pass
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
2. **检查类型注解**
|
|
135
|
+
```bash
|
|
136
|
+
aiecs-tools-check-annotations my_tool --verbose
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
确保所有方法都有 ✅ 标记。
|
|
140
|
+
|
|
141
|
+
3. **验证 Schema 质量**
|
|
142
|
+
```bash
|
|
143
|
+
aiecs-tools-validate-schemas my_tool --show-examples
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
目标:综合评分 ≥ 80% (B 良好)
|
|
147
|
+
|
|
148
|
+
4. **改进文档字符串**
|
|
149
|
+
|
|
150
|
+
根据验证器的建议,改进文档字符串:
|
|
151
|
+
```python
|
|
152
|
+
def process(self, data: List[Dict], threshold: float = 0.5) -> Dict:
|
|
153
|
+
"""
|
|
154
|
+
Process data with threshold filtering.
|
|
155
|
+
|
|
156
|
+
Args:
|
|
157
|
+
data: List of data records to process (each record is a dict)
|
|
158
|
+
threshold: Minimum confidence threshold for filtering (0.0 to 1.0, default: 0.5)
|
|
159
|
+
|
|
160
|
+
Returns:
|
|
161
|
+
Dictionary containing processed results and statistics
|
|
162
|
+
"""
|
|
163
|
+
pass
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
5. **重新验证**
|
|
167
|
+
```bash
|
|
168
|
+
aiecs-tools-validate-schemas my_tool
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### 现有工具维护流程
|
|
172
|
+
|
|
173
|
+
1. **定期检查**
|
|
174
|
+
```bash
|
|
175
|
+
# 每次修改工具后运行
|
|
176
|
+
aiecs-tools-check-annotations my_tool
|
|
177
|
+
aiecs-tools-validate-schemas my_tool
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
2. **批量检查**
|
|
181
|
+
```bash
|
|
182
|
+
# 检查所有工具
|
|
183
|
+
aiecs-tools-check-annotations
|
|
184
|
+
aiecs-tools-validate-schemas
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
3. **持续改进**
|
|
188
|
+
- 优先改进评分 < 80% 的工具
|
|
189
|
+
- 为通用描述(如 "Parameter xxx")添加有意义的说明
|
|
190
|
+
|
|
191
|
+
## 📊 质量标准
|
|
192
|
+
|
|
193
|
+
### 类型注解标准
|
|
194
|
+
|
|
195
|
+
- ✅ **优秀 (100%)**:所有方法都有完整类型注解
|
|
196
|
+
- ⚠️ **良好 (80-99%)**:大部分方法有完整类型注解
|
|
197
|
+
- ❌ **需改进 (<80%)**:缺少大量类型注解
|
|
198
|
+
|
|
199
|
+
### Schema 质量标准
|
|
200
|
+
|
|
201
|
+
- ✅ **A (优秀) ≥90%**:Schema 生成成功,描述质量高
|
|
202
|
+
- ⚠️ **B (良好) 80-89%**:Schema 生成成功,描述质量中等
|
|
203
|
+
- ⚠️ **C (中等) 70-79%**:Schema 生成成功,描述质量较低
|
|
204
|
+
- ❌ **D (需改进) <70%**:Schema 生成失败或描述质量差
|
|
205
|
+
|
|
206
|
+
## 💡 最佳实践
|
|
207
|
+
|
|
208
|
+
### 1. 完整的类型注解
|
|
209
|
+
|
|
210
|
+
```python
|
|
211
|
+
# ✅ 好的示例
|
|
212
|
+
def filter(self, records: List[Dict], condition: str) -> List[Dict]:
|
|
213
|
+
pass
|
|
214
|
+
|
|
215
|
+
# ❌ 不好的示例
|
|
216
|
+
def filter(self, records, condition): # 缺少类型注解
|
|
217
|
+
pass
|
|
218
|
+
|
|
219
|
+
def filter(self, records: List[Dict], condition): # 部分缺失
|
|
220
|
+
pass
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
### 2. 详细的文档字符串
|
|
224
|
+
|
|
225
|
+
使用 Google 或 NumPy 风格:
|
|
226
|
+
|
|
227
|
+
```python
|
|
228
|
+
# ✅ Google 风格(推荐)
|
|
229
|
+
def filter(self, records: List[Dict], condition: str) -> List[Dict]:
|
|
230
|
+
"""
|
|
231
|
+
Filter DataFrame based on a condition.
|
|
232
|
+
|
|
233
|
+
Args:
|
|
234
|
+
records: List of records to filter (each record is a dict)
|
|
235
|
+
condition: Filter condition using pandas query syntax (e.g., 'age > 30')
|
|
236
|
+
|
|
237
|
+
Returns:
|
|
238
|
+
Filtered list of records
|
|
239
|
+
"""
|
|
240
|
+
pass
|
|
241
|
+
|
|
242
|
+
# ✅ NumPy 风格
|
|
243
|
+
def filter(self, records: List[Dict], condition: str) -> List[Dict]:
|
|
244
|
+
"""
|
|
245
|
+
Filter DataFrame based on a condition.
|
|
246
|
+
|
|
247
|
+
Parameters
|
|
248
|
+
----------
|
|
249
|
+
records : List[Dict]
|
|
250
|
+
List of records to filter (each record is a dict)
|
|
251
|
+
condition : str
|
|
252
|
+
Filter condition using pandas query syntax (e.g., 'age > 30')
|
|
253
|
+
|
|
254
|
+
Returns
|
|
255
|
+
-------
|
|
256
|
+
List[Dict]
|
|
257
|
+
Filtered list of records
|
|
258
|
+
"""
|
|
259
|
+
pass
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
### 3. 有意义的描述
|
|
263
|
+
|
|
264
|
+
```python
|
|
265
|
+
# ❌ 不好的描述
|
|
266
|
+
"""
|
|
267
|
+
Args:
|
|
268
|
+
records: Parameter records
|
|
269
|
+
condition: Parameter condition
|
|
270
|
+
"""
|
|
271
|
+
|
|
272
|
+
# ✅ 好的描述
|
|
273
|
+
"""
|
|
274
|
+
Args:
|
|
275
|
+
records: List of data records to filter (each record contains fields like 'name', 'age', etc.)
|
|
276
|
+
condition: Filter condition using pandas query syntax (e.g., 'age > 30 and status == "active"')
|
|
277
|
+
"""
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
### 4. 处理复杂类型
|
|
281
|
+
|
|
282
|
+
```python
|
|
283
|
+
from typing import List, Dict, Optional, Union
|
|
284
|
+
import pandas as pd
|
|
285
|
+
|
|
286
|
+
# ✅ 使用标准类型
|
|
287
|
+
def process(self, data: List[Dict]) -> Dict:
|
|
288
|
+
pass
|
|
289
|
+
|
|
290
|
+
# ✅ pandas 类型会自动映射为 Any
|
|
291
|
+
def process(self, df: pd.DataFrame) -> pd.DataFrame:
|
|
292
|
+
pass
|
|
293
|
+
|
|
294
|
+
# ✅ 可选参数
|
|
295
|
+
def process(self, data: List[Dict], config: Optional[Dict] = None) -> Dict:
|
|
296
|
+
pass
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
## 🔧 故障排查
|
|
300
|
+
|
|
301
|
+
### 问题:类型注解检查失败
|
|
302
|
+
|
|
303
|
+
**原因**:缺少类型注解或使用了不支持的类型
|
|
304
|
+
|
|
305
|
+
**解决**:
|
|
306
|
+
1. 为所有参数添加类型注解
|
|
307
|
+
2. 添加返回类型注解
|
|
308
|
+
3. 使用标准类型(List, Dict, str, int, float, bool 等)
|
|
309
|
+
|
|
310
|
+
### 问题:Schema 生成失败
|
|
311
|
+
|
|
312
|
+
**原因**:
|
|
313
|
+
- 方法没有参数(除了 self)→ 这是正常的,无需 Schema
|
|
314
|
+
- 类型注解不完整 → 运行类型注解检查器
|
|
315
|
+
- 使用了不支持的类型 → 会自动映射为 Any
|
|
316
|
+
|
|
317
|
+
### 问题:描述质量低
|
|
318
|
+
|
|
319
|
+
**原因**:文档字符串缺少 Args 部分或描述不详细
|
|
320
|
+
|
|
321
|
+
**解决**:
|
|
322
|
+
1. 添加文档字符串的 Args 部分
|
|
323
|
+
2. 为每个参数添加详细描述
|
|
324
|
+
3. 使用 Google 或 NumPy 风格
|
|
325
|
+
|
|
326
|
+
## 📚 相关文档
|
|
327
|
+
|
|
328
|
+
- [Schema Generator 技术文档](../../../docs/TOOLS/TOOLS_SCHEMA_GENERATOR.md)
|
|
329
|
+
- [LangChain Adapter 技术文档](../../../docs/TOOLS/TOOLS_LANGCHAIN_ADAPTER.md)
|
|
330
|
+
- [BaseTool 开发指南](../../../docs/TOOLS/TOOLS_BASE_TOOL.md)
|
|
331
|
+
|
|
332
|
+
## 🤝 贡献
|
|
333
|
+
|
|
334
|
+
如果你发现这些工具有改进空间,欢迎提交 PR 或 Issue!
|
|
335
|
+
|
|
336
|
+
---
|
|
337
|
+
|
|
338
|
+
**维护者**: AIECS Tools Team
|
|
339
|
+
**最后更新**: 2025-10-02
|
|
340
|
+
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"""
|
|
2
|
+
工具开发辅助脚本
|
|
3
|
+
|
|
4
|
+
提供工具开发和维护所需的验证和检查功能。
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from .check_type_annotations import check_annotations, main as check_annotations_main
|
|
8
|
+
from .validate_tool_schemas import validate_schemas, main as validate_schemas_main
|
|
9
|
+
|
|
10
|
+
__all__ = [
|
|
11
|
+
'check_annotations',
|
|
12
|
+
'check_annotations_main',
|
|
13
|
+
'validate_schemas',
|
|
14
|
+
'validate_schemas_main',
|
|
15
|
+
]
|
|
16
|
+
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
工具类型注解检查器
|
|
4
|
+
|
|
5
|
+
用于工具开发和维护,检查工具方法的类型注解完整性。
|
|
6
|
+
帮助开发者确保工具方法有完整的类型注解,为自动 Schema 生成提供基础。
|
|
7
|
+
|
|
8
|
+
使用方法:
|
|
9
|
+
# 检查所有工具
|
|
10
|
+
aiecs tools check-annotations
|
|
11
|
+
|
|
12
|
+
# 检查特定工具
|
|
13
|
+
aiecs tools check-annotations pandas
|
|
14
|
+
|
|
15
|
+
# 检查多个工具
|
|
16
|
+
aiecs tools check-annotations pandas chart image
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
import sys
|
|
20
|
+
import inspect
|
|
21
|
+
from typing import get_type_hints, Optional, List, Dict, Any
|
|
22
|
+
|
|
23
|
+
# 确保可以导入 aiecs
|
|
24
|
+
import os
|
|
25
|
+
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(__file__)))))
|
|
26
|
+
|
|
27
|
+
from aiecs.tools import discover_tools, TOOL_CLASSES
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def check_method_type_annotations(method, method_name):
|
|
31
|
+
"""
|
|
32
|
+
检查方法的类型注解完整性
|
|
33
|
+
|
|
34
|
+
Returns:
|
|
35
|
+
dict: {
|
|
36
|
+
'has_annotations': bool,
|
|
37
|
+
'complete': bool,
|
|
38
|
+
'params_with_types': list,
|
|
39
|
+
'params_without_types': list,
|
|
40
|
+
'has_return_type': bool,
|
|
41
|
+
'suggestions': list # 改进建议
|
|
42
|
+
}
|
|
43
|
+
"""
|
|
44
|
+
try:
|
|
45
|
+
sig = inspect.signature(method)
|
|
46
|
+
type_hints = get_type_hints(method)
|
|
47
|
+
except Exception:
|
|
48
|
+
return {
|
|
49
|
+
'has_annotations': False,
|
|
50
|
+
'complete': False,
|
|
51
|
+
'params_with_types': [],
|
|
52
|
+
'params_without_types': [],
|
|
53
|
+
'has_return_type': False,
|
|
54
|
+
'error': True,
|
|
55
|
+
'suggestions': ['无法获取类型信息,请检查方法定义']
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
params_with_types = []
|
|
59
|
+
params_without_types = []
|
|
60
|
+
suggestions = []
|
|
61
|
+
|
|
62
|
+
for param_name, param in sig.parameters.items():
|
|
63
|
+
if param_name == 'self':
|
|
64
|
+
continue
|
|
65
|
+
|
|
66
|
+
if param_name in type_hints:
|
|
67
|
+
params_with_types.append(param_name)
|
|
68
|
+
else:
|
|
69
|
+
params_without_types.append(param_name)
|
|
70
|
+
suggestions.append(f"为参数 '{param_name}' 添加类型注解")
|
|
71
|
+
|
|
72
|
+
has_return_type = 'return' in type_hints
|
|
73
|
+
if not has_return_type:
|
|
74
|
+
suggestions.append("添加返回类型注解")
|
|
75
|
+
|
|
76
|
+
has_any_annotations = len(params_with_types) > 0 or has_return_type
|
|
77
|
+
is_complete = len(params_without_types) == 0 and has_return_type
|
|
78
|
+
|
|
79
|
+
return {
|
|
80
|
+
'has_annotations': has_any_annotations,
|
|
81
|
+
'complete': is_complete,
|
|
82
|
+
'params_with_types': params_with_types,
|
|
83
|
+
'params_without_types': params_without_types,
|
|
84
|
+
'has_return_type': has_return_type,
|
|
85
|
+
'error': False,
|
|
86
|
+
'suggestions': suggestions
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def analyze_tool(tool_name, tool_class):
|
|
91
|
+
"""分析单个工具的类型注解情况"""
|
|
92
|
+
methods_info = []
|
|
93
|
+
|
|
94
|
+
for method_name in dir(tool_class):
|
|
95
|
+
# 跳过私有方法和特殊方法
|
|
96
|
+
if method_name.startswith('_'):
|
|
97
|
+
continue
|
|
98
|
+
|
|
99
|
+
# 跳过基类方法
|
|
100
|
+
if method_name in ['run', 'run_async', 'run_batch']:
|
|
101
|
+
continue
|
|
102
|
+
|
|
103
|
+
method = getattr(tool_class, method_name)
|
|
104
|
+
|
|
105
|
+
# 跳过非方法属性
|
|
106
|
+
if not callable(method):
|
|
107
|
+
continue
|
|
108
|
+
|
|
109
|
+
# 跳过类(如 Config, Schema 等)
|
|
110
|
+
if isinstance(method, type):
|
|
111
|
+
continue
|
|
112
|
+
|
|
113
|
+
# 检查类型注解
|
|
114
|
+
annotation_info = check_method_type_annotations(method, method_name)
|
|
115
|
+
annotation_info['method_name'] = method_name
|
|
116
|
+
|
|
117
|
+
methods_info.append(annotation_info)
|
|
118
|
+
|
|
119
|
+
return methods_info
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def print_tool_report(tool_name: str, methods_info: List[Dict], verbose: bool = False):
|
|
123
|
+
"""打印单个工具的报告"""
|
|
124
|
+
|
|
125
|
+
total = len(methods_info)
|
|
126
|
+
complete = sum(1 for m in methods_info if m['complete'])
|
|
127
|
+
partial = sum(1 for m in methods_info if m['has_annotations'] and not m['complete'])
|
|
128
|
+
none = sum(1 for m in methods_info if not m['has_annotations'])
|
|
129
|
+
|
|
130
|
+
# 计算覆盖率
|
|
131
|
+
coverage = (complete / total * 100) if total > 0 else 0
|
|
132
|
+
|
|
133
|
+
# 状态图标
|
|
134
|
+
if coverage == 100:
|
|
135
|
+
status = "✅"
|
|
136
|
+
elif coverage >= 80:
|
|
137
|
+
status = "⚠️"
|
|
138
|
+
else:
|
|
139
|
+
status = "❌"
|
|
140
|
+
|
|
141
|
+
print(f"\n{status} {tool_name}: {complete}/{total} 方法有完整类型注解 ({coverage:.1f}%)")
|
|
142
|
+
|
|
143
|
+
if verbose or coverage < 100:
|
|
144
|
+
# 显示不完整的方法
|
|
145
|
+
incomplete = [m for m in methods_info if not m['complete']]
|
|
146
|
+
if incomplete:
|
|
147
|
+
print(f"\n 需要改进的方法:")
|
|
148
|
+
for method_info in incomplete:
|
|
149
|
+
method_name = method_info['method_name']
|
|
150
|
+
suggestions = method_info.get('suggestions', [])
|
|
151
|
+
|
|
152
|
+
if method_info['error']:
|
|
153
|
+
print(f" ✗ {method_name}: 无法获取类型信息")
|
|
154
|
+
elif not method_info['has_annotations']:
|
|
155
|
+
print(f" ✗ {method_name}: 无类型注解")
|
|
156
|
+
else:
|
|
157
|
+
print(f" ⚠ {method_name}: 部分类型注解")
|
|
158
|
+
|
|
159
|
+
# 显示改进建议
|
|
160
|
+
if suggestions and verbose:
|
|
161
|
+
for suggestion in suggestions:
|
|
162
|
+
print(f" → {suggestion}")
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def check_annotations(tool_names: Optional[List[str]] = None, verbose: bool = False):
|
|
166
|
+
"""
|
|
167
|
+
检查工具的类型注解
|
|
168
|
+
|
|
169
|
+
Args:
|
|
170
|
+
tool_names: 要检查的工具名称列表,None 表示检查所有工具
|
|
171
|
+
verbose: 是否显示详细信息
|
|
172
|
+
"""
|
|
173
|
+
print("=" * 100)
|
|
174
|
+
print("工具类型注解检查器")
|
|
175
|
+
print("=" * 100)
|
|
176
|
+
|
|
177
|
+
discover_tools()
|
|
178
|
+
|
|
179
|
+
# 确定要检查的工具
|
|
180
|
+
if tool_names:
|
|
181
|
+
tools_to_check = {}
|
|
182
|
+
for name in tool_names:
|
|
183
|
+
if name in TOOL_CLASSES:
|
|
184
|
+
tools_to_check[name] = TOOL_CLASSES[name]
|
|
185
|
+
else:
|
|
186
|
+
print(f"\n❌ 工具 '{name}' 不存在")
|
|
187
|
+
|
|
188
|
+
if not tools_to_check:
|
|
189
|
+
print("\n没有找到要检查的工具")
|
|
190
|
+
return
|
|
191
|
+
else:
|
|
192
|
+
tools_to_check = TOOL_CLASSES
|
|
193
|
+
|
|
194
|
+
# 检查每个工具
|
|
195
|
+
all_stats = []
|
|
196
|
+
for tool_name in sorted(tools_to_check.keys()):
|
|
197
|
+
tool_class = tools_to_check[tool_name]
|
|
198
|
+
methods_info = analyze_tool(tool_name, tool_class)
|
|
199
|
+
|
|
200
|
+
if methods_info:
|
|
201
|
+
print_tool_report(tool_name, methods_info, verbose)
|
|
202
|
+
|
|
203
|
+
total = len(methods_info)
|
|
204
|
+
complete = sum(1 for m in methods_info if m['complete'])
|
|
205
|
+
all_stats.append((tool_name, total, complete))
|
|
206
|
+
|
|
207
|
+
# 总体统计
|
|
208
|
+
if len(all_stats) > 1:
|
|
209
|
+
total_methods = sum(s[1] for s in all_stats)
|
|
210
|
+
total_complete = sum(s[2] for s in all_stats)
|
|
211
|
+
overall_coverage = (total_complete / total_methods * 100) if total_methods > 0 else 0
|
|
212
|
+
|
|
213
|
+
print("\n" + "=" * 100)
|
|
214
|
+
print(f"总体统计: {total_complete}/{total_methods} 方法有完整类型注解 ({overall_coverage:.1f}%)")
|
|
215
|
+
print("=" * 100)
|
|
216
|
+
|
|
217
|
+
print("\n💡 提示:")
|
|
218
|
+
print(" - 完整类型注解包括:所有参数的类型 + 返回类型")
|
|
219
|
+
print(" - 使用 --verbose 查看详细的改进建议")
|
|
220
|
+
print(" - 完整的类型注解是自动 Schema 生成的基础")
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
def main():
|
|
224
|
+
"""命令行入口"""
|
|
225
|
+
import argparse
|
|
226
|
+
|
|
227
|
+
parser = argparse.ArgumentParser(
|
|
228
|
+
description='检查工具方法的类型注解完整性',
|
|
229
|
+
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
230
|
+
epilog="""
|
|
231
|
+
示例:
|
|
232
|
+
# 检查所有工具
|
|
233
|
+
aiecs tools check-annotations
|
|
234
|
+
|
|
235
|
+
# 检查特定工具
|
|
236
|
+
aiecs tools check-annotations pandas
|
|
237
|
+
|
|
238
|
+
# 检查多个工具并显示详细信息
|
|
239
|
+
aiecs tools check-annotations pandas chart --verbose
|
|
240
|
+
"""
|
|
241
|
+
)
|
|
242
|
+
|
|
243
|
+
parser.add_argument(
|
|
244
|
+
'tools',
|
|
245
|
+
nargs='*',
|
|
246
|
+
help='要检查的工具名称(不指定则检查所有工具)'
|
|
247
|
+
)
|
|
248
|
+
|
|
249
|
+
parser.add_argument(
|
|
250
|
+
'-v', '--verbose',
|
|
251
|
+
action='store_true',
|
|
252
|
+
help='显示详细的改进建议'
|
|
253
|
+
)
|
|
254
|
+
|
|
255
|
+
args = parser.parse_args()
|
|
256
|
+
|
|
257
|
+
tool_names = args.tools if args.tools else None
|
|
258
|
+
check_annotations(tool_names, args.verbose)
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
if __name__ == '__main__':
|
|
262
|
+
main()
|
|
263
|
+
|