aiecs 1.5.1__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.
Files changed (302) hide show
  1. aiecs/__init__.py +72 -0
  2. aiecs/__main__.py +41 -0
  3. aiecs/aiecs_client.py +469 -0
  4. aiecs/application/__init__.py +10 -0
  5. aiecs/application/executors/__init__.py +10 -0
  6. aiecs/application/executors/operation_executor.py +363 -0
  7. aiecs/application/knowledge_graph/__init__.py +7 -0
  8. aiecs/application/knowledge_graph/builder/__init__.py +37 -0
  9. aiecs/application/knowledge_graph/builder/document_builder.py +375 -0
  10. aiecs/application/knowledge_graph/builder/graph_builder.py +356 -0
  11. aiecs/application/knowledge_graph/builder/schema_mapping.py +531 -0
  12. aiecs/application/knowledge_graph/builder/structured_pipeline.py +443 -0
  13. aiecs/application/knowledge_graph/builder/text_chunker.py +319 -0
  14. aiecs/application/knowledge_graph/extractors/__init__.py +27 -0
  15. aiecs/application/knowledge_graph/extractors/base.py +100 -0
  16. aiecs/application/knowledge_graph/extractors/llm_entity_extractor.py +327 -0
  17. aiecs/application/knowledge_graph/extractors/llm_relation_extractor.py +349 -0
  18. aiecs/application/knowledge_graph/extractors/ner_entity_extractor.py +244 -0
  19. aiecs/application/knowledge_graph/fusion/__init__.py +23 -0
  20. aiecs/application/knowledge_graph/fusion/entity_deduplicator.py +387 -0
  21. aiecs/application/knowledge_graph/fusion/entity_linker.py +343 -0
  22. aiecs/application/knowledge_graph/fusion/knowledge_fusion.py +580 -0
  23. aiecs/application/knowledge_graph/fusion/relation_deduplicator.py +189 -0
  24. aiecs/application/knowledge_graph/pattern_matching/__init__.py +21 -0
  25. aiecs/application/knowledge_graph/pattern_matching/pattern_matcher.py +344 -0
  26. aiecs/application/knowledge_graph/pattern_matching/query_executor.py +378 -0
  27. aiecs/application/knowledge_graph/profiling/__init__.py +12 -0
  28. aiecs/application/knowledge_graph/profiling/query_plan_visualizer.py +199 -0
  29. aiecs/application/knowledge_graph/profiling/query_profiler.py +223 -0
  30. aiecs/application/knowledge_graph/reasoning/__init__.py +27 -0
  31. aiecs/application/knowledge_graph/reasoning/evidence_synthesis.py +347 -0
  32. aiecs/application/knowledge_graph/reasoning/inference_engine.py +504 -0
  33. aiecs/application/knowledge_graph/reasoning/logic_form_parser.py +167 -0
  34. aiecs/application/knowledge_graph/reasoning/logic_parser/__init__.py +79 -0
  35. aiecs/application/knowledge_graph/reasoning/logic_parser/ast_builder.py +513 -0
  36. aiecs/application/knowledge_graph/reasoning/logic_parser/ast_nodes.py +630 -0
  37. aiecs/application/knowledge_graph/reasoning/logic_parser/ast_validator.py +654 -0
  38. aiecs/application/knowledge_graph/reasoning/logic_parser/error_handler.py +477 -0
  39. aiecs/application/knowledge_graph/reasoning/logic_parser/parser.py +390 -0
  40. aiecs/application/knowledge_graph/reasoning/logic_parser/query_context.py +217 -0
  41. aiecs/application/knowledge_graph/reasoning/logic_query_integration.py +169 -0
  42. aiecs/application/knowledge_graph/reasoning/query_planner.py +872 -0
  43. aiecs/application/knowledge_graph/reasoning/reasoning_engine.py +554 -0
  44. aiecs/application/knowledge_graph/retrieval/__init__.py +19 -0
  45. aiecs/application/knowledge_graph/retrieval/retrieval_strategies.py +596 -0
  46. aiecs/application/knowledge_graph/search/__init__.py +59 -0
  47. aiecs/application/knowledge_graph/search/hybrid_search.py +423 -0
  48. aiecs/application/knowledge_graph/search/reranker.py +295 -0
  49. aiecs/application/knowledge_graph/search/reranker_strategies.py +553 -0
  50. aiecs/application/knowledge_graph/search/text_similarity.py +398 -0
  51. aiecs/application/knowledge_graph/traversal/__init__.py +15 -0
  52. aiecs/application/knowledge_graph/traversal/enhanced_traversal.py +329 -0
  53. aiecs/application/knowledge_graph/traversal/path_scorer.py +269 -0
  54. aiecs/application/knowledge_graph/validators/__init__.py +13 -0
  55. aiecs/application/knowledge_graph/validators/relation_validator.py +189 -0
  56. aiecs/application/knowledge_graph/visualization/__init__.py +11 -0
  57. aiecs/application/knowledge_graph/visualization/graph_visualizer.py +321 -0
  58. aiecs/common/__init__.py +9 -0
  59. aiecs/common/knowledge_graph/__init__.py +17 -0
  60. aiecs/common/knowledge_graph/runnable.py +484 -0
  61. aiecs/config/__init__.py +16 -0
  62. aiecs/config/config.py +498 -0
  63. aiecs/config/graph_config.py +137 -0
  64. aiecs/config/registry.py +23 -0
  65. aiecs/core/__init__.py +46 -0
  66. aiecs/core/interface/__init__.py +34 -0
  67. aiecs/core/interface/execution_interface.py +152 -0
  68. aiecs/core/interface/storage_interface.py +171 -0
  69. aiecs/domain/__init__.py +289 -0
  70. aiecs/domain/agent/__init__.py +189 -0
  71. aiecs/domain/agent/base_agent.py +697 -0
  72. aiecs/domain/agent/exceptions.py +103 -0
  73. aiecs/domain/agent/graph_aware_mixin.py +559 -0
  74. aiecs/domain/agent/hybrid_agent.py +490 -0
  75. aiecs/domain/agent/integration/__init__.py +26 -0
  76. aiecs/domain/agent/integration/context_compressor.py +222 -0
  77. aiecs/domain/agent/integration/context_engine_adapter.py +252 -0
  78. aiecs/domain/agent/integration/retry_policy.py +219 -0
  79. aiecs/domain/agent/integration/role_config.py +213 -0
  80. aiecs/domain/agent/knowledge_aware_agent.py +646 -0
  81. aiecs/domain/agent/lifecycle.py +296 -0
  82. aiecs/domain/agent/llm_agent.py +300 -0
  83. aiecs/domain/agent/memory/__init__.py +12 -0
  84. aiecs/domain/agent/memory/conversation.py +197 -0
  85. aiecs/domain/agent/migration/__init__.py +14 -0
  86. aiecs/domain/agent/migration/conversion.py +160 -0
  87. aiecs/domain/agent/migration/legacy_wrapper.py +90 -0
  88. aiecs/domain/agent/models.py +317 -0
  89. aiecs/domain/agent/observability.py +407 -0
  90. aiecs/domain/agent/persistence.py +289 -0
  91. aiecs/domain/agent/prompts/__init__.py +29 -0
  92. aiecs/domain/agent/prompts/builder.py +161 -0
  93. aiecs/domain/agent/prompts/formatters.py +189 -0
  94. aiecs/domain/agent/prompts/template.py +255 -0
  95. aiecs/domain/agent/registry.py +260 -0
  96. aiecs/domain/agent/tool_agent.py +257 -0
  97. aiecs/domain/agent/tools/__init__.py +12 -0
  98. aiecs/domain/agent/tools/schema_generator.py +221 -0
  99. aiecs/domain/community/__init__.py +155 -0
  100. aiecs/domain/community/agent_adapter.py +477 -0
  101. aiecs/domain/community/analytics.py +481 -0
  102. aiecs/domain/community/collaborative_workflow.py +642 -0
  103. aiecs/domain/community/communication_hub.py +645 -0
  104. aiecs/domain/community/community_builder.py +320 -0
  105. aiecs/domain/community/community_integration.py +800 -0
  106. aiecs/domain/community/community_manager.py +813 -0
  107. aiecs/domain/community/decision_engine.py +879 -0
  108. aiecs/domain/community/exceptions.py +225 -0
  109. aiecs/domain/community/models/__init__.py +33 -0
  110. aiecs/domain/community/models/community_models.py +268 -0
  111. aiecs/domain/community/resource_manager.py +457 -0
  112. aiecs/domain/community/shared_context_manager.py +603 -0
  113. aiecs/domain/context/__init__.py +58 -0
  114. aiecs/domain/context/context_engine.py +989 -0
  115. aiecs/domain/context/conversation_models.py +354 -0
  116. aiecs/domain/context/graph_memory.py +467 -0
  117. aiecs/domain/execution/__init__.py +12 -0
  118. aiecs/domain/execution/model.py +57 -0
  119. aiecs/domain/knowledge_graph/__init__.py +19 -0
  120. aiecs/domain/knowledge_graph/models/__init__.py +52 -0
  121. aiecs/domain/knowledge_graph/models/entity.py +130 -0
  122. aiecs/domain/knowledge_graph/models/evidence.py +194 -0
  123. aiecs/domain/knowledge_graph/models/inference_rule.py +186 -0
  124. aiecs/domain/knowledge_graph/models/path.py +179 -0
  125. aiecs/domain/knowledge_graph/models/path_pattern.py +173 -0
  126. aiecs/domain/knowledge_graph/models/query.py +272 -0
  127. aiecs/domain/knowledge_graph/models/query_plan.py +187 -0
  128. aiecs/domain/knowledge_graph/models/relation.py +136 -0
  129. aiecs/domain/knowledge_graph/schema/__init__.py +23 -0
  130. aiecs/domain/knowledge_graph/schema/entity_type.py +135 -0
  131. aiecs/domain/knowledge_graph/schema/graph_schema.py +271 -0
  132. aiecs/domain/knowledge_graph/schema/property_schema.py +155 -0
  133. aiecs/domain/knowledge_graph/schema/relation_type.py +171 -0
  134. aiecs/domain/knowledge_graph/schema/schema_manager.py +496 -0
  135. aiecs/domain/knowledge_graph/schema/type_enums.py +205 -0
  136. aiecs/domain/task/__init__.py +13 -0
  137. aiecs/domain/task/dsl_processor.py +613 -0
  138. aiecs/domain/task/model.py +62 -0
  139. aiecs/domain/task/task_context.py +268 -0
  140. aiecs/infrastructure/__init__.py +24 -0
  141. aiecs/infrastructure/graph_storage/__init__.py +11 -0
  142. aiecs/infrastructure/graph_storage/base.py +601 -0
  143. aiecs/infrastructure/graph_storage/batch_operations.py +449 -0
  144. aiecs/infrastructure/graph_storage/cache.py +429 -0
  145. aiecs/infrastructure/graph_storage/distributed.py +226 -0
  146. aiecs/infrastructure/graph_storage/error_handling.py +390 -0
  147. aiecs/infrastructure/graph_storage/graceful_degradation.py +306 -0
  148. aiecs/infrastructure/graph_storage/health_checks.py +378 -0
  149. aiecs/infrastructure/graph_storage/in_memory.py +514 -0
  150. aiecs/infrastructure/graph_storage/index_optimization.py +483 -0
  151. aiecs/infrastructure/graph_storage/lazy_loading.py +410 -0
  152. aiecs/infrastructure/graph_storage/metrics.py +357 -0
  153. aiecs/infrastructure/graph_storage/migration.py +413 -0
  154. aiecs/infrastructure/graph_storage/pagination.py +471 -0
  155. aiecs/infrastructure/graph_storage/performance_monitoring.py +466 -0
  156. aiecs/infrastructure/graph_storage/postgres.py +871 -0
  157. aiecs/infrastructure/graph_storage/query_optimizer.py +635 -0
  158. aiecs/infrastructure/graph_storage/schema_cache.py +290 -0
  159. aiecs/infrastructure/graph_storage/sqlite.py +623 -0
  160. aiecs/infrastructure/graph_storage/streaming.py +495 -0
  161. aiecs/infrastructure/messaging/__init__.py +13 -0
  162. aiecs/infrastructure/messaging/celery_task_manager.py +383 -0
  163. aiecs/infrastructure/messaging/websocket_manager.py +298 -0
  164. aiecs/infrastructure/monitoring/__init__.py +34 -0
  165. aiecs/infrastructure/monitoring/executor_metrics.py +174 -0
  166. aiecs/infrastructure/monitoring/global_metrics_manager.py +213 -0
  167. aiecs/infrastructure/monitoring/structured_logger.py +48 -0
  168. aiecs/infrastructure/monitoring/tracing_manager.py +410 -0
  169. aiecs/infrastructure/persistence/__init__.py +24 -0
  170. aiecs/infrastructure/persistence/context_engine_client.py +187 -0
  171. aiecs/infrastructure/persistence/database_manager.py +333 -0
  172. aiecs/infrastructure/persistence/file_storage.py +754 -0
  173. aiecs/infrastructure/persistence/redis_client.py +220 -0
  174. aiecs/llm/__init__.py +86 -0
  175. aiecs/llm/callbacks/__init__.py +11 -0
  176. aiecs/llm/callbacks/custom_callbacks.py +264 -0
  177. aiecs/llm/client_factory.py +420 -0
  178. aiecs/llm/clients/__init__.py +33 -0
  179. aiecs/llm/clients/base_client.py +193 -0
  180. aiecs/llm/clients/googleai_client.py +181 -0
  181. aiecs/llm/clients/openai_client.py +131 -0
  182. aiecs/llm/clients/vertex_client.py +437 -0
  183. aiecs/llm/clients/xai_client.py +184 -0
  184. aiecs/llm/config/__init__.py +51 -0
  185. aiecs/llm/config/config_loader.py +275 -0
  186. aiecs/llm/config/config_validator.py +236 -0
  187. aiecs/llm/config/model_config.py +151 -0
  188. aiecs/llm/utils/__init__.py +10 -0
  189. aiecs/llm/utils/validate_config.py +91 -0
  190. aiecs/main.py +363 -0
  191. aiecs/scripts/__init__.py +3 -0
  192. aiecs/scripts/aid/VERSION_MANAGEMENT.md +97 -0
  193. aiecs/scripts/aid/__init__.py +19 -0
  194. aiecs/scripts/aid/version_manager.py +215 -0
  195. aiecs/scripts/dependance_check/DEPENDENCY_SYSTEM_SUMMARY.md +242 -0
  196. aiecs/scripts/dependance_check/README_DEPENDENCY_CHECKER.md +310 -0
  197. aiecs/scripts/dependance_check/__init__.py +17 -0
  198. aiecs/scripts/dependance_check/dependency_checker.py +938 -0
  199. aiecs/scripts/dependance_check/dependency_fixer.py +391 -0
  200. aiecs/scripts/dependance_check/download_nlp_data.py +396 -0
  201. aiecs/scripts/dependance_check/quick_dependency_check.py +270 -0
  202. aiecs/scripts/dependance_check/setup_nlp_data.sh +217 -0
  203. aiecs/scripts/dependance_patch/__init__.py +7 -0
  204. aiecs/scripts/dependance_patch/fix_weasel/README_WEASEL_PATCH.md +126 -0
  205. aiecs/scripts/dependance_patch/fix_weasel/__init__.py +11 -0
  206. aiecs/scripts/dependance_patch/fix_weasel/fix_weasel_validator.py +128 -0
  207. aiecs/scripts/dependance_patch/fix_weasel/fix_weasel_validator.sh +82 -0
  208. aiecs/scripts/dependance_patch/fix_weasel/patch_weasel_library.sh +188 -0
  209. aiecs/scripts/dependance_patch/fix_weasel/run_weasel_patch.sh +41 -0
  210. aiecs/scripts/tools_develop/README.md +449 -0
  211. aiecs/scripts/tools_develop/TOOL_AUTO_DISCOVERY.md +234 -0
  212. aiecs/scripts/tools_develop/__init__.py +21 -0
  213. aiecs/scripts/tools_develop/check_type_annotations.py +259 -0
  214. aiecs/scripts/tools_develop/validate_tool_schemas.py +422 -0
  215. aiecs/scripts/tools_develop/verify_tools.py +356 -0
  216. aiecs/tasks/__init__.py +1 -0
  217. aiecs/tasks/worker.py +172 -0
  218. aiecs/tools/__init__.py +299 -0
  219. aiecs/tools/apisource/__init__.py +99 -0
  220. aiecs/tools/apisource/intelligence/__init__.py +19 -0
  221. aiecs/tools/apisource/intelligence/data_fusion.py +381 -0
  222. aiecs/tools/apisource/intelligence/query_analyzer.py +413 -0
  223. aiecs/tools/apisource/intelligence/search_enhancer.py +388 -0
  224. aiecs/tools/apisource/monitoring/__init__.py +9 -0
  225. aiecs/tools/apisource/monitoring/metrics.py +303 -0
  226. aiecs/tools/apisource/providers/__init__.py +115 -0
  227. aiecs/tools/apisource/providers/base.py +664 -0
  228. aiecs/tools/apisource/providers/census.py +401 -0
  229. aiecs/tools/apisource/providers/fred.py +564 -0
  230. aiecs/tools/apisource/providers/newsapi.py +412 -0
  231. aiecs/tools/apisource/providers/worldbank.py +357 -0
  232. aiecs/tools/apisource/reliability/__init__.py +12 -0
  233. aiecs/tools/apisource/reliability/error_handler.py +375 -0
  234. aiecs/tools/apisource/reliability/fallback_strategy.py +391 -0
  235. aiecs/tools/apisource/tool.py +850 -0
  236. aiecs/tools/apisource/utils/__init__.py +9 -0
  237. aiecs/tools/apisource/utils/validators.py +338 -0
  238. aiecs/tools/base_tool.py +201 -0
  239. aiecs/tools/docs/__init__.py +121 -0
  240. aiecs/tools/docs/ai_document_orchestrator.py +599 -0
  241. aiecs/tools/docs/ai_document_writer_orchestrator.py +2403 -0
  242. aiecs/tools/docs/content_insertion_tool.py +1333 -0
  243. aiecs/tools/docs/document_creator_tool.py +1317 -0
  244. aiecs/tools/docs/document_layout_tool.py +1166 -0
  245. aiecs/tools/docs/document_parser_tool.py +994 -0
  246. aiecs/tools/docs/document_writer_tool.py +1818 -0
  247. aiecs/tools/knowledge_graph/__init__.py +17 -0
  248. aiecs/tools/knowledge_graph/graph_reasoning_tool.py +734 -0
  249. aiecs/tools/knowledge_graph/graph_search_tool.py +923 -0
  250. aiecs/tools/knowledge_graph/kg_builder_tool.py +476 -0
  251. aiecs/tools/langchain_adapter.py +542 -0
  252. aiecs/tools/schema_generator.py +275 -0
  253. aiecs/tools/search_tool/__init__.py +100 -0
  254. aiecs/tools/search_tool/analyzers.py +589 -0
  255. aiecs/tools/search_tool/cache.py +260 -0
  256. aiecs/tools/search_tool/constants.py +128 -0
  257. aiecs/tools/search_tool/context.py +216 -0
  258. aiecs/tools/search_tool/core.py +749 -0
  259. aiecs/tools/search_tool/deduplicator.py +123 -0
  260. aiecs/tools/search_tool/error_handler.py +271 -0
  261. aiecs/tools/search_tool/metrics.py +371 -0
  262. aiecs/tools/search_tool/rate_limiter.py +178 -0
  263. aiecs/tools/search_tool/schemas.py +277 -0
  264. aiecs/tools/statistics/__init__.py +80 -0
  265. aiecs/tools/statistics/ai_data_analysis_orchestrator.py +643 -0
  266. aiecs/tools/statistics/ai_insight_generator_tool.py +505 -0
  267. aiecs/tools/statistics/ai_report_orchestrator_tool.py +694 -0
  268. aiecs/tools/statistics/data_loader_tool.py +564 -0
  269. aiecs/tools/statistics/data_profiler_tool.py +658 -0
  270. aiecs/tools/statistics/data_transformer_tool.py +573 -0
  271. aiecs/tools/statistics/data_visualizer_tool.py +495 -0
  272. aiecs/tools/statistics/model_trainer_tool.py +487 -0
  273. aiecs/tools/statistics/statistical_analyzer_tool.py +459 -0
  274. aiecs/tools/task_tools/__init__.py +86 -0
  275. aiecs/tools/task_tools/chart_tool.py +732 -0
  276. aiecs/tools/task_tools/classfire_tool.py +922 -0
  277. aiecs/tools/task_tools/image_tool.py +447 -0
  278. aiecs/tools/task_tools/office_tool.py +684 -0
  279. aiecs/tools/task_tools/pandas_tool.py +635 -0
  280. aiecs/tools/task_tools/report_tool.py +635 -0
  281. aiecs/tools/task_tools/research_tool.py +392 -0
  282. aiecs/tools/task_tools/scraper_tool.py +715 -0
  283. aiecs/tools/task_tools/stats_tool.py +688 -0
  284. aiecs/tools/temp_file_manager.py +130 -0
  285. aiecs/tools/tool_executor/__init__.py +37 -0
  286. aiecs/tools/tool_executor/tool_executor.py +881 -0
  287. aiecs/utils/LLM_output_structor.py +445 -0
  288. aiecs/utils/__init__.py +34 -0
  289. aiecs/utils/base_callback.py +47 -0
  290. aiecs/utils/cache_provider.py +695 -0
  291. aiecs/utils/execution_utils.py +184 -0
  292. aiecs/utils/logging.py +1 -0
  293. aiecs/utils/prompt_loader.py +14 -0
  294. aiecs/utils/token_usage_repository.py +323 -0
  295. aiecs/ws/__init__.py +0 -0
  296. aiecs/ws/socket_server.py +52 -0
  297. aiecs-1.5.1.dist-info/METADATA +608 -0
  298. aiecs-1.5.1.dist-info/RECORD +302 -0
  299. aiecs-1.5.1.dist-info/WHEEL +5 -0
  300. aiecs-1.5.1.dist-info/entry_points.txt +10 -0
  301. aiecs-1.5.1.dist-info/licenses/LICENSE +225 -0
  302. aiecs-1.5.1.dist-info/top_level.txt +1 -0
