feat(dc/tool-c): 完成AI代码生成服务(Day 3 MVP)
核心功能: - 新增AICodeService(550行):AI代码生成核心服务 - 新增AIController(257行):4个API端点 - 新增dc_tool_c_ai_history表:存储对话历史 - 实现自我修正机制:最多3次智能重试 - 集成LLMFactory:复用通用能力层 - 10个Few-shot示例:覆盖Level 1-4场景 技术优化: - 修复NaN序列化问题(Python端转None) - 修复数据传递问题(从Session获取真实数据) - 优化System Prompt(明确环境信息) - 调整Few-shot示例(移除import语句) 测试结果: - 通过率:9/11(81.8%) 达到MVP标准 - 成功场景:缺失值处理、编码、分箱、BMI、筛选、填补、统计、分类 - 待优化:数值清洗、智能去重(已记录技术债务TD-C-006) API端点: - POST /api/v1/dc/tool-c/ai/generate(生成代码) - POST /api/v1/dc/tool-c/ai/execute(执行代码) - POST /api/v1/dc/tool-c/ai/process(生成并执行,一步到位) - GET /api/v1/dc/tool-c/ai/history/:sessionId(对话历史) 文档更新: - 新增Day 3开发完成总结(770行) - 新增复杂场景优化技术债务(TD-C-006) - 更新工具C当前状态文档 - 更新技术债务清单 影响范围: - backend/src/modules/dc/tool-c/*(新增2个文件,更新1个文件) - backend/scripts/create-tool-c-ai-history-table.mjs(新增) - backend/prisma/schema.prisma(新增DcToolCAiHistory模型) - extraction_service/services/dc_executor.py(NaN序列化修复) - docs/03-业务模块/DC-数据清洗整理/*(5份文档更新) Breaking Changes: 无 总代码行数:+950行 Refs: #Tool-C-Day3
This commit is contained in:
47
extraction_service/test_execute_simple.py
Normal file
47
extraction_service/test_execute_simple.py
Normal file
@@ -0,0 +1,47 @@
|
||||
"""简单的代码执行测试"""
|
||||
import requests
|
||||
import json
|
||||
|
||||
# 测试数据
|
||||
test_data = [
|
||||
{"patient_id": "P001", "age": 25, "gender": "男"},
|
||||
{"patient_id": "P002", "age": 65, "gender": "女"},
|
||||
{"patient_id": "P003", "age": 45, "gender": "男"},
|
||||
]
|
||||
|
||||
# 测试代码
|
||||
test_code = """
|
||||
df['age_group'] = df['age'].apply(lambda x: '老年' if x > 60 else '非老年')
|
||||
print(f"处理完成,共 {len(df)} 行")
|
||||
"""
|
||||
|
||||
print("=" * 60)
|
||||
print("测试: Pandas代码执行")
|
||||
print("=" * 60)
|
||||
|
||||
try:
|
||||
response = requests.post(
|
||||
"http://localhost:8000/api/dc/execute",
|
||||
json={"data": test_data, "code": test_code},
|
||||
timeout=10
|
||||
)
|
||||
|
||||
print(f"\n状态码: {response.status_code}")
|
||||
result = response.json()
|
||||
print(json.dumps(result, indent=2, ensure_ascii=False))
|
||||
|
||||
if result.get("success"):
|
||||
print("\n✅ 代码执行成功!")
|
||||
print(f"结果数据: {len(result.get('result_data', []))} 行")
|
||||
print(f"执行时间: {result.get('execution_time', 0):.3f}秒")
|
||||
print(f"\n打印输出:\n{result.get('output', '')}")
|
||||
print(f"\n结果数据示例:")
|
||||
for row in result.get('result_data', [])[:3]:
|
||||
print(f" {row}")
|
||||
else:
|
||||
print(f"\n❌ 代码执行失败: {result.get('error')}")
|
||||
|
||||
except Exception as e:
|
||||
print(f"\n❌ 测试异常: {str(e)}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user