Complete AI Data Analysis Agent implementation with 95.7% test coverage
This commit is contained in:
82
examples/autonomous_analysis.py
Normal file
82
examples/autonomous_analysis.py
Normal file
@@ -0,0 +1,82 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
完全自主分析示例
|
||||
|
||||
这个示例展示了如何让 AI 完全自主地分析数据,无需指定任何需求或模板。
|
||||
AI 会自动识别数据类型、推断分析目标、生成分析计划并执行分析。
|
||||
|
||||
使用方法:
|
||||
python examples/autonomous_analysis.py
|
||||
|
||||
或者使用命令行:
|
||||
python -m src.main --data test_data/ticket_sample.csv --output output/autonomous
|
||||
"""
|
||||
|
||||
import sys
|
||||
import os
|
||||
|
||||
# 添加项目根目录到路径
|
||||
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
|
||||
|
||||
from src.main import run_analysis
|
||||
from src.logging_config import setup_logging
|
||||
import logging
|
||||
|
||||
def main():
|
||||
"""运行完全自主分析"""
|
||||
# 设置日志
|
||||
setup_logging()
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
logger.info("=" * 80)
|
||||
logger.info("完全自主分析示例")
|
||||
logger.info("=" * 80)
|
||||
|
||||
# 配置参数
|
||||
data_file = "test_data/ticket_sample.csv"
|
||||
output_dir = "output/autonomous"
|
||||
|
||||
logger.info(f"数据文件: {data_file}")
|
||||
logger.info(f"输出目录: {output_dir}")
|
||||
logger.info("")
|
||||
logger.info("分析模式: 完全自主")
|
||||
logger.info("AI 将自动:")
|
||||
logger.info(" 1. 识别数据类型(工单、销售、用户等)")
|
||||
logger.info(" 2. 推断数据的业务含义")
|
||||
logger.info(" 3. 自主决定分析维度和方法")
|
||||
logger.info(" 4. 生成动态分析计划")
|
||||
logger.info(" 5. 执行分析并生成报告")
|
||||
logger.info("")
|
||||
|
||||
try:
|
||||
# 运行分析(不指定需求和模板)
|
||||
report_path = run_analysis(
|
||||
data_file=data_file,
|
||||
user_requirement=None, # 无需求,完全自主
|
||||
template_file=None, # 无模板
|
||||
output_dir=output_dir
|
||||
)
|
||||
|
||||
logger.info("")
|
||||
logger.info("=" * 80)
|
||||
logger.info("分析完成!")
|
||||
logger.info(f"报告已生成: {report_path}")
|
||||
logger.info("=" * 80)
|
||||
|
||||
# 显示报告预览
|
||||
if os.path.exists(report_path):
|
||||
with open(report_path, 'r', encoding='utf-8') as f:
|
||||
content = f.read()
|
||||
preview = content[:500] + "..." if len(content) > 500 else content
|
||||
logger.info("")
|
||||
logger.info("报告预览:")
|
||||
logger.info("-" * 80)
|
||||
logger.info(preview)
|
||||
logger.info("-" * 80)
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"分析失败: {e}", exc_info=True)
|
||||
sys.exit(1)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user