@@ -0,0 +1,188 @@
1
+ #!/bin/bash
2
+
3
+ # Comprehensive script to fix weasel library duplicate validator function error
4
+ # This script provides multiple approaches to patch the issue
5
+
6
+ set -e
7
+
8
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9
+ PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
10
+
11
+ echo "🔧 Weasel Library Patcher"
12
+ echo "========================="
13
+ echo "Project directory: $PROJECT_DIR"
14
+ echo ""
15
+
16
+ # Function to check if we're in the right directory
17
+ check_project_structure() {
18
+ if [ ! -f "$PROJECT_DIR/pyproject.toml" ]; then
19
+ echo "❌ Error: pyproject.toml not found. Please run this script from the python-middleware directory"
20
+ exit 1
21
+ fi
22
+ }
23
+
24
+ # Function to get poetry virtual environment path
25
+ get_venv_path() {
26
+ cd "$PROJECT_DIR"
27
+ local venv_path
28
+ venv_path=$(poetry env info --path 2>/dev/null || echo "")
29
+
30
+ if [ -z "$venv_path" ]; then
31
+ echo "❌ Error: Could not find poetry virtual environment"
32
+ echo "Please make sure poetry is installed and the virtual environment is created"
33
+ echo "Try running: poetry install"
34
+ exit 1
35
+ fi
36
+
37
+ echo "$venv_path"
38
+ }
39
+
40
+ # Function to apply the patch
41
+ apply_patch() {
42
+ local venv_path="$1"
43
+ local schemas_file="$venv_path/lib/python3.10/site-packages/weasel/schemas.py"
44
+
45
+ echo "📁 Target file: $schemas_file"
46
+
47
+ if [ ! -f "$schemas_file" ]; then
48
+ echo "❌ Error: weasel schemas.py file not found"
49
+ echo "The weasel package might not be installed or in a different location"
50
+ exit 1
51
+ fi
52
+
53
+ # Create backup
54
+ local backup_file="${schemas_file}.backup.$(date +%Y%m%d_%H%M%S)"
55
+ cp "$schemas_file" "$backup_file"
56
+ echo "💾 Backup created: $backup_file"
57
+
58
+ # Check if already patched
59
+ if grep -q "allow_reuse=True" "$schemas_file"; then
60
+ echo "✅ File already contains allow_reuse=True - may already be patched"
61
+ echo "Checking if the specific issue is resolved..."
62
+ fi
63
+
64
+ # Show current problematic content
65
+ echo ""
66
+ echo "📖 Current content around the problematic area:"
67
+ echo "------------------------------------------------"
68
+ sed -n '85,95p' "$schemas_file" | nl -ba -v85
69
+ echo "------------------------------------------------"
70
+ echo ""
71
+
72
+ # Apply the patch using Python for more precise control
73
+ python3 << EOF
74
+ import re
75
+ import sys
76
+
77
+ schemas_file = "$schemas_file"
78
+
79
+ try:
80
+ with open(schemas_file, 'r') as f:
81
+ content = f.read()
82
+
83
+ # Pattern to find @validator and @root_validator decorators that need allow_reuse=True
84
+ # Look for the specific problematic validator
85
+ pattern = r'(@(?:root_)?validator\([^)]*\))\s*\n(\s*def\s+check_legacy_keys)'
86
+
87
+ def fix_validator(match):
88
+ decorator = match.group(1)
89
+ func_def = match.group(2)
90
+
91
+ # Add allow_reuse=True if not present
92
+ if 'allow_reuse' not in decorator:
93
+ # Remove the closing parenthesis and add allow_reuse=True
94
+ fixed_decorator = decorator[:-1] + ', allow_reuse=True)'
95
+ return fixed_decorator + '\n' + func_def
96
+ return match.group(0)
97
+
98
+ # Apply the fix
99
+ fixed_content = re.sub(pattern, fix_validator, content)
100
+
101
+ # Also fix any other @validator or @root_validator decorators that might have the same issue
102
+ general_pattern = r'(@(?:root_)?validator\([^)]*)\)(?=\s*\n\s*def)'
103
+
104
+ def fix_general_validator(match):
105
+ decorator = match.group(1)
106
+ if 'allow_reuse' not in decorator:
107
+ return decorator + ', allow_reuse=True)'
108
+ return match.group(0)
109
+
110
+ fixed_content = re.sub(general_pattern, fix_general_validator, fixed_content)
111
+
112
+ # Write back the fixed content
113
+ with open(schemas_file, 'w') as f:
114
+ f.write(fixed_content)
115
+
116
+ print("✅ Patch applied successfully")
117
+
118
+ except Exception as e:
119
+ print(f"❌ Error applying patch: {e}")
120
+ sys.exit(1)
121
+ EOF
122
+
123
+ # Show the patched content
124
+ echo ""
125
+ echo "📖 Patched content:"
126
+ echo "-------------------"
127
+ sed -n '85,95p' "$schemas_file" | nl -ba -v85
128
+ echo "-------------------"
129
+ echo ""
130
+
131
+ # Verify the patch
132
+ if grep -q "allow_reuse=True" "$schemas_file"; then
133
+ echo "✅ Verification: allow_reuse=True found in the file"
134
+ else
135
+ echo "⚠️ Warning: allow_reuse=True not found after patching"
136
+ fi
137
+
138
+ echo "💾 Original file backed up to: $backup_file"
139
+ }
140
+
141
+ # Function to test the fix
142
+ test_fix() {
143
+ echo ""
144
+ echo "🧪 Testing the fix..."
145
+ cd "$PROJECT_DIR"
146
+
147
+ # Try to import the problematic module
148
+ if python3 -c "
149
+ import sys
150
+ sys.path.insert(0, '.')
151
+ try:
152
+ from aiecs.tools.task_tools.research_tool import *
153
+ print('✅ Import successful - fix appears to work!')
154
+ except Exception as e:
155
+ print(f'❌ Import still fails: {e}')
156
+ sys.exit(1)
157
+ " 2>/dev/null; then
158
+ echo "✅ Fix verification successful!"
159
+ else
160
+ echo "⚠️ Fix verification failed - you may need to restart your Python environment"
161
+ fi
162
+ }
163
+
164
+ # Main execution
165
+ main() {
166
+ echo "Starting patch process..."
167
+
168
+ check_project_structure
169
+
170
+ local venv_path
171
+ venv_path=$(get_venv_path)
172
+ echo "📍 Virtual environment: $venv_path"
173
+
174
+ apply_patch "$venv_path"
175
+
176
+ test_fix
177
+
178
+ echo ""
179
+ echo "🎉 Weasel library patch completed!"
180
+ echo ""
181
+ echo "Next steps:"
182
+ echo "1. Try running your tests again"
183
+ echo "2. If the issue persists, you may need to restart your Python environment"
184
+ echo "3. To revert changes, restore from the backup file shown above"
185
+ }
186
+
187
+ # Run the main function
188
+ main "$@"
@@ -0,0 +1,41 @@
1
+ #!/bin/bash
2
+
3
+ # Script to run the weasel library patch using poetry
4
+ # This ensures we're working within the correct virtual environment
5
+
6
+ set -e
7
+
8
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9
+ PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
10
+
11
+ echo "🔧 Running Weasel Library Patch via Poetry"
12
+ echo "=========================================="
13
+ echo "Project directory: $PROJECT_DIR"
14
+ echo ""
15
+
16
+ # Change to project directory
17
+ cd "$PROJECT_DIR"
18
+
19
+ # Check if pyproject.toml exists
20
+ if [ ! -f "pyproject.toml" ]; then
21
+ echo "❌ Error: pyproject.toml not found. Please run this script from the python-middleware directory"
22
+ exit 1
23
+ fi
24
+
25
+ # Check if poetry is available
26
+ if ! command -v poetry &> /dev/null; then
27
+ echo "❌ Error: Poetry is not installed or not in PATH"
28
+ echo "Please install poetry first: https://python-poetry.org/docs/#installation"
29
+ exit 1
30
+ fi
31
+
32
+ # Run the Python patch script using poetry
33
+ echo "🚀 Running patch script with poetry..."
34
+ poetry run python3 scripts/fix_weasel_validator.py
35
+
36
+ echo ""
37
+ echo "🎉 Patch execution completed!"
38
+ echo ""
39
+ echo "Next steps:"
40
+ echo "1. Try running your tests again with: poetry run pytest"
41
+ echo "2. If the issue persists, you may need to restart your development environment"
@@ -0,0 +1,449 @@
1
+ # 工具开发辅助脚本
2
+
3
+ 本目录包含用于 AIECS 工具开发和维护的验证脚本,帮助开发者确保工具质量和 Schema 自动生成的有效性。
4
+
5
+ ## 📋 脚本列表
6
+
7
+ ### 1. 工具验证器 (`verify_tools.py`)
8
+
9
+ 快速验证和展示 aiecs.tools 注册的所有工具和功能,帮助开发者了解工具注册情况。
10
+
11
+ **用途**:
12
+ - 列出所有注册的工具及其状态
13
+ - 显示每个工具的描述和功能方法
14
+ - 提供工具使用示例
15
+ - 分析工具注册表信息
16
+ - 展示工具继承关系和模块分布
17
+
18
+ **命令**:
19
+ ```bash
20
+ # 从项目根目录运行(推荐)
21
+ python -m aiecs.scripts.tools_develop.verify_tools
22
+
23
+ # 直接运行脚本
24
+ python aiecs/scripts/tools_develop/verify_tools.py
25
+ ```
26
+
27
+ **输出示例**:
28
+ ```
29
+ ================================================================================
30
+ AIECS Tools 注册工具验证
31
+ ================================================================================
32
+
33
+ 发现 26 个注册的工具
34
+
35
+ ================================================================================
36
+ 📁 任务工具 (10 个)
37
+ ================================================================================
38
+
39
+ [1] chart
40
+ 描述: Chart and visualization operations
41
+ 状态: loaded
42
+
43
+ [2] pandas
44
+ 描述: Data analysis and manipulation
45
+ 状态: loaded
46
+
47
+ ... (更多工具)
48
+
49
+ ================================================================================
50
+ 📁 文档工具 (7 个)
51
+ ================================================================================
52
+
53
+ [11] document_parser
54
+ 描述: Document parsing and content extraction
55
+ 状态: loaded
56
+
57
+ ... (更多工具)
58
+
59
+ ================================================================================
60
+ 📁 数据统计工具 (9 个)
61
+ ================================================================================
62
+
63
+ [18] data_loader
64
+ 描述: Universal data loading from multiple formats
65
+ 状态: loaded
66
+
67
+ ... (更多工具)
68
+
69
+ ================================================================================
70
+ ✅ 工具列表显示完成! 共 26 个工具
71
+ ================================================================================
72
+
73
+ ================================================================================
74
+ 🎮 交互模式
75
+ ================================================================================
76
+
77
+ 提示:
78
+ - 输入工具序号 (1-26) 查看详细功能
79
+ - 输入工具名称查看详细功能
80
+ - 输入 'list' 重新显示工具列表
81
+ - 输入 'q' 或 'quit' 退出
82
+
83
+ 👉 请选择工具 > pandas
84
+
85
+ ================================================================================
86
+ 🔍 加载工具: pandas
87
+ ================================================================================
88
+
89
+ ⏳ 正在加载...
90
+ 已触发 task_tools.pandas_tool 模块加载
91
+
92
+ ✅ 工具已成功加载
93
+ 类名: PandasTool
94
+ 模块: aiecs.tools.task_tools.pandas_tool
95
+
96
+ 📋 原子功能列表 (共 41 个方法):
97
+ --------------------------------------------------------------------------------
98
+
99
+ [1] apply(records: List, func: str, columns: List, axis: int = 0) -> List
100
+ Apply a function to specified columns or rows.
101
+
102
+ [2] astype(records: List, dtypes: Dict) -> List
103
+ Convert column types in DataFrame.
104
+
105
+ [3] concat(records_list: List, axis: int = 0) -> List
106
+ Concatenate multiple DataFrames.
107
+
108
+ ... (更多方法)
109
+
110
+ [41] write_file(records: List, file_path: str, file_type: str = 'csv') -> Dict
111
+ Write DataFrame to a file.
112
+
113
+ --------------------------------------------------------------------------------
114
+ ```
115
+
116
+ ### 2. 类型注解检查器 (`check_type_annotations.py`)
117
+
118
+ 检查工具方法的类型注解完整性,确保所有方法都有完整的类型注解(参数类型 + 返回类型)。
119
+
120
+ **用途**:
121
+ - 验证新开发的工具是否有完整的类型注解
122
+ - 检查现有工具的类型注解覆盖率
123
+ - 为自动 Schema 生成提供基础保障
124
+
125
+ **命令**:
126
+ ```bash
127
+ # 检查所有工具
128
+ aiecs-tools-check-annotations
129
+
130
+ # 检查特定工具
131
+ aiecs-tools-check-annotations pandas
132
+
133
+ # 检查多个工具
134
+ aiecs-tools-check-annotations pandas chart image
135
+
136
+ # 显示详细的改进建议
137
+ aiecs-tools-check-annotations pandas --verbose
138
+ ```
139
+
140
+ **输出示例**:
141
+ ```
142
+ ====================================================================================================
143
+ 工具类型注解检查器
144
+ ====================================================================================================
145
+
146
+ ✅ pandas: 38/38 方法有完整类型注解 (100.0%)
147
+
148
+ ⚠️ my_tool: 5/10 方法有完整类型注解 (50.0%)
149
+
150
+ 需要改进的方法:
151
+ ✗ process_data: 无类型注解
152
+ ⚠ filter_records: 部分类型注解
153
+ → 为参数 'condition' 添加类型注解
154
+ → 添加返回类型注解
155
+
156
+ ====================================================================================================
157
+ 总体统计: 43/48 方法有完整类型注解 (89.6%)
158
+ ====================================================================================================
159
+ ```
160
+
161
+ ### 3. Schema 质量验证器 (`validate_tool_schemas.py`)
162
+
163
+ 验证自动生成的 Schema 质量,识别需要改进的文档字符串。
164
+
165
+ **用途**:
166
+ - 验证 Schema 自动生成是否成功
167
+ - 评估生成的 Schema 描述质量
168
+ - 指导开发者改进文档字符串
169
+
170
+ **命令**:
171
+ ```bash
172
+ # 验证所有工具
173
+ aiecs-tools-validate-schemas
174
+
175
+ # 验证特定工具
176
+ aiecs-tools-validate-schemas pandas
177
+
178
+ # 显示详细的改进建议
179
+ aiecs-tools-validate-schemas pandas --verbose
180
+
181
+ # 显示示例 Schema
182
+ aiecs-tools-validate-schemas pandas --show-examples
183
+ ```
184
+
185
+ **输出示例**:
186
+ ```
187
+ ====================================================================================================
188
+ 工具 Schema 质量验证器
189
+ ====================================================================================================
190
+
191
+ ✅ chart
192
+ 方法数: 3
193
+ 成功生成 Schema: 3 (100.0%)
194
+ 描述质量: 100.0%
195
+ 综合评分: 100.0% (A (优秀))
196
+
197
+ ❌ pandas
198
+ 方法数: 38
199
+ 成功生成 Schema: 38 (100.0%)
200
+ 描述质量: 0.0%
201
+ 综合评分: 66.7% (D (需改进))
202
+
203
+ 需要改进的方法 (38 个):
204
+
205
+ filter:
206
+ 💡 在文档字符串的 Args 部分为参数 'records' 添加描述
207
+ 💡 在文档字符串的 Args 部分为参数 'condition' 添加描述
208
+
209
+ ====================================================================================================
210
+ 总体统计:
211
+ 方法数: 41
212
+ Schema 生成率: 41/41 (100.0%)
213
+ 描述质量: 7.3%
214
+ ====================================================================================================
215
+ ```
216
+
217
+ ## 🚀 工具开发工作流
218
+
219
+ ### 新工具开发流程
220
+
221
+ 1. **编写工具类**
222
+ ```python
223
+ from aiecs.tools.base_tool import BaseTool
224
+ from typing import List, Dict
225
+
226
+ class MyTool(BaseTool):
227
+ """My custom tool"""
228
+
229
+ def process(self, data: List[Dict], threshold: float = 0.5) -> Dict:
230
+ """
231
+ Process data with threshold.
232
+
233
+ Args:
234
+ data: Input data to process
235
+ threshold: Processing threshold (0.0 to 1.0)
236
+
237
+ Returns:
238
+ Processing results
239
+ """
240
+ pass
241
+ ```
242
+
243
+ 2. **检查类型注解**
244
+ ```bash
245
+ aiecs-tools-check-annotations my_tool --verbose
246
+ ```
247
+
248
+ 确保所有方法都有 ✅ 标记。
249
+
250
+ 3. **验证 Schema 质量**
251
+ ```bash
252
+ aiecs-tools-validate-schemas my_tool --show-examples
253
+ ```
254
+
255
+ 目标:综合评分 ≥ 80% (B 良好)
256
+
257
+ 4. **改进文档字符串**
258
+
259
+ 根据验证器的建议,改进文档字符串:
260
+ ```python
261
+ def process(self, data: List[Dict], threshold: float = 0.5) -> Dict:
262
+ """
263
+ Process data with threshold filtering.
264
+
265
+ Args:
266
+ data: List of data records to process (each record is a dict)
267
+ threshold: Minimum confidence threshold for filtering (0.0 to 1.0, default: 0.5)
268
+
269
+ Returns:
270
+ Dictionary containing processed results and statistics
271
+ """
272
+ pass
273
+ ```
274
+
275
+ 5. **重新验证**
276
+ ```bash
277
+ aiecs-tools-validate-schemas my_tool
278
+ ```
279
+
280
+ ### 现有工具维护流程
281
+
282
+ 1. **定期检查**
283
+ ```bash
284
+ # 每次修改工具后运行
285
+ aiecs-tools-check-annotations my_tool
286
+ aiecs-tools-validate-schemas my_tool
287
+ ```
288
+
289
+ 2. **批量检查**
290
+ ```bash
291
+ # 检查所有工具
292
+ aiecs-tools-check-annotations
293
+ aiecs-tools-validate-schemas
294
+ ```
295
+
296
+ 3. **持续改进**
297
+ - 优先改进评分 < 80% 的工具
298
+ - 为通用描述(如 "Parameter xxx")添加有意义的说明
299
+
300
+ ## 📊 质量标准
301
+
302
+ ### 类型注解标准
303
+
304
+ - ✅ **优秀 (100%)**:所有方法都有完整类型注解
305
+ - ⚠️ **良好 (80-99%)**:大部分方法有完整类型注解
306
+ - ❌ **需改进 (<80%)**:缺少大量类型注解
307
+
308
+ ### Schema 质量标准
309
+
310
+ - ✅ **A (优秀) ≥90%**:Schema 生成成功,描述质量高
311
+ - ⚠️ **B (良好) 80-89%**:Schema 生成成功,描述质量中等
312
+ - ⚠️ **C (中等) 70-79%**:Schema 生成成功,描述质量较低
313
+ - ❌ **D (需改进) <70%**:Schema 生成失败或描述质量差
314
+
315
+ ## 💡 最佳实践
316
+
317
+ ### 1. 完整的类型注解
318
+
319
+ ```python
320
+ # ✅ 好的示例
321
+ def filter(self, records: List[Dict], condition: str) -> List[Dict]:
322
+ pass
323
+
324
+ # ❌ 不好的示例
325
+ def filter(self, records, condition): # 缺少类型注解
326
+ pass
327
+
328
+ def filter(self, records: List[Dict], condition): # 部分缺失
329
+ pass
330
+ ```
331
+
332
+ ### 2. 详细的文档字符串
333
+
334
+ 使用 Google 或 NumPy 风格:
335
+
336
+ ```python
337
+ # ✅ Google 风格(推荐)
338
+ def filter(self, records: List[Dict], condition: str) -> List[Dict]:
339
+ """
340
+ Filter DataFrame based on a condition.
341
+
342
+ Args:
343
+ records: List of records to filter (each record is a dict)
344
+ condition: Filter condition using pandas query syntax (e.g., 'age > 30')
345
+
346
+ Returns:
347
+ Filtered list of records
348
+ """
349
+ pass
350
+
351
+ # ✅ NumPy 风格
352
+ def filter(self, records: List[Dict], condition: str) -> List[Dict]:
353
+ """
354
+ Filter DataFrame based on a condition.
355
+
356
+ Parameters
357
+ ----------
358
+ records : List[Dict]
359
+ List of records to filter (each record is a dict)
360
+ condition : str
361
+ Filter condition using pandas query syntax (e.g., 'age > 30')
362
+
363
+ Returns
364
+ -------
365
+ List[Dict]
366
+ Filtered list of records
367
+ """
368
+ pass
369
+ ```
370
+
371
+ ### 3. 有意义的描述
372
+
373
+ ```python
374
+ # ❌ 不好的描述
375
+ """
376
+ Args:
377
+ records: Parameter records
378
+ condition: Parameter condition
379
+ """
380
+
381
+ # ✅ 好的描述
382
+ """
383
+ Args:
384
+ records: List of data records to filter (each record contains fields like 'name', 'age', etc.)
385
+ condition: Filter condition using pandas query syntax (e.g., 'age > 30 and status == "active"')
386
+ """
387
+ ```
388
+
389
+ ### 4. 处理复杂类型
390
+
391
+ ```python
392
+ from typing import List, Dict, Optional, Union
393
+ import pandas as pd
394
+
395
+ # ✅ 使用标准类型
396
+ def process(self, data: List[Dict]) -> Dict:
397
+ pass
398
+
399
+ # ✅ pandas 类型会自动映射为 Any
400
+ def process(self, df: pd.DataFrame) -> pd.DataFrame:
401
+ pass
402
+
403
+ # ✅ 可选参数
404
+ def process(self, data: List[Dict], config: Optional[Dict] = None) -> Dict:
405
+ pass
406
+ ```
407
+
408
+ ## 🔧 故障排查
409
+
410
+ ### 问题:类型注解检查失败
411
+
412
+ **原因**:缺少类型注解或使用了不支持的类型
413
+
414
+ **解决**:
415
+ 1. 为所有参数添加类型注解
416
+ 2. 添加返回类型注解
417
+ 3. 使用标准类型(List, Dict, str, int, float, bool 等)
418
+
419
+ ### 问题:Schema 生成失败
420
+
421
+ **原因**:
422
+ - 方法没有参数(除了 self)→ 这是正常的,无需 Schema
423
+ - 类型注解不完整 → 运行类型注解检查器
424
+ - 使用了不支持的类型 → 会自动映射为 Any
425
+
426
+ ### 问题:描述质量低
427
+
428
+ **原因**:文档字符串缺少 Args 部分或描述不详细
429
+
430
+ **解决**:
431
+ 1. 添加文档字符串的 Args 部分
432
+ 2. 为每个参数添加详细描述
433
+ 3. 使用 Google 或 NumPy 风格
434
+
435
+ ## 📚 相关文档
436
+
437
+ - [Schema Generator 技术文档](../../../docs/TOOLS/TOOLS_SCHEMA_GENERATOR.md)
438
+ - [LangChain Adapter 技术文档](../../../docs/TOOLS/TOOLS_LANGCHAIN_ADAPTER.md)
439
+ - [BaseTool 开发指南](../../../docs/TOOLS/TOOLS_BASE_TOOL.md)
440
+
441
+ ## 🤝 贡献
442
+
443
+ 如果你发现这些工具有改进空间,欢迎提交 PR 或 Issue!
444
+
445
+ ---
446
+
447
+ **维护者**: AIECS Tools Team
448
+ **最后更新**: 2025-10-02
449
+