去除ROS2相关内容,新增一键启动脚本
This commit is contained in:
@@ -17,7 +17,7 @@ SUMMARY_CSV = "test_summary.csv"
|
||||
LOG_FILE = "api_test_log.txt"
|
||||
|
||||
# 测试参数
|
||||
TESTS_PER_INSTRUCTION = 10
|
||||
TESTS_PER_INSTRUCTION = 1
|
||||
MAX_RETRIES = 3
|
||||
RETRY_DELAY = 2
|
||||
|
||||
@@ -207,20 +207,38 @@ def read_instructions(filename):
|
||||
return []
|
||||
|
||||
def write_log_entry(log_file, instruction_idx, run_number, prompt, result):
|
||||
"""写入详细日志"""
|
||||
"""写入详细日志,包含完整的API响应"""
|
||||
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||
|
||||
with open(log_file, 'a', encoding='utf-8') as f:
|
||||
f.write(f"\n{'='*80}\n")
|
||||
f.write(f"指令 #{instruction_idx} - 运行 #{run_number} - {timestamp}\n")
|
||||
f.write(f"HTTP状态: {result.get('http_status', 'N/A')}\n")
|
||||
f.write(f"指令: {prompt}\n")
|
||||
f.write(f"原始指令: {prompt}\n")
|
||||
f.write(f"尝试次数: {result['attempts']}\n")
|
||||
f.write(f"响应时间: {result['response_time']:.2f}秒\n")
|
||||
f.write(f"结果: {'✅ 成功' if result['success'] else '❌ 失败'}\n")
|
||||
|
||||
if result['success']:
|
||||
f.write("验证结果:\n")
|
||||
if result['success'] and result.get('data'):
|
||||
data = result['data']
|
||||
|
||||
# 提取并记录组织后的prompt(如果存在)
|
||||
organized_prompt = None
|
||||
if isinstance(data, dict):
|
||||
organized_prompt = data.get("organized_prompt") or \
|
||||
data.get("processed_prompt") or \
|
||||
data.get("final_prompt") or \
|
||||
data.get("enhanced_prompt") or \
|
||||
data.get("user_prompt_enhanced")
|
||||
|
||||
if organized_prompt:
|
||||
f.write(f"\n📝 组织后的Prompt:\n")
|
||||
f.write(f"{organized_prompt}\n")
|
||||
else:
|
||||
f.write(f"\n📝 组织后的Prompt: (未在响应中返回)\n")
|
||||
|
||||
# 记录验证结果
|
||||
f.write("\n验证结果:\n")
|
||||
for check_name, check_result in result['validation_checks'].items():
|
||||
f.write(f" {check_name}: {'✅' if check_result else '❌'}\n")
|
||||
|
||||
@@ -229,8 +247,27 @@ def write_log_entry(log_file, instruction_idx, run_number, prompt, result):
|
||||
|
||||
if result['invalid_conditions']:
|
||||
f.write(f"⚠️ 无效条件节点: {result['invalid_conditions']}\n")
|
||||
|
||||
# 记录完整的API响应
|
||||
f.write(f"\n完整API响应:\n")
|
||||
try:
|
||||
response_json = json.dumps(data, indent=2, ensure_ascii=False)
|
||||
f.write(response_json)
|
||||
f.write("\n")
|
||||
except Exception as e:
|
||||
f.write(f"⚠️ 无法序列化响应数据: {e}\n")
|
||||
f.write(f"原始数据: {str(data)}\n")
|
||||
else:
|
||||
f.write(f"错误信息: {result['error']}\n")
|
||||
# 即使失败也尝试记录响应数据(如果有)
|
||||
if result.get('data'):
|
||||
f.write(f"\n部分响应数据:\n")
|
||||
try:
|
||||
response_json = json.dumps(result['data'], indent=2, ensure_ascii=False)
|
||||
f.write(response_json)
|
||||
f.write("\n")
|
||||
except Exception:
|
||||
f.write(f"原始数据: {str(result['data'])}\n")
|
||||
|
||||
def generate_summary_report(instructions, results_summary):
|
||||
"""
|
||||
@@ -311,6 +348,10 @@ def main():
|
||||
write_log_entry(LOG_FILE, instruction_idx, run_number, prompt, result)
|
||||
|
||||
# 记录结果
|
||||
plan_id = ""
|
||||
if result.get("success") and result.get("data") and isinstance(result["data"], dict):
|
||||
plan_id = result["data"].get("plan_id", "")
|
||||
|
||||
detailed_result = {
|
||||
"instruction_index": instruction_idx,
|
||||
"instruction": prompt,
|
||||
@@ -318,7 +359,7 @@ def main():
|
||||
"success": result["success"],
|
||||
"attempts": result["attempts"],
|
||||
"response_time": result["response_time"],
|
||||
"http_status": result.get("http_status"),
|
||||
"plan_id": plan_id,
|
||||
"error": result["error"] or "",
|
||||
"timestamp": datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||
}
|
||||
@@ -363,6 +404,10 @@ def main():
|
||||
# 生成统计摘要
|
||||
generate_summary_report(instructions, results_summary)
|
||||
|
||||
# 计算总统计
|
||||
total_tests = len(instructions) * TESTS_PER_INSTRUCTION
|
||||
total_successful = sum(summary['success_count'] for summary in results_summary)
|
||||
|
||||
# 打印最终统计
|
||||
print(f"\n{'='*60}")
|
||||
print("📈 最终测试统计")
|
||||
@@ -370,7 +415,10 @@ def main():
|
||||
print(f"总测试次数: {total_tests}")
|
||||
print(f"成功次数: {total_successful}")
|
||||
print(f"失败次数: {total_tests - total_successful}")
|
||||
print(f"总成功率: {(total_successful / total_tests * 100):.2f}%")
|
||||
if total_tests > 0:
|
||||
print(f"总成功率: {(total_successful / total_tests * 100):.2f}%")
|
||||
else:
|
||||
print(f"总成功率: N/A")
|
||||
|
||||
# 打印每个指令的统计
|
||||
print(f"\n📋 每个指令的统计:")
|
||||
|
||||
Reference in New Issue
Block a user