2026-01-06 19:44:17 +08:00
|
|
|
|
|
|
|
|
from typing import Any, Dict
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def format_execution_result(result: Dict[str, Any]) -> str:
|
|
|
|
|
"""格式化执行结果为用户可读的反馈"""
|
|
|
|
|
feedback = []
|
|
|
|
|
|
|
|
|
|
if result['success']:
|
2026-01-31 18:00:05 +08:00
|
|
|
feedback.append("[OK] 代码执行成功")
|
2026-01-06 19:44:17 +08:00
|
|
|
|
|
|
|
|
if result['output']:
|
2026-01-31 18:00:05 +08:00
|
|
|
feedback.append(f"[CHART] 输出结果:\n{result['output']}")
|
2026-01-06 19:44:17 +08:00
|
|
|
|
|
|
|
|
if result.get('variables'):
|
2026-01-31 18:00:05 +08:00
|
|
|
feedback.append("[LIST] 新生成的变量:")
|
2026-01-06 19:44:17 +08:00
|
|
|
for var_name, var_info in result['variables'].items():
|
|
|
|
|
feedback.append(f" - {var_name}: {var_info}")
|
|
|
|
|
else:
|
2026-01-31 18:00:05 +08:00
|
|
|
feedback.append("[ERROR] 代码执行失败")
|
2026-01-06 19:44:17 +08:00
|
|
|
feedback.append(f"错误信息: {result['error']}")
|
|
|
|
|
if result['output']:
|
|
|
|
|
feedback.append(f"部分输出: {result['output']}")
|
|
|
|
|
|
|
|
|
|
return "\n".join(feedback)
|