Add workplace verifiers for ClawBenchPro
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- checksums.sha256 +0 -0
- manifest.json +8 -6
- persona_aligned_mix_200/checksums.sha256 +0 -0
- persona_aligned_mix_200/manifest.json +8 -2
- persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0001/verify_workplace.py +68 -0
- persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0002/verify_workplace.py +78 -0
- persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0003/verify_workplace.py +105 -0
- persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0004/verify_workplace.py +79 -0
- persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0005/verify_workplace.py +96 -0
- persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0006/verify_workplace.py +120 -0
- persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0007/verify_workplace.py +116 -0
- persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0008/verify_workplace.py +61 -0
- persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0009/verify_workplace.py +216 -0
- persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0010/verify_workplace.py +117 -0
- persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0011/verify_workplace.py +74 -0
- persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0012/verify_workplace.py +111 -0
- persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0013/verify_workplace.py +110 -0
- persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0014/verify_workplace.py +93 -0
- persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0015/verify_workplace.py +114 -0
- persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0016/verify_workplace.py +160 -0
- persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0017/verify_workplace.py +124 -0
- persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0018/verify_workplace.py +142 -0
- persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0019/verify_workplace.py +107 -0
- persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0020/verify_workplace.py +156 -0
- persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0021/verify_workplace.py +214 -0
- persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0022/verify_workplace.py +117 -0
- persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0023/verify_workplace.py +132 -0
- persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0024/verify_workplace.py +122 -0
- persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0025/verify_workplace.py +129 -0
- persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0026/verify_workplace.py +170 -0
- persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0027/verify_workplace.py +193 -0
- persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0028/verify_workplace.py +136 -0
- persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0029/verify_workplace.py +172 -0
- persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0030/verify_workplace.py +159 -0
- persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0031/verify_workplace.py +138 -0
- persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0032/verify_workplace.py +226 -0
- persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0033/verify_workplace.py +174 -0
- persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0034/verify_workplace.py +132 -0
- persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0035/verify_workplace.py +185 -0
- persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0036/verify_workplace.py +164 -0
- persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0037/verify_workplace.py +183 -0
- persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0038/verify_workplace.py +130 -0
- persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0039/verify_workplace.py +1 -0
- persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0040/verify_workplace.py +162 -0
- persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0041/verify_workplace.py +100 -0
- persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0042/verify_workplace.py +135 -0
- persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0043/verify_workplace.py +64 -0
- persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0044/verify_workplace.py +114 -0
- persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0045/verify_workplace.py +180 -0
- persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0046/verify_workplace.py +100 -0
checksums.sha256
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
manifest.json
CHANGED
|
@@ -16,9 +16,10 @@
|
|
| 16 |
"multi_turn_aligned": 200,
|
| 17 |
"skills_aligned": 200
|
| 18 |
},
|
| 19 |
-
"files":
|
| 20 |
-
"bytes":
|
| 21 |
-
"checksums": "round_01_aligned_mix_800/checksums.sha256"
|
|
|
|
| 22 |
},
|
| 23 |
{
|
| 24 |
"name": "persona_aligned_mix_200",
|
|
@@ -31,9 +32,10 @@
|
|
| 31 |
"multi_turn": 50,
|
| 32 |
"skills": 50
|
| 33 |
},
|
| 34 |
-
"files":
|
| 35 |
-
"bytes":
|
| 36 |
-
"checksums": "persona_aligned_mix_200/checksums.sha256"
|
|
|
|
| 37 |
}
|
| 38 |
]
|
| 39 |
}
|
|
|
|
| 16 |
"multi_turn_aligned": 200,
|
| 17 |
"skills_aligned": 200
|
| 18 |
},
|
| 19 |
+
"files": 6358,
|
| 20 |
+
"bytes": 23733095,
|
| 21 |
+
"checksums": "round_01_aligned_mix_800/checksums.sha256",
|
| 22 |
+
"verifiers": "round_01_aligned_mix_800/verifiers"
|
| 23 |
},
|
| 24 |
{
|
| 25 |
"name": "persona_aligned_mix_200",
|
|
|
|
| 32 |
"multi_turn": 50,
|
| 33 |
"skills": 50
|
| 34 |
},
|
| 35 |
+
"files": 1396,
|
| 36 |
+
"bytes": 5965620,
|
| 37 |
+
"checksums": "persona_aligned_mix_200/checksums.sha256",
|
| 38 |
+
"verifiers": "persona_aligned_mix_200/verifiers"
|
| 39 |
}
|
| 40 |
]
|
| 41 |
}
|
persona_aligned_mix_200/checksums.sha256
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
persona_aligned_mix_200/manifest.json
CHANGED
|
@@ -39,8 +39,8 @@
|
|
| 39 |
}
|
| 40 |
},
|
| 41 |
"files": {
|
| 42 |
-
"count":
|
| 43 |
-
"bytes":
|
| 44 |
"checksums": "checksums.sha256"
|
| 45 |
},
|
| 46 |
"skills": {
|
|
@@ -177,5 +177,11 @@
|
|
| 177 |
"data-persona-aligned-skills-50-0050-query-xid-v1",
|
| 178 |
"data-persona-aligned-skills-50-0050-query-xid-v2"
|
| 179 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 180 |
}
|
| 181 |
}
|
|
|
|
| 39 |
}
|
| 40 |
},
|
| 41 |
"files": {
|
| 42 |
+
"count": 1396,
|
| 43 |
+
"bytes": 5965620,
|
| 44 |
"checksums": "checksums.sha256"
|
| 45 |
},
|
| 46 |
"skills": {
|
|
|
|
| 177 |
"data-persona-aligned-skills-50-0050-query-xid-v1",
|
| 178 |
"data-persona-aligned-skills-50-0050-query-xid-v2"
|
| 179 |
]
|
| 180 |
+
},
|
| 181 |
+
"verifiers": {
|
| 182 |
+
"base": "verifiers/base.jsonl",
|
| 183 |
+
"multi_turn": "verifiers/multi_turn.jsonl",
|
| 184 |
+
"hard": "verifiers/hard.jsonl",
|
| 185 |
+
"skills": "verifiers/skills.jsonl"
|
| 186 |
}
|
| 187 |
}
|
persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0001/verify_workplace.py
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
import json
|
| 4 |
+
|
| 5 |
+
def verify():
|
| 6 |
+
workspace = sys.argv[1] if len(sys.argv) > 1 else "."
|
| 7 |
+
target_file = os.path.join(workspace, "triage", "conflict_target.json")
|
| 8 |
+
|
| 9 |
+
score = 0
|
| 10 |
+
details = []
|
| 11 |
+
|
| 12 |
+
# 1. 检查文件是否存在与基础格式 (10分)
|
| 13 |
+
if os.path.exists(target_file):
|
| 14 |
+
try:
|
| 15 |
+
with open(target_file, 'r', encoding='utf-8') as f:
|
| 16 |
+
data = json.load(f)
|
| 17 |
+
score += 10
|
| 18 |
+
details.append({"item": "JSON文件存在且格式正确", "score": 10, "max_score": 10, "passed": True, "reason": "文件读取成功"})
|
| 19 |
+
except Exception as e:
|
| 20 |
+
details.append({"item": "JSON文件格式解析", "score": 0, "max_score": 10, "passed": False, "reason": f"解析失败: {str(e)}"})
|
| 21 |
+
data = {}
|
| 22 |
+
else:
|
| 23 |
+
details.append({"item": "JSON文件是否存在", "score": 0, "max_score": 10, "passed": False, "reason": "未找到 triage/conflict_target.json"})
|
| 24 |
+
data = {}
|
| 25 |
+
|
| 26 |
+
# 预定义的标准答案 (根据 env_builder.py 的逻辑)
|
| 27 |
+
# 冲突发生点:node-beta 在收到 node-gamma (T5) 的心跳时,本地 index 100 的 term 是 4
|
| 28 |
+
expected_node = "node-beta"
|
| 29 |
+
expected_term = 4
|
| 30 |
+
expected_index = 100
|
| 31 |
+
|
| 32 |
+
# 2. 检查 node_id (30分)
|
| 33 |
+
node_id = data.get("node_id")
|
| 34 |
+
if node_id == expected_node:
|
| 35 |
+
score += 30
|
| 36 |
+
details.append({"item": "匹配冲突节点 ID", "score": 30, "max_score": 30, "passed": True, "reason": f"成功识别节点: {node_id}"})
|
| 37 |
+
else:
|
| 38 |
+
details.append({"item": "匹配冲突节点 ID", "score": 0, "max_score": 30, "passed": False, "reason": f"期望 {expected_node}, 实际得到 {node_id}"})
|
| 39 |
+
|
| 40 |
+
# 3. 检查 conflict_term (30分)
|
| 41 |
+
try:
|
| 42 |
+
term = int(data.get("conflict_term", -1))
|
| 43 |
+
if term == expected_term:
|
| 44 |
+
score += 30
|
| 45 |
+
details.append({"item": "匹配冲突任期号 (Term)", "score": 30, "max_score": 30, "passed": True, "reason": f"成功识别任期: {term}"})
|
| 46 |
+
else:
|
| 47 |
+
details.append({"item": "匹配冲突任期号 (Term)", "score": 0, "max_score": 30, "passed": False, "reason": f"期望 {expected_term}, 实际得到 {term}"})
|
| 48 |
+
except (ValueError, TypeError):
|
| 49 |
+
details.append({"item": "匹配冲突任期号 (Term)", "score": 0, "max_score": 30, "passed": False, "reason": "任期号缺失或非整数"})
|
| 50 |
+
|
| 51 |
+
# 4. 检查 conflict_index (30分)
|
| 52 |
+
try:
|
| 53 |
+
idx = int(data.get("conflict_index", -1))
|
| 54 |
+
if idx == expected_index:
|
| 55 |
+
score += 30
|
| 56 |
+
details.append({"item": "匹配冲突日志索引 (Log Index)", "score": 30, "max_score": 30, "passed": True, "reason": f"成功识别索引: {idx}"})
|
| 57 |
+
else:
|
| 58 |
+
details.append({"item": "匹配冲突日志索引 (Log Index)", "score": 0, "max_score": 30, "passed": False, "reason": f"期望 {expected_index}, 实际得到 {idx}"})
|
| 59 |
+
except (ValueError, TypeError):
|
| 60 |
+
details.append({"item": "匹配冲突日志索引 (Log Index)", "score": 0, "max_score": 30, "passed": False, "reason": "索引号缺失或非整数"})
|
| 61 |
+
|
| 62 |
+
# 结果写入
|
| 63 |
+
output_file = "workplace_score.json"
|
| 64 |
+
with open(output_file, 'w', encoding='utf-8') as f:
|
| 65 |
+
json.dump({"total_score": score, "details": details}, f, indent=2, ensure_ascii=False)
|
| 66 |
+
|
| 67 |
+
if __name__ == "__main__":
|
| 68 |
+
verify()
|
persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0002/verify_workplace.py
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
import json
|
| 4 |
+
|
| 5 |
+
def verify_workplace():
|
| 6 |
+
workspace = sys.argv[1] if len(sys.argv) > 1 else "."
|
| 7 |
+
report_path = os.path.join(workspace, "ci_patch/conflict_report.json")
|
| 8 |
+
|
| 9 |
+
score = 0
|
| 10 |
+
details = []
|
| 11 |
+
|
| 12 |
+
# 1. Check if the directory and file exist (10 points)
|
| 13 |
+
if os.path.exists(report_path):
|
| 14 |
+
score += 10
|
| 15 |
+
details.append({"item": "检查结果文件是否存在", "score": 10, "max_score": 10, "passed": True, "reason": "文件 ci_patch/conflict_report.json 存在"})
|
| 16 |
+
|
| 17 |
+
# 2. Check if the file is valid JSON (10 points)
|
| 18 |
+
try:
|
| 19 |
+
with open(report_path, "r", encoding="utf-8") as f:
|
| 20 |
+
data = json.load(f)
|
| 21 |
+
score += 10
|
| 22 |
+
details.append({"item": "检查 JSON 格式合法性", "score": 10, "max_score": 10, "passed": True, "reason": "JSON 解析成功"})
|
| 23 |
+
|
| 24 |
+
# 3. Check for required fields (10 points)
|
| 25 |
+
required_fields = ["package", "version_a", "version_b"]
|
| 26 |
+
missing_fields = [f for f in required_fields if f not in data]
|
| 27 |
+
if not missing_fields:
|
| 28 |
+
score += 10
|
| 29 |
+
details.append({"item": "检查必填字段", "score": 10, "max_score": 10, "passed": True, "reason": "包含所有必需字段"})
|
| 30 |
+
|
| 31 |
+
# 4. Check package name (30 points)
|
| 32 |
+
# Allow case-insensitive check and trim
|
| 33 |
+
actual_package = str(data.get("package", "")).strip().lower()
|
| 34 |
+
expected_package = "eigen_matrix"
|
| 35 |
+
if actual_package == expected_package:
|
| 36 |
+
score += 30
|
| 37 |
+
details.append({"item": "验证冲突包名", "score": 30, "max_score": 30, "passed": True, "reason": f"匹配正确: {expected_package}"})
|
| 38 |
+
else:
|
| 39 |
+
details.append({"item": "验证冲突包名", "score": 0, "max_score": 30, "passed": False, "reason": f"期望 {expected_package}, 实际为 {actual_package}"})
|
| 40 |
+
|
| 41 |
+
# 5. Check versions (20 + 20 points)
|
| 42 |
+
# Versions might be swapped, we accept both orders
|
| 43 |
+
actual_versions = sorted([str(data.get("version_a", "")), str(data.get("version_b", ""))])
|
| 44 |
+
expected_versions = sorted(["3.3.9", "3.4.2"])
|
| 45 |
+
|
| 46 |
+
if actual_versions[0] == expected_versions[0]:
|
| 47 |
+
score += 20
|
| 48 |
+
details.append({"item": "验证版本号 A", "score": 20, "max_score": 20, "passed": True, "reason": f"版本 {actual_versions[0]} 匹配成功"})
|
| 49 |
+
else:
|
| 50 |
+
details.append({"item": "验证版本号 A", "score": 0, "max_score": 20, "passed": False, "reason": f"未找到版本 {expected_versions[0]}"})
|
| 51 |
+
|
| 52 |
+
if actual_versions[1] == expected_versions[1]:
|
| 53 |
+
score += 20
|
| 54 |
+
details.append({"item": "验证版本号 B", "score": 20, "max_score": 20, "passed": True, "reason": f"版本 {actual_versions[1]} 匹配成功"})
|
| 55 |
+
else:
|
| 56 |
+
details.append({"item": "验证版本号 B", "score": 0, "max_score": 20, "passed": False, "reason": f"未找到版本 {expected_versions[1]}"})
|
| 57 |
+
|
| 58 |
+
else:
|
| 59 |
+
details.append({"item": "检查必填字段", "score": 0, "max_score": 10, "passed": False, "reason": f"缺失字段: {missing_fields}"})
|
| 60 |
+
details.append({"item": "验证详细内容", "score": 0, "max_score": 70, "passed": False, "reason": "由于 JSON 字段不全,无法进行内容比对"})
|
| 61 |
+
|
| 62 |
+
except json.JSONDecodeError:
|
| 63 |
+
details.append({"item": "检查 JSON 格式合法性", "score": 0, "max_score": 10, "passed": False, "reason": "JSON 格式错误,无法解析"})
|
| 64 |
+
details.append({"item": "验证后续内容", "score": 0, "max_score": 80, "passed": False, "reason": "由于 JSON 解析失败,跳过内容验证"})
|
| 65 |
+
else:
|
| 66 |
+
details.append({"item": "检查结果文件是否存在", "score": 0, "max_score": 10, "passed": False, "reason": "文件 ci_patch/conflict_report.json 未找到"})
|
| 67 |
+
details.append({"item": "验证后续所有项", "score": 0, "max_score": 90, "passed": False, "reason": "找不到目标文件"})
|
| 68 |
+
|
| 69 |
+
# Output results
|
| 70 |
+
output_data = {
|
| 71 |
+
"total_score": score,
|
| 72 |
+
"details": details
|
| 73 |
+
}
|
| 74 |
+
with open("workplace_score.json", "w", encoding="utf-8") as f:
|
| 75 |
+
json.dump(output_data, f, ensure_ascii=False, indent=2)
|
| 76 |
+
|
| 77 |
+
if __name__ == "__main__":
|
| 78 |
+
verify_workplace()
|
persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0003/verify_workplace.py
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
import json
|
| 4 |
+
|
| 5 |
+
def calculate_average_phred(qual_str):
|
| 6 |
+
if not qual_str:
|
| 7 |
+
return 0
|
| 8 |
+
return sum(ord(c) - 33 for c in qual_str) / len(qual_str)
|
| 9 |
+
|
| 10 |
+
def get_gold_standard(fastq_path):
|
| 11 |
+
adapter = "GATCGGAAGAGCACACGTC"
|
| 12 |
+
surviving_ids = []
|
| 13 |
+
|
| 14 |
+
if not os.path.exists(fastq_path):
|
| 15 |
+
return surviving_ids
|
| 16 |
+
|
| 17 |
+
with open(fastq_path, 'r') as f:
|
| 18 |
+
while True:
|
| 19 |
+
header = f.readline().strip()
|
| 20 |
+
if not header:
|
| 21 |
+
break
|
| 22 |
+
seq = f.readline().strip()
|
| 23 |
+
plus = f.readline().strip()
|
| 24 |
+
qual = f.readline().strip()
|
| 25 |
+
|
| 26 |
+
# 规则 1: 剔除包含接头的
|
| 27 |
+
if adapter in seq:
|
| 28 |
+
continue
|
| 29 |
+
|
| 30 |
+
# 规则 2: 平均质量分数低于 20 的剔除
|
| 31 |
+
if calculate_average_phred(qual) < 20:
|
| 32 |
+
continue
|
| 33 |
+
|
| 34 |
+
# 提取 ID (去除开头的 @)
|
| 35 |
+
read_id = header[1:] if header.startswith('@') else header
|
| 36 |
+
surviving_ids.append(read_id)
|
| 37 |
+
|
| 38 |
+
return surviving_ids
|
| 39 |
+
|
| 40 |
+
def main():
|
| 41 |
+
workspace = sys.argv[1] if len(sys.argv) > 1 else "."
|
| 42 |
+
fastq_path = os.path.join(workspace, "raw_data/run_774.fastq")
|
| 43 |
+
result_path = os.path.join(workspace, "results/surviving_reads.txt")
|
| 44 |
+
|
| 45 |
+
score = 0
|
| 46 |
+
details = []
|
| 47 |
+
|
| 48 |
+
# 1. 检查结果文件是否存在
|
| 49 |
+
if os.path.exists(result_path):
|
| 50 |
+
score += 10
|
| 51 |
+
details.append({"item": "结果文件存在性", "score": 10, "max_score": 10, "passed": True, "reason": "results/surviving_reads.txt 已生成"})
|
| 52 |
+
else:
|
| 53 |
+
details.append({"item": "结果文件存在性", "score": 0, "max_score": 10, "passed": False, "reason": "未找到 results/surviving_reads.txt"})
|
| 54 |
+
# 如果文件不存在,后续检查无法进行
|
| 55 |
+
with open("workplace_score.json", "w") as f:
|
| 56 |
+
json.dump({"total_score": 0, "details": details}, f)
|
| 57 |
+
return
|
| 58 |
+
|
| 59 |
+
# 2. 读取并验证结果格式
|
| 60 |
+
with open(result_path, 'r') as f:
|
| 61 |
+
agent_lines = [line.strip() for line in f.readlines() if line.strip()]
|
| 62 |
+
|
| 63 |
+
has_at_prefix = any(line.startswith('@') for line in agent_lines)
|
| 64 |
+
if not has_at_prefix:
|
| 65 |
+
score += 20
|
| 66 |
+
details.append({"item": "输出格式正确性(无@前缀)", "score": 20, "max_score": 20, "passed": True, "reason": "Read ID 符合要求,没有包含 @ 符号"})
|
| 67 |
+
else:
|
| 68 |
+
details.append({"item": "输出格式正确性(无@前缀)", "score": 0, "max_score": 20, "passed": False, "reason": "部分 Read ID 仍保留了 FASTQ 的 @ 前缀"})
|
| 69 |
+
|
| 70 |
+
# 3. 逻辑验证(金标准比对)
|
| 71 |
+
gold_ids = set(get_gold_standard(fastq_path))
|
| 72 |
+
agent_ids = set(agent_lines)
|
| 73 |
+
|
| 74 |
+
# 计算交集、差集
|
| 75 |
+
tp = len(gold_ids.intersection(agent_ids))
|
| 76 |
+
fp = len(agent_ids - gold_ids)
|
| 77 |
+
fn = len(gold_ids - agent_ids)
|
| 78 |
+
|
| 79 |
+
if len(gold_ids) == 0:
|
| 80 |
+
accuracy_score = 0 # 异常情况
|
| 81 |
+
else:
|
| 82 |
+
# 允许极小误差,但逻辑错误(如没过滤接头或质量分算错)会导致大量差异
|
| 83 |
+
accuracy = tp / len(gold_ids) if len(gold_ids) > 0 else 0
|
| 84 |
+
penalty = (fp / len(gold_ids)) * 0.5 # 错选惩罚
|
| 85 |
+
|
| 86 |
+
final_acc_score = max(0, (accuracy - penalty) * 70)
|
| 87 |
+
score += int(final_acc_score)
|
| 88 |
+
|
| 89 |
+
if final_acc_score >= 65:
|
| 90 |
+
details.append({"item": "数据过滤准确性", "score": int(final_acc_score), "max_score": 70, "passed": True, "reason": f"匹配率极高: 命中 {tp}, 多选 {fp}, 漏选 {fn}"})
|
| 91 |
+
else:
|
| 92 |
+
details.append({"item": "数据过滤准确性", "score": int(final_acc_score), "max_score": 70, "passed": False, "reason": f"过滤逻辑存在明显偏差: 命中 {tp}, 多选 {fp}, 漏选 {fn}"})
|
| 93 |
+
|
| 94 |
+
# 总结输出
|
| 95 |
+
final_score = min(100, score)
|
| 96 |
+
output = {
|
| 97 |
+
"total_score": int(final_score),
|
| 98 |
+
"details": details
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
with open("workplace_score.json", "w") as f:
|
| 102 |
+
json.dump(output, f, indent=2)
|
| 103 |
+
|
| 104 |
+
if __name__ == "__main__":
|
| 105 |
+
main()
|
persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0004/verify_workplace.py
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
import json
|
| 4 |
+
|
| 5 |
+
def verify():
|
| 6 |
+
workspace = sys.argv[1] if len(sys.argv) > 1 else "."
|
| 7 |
+
score = 0
|
| 8 |
+
details = []
|
| 9 |
+
|
| 10 |
+
target_file = os.path.join(workspace, "calibration/ghost_ids.txt")
|
| 11 |
+
|
| 12 |
+
# 1. 基础检查:文件是否存在 (10分)
|
| 13 |
+
if os.path.exists(target_file):
|
| 14 |
+
score += 10
|
| 15 |
+
details.append({"item": "检查结果文件是否存在", "score": 10, "max_score": 10, "passed": True, "reason": "文件 ghost_ids.txt 存在"})
|
| 16 |
+
|
| 17 |
+
try:
|
| 18 |
+
with open(target_file, "r", encoding="utf-8") as f:
|
| 19 |
+
content = f.read().strip()
|
| 20 |
+
|
| 21 |
+
# 解析内容
|
| 22 |
+
raw_ids = [s.strip() for s in content.split(",") if s.strip()]
|
| 23 |
+
try:
|
| 24 |
+
agent_ghost_ids = set(int(rid) for rid in raw_ids)
|
| 25 |
+
except ValueError:
|
| 26 |
+
details.append({"item": "检查文件内容格式", "score": 0, "max_score": 10, "passed": False, "reason": f"文件内容无法解析为整数列表: {content}"})
|
| 27 |
+
return score, details
|
| 28 |
+
|
| 29 |
+
# 2. 格式合规性检查 (10分)
|
| 30 |
+
# 要求:仅逗号分隔,无额外描述
|
| 31 |
+
if len(content.split("\n")) == 1 and "," in content:
|
| 32 |
+
score += 10
|
| 33 |
+
details.append({"item": "检查输出格式合规性", "score": 10, "max_score": 10, "passed": True, "reason": "格式符合逗号分隔要求"})
|
| 34 |
+
else:
|
| 35 |
+
details.append({"item": "检查输出格式合规性", "score": 0, "max_score": 10, "passed": False, "reason": "格式不符合单行逗号分隔要求"})
|
| 36 |
+
|
| 37 |
+
# 3. 核心逻辑:检测幽灵障碍物 ID 的准确性
|
| 38 |
+
# 根据 env_builder.py,正确答案是 {18, 27, 42, 68}
|
| 39 |
+
# 正常 ID 是 {12, 33, 55}
|
| 40 |
+
ground_truth_ghosts = {18, 27, 42, 68}
|
| 41 |
+
ground_truth_normals = {12, 33, 55}
|
| 42 |
+
|
| 43 |
+
# 正确识别的幽灵 (每个15分,共60分)
|
| 44 |
+
for gid in ground_truth_ghosts:
|
| 45 |
+
if gid in agent_ghost_ids:
|
| 46 |
+
score += 15
|
| 47 |
+
details.append({"item": f"检测幽灵 ID {gid}", "score": 15, "max_score": 15, "passed": True, "reason": "正确识别"})
|
| 48 |
+
else:
|
| 49 |
+
details.append({"item": f"检测幽灵 ID {gid}", "score": 0, "max_score": 15, "passed": False, "reason": "漏检"})
|
| 50 |
+
|
| 51 |
+
# 错误识别的正常障碍物 (误报,每个扣10分,最低到0分)
|
| 52 |
+
for nid in ground_truth_normals:
|
| 53 |
+
if nid in agent_ghost_ids:
|
| 54 |
+
score -= 10
|
| 55 |
+
details.append({"item": f"误报检查 ID {nid}", "score": -10, "max_score": 0, "passed": False, "reason": f"将正常目标 {nid} 误判为幽灵"})
|
| 56 |
+
|
| 57 |
+
# 检查是否包含虚构的 ID
|
| 58 |
+
for aid in agent_ghost_ids:
|
| 59 |
+
if aid not in ground_truth_ghosts and aid not in ground_truth_normals:
|
| 60 |
+
score -= 5
|
| 61 |
+
details.append({"item": f"虚构检测 ID {aid}", "score": -5, "max_score": 0, "passed": False, "reason": "结果中包含数据中不存在的 ID"})
|
| 62 |
+
|
| 63 |
+
except Exception as e:
|
| 64 |
+
details.append({"item": "解析文件异常", "score": 0, "max_score": 80, "passed": False, "reason": str(e)})
|
| 65 |
+
else:
|
| 66 |
+
details.append({"item": "检查结果文件是否存在", "score": 0, "max_score": 100, "passed": False, "reason": "找不到 calibration/ghost_ids.txt"})
|
| 67 |
+
|
| 68 |
+
# 最终分修正
|
| 69 |
+
score = max(0, min(100, score))
|
| 70 |
+
return score, details
|
| 71 |
+
|
| 72 |
+
if __name__ == "__main__":
|
| 73 |
+
total_score, score_details = verify()
|
| 74 |
+
output = {
|
| 75 |
+
"total_score": total_score,
|
| 76 |
+
"details": score_details
|
| 77 |
+
}
|
| 78 |
+
with open("workplace_score.json", "w", encoding="utf-8") as f:
|
| 79 |
+
json.dump(output, f, indent=2, ensure_ascii=False)
|
persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0005/verify_workplace.py
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
import json
|
| 4 |
+
|
| 5 |
+
def load_json(path):
|
| 6 |
+
try:
|
| 7 |
+
with open(path, 'r', encoding='utf-8') as f:
|
| 8 |
+
return json.load(f)
|
| 9 |
+
except Exception:
|
| 10 |
+
return None
|
| 11 |
+
|
| 12 |
+
def verify():
|
| 13 |
+
workspace = sys.argv[1] if len(sys.argv) > 1 else "."
|
| 14 |
+
report_path = os.path.join(workspace, "reports/termination_list.json")
|
| 15 |
+
|
| 16 |
+
score = 0
|
| 17 |
+
details = []
|
| 18 |
+
|
| 19 |
+
# 1. 基础结构检查 (10分)
|
| 20 |
+
if not os.path.exists(report_path):
|
| 21 |
+
details.append({"item": "文件存在性", "score": 0, "max_score": 10, "passed": False, "reason": "报告文件 reports/termination_list.json 未生成"})
|
| 22 |
+
else:
|
| 23 |
+
data = load_json(report_path)
|
| 24 |
+
if isinstance(data, list):
|
| 25 |
+
score += 10
|
| 26 |
+
details.append({"item": "JSON 格式检查", "score": 10, "max_score": 10, "passed": True, "reason": "报告为合法的 JSON 数组"})
|
| 27 |
+
else:
|
| 28 |
+
details.append({"item": "JSON 格式检查", "score": 0, "max_score": 10, "passed": False, "reason": "报告格式不是 JSON 数组"})
|
| 29 |
+
data = []
|
| 30 |
+
|
| 31 |
+
# 2. 核心数据解析与验证准备
|
| 32 |
+
# 预期结果集合 (根据 env_builder 生成逻辑)
|
| 33 |
+
# EBS: vol-0abcd111111111111 (ai-core -> alice), vol-0abcd222222222222 (data-eng -> charlie), vol-0abcd333333333333 (unknown-team -> unknown)
|
| 34 |
+
# EC2: i-0ffff111111111111 (ai-research -> bob)
|
| 35 |
+
expected_ebs = {"vol-0abcd111111111111", "vol-0abcd222222222222", "vol-0abcd333333333333"}
|
| 36 |
+
expected_ec2 = {"i-0ffff111111111111"}
|
| 37 |
+
|
| 38 |
+
owners_map = {
|
| 39 |
+
"vol-0abcd111111111111": "alice.ai@mega-corp.local",
|
| 40 |
+
"vol-0abcd222222222222": "charlie.data@mega-corp.local",
|
| 41 |
+
"vol-0abcd333333333333": "unknown",
|
| 42 |
+
"i-0ffff111111111111": "bob.research@mega-corp.local"
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
if data:
|
| 46 |
+
# 3. EBS 资源识别 (30分)
|
| 47 |
+
found_ebs = {item['resource_id'] for item in data if item.get('resource_type') == 'EBS'}
|
| 48 |
+
ebs_correct = found_ebs == expected_ebs
|
| 49 |
+
ebs_excess = found_ebs - expected_ebs # 检查是否有误杀 (如 vol-0abcd999999999999)
|
| 50 |
+
|
| 51 |
+
ebs_score = 0
|
| 52 |
+
if "vol-0abcd111111111111" in found_ebs: ebs_score += 10
|
| 53 |
+
if "vol-0abcd222222222222" in found_ebs: ebs_score += 10
|
| 54 |
+
if "vol-0abcd333333333333" in found_ebs: ebs_score += 10
|
| 55 |
+
if "vol-0abcd999999999999" in found_ebs: ebs_score -= 10 # 误杀扣分
|
| 56 |
+
|
| 57 |
+
ebs_score = max(0, ebs_score)
|
| 58 |
+
score += ebs_score
|
| 59 |
+
details.append({"item": "EBS 闲置资源识别", "score": ebs_score, "max_score": 30, "passed": ebs_score >= 30, "reason": f"识别到 EBS: {found_ebs}"})
|
| 60 |
+
|
| 61 |
+
# 4. EC2 资源识别 (30分)
|
| 62 |
+
found_ec2 = {item['resource_id'] for item in data if item.get('resource_type') == 'EC2'}
|
| 63 |
+
ec2_score = 0
|
| 64 |
+
if "i-0ffff111111111111" in found_ec2: ec2_score += 30
|
| 65 |
+
if "i-0ffff222222222222" in found_ec2 or "i-0ffff333333333333" in found_ec2:
|
| 66 |
+
ec2_score = max(0, ec2_score - 20) # 误将高负载或平均负载正常的实例列入
|
| 67 |
+
|
| 68 |
+
score += ec2_score
|
| 69 |
+
details.append({"item": "EC2 GPU低利用率识别", "score": ec2_score, "max_score": 30, "passed": ec2_score == 30, "reason": f"识别到 EC2: {found_ec2}"})
|
| 70 |
+
|
| 71 |
+
# 5. Owner 匹配正确性 (30分)
|
| 72 |
+
owner_correct_count = 0
|
| 73 |
+
total_items = len(data)
|
| 74 |
+
for item in data:
|
| 75 |
+
rid = item.get('resource_id')
|
| 76 |
+
provided_owner = item.get('owner')
|
| 77 |
+
if rid in owners_map and provided_owner == owners_map[rid]:
|
| 78 |
+
owner_correct_count += 1
|
| 79 |
+
|
| 80 |
+
owner_score = int((owner_correct_count / total_items * 30)) if total_items > 0 else 0
|
| 81 |
+
score += owner_score
|
| 82 |
+
details.append({"item": "负责人邮箱交叉比对", "score": owner_score, "max_score": 30, "passed": owner_score == 30, "reason": f"正确匹配了 {owner_correct_count}/{total_items} 个负责人"})
|
| 83 |
+
|
| 84 |
+
# 最终分处理
|
| 85 |
+
final_score = min(100, max(0, score))
|
| 86 |
+
|
| 87 |
+
result = {
|
| 88 |
+
"total_score": final_score,
|
| 89 |
+
"details": details
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
with open("workplace_score.json", "w", encoding="utf-8") as f:
|
| 93 |
+
json.dump(result, f, indent=2, ensure_ascii=False)
|
| 94 |
+
|
| 95 |
+
if __name__ == "__main__":
|
| 96 |
+
verify()
|
persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0006/verify_workplace.py
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
import json
|
| 4 |
+
import httpx
|
| 5 |
+
from openai import OpenAI
|
| 6 |
+
|
| 7 |
+
# Configuration for potential LLM usage
|
| 8 |
+
MOCK_API_KEY = os.environ.get("MOCK_API_KEY", "dummy_key")
|
| 9 |
+
MOCK_API_BASE = os.environ.get("MOCK_API_BASE", "http://localhost/v1")
|
| 10 |
+
MOCK_MODEL_NAME = os.environ.get("MOCK_MODEL_NAME", "gpt-5.4")
|
| 11 |
+
|
| 12 |
+
http_client = httpx.Client(verify=False)
|
| 13 |
+
client = OpenAI(
|
| 14 |
+
api_key=MOCK_API_KEY,
|
| 15 |
+
base_url=MOCK_API_BASE,
|
| 16 |
+
http_client=http_client
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
def llm_judge_content(prompt_text, file_content):
|
| 20 |
+
try:
|
| 21 |
+
response = client.chat.completions.create(
|
| 22 |
+
model=MOCK_MODEL_NAME,
|
| 23 |
+
messages=[
|
| 24 |
+
{"role": "system", "content": "You are a strict data validation assistant. Answer ONLY with 'YES' or 'NO'."},
|
| 25 |
+
{"role": "user", "content": f"{prompt_text}\n\n[File Content]:\n{file_content}"}
|
| 26 |
+
],
|
| 27 |
+
temperature=0
|
| 28 |
+
)
|
| 29 |
+
return "yes" in response.choices[0].message.content.strip().lower()
|
| 30 |
+
except Exception as e:
|
| 31 |
+
print(f"LLM API Error: {e}")
|
| 32 |
+
return False
|
| 33 |
+
|
| 34 |
+
def verify():
|
| 35 |
+
workspace = sys.argv[1] if len(sys.argv) > 1 else "."
|
| 36 |
+
score = 0
|
| 37 |
+
details = []
|
| 38 |
+
|
| 39 |
+
output_path = os.path.join(workspace, "analysis/valid_p300_peaks.json")
|
| 40 |
+
|
| 41 |
+
# 1. Check file existence (10 points)
|
| 42 |
+
if os.path.exists(output_path):
|
| 43 |
+
score += 10
|
| 44 |
+
details.append({"item": "Output file existence", "score": 10, "max_score": 10, "passed": True, "reason": "Found analysis/valid_p300_peaks.json"})
|
| 45 |
+
|
| 46 |
+
# 2. JSON Validity & Structure (10 points)
|
| 47 |
+
try:
|
| 48 |
+
with open(output_path, 'r', encoding='utf-8') as f:
|
| 49 |
+
content = f.read()
|
| 50 |
+
data = json.loads(content)
|
| 51 |
+
score += 10
|
| 52 |
+
details.append({"item": "JSON validity", "score": 10, "max_score": 10, "passed": True, "reason": "File is valid JSON"})
|
| 53 |
+
|
| 54 |
+
# 3. Precision Check: EVT_001 (25 points)
|
| 55 |
+
# Expected: 14.5
|
| 56 |
+
if "EVT_001" in data and abs(float(data["EVT_001"]) - 14.5) < 0.01:
|
| 57 |
+
score += 25
|
| 58 |
+
details.append({"item": "EVT_001 Correctness", "score": 25, "max_score": 25, "passed": True, "reason": "Correct peak (14.5) for EVT_001"})
|
| 59 |
+
else:
|
| 60 |
+
details.append({"item": "EVT_001 Correctness", "score": 0, "max_score": 25, "passed": False, "reason": f"Expected 14.5, got {data.get('EVT_001')}"})
|
| 61 |
+
|
| 62 |
+
# 4. Precision Check: EVT_005 (25 points)
|
| 63 |
+
# Expected: 18.2
|
| 64 |
+
if "EVT_005" in data and abs(float(data["EVT_005"]) - 18.2) < 0.01:
|
| 65 |
+
score += 25
|
| 66 |
+
details.append({"item": "EVT_005 Correctness", "score": 25, "max_score": 25, "passed": True, "reason": "Correct peak (18.2) for EVT_005"})
|
| 67 |
+
else:
|
| 68 |
+
details.append({"item": "EVT_005 Correctness", "score": 0, "max_score": 25, "passed": False, "reason": f"Expected 18.2, got {data.get('EVT_005')}"})
|
| 69 |
+
|
| 70 |
+
# 5. Artifact Rejection: EVT_003 and EVT_004 (20 points total)
|
| 71 |
+
# EVT_003 has FZ artifact, EVT_004 has CZ artifact.
|
| 72 |
+
rejected_003 = "EVT_003" not in data
|
| 73 |
+
rejected_004 = "EVT_004" not in data
|
| 74 |
+
|
| 75 |
+
if rejected_003:
|
| 76 |
+
score += 10
|
| 77 |
+
details.append({"item": "Artifact Rejection (FZ)", "score": 10, "max_score": 10, "passed": True, "reason": "Correctly rejected EVT_003 due to FZ spike"})
|
| 78 |
+
else:
|
| 79 |
+
details.append({"item": "Artifact Rejection (FZ)", "score": 0, "max_score": 10, "passed": False, "reason": "Failed to reject EVT_003 (FZ artifact)"})
|
| 80 |
+
|
| 81 |
+
if rejected_004:
|
| 82 |
+
score += 10
|
| 83 |
+
details.append({"item": "Artifact Rejection (CZ)", "score": 10, "max_score": 10, "passed": True, "reason": "Correctly rejected EVT_004 due to CZ spike"})
|
| 84 |
+
else:
|
| 85 |
+
details.append({"item": "Artifact Rejection (CZ)", "score": 0, "max_score": 10, "passed": False, "reason": "Failed to reject EVT_004 (CZ artifact)"})
|
| 86 |
+
|
| 87 |
+
# 6. Type Filtering: EVT_002 (10 points)
|
| 88 |
+
# EVT_002 is N200, should be ignored.
|
| 89 |
+
if "EVT_002" not in data:
|
| 90 |
+
score += 10
|
| 91 |
+
details.append({"item": "Target Type Filtering", "score": 10, "max_score": 10, "passed": True, "reason": "Correctly ignored non-P300 stimulus EVT_002"})
|
| 92 |
+
else:
|
| 93 |
+
details.append({"item": "Target Type Filtering", "score": 0, "max_score": 10, "passed": False, "reason": "Failed to filter out non-P300 stimulus"})
|
| 94 |
+
|
| 95 |
+
# Bonus/Cleanup: No extra verbosity check (LLM)
|
| 96 |
+
# The prompt requested NO code explanations in the output.
|
| 97 |
+
is_clean = llm_judge_content("Does the provided JSON file contain ONLY the stimulus-to-peak-voltage mapping without any conversational filler, explanations, or code commentary?", content)
|
| 98 |
+
if not is_clean:
|
| 99 |
+
penalty = 10
|
| 100 |
+
score = max(0, score - penalty)
|
| 101 |
+
details.append({"item": "Output Cleanliness", "score": -penalty, "max_score": 0, "passed": False, "reason": "Output contained forbidden explanations or commentary"})
|
| 102 |
+
|
| 103 |
+
except Exception as e:
|
| 104 |
+
details.append({"item": "JSON Parsing", "score": 0, "max_score": 10, "passed": False, "reason": f"Error parsing JSON: {str(e)}"})
|
| 105 |
+
else:
|
| 106 |
+
details.append({"item": "Output file existence", "score": 0, "max_score": 100, "passed": False, "reason": "analysis/valid_p300_peaks.json not found"})
|
| 107 |
+
|
| 108 |
+
# Ensure score is integer and capped
|
| 109 |
+
final_score = min(100, max(0, int(score)))
|
| 110 |
+
|
| 111 |
+
result = {
|
| 112 |
+
"total_score": final_score,
|
| 113 |
+
"details": details
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
with open("workplace_score.json", "w", encoding="utf-8") as f:
|
| 117 |
+
json.dump(result, f, indent=2, ensure_ascii=False)
|
| 118 |
+
|
| 119 |
+
if __name__ == "__main__":
|
| 120 |
+
verify()
|
persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0007/verify_workplace.py
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
import json
|
| 4 |
+
import math
|
| 5 |
+
|
| 6 |
+
def calculate_expected_norm(fx, fy, fz):
|
| 7 |
+
return math.sqrt(fx**2 + fy**2 + fz**2)
|
| 8 |
+
|
| 9 |
+
def verify():
|
| 10 |
+
# 默认工作区路径获取
|
| 11 |
+
workspace = sys.argv[1] if len(sys.argv) > 1 else "."
|
| 12 |
+
report_path = os.path.join(workspace, "report/culprit.json")
|
| 13 |
+
score_file = "workplace_score.json"
|
| 14 |
+
|
| 15 |
+
total_score = 0
|
| 16 |
+
details = []
|
| 17 |
+
|
| 18 |
+
# 预设的正确答案(基于 env_builder.py)
|
| 19 |
+
EXPECTED_STEP = 14
|
| 20 |
+
EXPECTED_ATOM_IDX = 42
|
| 21 |
+
# fx, fy, fz = 845.210, -991.330, 1502.440
|
| 22 |
+
EXPECTED_FORCE_NORM = calculate_expected_norm(845.210, -991.330, 1502.440) # 约 1988.577...
|
| 23 |
+
|
| 24 |
+
# 1. 检查目录和文件是否存在 (10分)
|
| 25 |
+
if os.path.exists(report_path):
|
| 26 |
+
score_1 = 10
|
| 27 |
+
details.append({"item": "检查报告文件是否存在", "score": 10, "max_score": 10, "passed": True, "reason": "找到 report/culprit.json"})
|
| 28 |
+
else:
|
| 29 |
+
score_1 = 0
|
| 30 |
+
details.append({"item": "检查报告文件是否存在", "score": 0, "max_score": 10, "passed": False, "reason": "未找到 report/culprit.json"})
|
| 31 |
+
# 如果文件不存在,后续检查无法进行,直接写入结果
|
| 32 |
+
with open(score_file, "w") as f:
|
| 33 |
+
json.dump({"total_score": 0, "details": details}, f, indent=2)
|
| 34 |
+
return
|
| 35 |
+
|
| 36 |
+
# 2. 检查 JSON 格式合法性 (10分)
|
| 37 |
+
try:
|
| 38 |
+
with open(report_path, 'r', encoding='utf-8') as f:
|
| 39 |
+
data = json.load(f)
|
| 40 |
+
score_2 = 10
|
| 41 |
+
details.append({"item": "检查 JSON 格式合法性", "score": 10, "max_score": 10, "passed": True, "reason": "JSON 解析成功"})
|
| 42 |
+
except Exception as e:
|
| 43 |
+
score_2 = 0
|
| 44 |
+
details.append({"item": "检查 JSON 格式合法性", "score": 0, "max_score": 10, "passed": False, "reason": f"JSON 解析失败: {str(e)}"})
|
| 45 |
+
with open(score_file, "w") as f:
|
| 46 |
+
json.dump({"total_score": score_1, "details": details}, f, indent=2)
|
| 47 |
+
return
|
| 48 |
+
|
| 49 |
+
# 3. 验证离子步序号 (20分)
|
| 50 |
+
# 字段名可能不唯一,允许 agent 使用常用字段名,但优先匹配题目要求的逻辑
|
| 51 |
+
step_keys = ["ionic_step", "step", "step_number", "fatal_step"]
|
| 52 |
+
found_step = None
|
| 53 |
+
for k in step_keys:
|
| 54 |
+
if k in data:
|
| 55 |
+
found_step = data[k]
|
| 56 |
+
break
|
| 57 |
+
|
| 58 |
+
if found_step == EXPECTED_STEP:
|
| 59 |
+
score_3 = 20
|
| 60 |
+
details.append({"item": "验证致命离子步序号", "score": 20, "max_score": 20, "passed": True, "reason": f"离子步序号正确: {found_step}"})
|
| 61 |
+
else:
|
| 62 |
+
score_3 = 0
|
| 63 |
+
details.append({"item": "验证致命离子步序号", "score": 0, "max_score": 20, "passed": False, "reason": f"序号错误或缺失,期望 {EXPECTED_STEP},实际拿到 {found_step}"})
|
| 64 |
+
|
| 65 |
+
# 4. 验证原子索引 (30分)
|
| 66 |
+
atom_keys = ["atom_index", "culprit_atom", "atom_id", "atom_idx"]
|
| 67 |
+
found_atom = None
|
| 68 |
+
for k in atom_keys:
|
| 69 |
+
if k in data:
|
| 70 |
+
found_atom = data[k]
|
| 71 |
+
break
|
| 72 |
+
|
| 73 |
+
if found_atom == EXPECTED_ATOM_IDX:
|
| 74 |
+
score_4 = 30
|
| 75 |
+
details.append({"item": "验证异常原子索引", "score": 30, "max_score": 30, "passed": True, "reason": f"原子索引正确: {found_atom}"})
|
| 76 |
+
else:
|
| 77 |
+
score_4 = 0
|
| 78 |
+
details.append({"item": "验证异常原子索引", "score": 0, "max_score": 30, "passed": False, "reason": f"索引错误或缺失,期望 {EXPECTED_ATOM_IDX},实际拿到 {found_atom}"})
|
| 79 |
+
|
| 80 |
+
# 5. 验证受力大小 (30分)
|
| 81 |
+
force_keys = ["force_magnitude", "force_norm", "max_force", "force"]
|
| 82 |
+
found_force = None
|
| 83 |
+
for k in force_keys:
|
| 84 |
+
if k in data:
|
| 85 |
+
found_force = data[k]
|
| 86 |
+
break
|
| 87 |
+
|
| 88 |
+
if found_force is not None:
|
| 89 |
+
try:
|
| 90 |
+
val = float(found_force)
|
| 91 |
+
if math.isclose(val, EXPECTED_FORCE_NORM, rel_tol=1e-3):
|
| 92 |
+
score_5 = 30
|
| 93 |
+
details.append({"item": "验证受力绝对值计算", "score": 30, "max_score": 30, "passed": True, "reason": f"受力大小符合预期: {val}"})
|
| 94 |
+
else:
|
| 95 |
+
score_5 = 0
|
| 96 |
+
details.append({"item": "验证受力绝对值计算", "score": 0, "max_score": 30, "passed": False, "reason": f"数值偏差过大,期望约 {EXPECTED_FORCE_NORM:.4f}, 实际为 {val}"})
|
| 97 |
+
except:
|
| 98 |
+
score_5 = 0
|
| 99 |
+
details.append({"item": "验证受力绝对值计算", "score": 0, "max_score": 30, "passed": False, "reason": "受力字段无法转换为浮点数"})
|
| 100 |
+
else:
|
| 101 |
+
score_5 = 0
|
| 102 |
+
details.append({"item": "验证受力绝对值计算", "score": 0, "max_score": 30, "passed": False, "reason": "未找到受力大小字段"})
|
| 103 |
+
|
| 104 |
+
# 汇总
|
| 105 |
+
total_score = score_1 + score_2 + score_3 + score_4 + score_5
|
| 106 |
+
|
| 107 |
+
# 额外检查:如果 Agent 提供了多余的虚假字段(如猜测的化学元素等题目没给的信息),酌情扣分 (可选防御性逻辑)
|
| 108 |
+
if len(data) > 6:
|
| 109 |
+
total_score = max(0, total_score - 5)
|
| 110 |
+
details.append({"item": "冗余信息惩罚", "score": -5, "max_score": 0, "passed": False, "reason": "JSON中包含过量未要求的字段,可能存在幻觉"})
|
| 111 |
+
|
| 112 |
+
with open(score_file, "w") as f:
|
| 113 |
+
json.dump({"total_score": int(total_score), "details": details}, f, indent=2)
|
| 114 |
+
|
| 115 |
+
if __name__ == "__main__":
|
| 116 |
+
verify()
|
persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0008/verify_workplace.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
import json
|
| 4 |
+
|
| 5 |
+
def verify():
|
| 6 |
+
# 基础路径处理
|
| 7 |
+
workspace = sys.argv[1] if len(sys.argv) > 1 else "."
|
| 8 |
+
report_path = os.path.join(workspace, "reports/bottleneck.json")
|
| 9 |
+
|
| 10 |
+
score = 0
|
| 11 |
+
details = []
|
| 12 |
+
|
| 13 |
+
# 1. 检查结果文件是否存在 (10分)
|
| 14 |
+
if os.path.exists(report_path):
|
| 15 |
+
score += 10
|
| 16 |
+
details.append({"item": "Check reports/bottleneck.json existence", "score": 10, "max_score": 10, "passed": True, "reason": "Report file found."})
|
| 17 |
+
else:
|
| 18 |
+
details.append({"item": "Check reports/bottleneck.json existence", "score": 0, "max_score": 10, "passed": False, "reason": "Report file not found."})
|
| 19 |
+
# 如果文件不存在,后续检查无法进行,直接写入结果
|
| 20 |
+
write_score(score, details)
|
| 21 |
+
return
|
| 22 |
+
|
| 23 |
+
# 2. 检查 JSON 格式与 Schema 合法性 (20分)
|
| 24 |
+
try:
|
| 25 |
+
with open(report_path, 'r', encoding='utf-8') as f:
|
| 26 |
+
data = json.load(f)
|
| 27 |
+
|
| 28 |
+
if "bottleneck_entity" in data:
|
| 29 |
+
score += 20
|
| 30 |
+
details.append({"item": "Verify JSON Schema", "score": 20, "max_score": 20, "passed": True, "reason": "Key 'bottleneck_entity' exists."})
|
| 31 |
+
|
| 32 |
+
# 3. 检查 Entity ID 准确性 (70分)
|
| 33 |
+
# 根据 env_builder.py, target_entity = "8847291"
|
| 34 |
+
actual_id = str(data["bottleneck_entity"]).strip()
|
| 35 |
+
expected_id = "8847291"
|
| 36 |
+
|
| 37 |
+
if actual_id == expected_id:
|
| 38 |
+
score += 70
|
| 39 |
+
details.append({"item": "Verify Bottleneck Entity ID", "score": 70, "max_score": 70, "passed": True, "reason": f"Correct entity ID found: {actual_id}"})
|
| 40 |
+
else:
|
| 41 |
+
details.append({"item": "Verify Bottleneck Entity ID", "score": 0, "max_score": 70, "passed": False, "reason": f"Incorrect entity ID. Expected {expected_id}, but got {actual_id}"})
|
| 42 |
+
|
| 43 |
+
else:
|
| 44 |
+
details.append({"item": "Verify JSON Schema", "score": 0, "max_score": 20, "passed": False, "reason": "Required key 'bottleneck_entity' is missing."})
|
| 45 |
+
|
| 46 |
+
except json.JSONDecodeError:
|
| 47 |
+
details.append({"item": "Verify JSON Schema", "score": 0, "max_score": 20, "passed": False, "reason": "File is not a valid JSON."})
|
| 48 |
+
except Exception as e:
|
| 49 |
+
details.append({"item": "Verify JSON Schema", "score": 0, "max_score": 20, "passed": False, "reason": f"Unexpected error: {str(e)}"})
|
| 50 |
+
|
| 51 |
+
write_score(score, details)
|
| 52 |
+
|
| 53 |
+
def write_score(total_score, details):
|
| 54 |
+
with open("workplace_score.json", "w", encoding="utf-8") as f:
|
| 55 |
+
json.dump({
|
| 56 |
+
"total_score": total_score,
|
| 57 |
+
"details": details
|
| 58 |
+
}, f, indent=2, ensure_ascii=False)
|
| 59 |
+
|
| 60 |
+
if __name__ == "__main__":
|
| 61 |
+
verify()
|
persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0009/verify_workplace.py
ADDED
|
@@ -0,0 +1,216 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
import json
|
| 4 |
+
import math
|
| 5 |
+
import httpx
|
| 6 |
+
from openai import OpenAI
|
| 7 |
+
|
| 8 |
+
MOCK_API_KEY = os.environ.get("MOCK_API_KEY", "dummy_key")
|
| 9 |
+
MOCK_API_BASE = os.environ.get("MOCK_API_BASE", "http://localhost/v1")
|
| 10 |
+
MOCK_MODEL_NAME = os.environ.get("MOCK_MODEL_NAME", "gpt-5.4")
|
| 11 |
+
|
| 12 |
+
# 初始化客户端,强制关闭 SSL 验证
|
| 13 |
+
http_client = httpx.Client(verify=False)
|
| 14 |
+
client = OpenAI(
|
| 15 |
+
api_key=MOCK_API_KEY,
|
| 16 |
+
base_url=MOCK_API_BASE,
|
| 17 |
+
http_client=http_client
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
def llm_judge_content(prompt_text, file_content):
|
| 21 |
+
try:
|
| 22 |
+
response = client.chat.completions.create(
|
| 23 |
+
model=MOCK_MODEL_NAME,
|
| 24 |
+
messages=[
|
| 25 |
+
{"role": "system", "content": "You are a strict data validation assistant. Answer ONLY with 'YES' or 'NO'."},
|
| 26 |
+
{"role": "user", "content": f"{prompt_text}\n\n[File Content]:\n{file_content}"}
|
| 27 |
+
],
|
| 28 |
+
temperature=0
|
| 29 |
+
)
|
| 30 |
+
return "yes" in response.choices[0].message.content.strip().lower()
|
| 31 |
+
except Exception as e:
|
| 32 |
+
print(f"LLM API Error: {e}")
|
| 33 |
+
return False
|
| 34 |
+
|
| 35 |
+
def verify(workspace):
|
| 36 |
+
score_details = []
|
| 37 |
+
total_score = 0
|
| 38 |
+
target_file = os.path.join(workspace, "output", "critical_state.json")
|
| 39 |
+
|
| 40 |
+
# 1. 检查文件是否存在 (20分)
|
| 41 |
+
if not os.path.exists(target_file):
|
| 42 |
+
score_details.append({
|
| 43 |
+
"item": "检查结果文件是否存在",
|
| 44 |
+
"score": 0,
|
| 45 |
+
"max_score": 20,
|
| 46 |
+
"passed": False,
|
| 47 |
+
"reason": f"未找到文件 {target_file}"
|
| 48 |
+
})
|
| 49 |
+
write_score(0, score_details, workspace)
|
| 50 |
+
return
|
| 51 |
+
else:
|
| 52 |
+
score_details.append({
|
| 53 |
+
"item": "检查结果文件是否存在",
|
| 54 |
+
"score": 20,
|
| 55 |
+
"max_score": 20,
|
| 56 |
+
"passed": True,
|
| 57 |
+
"reason": "文件 output/critical_state.json 存在"
|
| 58 |
+
})
|
| 59 |
+
total_score += 20
|
| 60 |
+
|
| 61 |
+
# 2. 检查 JSON 格式合法性 (15分)
|
| 62 |
+
try:
|
| 63 |
+
with open(target_file, "r", encoding="utf-8") as f:
|
| 64 |
+
data = json.load(f)
|
| 65 |
+
score_details.append({
|
| 66 |
+
"item": "检查 JSON 解析",
|
| 67 |
+
"score": 15,
|
| 68 |
+
"max_score": 15,
|
| 69 |
+
"passed": True,
|
| 70 |
+
"reason": "文件为合法 JSON"
|
| 71 |
+
})
|
| 72 |
+
total_score += 15
|
| 73 |
+
except Exception as e:
|
| 74 |
+
score_details.append({
|
| 75 |
+
"item": "检查 JSON 解析",
|
| 76 |
+
"score": 0,
|
| 77 |
+
"max_score": 15,
|
| 78 |
+
"passed": False,
|
| 79 |
+
"reason": f"解析 JSON 失败: {e}"
|
| 80 |
+
})
|
| 81 |
+
write_score(total_score, score_details, workspace)
|
| 82 |
+
return
|
| 83 |
+
|
| 84 |
+
# 3. 检查 JSON 键名准确性与无幻觉字段 (15分)
|
| 85 |
+
expected_keys = {"latest_quaternion", "max_temperature"}
|
| 86 |
+
actual_keys = set(data.keys())
|
| 87 |
+
if actual_keys == expected_keys:
|
| 88 |
+
score_details.append({
|
| 89 |
+
"item": "检查 JSON 字段严格匹配",
|
| 90 |
+
"score": 15,
|
| 91 |
+
"max_score": 15,
|
| 92 |
+
"passed": True,
|
| 93 |
+
"reason": "字段名称完全匹配,无多余捏造字段"
|
| 94 |
+
})
|
| 95 |
+
total_score += 15
|
| 96 |
+
else:
|
| 97 |
+
missing = expected_keys - actual_keys
|
| 98 |
+
extra = actual_keys - expected_keys
|
| 99 |
+
reason_parts = []
|
| 100 |
+
if missing: reason_parts.append(f"缺失: {missing}")
|
| 101 |
+
if extra: reason_parts.append(f"多余: {extra}")
|
| 102 |
+
score_details.append({
|
| 103 |
+
"item": "检查 JSON 字段严格匹配",
|
| 104 |
+
"score": 0,
|
| 105 |
+
"max_score": 15,
|
| 106 |
+
"passed": False,
|
| 107 |
+
"reason": "字段不完全匹配。 " + " | ".join(reason_parts)
|
| 108 |
+
})
|
| 109 |
+
|
| 110 |
+
# 4. 检查 max_temperature 计算结果 (25分)
|
| 111 |
+
temp = data.get("max_temperature", None)
|
| 112 |
+
if temp is not None:
|
| 113 |
+
try:
|
| 114 |
+
temp_val = float(temp)
|
| 115 |
+
# 正确值为 94.75。容忍度很低
|
| 116 |
+
if math.isclose(temp_val, 94.75, abs_tol=0.01):
|
| 117 |
+
score_details.append({
|
| 118 |
+
"item": "验证最大异常温度峰值",
|
| 119 |
+
"score": 25,
|
| 120 |
+
"max_score": 25,
|
| 121 |
+
"passed": True,
|
| 122 |
+
"reason": "最高异常温度峰值精确等于 94.75"
|
| 123 |
+
})
|
| 124 |
+
total_score += 25
|
| 125 |
+
else:
|
| 126 |
+
score_details.append({
|
| 127 |
+
"item": "验证最大异常温度峰值",
|
| 128 |
+
"score": 0,
|
| 129 |
+
"max_score": 25,
|
| 130 |
+
"passed": False,
|
| 131 |
+
"reason": f"温度值错误,期望 94.75,实际为 {temp_val}"
|
| 132 |
+
})
|
| 133 |
+
except ValueError:
|
| 134 |
+
score_details.append({
|
| 135 |
+
"item": "验证最大异常温度峰值",
|
| 136 |
+
"score": 0,
|
| 137 |
+
"max_score": 25,
|
| 138 |
+
"passed": False,
|
| 139 |
+
"reason": "max_temperature 并非有效数值类型"
|
| 140 |
+
})
|
| 141 |
+
else:
|
| 142 |
+
score_details.append({
|
| 143 |
+
"item": "验证最大异常温度峰值",
|
| 144 |
+
"score": 0,
|
| 145 |
+
"max_score": 25,
|
| 146 |
+
"passed": False,
|
| 147 |
+
"reason": "未找到 max_temperature 字段"
|
| 148 |
+
})
|
| 149 |
+
|
| 150 |
+
# 5. 检查 latest_quaternion 提取与计算结果 (25分)
|
| 151 |
+
quat = data.get("latest_quaternion", None)
|
| 152 |
+
if quat is not None:
|
| 153 |
+
if isinstance(quat, list) and len(quat) == 4:
|
| 154 |
+
expected_quat = [0.4999, 0.5001, -0.4999, -0.5001]
|
| 155 |
+
try:
|
| 156 |
+
match_all = True
|
| 157 |
+
for val, exp in zip(quat, expected_quat):
|
| 158 |
+
if not math.isclose(float(val), exp, abs_tol=0.0002):
|
| 159 |
+
match_all = False
|
| 160 |
+
break
|
| 161 |
+
if match_all:
|
| 162 |
+
score_details.append({
|
| 163 |
+
"item": "验证最新星象仪四元数",
|
| 164 |
+
"score": 25,
|
| 165 |
+
"max_score": 25,
|
| 166 |
+
"passed": True,
|
| 167 |
+
"reason": f"成功提取有效时间最新的一帧四元数并保留正确小数位"
|
| 168 |
+
})
|
| 169 |
+
total_score += 25
|
| 170 |
+
else:
|
| 171 |
+
score_details.append({
|
| 172 |
+
"item": "验证最新星象仪四元数",
|
| 173 |
+
"score": 0,
|
| 174 |
+
"max_score": 25,
|
| 175 |
+
"passed": False,
|
| 176 |
+
"reason": f"四元数值不匹配,可能找错了时间帧、提取到了被破坏的帧头数据或解析小/大端序出错。实际值:{quat}"
|
| 177 |
+
})
|
| 178 |
+
except ValueError:
|
| 179 |
+
score_details.append({
|
| 180 |
+
"item": "验证最新星象仪四元数",
|
| 181 |
+
"score": 0,
|
| 182 |
+
"max_score": 25,
|
| 183 |
+
"passed": False,
|
| 184 |
+
"reason": "数组内含有非数值数据"
|
| 185 |
+
})
|
| 186 |
+
else:
|
| 187 |
+
score_details.append({
|
| 188 |
+
"item": "验证最新星象仪四元数",
|
| 189 |
+
"score": 0,
|
| 190 |
+
"max_score": 25,
|
| 191 |
+
"passed": False,
|
| 192 |
+
"reason": "latest_quaternion 格式错误,必须为包含4个数值的数组"
|
| 193 |
+
})
|
| 194 |
+
else:
|
| 195 |
+
score_details.append({
|
| 196 |
+
"item": "验证最新星象仪四元数",
|
| 197 |
+
"score": 0,
|
| 198 |
+
"max_score": 25,
|
| 199 |
+
"passed": False,
|
| 200 |
+
"reason": "未找到 latest_quaternion 字段"
|
| 201 |
+
})
|
| 202 |
+
|
| 203 |
+
write_score(total_score, score_details, workspace)
|
| 204 |
+
|
| 205 |
+
def write_score(total_score, details, workspace):
|
| 206 |
+
result = {
|
| 207 |
+
"total_score": total_score,
|
| 208 |
+
"details": details
|
| 209 |
+
}
|
| 210 |
+
with open(os.path.join(workspace, "workplace_score.json"), "w", encoding="utf-8") as f:
|
| 211 |
+
json.dump(result, f, indent=2, ensure_ascii=False)
|
| 212 |
+
print(json.dumps(result, indent=2, ensure_ascii=False))
|
| 213 |
+
|
| 214 |
+
if __name__ == "__main__":
|
| 215 |
+
work_dir = sys.argv[1] if len(sys.argv) > 1 else "."
|
| 216 |
+
verify(work_dir)
|
persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0010/verify_workplace.py
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
import json
|
| 4 |
+
import httpx
|
| 5 |
+
from openai import OpenAI
|
| 6 |
+
|
| 7 |
+
MOCK_API_KEY = os.environ.get("MOCK_API_KEY", "dummy_key")
|
| 8 |
+
MOCK_API_BASE = os.environ.get("MOCK_API_BASE", "http://localhost/v1")
|
| 9 |
+
MOCK_MODEL_NAME = os.environ.get("MOCK_MODEL_NAME", "gpt-5.4")
|
| 10 |
+
|
| 11 |
+
# 初始化客户端,必须关闭 SSL 验证
|
| 12 |
+
http_client = httpx.Client(verify=False)
|
| 13 |
+
client = OpenAI(
|
| 14 |
+
api_key=MOCK_API_KEY,
|
| 15 |
+
base_url=MOCK_API_BASE,
|
| 16 |
+
http_client=http_client
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
def llm_judge_content(prompt_text, file_content):
|
| 20 |
+
# 此函数为检测非结构化文本的统一接口
|
| 21 |
+
try:
|
| 22 |
+
response = client.chat.completions.create(
|
| 23 |
+
model=MOCK_MODEL_NAME,
|
| 24 |
+
messages=[
|
| 25 |
+
{"role": "system", "content": "You are a strict data validation assistant. Answer ONLY with 'YES' or 'NO'."},
|
| 26 |
+
{"role": "user", "content": f"{prompt_text}\n\n[File Content]:\n{file_content}"}
|
| 27 |
+
],
|
| 28 |
+
temperature=0
|
| 29 |
+
)
|
| 30 |
+
return "yes" in response.choices[0].message.content.strip().lower()
|
| 31 |
+
except Exception as e:
|
| 32 |
+
print(f"LLM API Error: {e}")
|
| 33 |
+
return False
|
| 34 |
+
|
| 35 |
+
def verify():
|
| 36 |
+
workspace = sys.argv[1] if len(sys.argv) > 1 else "."
|
| 37 |
+
target_file = os.path.join(workspace, "report", "failed_init.json")
|
| 38 |
+
|
| 39 |
+
total_score = 0
|
| 40 |
+
details = []
|
| 41 |
+
|
| 42 |
+
# 1. 检查目标文件是否存在 (20分)
|
| 43 |
+
if os.path.isfile(target_file):
|
| 44 |
+
total_score += 20
|
| 45 |
+
details.append({"item": "检查结果文件是否存在", "score": 20, "max_score": 20, "passed": True, "reason": "文件 report/failed_init.json 存在"})
|
| 46 |
+
else:
|
| 47 |
+
details.append({"item": "检查结果文件是否存在", "score": 0, "max_score": 20, "passed": False, "reason": "文件 report/failed_init.json 不存在"})
|
| 48 |
+
write_score(total_score, details)
|
| 49 |
+
return
|
| 50 |
+
|
| 51 |
+
# 2. 检查文件是否为合法的 JSON 格式 (20分)
|
| 52 |
+
try:
|
| 53 |
+
with open(target_file, 'r', encoding='utf-8') as f:
|
| 54 |
+
data = json.load(f)
|
| 55 |
+
total_score += 20
|
| 56 |
+
details.append({"item": "检查文件是否为合法 JSON", "score": 20, "max_score": 20, "passed": True, "reason": "成功解析 JSON 文件"})
|
| 57 |
+
except json.JSONDecodeError:
|
| 58 |
+
details.append({"item": "检查文件是否为合法 JSON", "score": 0, "max_score": 20, "passed": False, "reason": "文件内容不是合法的 JSON 格式"})
|
| 59 |
+
write_score(total_score, details)
|
| 60 |
+
return
|
| 61 |
+
except Exception as e:
|
| 62 |
+
details.append({"item": "检查文件是否为合法 JSON", "score": 0, "max_score": 20, "passed": False, "reason": f"文件读取发生未知错误: {str(e)}"})
|
| 63 |
+
write_score(total_score, details)
|
| 64 |
+
return
|
| 65 |
+
|
| 66 |
+
# 3. 检查 JSON 字段完整性 (10分)
|
| 67 |
+
if not isinstance(data, dict):
|
| 68 |
+
details.append({"item": "检查 JSON 结构类型", "score": 0, "max_score": 10, "passed": False, "reason": "JSON 根节点必须是一个对象 (dict)"})
|
| 69 |
+
write_score(total_score, details)
|
| 70 |
+
return
|
| 71 |
+
|
| 72 |
+
has_register = "register" in data
|
| 73 |
+
has_value = "value" in data
|
| 74 |
+
extra_keys = set(data.keys()) - {"register", "value"}
|
| 75 |
+
|
| 76 |
+
if has_register and has_value:
|
| 77 |
+
if extra_keys:
|
| 78 |
+
# 存在冗余字段,扣5分
|
| 79 |
+
total_score += 5
|
| 80 |
+
details.append({"item": "检查 JSON 字段", "score": 5, "max_score": 10, "passed": False, "reason": f"包含了必要的字段,但存在冗余字段: {extra_keys}"})
|
| 81 |
+
else:
|
| 82 |
+
total_score += 10
|
| 83 |
+
details.append({"item": "检查 JSON 字段", "score": 10, "max_score": 10, "passed": True, "reason": "精确包含了 register 和 value 字段"})
|
| 84 |
+
else:
|
| 85 |
+
details.append({"item": "检查 JSON 字段", "score": 0, "max_score": 10, "passed": False, "reason": "缺失 register 或 value 字段"})
|
| 86 |
+
write_score(total_score, details)
|
| 87 |
+
return
|
| 88 |
+
|
| 89 |
+
# 4. 提取并校验 register 的值 (25分)
|
| 90 |
+
reg_val = str(data.get("register", "")).strip().lower()
|
| 91 |
+
if reg_val == "0x2a":
|
| 92 |
+
total_score += 25
|
| 93 |
+
details.append({"item": "校验报错的寄存器地址", "score": 25, "max_score": 25, "passed": True, "reason": "找到了正确的寄存器地址 0x2A"})
|
| 94 |
+
else:
|
| 95 |
+
details.append({"item": "校验报错的寄存器地址", "score": 0, "max_score": 25, "passed": False, "reason": f"寄存器地址错误或格式不标准,预期 '0x2A',实际获取到 '{reg_val}'"})
|
| 96 |
+
|
| 97 |
+
# 5. 提取并校验 value 的值 (25分)
|
| 98 |
+
val_val = str(data.get("value", "")).strip().lower()
|
| 99 |
+
if val_val == "0x7f":
|
| 100 |
+
total_score += 25
|
| 101 |
+
details.append({"item": "校验试图写入的错误数据", "score": 25, "max_score": 25, "passed": True, "reason": "找到了正确的报错数据 0x7F"})
|
| 102 |
+
else:
|
| 103 |
+
details.append({"item": "校验试图写入的错误数据", "score": 0, "max_score": 25, "passed": False, "reason": f"试图写入的数据错误或格式不标准,预期 '0x7F',实际获取到 '{val_val}'"})
|
| 104 |
+
|
| 105 |
+
write_score(total_score, details)
|
| 106 |
+
|
| 107 |
+
def write_score(total_score, details):
|
| 108 |
+
report = {
|
| 109 |
+
"total_score": total_score,
|
| 110 |
+
"details": details
|
| 111 |
+
}
|
| 112 |
+
with open("workplace_score.json", "w", encoding="utf-8") as f:
|
| 113 |
+
json.dump(report, f, indent=2, ensure_ascii=False)
|
| 114 |
+
print(json.dumps(report, indent=2, ensure_ascii=False))
|
| 115 |
+
|
| 116 |
+
if __name__ == "__main__":
|
| 117 |
+
verify()
|
persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0011/verify_workplace.py
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
import json
|
| 4 |
+
|
| 5 |
+
def verify():
|
| 6 |
+
workspace = sys.argv[1] if len(sys.argv) > 1 else "."
|
| 7 |
+
score = 0
|
| 8 |
+
details = []
|
| 9 |
+
|
| 10 |
+
target_file = os.path.join(workspace, "ops/kill_target.json")
|
| 11 |
+
|
| 12 |
+
# 预期结果
|
| 13 |
+
EXPECTED_PID = 14920
|
| 14 |
+
EXPECTED_XID = 9948271
|
| 15 |
+
|
| 16 |
+
# 1. 检查文件是否存在 (10分)
|
| 17 |
+
if os.path.exists(target_file):
|
| 18 |
+
score += 10
|
| 19 |
+
details.append({"item": "文件检查", "score": 10, "max_score": 10, "passed": True, "reason": "ops/kill_target.json 存在"})
|
| 20 |
+
|
| 21 |
+
# 2. 检查 JSON 格式与合法性 (20分)
|
| 22 |
+
try:
|
| 23 |
+
with open(target_file, 'r', encoding='utf-8') as f:
|
| 24 |
+
data = json.load(f)
|
| 25 |
+
|
| 26 |
+
score += 20
|
| 27 |
+
details.append({"item": "JSON格式验证", "score": 20, "max_score": 20, "passed": True, "reason": "JSON 解析成功"})
|
| 28 |
+
|
| 29 |
+
# 3. 检查 PID 是否正确 (30分)
|
| 30 |
+
actual_pid = data.get("pid")
|
| 31 |
+
if actual_pid == EXPECTED_PID:
|
| 32 |
+
score += 30
|
| 33 |
+
details.append({"item": "PID 识别", "score": 30, "max_score": 30, "passed": True, "reason": "成功识别罪魁祸首 PID: 14920"})
|
| 34 |
+
elif str(actual_pid) == "0x3a48":
|
| 35 |
+
score += 15
|
| 36 |
+
details.append({"item": "PID 识别", "score": 15, "max_score": 30, "passed": False, "reason": "未将 PID 从十六进制转换为十进制"})
|
| 37 |
+
else:
|
| 38 |
+
details.append({"item": "PID 识别", "score": 0, "max_score": 30, "passed": False, "reason": f"PID 错误,识别为 {actual_pid}"})
|
| 39 |
+
|
| 40 |
+
# 4. 检查 XID 是否正确 (30分)
|
| 41 |
+
actual_xid = data.get("xid")
|
| 42 |
+
if actual_xid == EXPECTED_XID:
|
| 43 |
+
score += 30
|
| 44 |
+
details.append({"item": "XID 识别", "score": 30, "max_score": 30, "passed": True, "reason": "成功识别事务 ID: 9948271"})
|
| 45 |
+
else:
|
| 46 |
+
details.append({"item": "XID 识别", "score": 0, "max_score": 30, "passed": False, "reason": f"XID 错误,识别为 {actual_xid}"})
|
| 47 |
+
|
| 48 |
+
# 5. 检查是否存在多余字段或干扰项 (10分)
|
| 49 |
+
# 要求只有 pid 和 xid
|
| 50 |
+
allowed_keys = {"pid", "xid"}
|
| 51 |
+
actual_keys = set(data.keys())
|
| 52 |
+
if actual_keys == allowed_keys:
|
| 53 |
+
score += 10
|
| 54 |
+
details.append({"item": "字段精简度", "score": 10, "max_score": 10, "passed": True, "reason": "输出字段精准,无多余分析"})
|
| 55 |
+
else:
|
| 56 |
+
details.append({"item": "字段精简度", "score": 0, "max_score": 10, "passed": False, "reason": f"包含多余字段: {actual_keys - allowed_keys}"})
|
| 57 |
+
|
| 58 |
+
except json.JSONDecodeError:
|
| 59 |
+
details.append({"item": "JSON格式验证", "score": 0, "max_score": 20, "passed": False, "reason": "JSON 格式非法"})
|
| 60 |
+
except Exception as e:
|
| 61 |
+
details.append({"item": "异常错误", "score": 0, "max_score": 0, "passed": False, "reason": str(e)})
|
| 62 |
+
else:
|
| 63 |
+
details.append({"item": "文件检查", "score": 0, "max_score": 10, "passed": False, "reason": "ops/kill_target.json 不存在"})
|
| 64 |
+
|
| 65 |
+
# 写入评分结果
|
| 66 |
+
output_result = {
|
| 67 |
+
"total_score": score,
|
| 68 |
+
"details": details
|
| 69 |
+
}
|
| 70 |
+
with open("workplace_score.json", "w", encoding='utf-8') as f:
|
| 71 |
+
json.dump(output_result, f, indent=2, ensure_ascii=False)
|
| 72 |
+
|
| 73 |
+
if __name__ == "__main__":
|
| 74 |
+
verify()
|
persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0012/verify_workplace.py
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
import json
|
| 4 |
+
import httpx
|
| 5 |
+
from openai import OpenAI
|
| 6 |
+
|
| 7 |
+
# Configuration for LLM Judge
|
| 8 |
+
MOCK_API_KEY = os.environ.get("MOCK_API_KEY", "dummy_key")
|
| 9 |
+
MOCK_API_BASE = os.environ.get("MOCK_API_BASE", "http://localhost/v1")
|
| 10 |
+
MOCK_MODEL_NAME = os.environ.get("MOCK_MODEL_NAME", "gpt-5.4")
|
| 11 |
+
|
| 12 |
+
http_client = httpx.Client(verify=False)
|
| 13 |
+
client = OpenAI(
|
| 14 |
+
api_key=MOCK_API_KEY,
|
| 15 |
+
base_url=MOCK_API_BASE,
|
| 16 |
+
http_client=http_client
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
def llm_judge_content(prompt_text, file_content):
|
| 20 |
+
"""Unified interface for non-structured text validation."""
|
| 21 |
+
try:
|
| 22 |
+
response = client.chat.completions.create(
|
| 23 |
+
model=MOCK_MODEL_NAME,
|
| 24 |
+
messages=[
|
| 25 |
+
{"role": "system", "content": "You are a strict data validation assistant. Answer ONLY with 'YES' or 'NO'."},
|
| 26 |
+
{"role": "user", "content": f"{prompt_text}\n\n[File Content]:\n{file_content}"}
|
| 27 |
+
],
|
| 28 |
+
temperature=0
|
| 29 |
+
)
|
| 30 |
+
return "yes" in response.choices[0].message.content.strip().lower()
|
| 31 |
+
except Exception as e:
|
| 32 |
+
print(f"LLM API Error: {e}")
|
| 33 |
+
return False
|
| 34 |
+
|
| 35 |
+
def verify():
|
| 36 |
+
workspace = sys.argv[1] if len(sys.argv) > 1 else "."
|
| 37 |
+
score = 0
|
| 38 |
+
details = []
|
| 39 |
+
|
| 40 |
+
report_path = os.path.join(workspace, "report/conflict_summary.json")
|
| 41 |
+
|
| 42 |
+
# 1. Check file existence (10 points)
|
| 43 |
+
if os.path.exists(report_path):
|
| 44 |
+
score += 10
|
| 45 |
+
details.append({"item": "Check report existence", "score": 10, "max_score": 10, "passed": True, "reason": "File exists."})
|
| 46 |
+
else:
|
| 47 |
+
details.append({"item": "Check report existence", "score": 0, "max_score": 10, "passed": False, "reason": "File not found."})
|
| 48 |
+
# Cannot proceed without file
|
| 49 |
+
final_output(score, details)
|
| 50 |
+
return
|
| 51 |
+
|
| 52 |
+
# 2. Check JSON validity (10 points)
|
| 53 |
+
data = {}
|
| 54 |
+
try:
|
| 55 |
+
with open(report_path, 'r', encoding='utf-8') as f:
|
| 56 |
+
data = json.load(f)
|
| 57 |
+
score += 10
|
| 58 |
+
details.append({"item": "JSON Format Validation", "score": 10, "max_score": 10, "passed": True, "reason": "Valid JSON format."})
|
| 59 |
+
except Exception as e:
|
| 60 |
+
details.append({"item": "JSON Format Validation", "score": 0, "max_score": 10, "passed": False, "reason": f"Invalid JSON: {e}"})
|
| 61 |
+
final_output(score, details)
|
| 62 |
+
return
|
| 63 |
+
|
| 64 |
+
# 3. Check for the exactly three pieces of information constraint (10 points)
|
| 65 |
+
# The prompt asks for "exactly three pieces of information"
|
| 66 |
+
if len(data.keys()) == 3:
|
| 67 |
+
score += 10
|
| 68 |
+
details.append({"item": "Constraint: Exactly 3 fields", "score": 10, "max_score": 10, "passed": True, "reason": "Report contains exactly three keys."})
|
| 69 |
+
else:
|
| 70 |
+
details.append({"item": "Constraint: Exactly 3 fields", "score": 0, "max_score": 10, "passed": False, "reason": f"Expected 3 fields, found {len(data.keys())}."})
|
| 71 |
+
|
| 72 |
+
# 4. Verify Library Name (25 points)
|
| 73 |
+
# Use LLM to ensure flexible naming (fmt vs fmtlib)
|
| 74 |
+
lib_name = str(next(iter(data.values()))) # Get first value as a placeholder if keys aren't named
|
| 75 |
+
# Better to look for specific key logic, but prompt didn't define keys. Let's find the library name in the values.
|
| 76 |
+
values_str = json.dumps(data)
|
| 77 |
+
lib_correct = llm_judge_content("Does the following JSON content identify 'fmt' or 'fmtlib' as the conflicting library?", values_str)
|
| 78 |
+
if lib_correct:
|
| 79 |
+
score += 25
|
| 80 |
+
details.append({"item": "Library Identification", "score": 25, "max_score": 25, "passed": True, "reason": "Identified 'fmtlib' correctly."})
|
| 81 |
+
else:
|
| 82 |
+
details.append({"item": "Library Identification", "score": 0, "max_score": 25, "passed": False, "reason": "Failed to identify 'fmtlib' as the conflicting library."})
|
| 83 |
+
|
| 84 |
+
# 5. Verify Expected Version (20 points)
|
| 85 |
+
# Expected version in manifest is 9.1.0
|
| 86 |
+
if "9.1.0" in values_str:
|
| 87 |
+
score += 20
|
| 88 |
+
details.append({"item": "Expected Version Accuracy", "score": 20, "max_score": 20, "passed": True, "reason": "Found expected version 9.1.0."})
|
| 89 |
+
else:
|
| 90 |
+
details.append({"item": "Expected Version Accuracy", "score": 0, "max_score": 20, "passed": False, "reason": "Missing or incorrect expected version (should be 9.1.0)."})
|
| 91 |
+
|
| 92 |
+
# 6. Verify Rogue Version (25 points)
|
| 93 |
+
# Rogue version in log is 8.0.1
|
| 94 |
+
if "8.0.1" in values_str:
|
| 95 |
+
score += 25
|
| 96 |
+
details.append({"item": "Rogue Version Accuracy", "score": 25, "max_score": 25, "passed": True, "reason": "Found rogue version 8.0.1."})
|
| 97 |
+
else:
|
| 98 |
+
details.append({"item": "Rogue Version Accuracy", "score": 0, "max_score": 25, "passed": False, "reason": "Missing or incorrect rogue version (should be 8.0.1)."})
|
| 99 |
+
|
| 100 |
+
final_output(score, details)
|
| 101 |
+
|
| 102 |
+
def final_output(score, details):
|
| 103 |
+
output = {
|
| 104 |
+
"total_score": min(100, score),
|
| 105 |
+
"details": details
|
| 106 |
+
}
|
| 107 |
+
with open("workplace_score.json", "w", encoding="utf-8") as f:
|
| 108 |
+
json.dump(output, f, indent=2, ensure_ascii=False)
|
| 109 |
+
|
| 110 |
+
if __name__ == "__main__":
|
| 111 |
+
verify()
|
persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0013/verify_workplace.py
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
import json
|
| 4 |
+
|
| 5 |
+
def run_reference_logic(file_path):
|
| 6 |
+
"""
|
| 7 |
+
参考实现逻辑:解析原始 L2 数据并找出首个有效的买卖盘倒挂。
|
| 8 |
+
"""
|
| 9 |
+
max_ts = -1
|
| 10 |
+
result = None
|
| 11 |
+
|
| 12 |
+
if not os.path.exists(file_path):
|
| 13 |
+
return None
|
| 14 |
+
|
| 15 |
+
with open(file_path, "r", encoding="utf-8") as f:
|
| 16 |
+
for line in f:
|
| 17 |
+
parts = line.strip().split('\x01')
|
| 18 |
+
if len(parts) != 4:
|
| 19 |
+
continue
|
| 20 |
+
|
| 21 |
+
try:
|
| 22 |
+
ts = int(parts[0])
|
| 23 |
+
symbol = parts[1]
|
| 24 |
+
bids_str = parts[2]
|
| 25 |
+
asks_str = parts[3]
|
| 26 |
+
except ValueError:
|
| 27 |
+
continue
|
| 28 |
+
|
| 29 |
+
# 严格单调递增检查
|
| 30 |
+
if ts <= max_ts:
|
| 31 |
+
continue
|
| 32 |
+
max_ts = ts
|
| 33 |
+
|
| 34 |
+
# 解析买盘最优价 (Bid[0])
|
| 35 |
+
try:
|
| 36 |
+
best_bid = float(bids_str.split('|')[0].split(':')[0])
|
| 37 |
+
best_ask = float(asks_str.split('|')[0].split(':')[0])
|
| 38 |
+
except (IndexError, ValueError):
|
| 39 |
+
continue
|
| 40 |
+
|
| 41 |
+
# 检查买卖盘倒挂 (Crossed Book)
|
| 42 |
+
if best_bid >= best_ask:
|
| 43 |
+
result = {"symbol": symbol, "timestamp": ts}
|
| 44 |
+
break # 找到第一个符合条件的即可
|
| 45 |
+
return result
|
| 46 |
+
|
| 47 |
+
def main():
|
| 48 |
+
workspace = sys.argv[1] if len(sys.argv) > 1 else "."
|
| 49 |
+
target_json_path = os.path.join(workspace, "ops/target_replay.json")
|
| 50 |
+
raw_data_path = os.path.join(workspace, "snapshots/l2_orderbook.dat")
|
| 51 |
+
|
| 52 |
+
score = 0
|
| 53 |
+
details = []
|
| 54 |
+
|
| 55 |
+
# 1. 检查目标文件是否存在 (10分)
|
| 56 |
+
if os.path.exists(target_json_path):
|
| 57 |
+
score += 10
|
| 58 |
+
details.append({"item": "检查结果文件是否存在", "score": 10, "max_score": 10, "passed": True, "reason": "文件 ops/target_replay.json 已生成"})
|
| 59 |
+
else:
|
| 60 |
+
details.append({"item": "检查结果文件是否存在", "score": 0, "max_score": 10, "passed": False, "reason": "文件 ops/target_replay.json 未找到"})
|
| 61 |
+
# 写入最终结果并提前退出
|
| 62 |
+
with open("workplace_score.json", "w") as f:
|
| 63 |
+
json.dump({"total_score": 0, "details": details}, f)
|
| 64 |
+
return
|
| 65 |
+
|
| 66 |
+
# 2. 检查 JSON 格式及字段 (20分)
|
| 67 |
+
agent_data = {}
|
| 68 |
+
try:
|
| 69 |
+
with open(target_json_path, "r") as f:
|
| 70 |
+
agent_data = json.load(f)
|
| 71 |
+
score += 10
|
| 72 |
+
details.append({"item": "JSON 格式合法性", "score": 10, "max_score": 10, "passed": True, "reason": "JSON 解析成功"})
|
| 73 |
+
|
| 74 |
+
# 检查是否包含核心字段(允许大小写差异,但必须逻辑清晰)
|
| 75 |
+
keys = [k.lower() for k in agent_data.keys()]
|
| 76 |
+
if any("symbol" in k for k in keys) and any("timestamp" in k for k in keys):
|
| 77 |
+
score += 10
|
| 78 |
+
details.append({"item": "核心字段检查", "score": 10, "max_score": 10, "passed": True, "reason": "包含 symbol 和 timestamp 相关字段"})
|
| 79 |
+
else:
|
| 80 |
+
details.append({"item": "核心字段检查", "score": 0, "max_score": 10, "passed": False, "reason": f"缺少必要字段,当前包含: {list(agent_data.keys())}"})
|
| 81 |
+
except Exception as e:
|
| 82 |
+
details.append({"item": "JSON 格式合法性", "score": 0, "max_score": 20, "passed": False, "reason": f"解析失败: {str(e)}"})
|
| 83 |
+
|
| 84 |
+
# 3. 核心逻辑验证 (70分)
|
| 85 |
+
gold_standard = run_reference_logic(raw_data_path)
|
| 86 |
+
if not gold_standard:
|
| 87 |
+
details.append({"item": "数据源验证", "score": 0, "max_score": 70, "passed": False, "reason": "无法从原始数据中计算出参考答案,请检查环境"})
|
| 88 |
+
else:
|
| 89 |
+
agent_symbol = None
|
| 90 |
+
agent_ts = None
|
| 91 |
+
# 模糊匹配 Key
|
| 92 |
+
for k, v in agent_data.items():
|
| 93 |
+
if "symbol" in k.lower(): agent_symbol = v
|
| 94 |
+
if "timestamp" in k.lower() or "ts" in k.lower(): agent_ts = v
|
| 95 |
+
|
| 96 |
+
if str(agent_symbol) == str(gold_standard["symbol"]) and str(agent_ts) == str(gold_standard["timestamp"]):
|
| 97 |
+
score += 70
|
| 98 |
+
details.append({"item": "计算结果准确性", "score": 70, "max_score": 70, "passed": True, "reason": "成功定位到唯一的有效倒挂记录:FAT_FINGER_X"})
|
| 99 |
+
elif str(agent_symbol) == "TRAP_SYM":
|
| 100 |
+
score += 20
|
| 101 |
+
details.append({"item": "计算结果准确性", "score": 20, "max_score": 70, "passed": False, "reason": "错误!Agent 抓取了被时间戳倒挂过滤掉的陷阱数据 (TRAP_SYM)"})
|
| 102 |
+
else:
|
| 103 |
+
details.append({"item": "计算结果准确性", "score": 0, "max_score": 70, "passed": False, "reason": f"结果不匹配。期望: {gold_standard}, 实际: {agent_data}"})
|
| 104 |
+
|
| 105 |
+
# 写入最终总分
|
| 106 |
+
with open("workplace_score.json", "w") as f:
|
| 107 |
+
json.dump({"total_score": score, "details": details}, f, indent=2)
|
| 108 |
+
|
| 109 |
+
if __name__ == "__main__":
|
| 110 |
+
main()
|
persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0014/verify_workplace.py
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
import json
|
| 4 |
+
|
| 5 |
+
def verify():
|
| 6 |
+
workspace = sys.argv[1] if len(sys.argv) > 1 else "."
|
| 7 |
+
report_path = os.path.join(workspace, "report/root_cause.json")
|
| 8 |
+
score = 0
|
| 9 |
+
details = []
|
| 10 |
+
|
| 11 |
+
# 1. Check Directory and File Existence (10 points)
|
| 12 |
+
if os.path.exists(os.path.join(workspace, "report")):
|
| 13 |
+
score += 5
|
| 14 |
+
details.append({"item": "检查报告目录", "score": 5, "max_score": 5, "passed": True, "reason": "目录 report 存在"})
|
| 15 |
+
else:
|
| 16 |
+
details.append({"item": "检查报告目录", "score": 0, "max_score": 5, "passed": False, "reason": "目录 report 不存在"})
|
| 17 |
+
|
| 18 |
+
if os.path.exists(report_path):
|
| 19 |
+
score += 5
|
| 20 |
+
details.append({"item": "检查报告文件是否存在", "score": 5, "max_score": 5, "passed": True, "reason": "文件 root_cause.json 存在"})
|
| 21 |
+
else:
|
| 22 |
+
details.append({"item": "检查报告文件是否存在", "score": 0, "max_score": 5, "passed": False, "reason": "文件 root_cause.json 不存在"})
|
| 23 |
+
# If the file doesn't exist, we can't perform further checks
|
| 24 |
+
save_results(score, details)
|
| 25 |
+
return
|
| 26 |
+
|
| 27 |
+
# 2. JSON Validity and Structure (20 points)
|
| 28 |
+
try:
|
| 29 |
+
with open(report_path, 'r', encoding='utf-8') as f:
|
| 30 |
+
data = json.load(f)
|
| 31 |
+
score += 10
|
| 32 |
+
details.append({"item": "检查JSON格式合法性", "score": 10, "max_score": 10, "passed": True, "reason": "JSON解析成功"})
|
| 33 |
+
|
| 34 |
+
required_keys = ["device_address", "register_address", "illegal_value"]
|
| 35 |
+
missing_keys = [k for k in required_keys if k not in data]
|
| 36 |
+
if not missing_keys:
|
| 37 |
+
score += 10
|
| 38 |
+
details.append({"item": "检查JSON关键字段", "score": 10, "max_score": 10, "passed": True, "reason": "包含所有必需字段"})
|
| 39 |
+
else:
|
| 40 |
+
details.append({"item": "检查JSON关键字段", "score": 0, "max_score": 10, "passed": False, "reason": f"缺失字段: {missing_keys}"})
|
| 41 |
+
except Exception as e:
|
| 42 |
+
details.append({"item": "检查JSON格式合法性", "score": 0, "max_score": 20, "passed": False, "reason": f"JSON解析失败: {str(e)}"})
|
| 43 |
+
save_results(score, details)
|
| 44 |
+
return
|
| 45 |
+
|
| 46 |
+
# 3. Content Accuracy (70 points)
|
| 47 |
+
# Target Values based on env_builder.py:
|
| 48 |
+
# device_address: 0x5C, register_address: 0x10, illegal_value: 0x4B
|
| 49 |
+
|
| 50 |
+
def normalize_hex(val):
|
| 51 |
+
if not isinstance(val, str): return None
|
| 52 |
+
try:
|
| 53 |
+
return hex(int(val, 16)).lower()
|
| 54 |
+
except:
|
| 55 |
+
return None
|
| 56 |
+
|
| 57 |
+
dev_addr = normalize_hex(data.get("device_address"))
|
| 58 |
+
reg_addr = normalize_hex(data.get("register_address"))
|
| 59 |
+
ill_val = normalize_hex(data.get("illegal_value"))
|
| 60 |
+
|
| 61 |
+
# Device Address (20 points)
|
| 62 |
+
if dev_addr == "0x5c":
|
| 63 |
+
score += 20
|
| 64 |
+
details.append({"item": "验证设备地址 (device_address)", "score": 20, "max_score": 20, "passed": True, "reason": "正确识别 PMIC 地址 0x5C"})
|
| 65 |
+
else:
|
| 66 |
+
details.append({"item": "验证设备地址 (device_address)", "score": 0, "max_score": 20, "passed": False, "reason": f"预期 0x5C, 实际得到 {data.get('device_address')}"})
|
| 67 |
+
|
| 68 |
+
# Register Address (20 points)
|
| 69 |
+
if reg_addr == "0x10":
|
| 70 |
+
score += 20
|
| 71 |
+
details.append({"item": "验证寄存器地址 (register_address)", "score": 20, "max_score": 20, "passed": True, "reason": "正确识别核心电压寄存器 0x10"})
|
| 72 |
+
else:
|
| 73 |
+
details.append({"item": "验证寄存器地址 (register_address)", "score": 0, "max_score": 20, "passed": False, "reason": f"预期 0x10, 实际得到 {data.get('register_address')}"})
|
| 74 |
+
|
| 75 |
+
# Illegal Value (30 points)
|
| 76 |
+
if ill_val == "0x4b":
|
| 77 |
+
score += 30
|
| 78 |
+
details.append({"item": "验证非法写入值 (illegal_value)", "score": 30, "max_score": 30, "passed": True, "reason": "正确锁定导致崩溃的非法值 0x4B (超过 0x3F)"})
|
| 79 |
+
else:
|
| 80 |
+
details.append({"item": "验证非法写入值 (illegal_value)", "score": 0, "max_score": 30, "passed": False, "reason": f"预期 0x4B, 实际得到 {data.get('illegal_value')}"})
|
| 81 |
+
|
| 82 |
+
save_results(score, details)
|
| 83 |
+
|
| 84 |
+
def save_results(score, details):
|
| 85 |
+
output = {
|
| 86 |
+
"total_score": score,
|
| 87 |
+
"details": details
|
| 88 |
+
}
|
| 89 |
+
with open("workplace_score.json", "w", encoding="utf-8") as f:
|
| 90 |
+
json.dump(output, f, indent=2, ensure_ascii=False)
|
| 91 |
+
|
| 92 |
+
if __name__ == "__main__":
|
| 93 |
+
verify()
|
persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0015/verify_workplace.py
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
import json
|
| 4 |
+
import httpx
|
| 5 |
+
from openai import OpenAI
|
| 6 |
+
|
| 7 |
+
MOCK_API_KEY = os.environ.get("MOCK_API_KEY", "dummy_key")
|
| 8 |
+
MOCK_API_BASE = os.environ.get("MOCK_API_BASE", "http://localhost/v1")
|
| 9 |
+
MOCK_MODEL_NAME = os.environ.get("MOCK_MODEL_NAME", "gpt-5.4")
|
| 10 |
+
|
| 11 |
+
# 初始化客户端,必须关闭 SSL 验证
|
| 12 |
+
http_client = httpx.Client(verify=False)
|
| 13 |
+
client = OpenAI(
|
| 14 |
+
api_key=MOCK_API_KEY,
|
| 15 |
+
base_url=MOCK_API_BASE,
|
| 16 |
+
http_client=http_client
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
def llm_judge_content(prompt_text, file_content):
|
| 20 |
+
# 此函数为检测非结构化文本的统一接口
|
| 21 |
+
try:
|
| 22 |
+
response = client.chat.completions.create(
|
| 23 |
+
model=MOCK_MODEL_NAME,
|
| 24 |
+
messages=[
|
| 25 |
+
{"role": "system", "content": "You are a strict data validation assistant. Answer ONLY with 'YES' or 'NO'."},
|
| 26 |
+
{"role": "user", "content": f"{prompt_text}\n\n[File Content]:\n{file_content}"}
|
| 27 |
+
],
|
| 28 |
+
temperature=0
|
| 29 |
+
)
|
| 30 |
+
return "yes" in response.choices[0].message.content.strip().lower()
|
| 31 |
+
except Exception as e:
|
| 32 |
+
print(f"LLM API Error: {e}")
|
| 33 |
+
return False
|
| 34 |
+
|
| 35 |
+
def verify():
|
| 36 |
+
workspace = sys.argv[1] if len(sys.argv) > 1 else "."
|
| 37 |
+
target_file = os.path.join(workspace, "optimizations", "target_gates.json")
|
| 38 |
+
|
| 39 |
+
details = []
|
| 40 |
+
total_score = 0
|
| 41 |
+
|
| 42 |
+
# 1. 检查目标文件是否存在 (10分)
|
| 43 |
+
if os.path.exists(target_file):
|
| 44 |
+
details.append({"item": "检查目标文件 target_gates.json 是否存在", "score": 10, "max_score": 10, "passed": True, "reason": "文件已建立"})
|
| 45 |
+
total_score += 10
|
| 46 |
+
else:
|
| 47 |
+
details.append({"item": "检查目标文件 target_gates.json 是否存在", "score": 0, "max_score": 10, "passed": False, "reason": "文件不存在,未按要求输出"})
|
| 48 |
+
write_score(total_score, details)
|
| 49 |
+
return
|
| 50 |
+
|
| 51 |
+
# 2. 检查 JSON 格式合法性 (10分)
|
| 52 |
+
# 此处严禁对结构化数据进行模糊匹配,必须原生解析
|
| 53 |
+
try:
|
| 54 |
+
with open(target_file, "r", encoding="utf-8") as f:
|
| 55 |
+
data = json.load(f)
|
| 56 |
+
details.append({"item": "检查 JSON 格式合法性", "score": 10, "max_score": 10, "passed": True, "reason": "可成功解析为 JSON"})
|
| 57 |
+
total_score += 10
|
| 58 |
+
except Exception as e:
|
| 59 |
+
details.append({"item": "检查 JSON 格式合法性", "score": 0, "max_score": 10, "passed": False, "reason": f"非合法 JSON 格式,解析报错: {e}"})
|
| 60 |
+
write_score(total_score, details)
|
| 61 |
+
return
|
| 62 |
+
|
| 63 |
+
# 3. 检查 Schema 数据结构合规性 (10分)
|
| 64 |
+
# 题目明确要求输出 3 个逻辑门的 ID
|
| 65 |
+
if isinstance(data, list) and len(data) == 3 and all(isinstance(x, str) for x in data):
|
| 66 |
+
details.append({"item": "检查 Schema(含有3个字符串的数组)", "score": 10, "max_score": 10, "passed": True, "reason": "结构符合要求:一个包含3个字符串元素的列表"})
|
| 67 |
+
total_score += 10
|
| 68 |
+
else:
|
| 69 |
+
details.append({"item": "检查 Schema(含有3个字符串的数组)", "score": 0, "max_score": 10, "passed": False, "reason": f"未返回仅包含 3 个字符串的数组。当前数据:{data}"})
|
| 70 |
+
# 结构不对扣光后续分数,结束验证
|
| 71 |
+
write_score(total_score, details)
|
| 72 |
+
return
|
| 73 |
+
|
| 74 |
+
# 4. 检查内容:命中率 (30分,每个关键 ID 10分)
|
| 75 |
+
# 根据底层注入规则:数据量最大的 3 个门固定为 F9A1, F9A2, F9A3
|
| 76 |
+
expected_gates = {"GATE_F9A1", "GATE_F9A2", "GATE_F9A3"}
|
| 77 |
+
matched = set(data).intersection(expected_gates)
|
| 78 |
+
hit_count = len(matched)
|
| 79 |
+
hit_score = hit_count * 10
|
| 80 |
+
|
| 81 |
+
if hit_count == 3:
|
| 82 |
+
details.append({"item": "检查提取目标门 ID 的精确度", "score": 30, "max_score": 30, "passed": True, "reason": "完美找出所有 3 个异常通信量的逻辑门"})
|
| 83 |
+
else:
|
| 84 |
+
missing = expected_gates - set(data)
|
| 85 |
+
details.append({"item": "检查提取目标门 ID 的精确度", "score": hit_score, "max_score": 30, "passed": False, "reason": f"找到了 {hit_count} 个异常逻辑门, 缺失 {missing}"})
|
| 86 |
+
total_score += hit_score
|
| 87 |
+
|
| 88 |
+
# 5. 检查内容:排序正确性 (40分)
|
| 89 |
+
# 数据量排序:GATE_F9A1(3500B) > GATE_F9A2(2800B) > GATE_F9A3(2100B)
|
| 90 |
+
expected_order = ["GATE_F9A1", "GATE_F9A2", "GATE_F9A3"]
|
| 91 |
+
if data == expected_order:
|
| 92 |
+
details.append({"item": "检查数组降序排序正确性", "score": 40, "max_score": 40, "passed": True, "reason": "元素严格按数据载荷大小从大到小排列"})
|
| 93 |
+
total_score += 40
|
| 94 |
+
else:
|
| 95 |
+
# 如果找齐了三个,但排序错误,可给出部分分数 10 分以作梯度区分,如果没找齐则得 0 分。
|
| 96 |
+
if hit_count == 3:
|
| 97 |
+
details.append({"item": "检查数组降序排序正确性", "score": 10, "max_score": 40, "passed": False, "reason": f"找出了所有门但排序错误,期望 {expected_order},实际 {data}"})
|
| 98 |
+
total_score += 10
|
| 99 |
+
else:
|
| 100 |
+
details.append({"item": "检查数组降序排序正��性", "score": 0, "max_score": 40, "passed": False, "reason": "由于存在找错的门,排序亦判定为完全失败"})
|
| 101 |
+
|
| 102 |
+
write_score(total_score, details)
|
| 103 |
+
|
| 104 |
+
def write_score(total_score, details):
|
| 105 |
+
res = {
|
| 106 |
+
"total_score": total_score,
|
| 107 |
+
"details": details
|
| 108 |
+
}
|
| 109 |
+
# 确保写入工作目录下的 workplace_score.json
|
| 110 |
+
with open("workplace_score.json", "w", encoding="utf-8") as f:
|
| 111 |
+
json.dump(res, f, ensure_ascii=False, indent=2)
|
| 112 |
+
|
| 113 |
+
if __name__ == "__main__":
|
| 114 |
+
verify()
|
persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0016/verify_workplace.py
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
import json
|
| 4 |
+
import re
|
| 5 |
+
import httpx
|
| 6 |
+
from openai import OpenAI
|
| 7 |
+
|
| 8 |
+
MOCK_API_KEY = os.environ.get("MOCK_API_KEY", "dummy_key")
|
| 9 |
+
MOCK_API_BASE = os.environ.get("MOCK_API_BASE", "http://localhost/v1")
|
| 10 |
+
MOCK_MODEL_NAME = os.environ.get("MOCK_MODEL_NAME", "gpt-5.4")
|
| 11 |
+
|
| 12 |
+
# 初始化客户端,必须关闭 SSL 验证
|
| 13 |
+
http_client = httpx.Client(verify=False)
|
| 14 |
+
client = OpenAI(
|
| 15 |
+
api_key=MOCK_API_KEY,
|
| 16 |
+
base_url=MOCK_API_BASE,
|
| 17 |
+
http_client=http_client
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
def llm_judge_content(prompt_text, file_content):
|
| 21 |
+
try:
|
| 22 |
+
response = client.chat.completions.create(
|
| 23 |
+
model=MOCK_MODEL_NAME,
|
| 24 |
+
messages=[
|
| 25 |
+
{"role": "system", "content": "You are a strict data validation assistant. Answer ONLY with 'YES' or 'NO'."},
|
| 26 |
+
{"role": "user", "content": f"{prompt_text}\n\n[File Content]:\n{file_content}"}
|
| 27 |
+
],
|
| 28 |
+
temperature=0
|
| 29 |
+
)
|
| 30 |
+
return "yes" in response.choices[0].message.content.strip().lower()
|
| 31 |
+
except Exception as e:
|
| 32 |
+
print(f"LLM API Error: {e}")
|
| 33 |
+
return False
|
| 34 |
+
|
| 35 |
+
def verify():
|
| 36 |
+
workspace = sys.argv[1] if len(sys.argv) > 1 else "."
|
| 37 |
+
target_file = os.path.join(workspace, "processed", "clean_traj_ids.txt")
|
| 38 |
+
|
| 39 |
+
score_details = []
|
| 40 |
+
total_score = 0
|
| 41 |
+
|
| 42 |
+
# 1. 检查目标文件是否存在 (15分)
|
| 43 |
+
file_exists = os.path.exists(target_file) and os.path.isfile(target_file)
|
| 44 |
+
if file_exists:
|
| 45 |
+
score_details.append({"item": "检查目标文件是否存在", "score": 15, "max_score": 15, "passed": True, "reason": "成功找到 `processed/clean_traj_ids.txt`"})
|
| 46 |
+
total_score += 15
|
| 47 |
+
else:
|
| 48 |
+
score_details.append({"item": "检查目标文件是否存在", "score": 0, "max_score": 15, "passed": False, "reason": "未找到目标文件 `processed/clean_traj_ids.txt`"})
|
| 49 |
+
|
| 50 |
+
extracted_ids = []
|
| 51 |
+
pure_format = False
|
| 52 |
+
|
| 53 |
+
if file_exists:
|
| 54 |
+
try:
|
| 55 |
+
with open(target_file, "r", encoding="utf-8") as f:
|
| 56 |
+
lines = f.readlines()
|
| 57 |
+
|
| 58 |
+
# 清理空行并解析
|
| 59 |
+
raw_lines = [line.strip() for line in lines if line.strip()]
|
| 60 |
+
|
| 61 |
+
# 2. 检查输出纯净度 (10分)
|
| 62 |
+
# 要求:别整那些没用的报告,只要 ID。所有的非空行应当全都是形如 T-xxxx 的格式。
|
| 63 |
+
pure_format = all(re.match(r'^T-\d+$', line) for line in raw_lines)
|
| 64 |
+
if pure_format and len(raw_lines) > 0:
|
| 65 |
+
score_details.append({"item": "检查输出纯净度", "score": 10, "max_score": 10, "passed": True, "reason": "输出无冗余报告废话,每行格式均为合法的 ID"})
|
| 66 |
+
total_score += 10
|
| 67 |
+
else:
|
| 68 |
+
score_details.append({"item": "检查输出纯净度", "score": 0, "max_score": 10, "passed": False, "reason": "输出中混杂了自然语言报告、无效格式或文件全空"})
|
| 69 |
+
|
| 70 |
+
# 尝试提取出里面看起来像ID的串用于进一步逻辑验证
|
| 71 |
+
extracted_ids = []
|
| 72 |
+
for line in raw_lines:
|
| 73 |
+
# 若包含自然语言,则利用正则从中强行提取 T-xxx 评估实质清洗逻辑
|
| 74 |
+
matches = re.findall(r'T-\d+', line)
|
| 75 |
+
extracted_ids.extend(matches)
|
| 76 |
+
|
| 77 |
+
except Exception as e:
|
| 78 |
+
score_details.append({"item": "检查输出纯净度", "score": 0, "max_score": 10, "passed": False, "reason": f"文件读取异常: {e}"})
|
| 79 |
+
else:
|
| 80 |
+
score_details.append({"item": "检查输出纯净度", "score": 0, "max_score": 10, "passed": False, "reason": "文件不存在,跳过纯净度检查"})
|
| 81 |
+
|
| 82 |
+
extracted_set = set(extracted_ids)
|
| 83 |
+
|
| 84 |
+
# 3. 检查乱码与损坏数据过滤能力 (15分)
|
| 85 |
+
# T-1005 (json未闭合) 和 T-1006 (十六进制乱码前缀) 不应存在
|
| 86 |
+
if file_exists:
|
| 87 |
+
if "T-1005" not in extracted_set and "T-1006" not in extracted_set:
|
| 88 |
+
score_details.append({"item": "过滤损坏的JSON与乱码数据", "score": 15, "max_score": 15, "passed": True, "reason": "正确剔除了无法被正常解析的 T-1005 和 T-1006"})
|
| 89 |
+
total_score += 15
|
| 90 |
+
else:
|
| 91 |
+
score_details.append({"item": "过滤损坏的JSON与乱码数据", "score": 0, "max_score": 15, "passed": False, "reason": "未正确拦截格式残缺或含乱码前缀的脏数据"})
|
| 92 |
+
else:
|
| 93 |
+
score_details.append({"item": "过滤损坏的JSON与乱码数据", "score": 0, "max_score": 15, "passed": False, "reason": "文件不存在,该项记 0 分"})
|
| 94 |
+
|
| 95 |
+
# 4. 检查 Token 截断数据的过滤能力 (15分)
|
| 96 |
+
# T-1003 (finish_reason = length) 不应存在
|
| 97 |
+
if file_exists:
|
| 98 |
+
if "T-1003" not in extracted_set:
|
| 99 |
+
score_details.append({"item": "过滤严重截断数据", "score": 15, "max_score": 15, "passed": True, "reason": "正确剔除了因为 max_tokens 截断(length)的残缺数据 T-1003"})
|
| 100 |
+
total_score += 15
|
| 101 |
+
else:
|
| 102 |
+
score_details.append({"item": "过滤严重截断数据", "score": 0, "max_score": 15, "passed": False, "reason": "未正确拦截 finish_reason 为 length 的数据"})
|
| 103 |
+
else:
|
| 104 |
+
score_details.append({"item": "过滤严重截断数据", "score": 0, "max_score": 15, "passed": False, "reason": "文件不存在,该项记 0 分"})
|
| 105 |
+
|
| 106 |
+
# 5. 检查 Agent 死循环数据的过滤能力 (15分)
|
| 107 |
+
# T-1002 (连续相同的 tool calls) 不应存在
|
| 108 |
+
if file_exists:
|
| 109 |
+
if "T-1002" not in extracted_set:
|
| 110 |
+
score_details.append({"item": "过滤陷入死循环的工具调用数据", "score": 15, "max_score": 15, "passed": True, "reason": "正确剔除了陷入无意义重复调用的 T-1002 数据"})
|
| 111 |
+
total_score += 15
|
| 112 |
+
else:
|
| 113 |
+
score_details.append({"item": "过滤陷入死循环的工具调用数据", "score": 0, "max_score": 15, "passed": False, "reason": "未正确拦截呈现死循环特征的轨迹数据 T-1002"})
|
| 114 |
+
else:
|
| 115 |
+
score_details.append({"item": "过滤陷入死循环的工具调用数据", "score": 0, "max_score": 15, "passed": False, "reason": "文件不存在,该项记 0 分"})
|
| 116 |
+
|
| 117 |
+
# 6. 检查健康轨迹的全量留存与拒答幻觉情况 (30分)
|
| 118 |
+
# 正确的数据集应当只包含:T-1001, T-1004, T-1007
|
| 119 |
+
if file_exists:
|
| 120 |
+
expected_ids = {"T-1001", "T-1004", "T-1007"}
|
| 121 |
+
missing_ids = expected_ids - extracted_set
|
| 122 |
+
# 计算提取列表中多出的且不在剔除名单里的虚构 ID (幻觉)
|
| 123 |
+
dirty_ids = {"T-1002", "T-1003", "T-1005", "T-1006"}
|
| 124 |
+
hallucinated_ids = extracted_set - expected_ids - dirty_ids
|
| 125 |
+
|
| 126 |
+
health_score = 30
|
| 127 |
+
penalties = []
|
| 128 |
+
|
| 129 |
+
if len(missing_ids) > 0:
|
| 130 |
+
penalty = len(missing_ids) * 10
|
| 131 |
+
health_score -= penalty
|
| 132 |
+
penalties.append(f"遗漏了合法数据 {missing_ids},扣 {penalty} 分")
|
| 133 |
+
|
| 134 |
+
if len(hallucinated_ids) > 0:
|
| 135 |
+
penalty = len(hallucinated_ids) * 10
|
| 136 |
+
health_score -= penalty
|
| 137 |
+
penalties.append(f"捏造了不存在的数据 ID {hallucinated_ids},扣 {penalty} 分")
|
| 138 |
+
|
| 139 |
+
health_score = max(0, health_score)
|
| 140 |
+
|
| 141 |
+
if health_score == 30:
|
| 142 |
+
score_details.append({"item": "精准留存合法数据与幻觉抑制", "score": 30, "max_score": 30, "passed": True, "reason": "完美找出了所有的健康数据 T-1001, T-1004, T-1007,且无捏造或多余数据!"})
|
| 143 |
+
else:
|
| 144 |
+
score_details.append({"item": "精准留存合法数据与幻觉抑制", "score": health_score, "max_score": 30, "passed": False, "reason": "; ".join(penalties)})
|
| 145 |
+
|
| 146 |
+
total_score += health_score
|
| 147 |
+
else:
|
| 148 |
+
score_details.append({"item": "精准留存合法数据与幻觉抑制", "score": 0, "max_score": 30, "passed": False, "reason": "文件不存在,该项记 0 分"})
|
| 149 |
+
|
| 150 |
+
# 保存评分文件
|
| 151 |
+
score_data = {
|
| 152 |
+
"total_score": total_score,
|
| 153 |
+
"details": score_details
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
with open(os.path.join(workspace, "workplace_score.json"), "w", encoding="utf-8") as f:
|
| 157 |
+
json.dump(score_data, f, ensure_ascii=False, indent=2)
|
| 158 |
+
|
| 159 |
+
if __name__ == "__main__":
|
| 160 |
+
verify()
|
persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0017/verify_workplace.py
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
import json
|
| 4 |
+
import httpx
|
| 5 |
+
from openai import OpenAI
|
| 6 |
+
|
| 7 |
+
MOCK_API_KEY = os.environ.get("MOCK_API_KEY", "dummy_key")
|
| 8 |
+
MOCK_API_BASE = os.environ.get("MOCK_API_BASE", "http://localhost/v1")
|
| 9 |
+
MOCK_MODEL_NAME = os.environ.get("MOCK_MODEL_NAME", "gpt-5.4")
|
| 10 |
+
|
| 11 |
+
# 初始化客户端,必须关闭 SSL 验证
|
| 12 |
+
http_client = httpx.Client(verify=False)
|
| 13 |
+
client = OpenAI(
|
| 14 |
+
api_key=MOCK_API_KEY,
|
| 15 |
+
base_url=MOCK_API_BASE,
|
| 16 |
+
http_client=http_client
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
def llm_judge_content(prompt_text, file_content):
|
| 20 |
+
# 此函数为检测非结构化文本的统一接口
|
| 21 |
+
try:
|
| 22 |
+
response = client.chat.completions.create(
|
| 23 |
+
model=MOCK_MODEL_NAME,
|
| 24 |
+
messages=[
|
| 25 |
+
{"role": "system", "content": "You are a strict data validation assistant. Answer ONLY with 'YES' or 'NO'."},
|
| 26 |
+
{"role": "user", "content": f"{prompt_text}\n\n[File Content]:\n{file_content}"}
|
| 27 |
+
],
|
| 28 |
+
temperature=0
|
| 29 |
+
)
|
| 30 |
+
return "yes" in response.choices[0].message.content.strip().lower()
|
| 31 |
+
except Exception as e:
|
| 32 |
+
print(f"LLM API Error: {e}")
|
| 33 |
+
return False
|
| 34 |
+
|
| 35 |
+
def main():
|
| 36 |
+
workspace = sys.argv[1] if len(sys.argv) > 1 else "."
|
| 37 |
+
report_file = os.path.join(workspace, "report", "hacker.json")
|
| 38 |
+
|
| 39 |
+
score = 0
|
| 40 |
+
details = []
|
| 41 |
+
|
| 42 |
+
# 1. 检查目标目录存在性 (5分)
|
| 43 |
+
has_dir = os.path.isdir(os.path.join(workspace, "report"))
|
| 44 |
+
if has_dir:
|
| 45 |
+
score += 5
|
| 46 |
+
details.append({"item": "检查 report 目录是否存在", "score": 5, "max_score": 5, "passed": True, "reason": "report 目录存在"})
|
| 47 |
+
else:
|
| 48 |
+
details.append({"item": "检查 report 目录是否存在", "score": 0, "max_score": 5, "passed": False, "reason": "report 目录不存在"})
|
| 49 |
+
|
| 50 |
+
# 2. 检查结果文件存在性 (15分)
|
| 51 |
+
has_file = os.path.isfile(report_file)
|
| 52 |
+
if has_file:
|
| 53 |
+
score += 15
|
| 54 |
+
details.append({"item": "检查 hacker.json 文件是否存在", "score": 15, "max_score": 15, "passed": True, "reason": "hacker.json 文件存在"})
|
| 55 |
+
else:
|
| 56 |
+
details.append({"item": "检查 hacker.json 文件是否存在", "score": 0, "max_score": 15, "passed": False, "reason": "hacker.json 文件不存在"})
|
| 57 |
+
|
| 58 |
+
if not has_file:
|
| 59 |
+
save_score(score, details)
|
| 60 |
+
return
|
| 61 |
+
|
| 62 |
+
# 3. 检查文件格式合法性 (10分)
|
| 63 |
+
try:
|
| 64 |
+
with open(report_file, "r", encoding="utf-8") as f:
|
| 65 |
+
data = json.load(f)
|
| 66 |
+
score += 10
|
| 67 |
+
details.append({"item": "文件 JSON 格式合法性", "score": 10, "max_score": 10, "passed": True, "reason": "成功解析为 JSON 格式"})
|
| 68 |
+
except Exception as e:
|
| 69 |
+
details.append({"item": "文件 JSON 格式合法性", "score": 0, "max_score": 10, "passed": False, "reason": f"无法解析为 JSON,解析失败: {str(e)}"})
|
| 70 |
+
save_score(score, details)
|
| 71 |
+
return
|
| 72 |
+
|
| 73 |
+
# 4. 字段规范与幻觉严查 (10分)
|
| 74 |
+
if not isinstance(data, dict):
|
| 75 |
+
details.append({"item": "字段规范检查", "score": 0, "max_score": 10, "passed": False, "reason": "JSON 根节点不是对象(dict)结构"})
|
| 76 |
+
else:
|
| 77 |
+
keys = list(data.keys())
|
| 78 |
+
expected_keys = {"hacker_address", "exploit_tx_hash"}
|
| 79 |
+
if set(keys) == expected_keys:
|
| 80 |
+
score += 10
|
| 81 |
+
details.append({"item": "字段规范检查", "score": 10, "max_score": 10, "passed": True, "reason": "字段完全匹配要求,无多余捏造字段"})
|
| 82 |
+
elif expected_keys.issubset(set(keys)):
|
| 83 |
+
score += 5
|
| 84 |
+
details.append({"item": "字段规范检查", "score": 5, "max_score": 10, "passed": False, "reason": "包含目标字段,但存在捏造的多余字段,部分扣分"})
|
| 85 |
+
else:
|
| 86 |
+
missing = expected_keys - set(keys)
|
| 87 |
+
details.append({"item": "字段规范检查", "score": 0, "max_score": 10, "passed": False, "reason": f"缺失必要字段: {missing}"})
|
| 88 |
+
|
| 89 |
+
# 5. 黑客原始地址提取准确性 (30分)
|
| 90 |
+
ans_addr = "0xbadc0ffeebadc0ffeebadc0ffeebadc0ffeebadc"
|
| 91 |
+
if isinstance(data, dict) and "hacker_address" in data:
|
| 92 |
+
addr = str(data["hacker_address"]).strip().lower()
|
| 93 |
+
if addr == ans_addr:
|
| 94 |
+
score += 30
|
| 95 |
+
details.append({"item": "黑客地址正确性", "score": 30, "max_score": 30, "passed": True, "reason": "精准定位并提取了对应的 hacker_address"})
|
| 96 |
+
else:
|
| 97 |
+
details.append({"item": "黑客地址正确性", "score": 0, "max_score": 30, "passed": False, "reason": f"hacker_address 错误。期望: {ans_addr},实际: {addr}"})
|
| 98 |
+
else:
|
| 99 |
+
details.append({"item": "黑客地址正确性", "score": 0, "max_score": 30, "passed": False, "reason": "无法验证,因文件内缺失 hacker_address 字段"})
|
| 100 |
+
|
| 101 |
+
# 6. 致命交易哈希提取准确性 (30分)
|
| 102 |
+
ans_hash = "0xdeadbeef999999999999999999999999999999999999999999999999deadbeef"
|
| 103 |
+
if isinstance(data, dict) and "exploit_tx_hash" in data:
|
| 104 |
+
tx_hash = str(data["exploit_tx_hash"]).strip().lower()
|
| 105 |
+
if tx_hash == ans_hash:
|
| 106 |
+
score += 30
|
| 107 |
+
details.append({"item": "攻击交易哈希正确性", "score": 30, "max_score": 30, "passed": True, "reason": "精准提取了对应的 exploit_tx_hash"})
|
| 108 |
+
else:
|
| 109 |
+
details.append({"item": "攻击交易哈希正确性", "score": 0, "max_score": 30, "passed": False, "reason": f"exploit_tx_hash 错误。期望: {ans_hash},实际: {tx_hash}"})
|
| 110 |
+
else:
|
| 111 |
+
details.append({"item": "攻击交易哈希正确性", "score": 0, "max_score": 30, "passed": False, "reason": "无法验证,因文件内缺失 exploit_tx_hash 字段"})
|
| 112 |
+
|
| 113 |
+
save_score(score, details)
|
| 114 |
+
|
| 115 |
+
def save_score(score, details):
|
| 116 |
+
res = {
|
| 117 |
+
"total_score": score,
|
| 118 |
+
"details": details
|
| 119 |
+
}
|
| 120 |
+
with open("workplace_score.json", "w", encoding="utf-8") as f:
|
| 121 |
+
json.dump(res, f, ensure_ascii=False, indent=2)
|
| 122 |
+
|
| 123 |
+
if __name__ == "__main__":
|
| 124 |
+
main()
|
persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0018/verify_workplace.py
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
import json
|
| 4 |
+
import re
|
| 5 |
+
import httpx
|
| 6 |
+
from openai import OpenAI
|
| 7 |
+
|
| 8 |
+
MOCK_API_KEY = os.environ.get("MOCK_API_KEY", "dummy_key")
|
| 9 |
+
MOCK_API_BASE = os.environ.get("MOCK_API_BASE", "http://localhost/v1")
|
| 10 |
+
MOCK_MODEL_NAME = os.environ.get("MOCK_MODEL_NAME", "gpt-5.4")
|
| 11 |
+
|
| 12 |
+
# 初始化客户端,必须关闭 SSL 验证
|
| 13 |
+
http_client = httpx.Client(verify=False)
|
| 14 |
+
client = OpenAI(
|
| 15 |
+
api_key=MOCK_API_KEY,
|
| 16 |
+
base_url=MOCK_API_BASE,
|
| 17 |
+
http_client=http_client
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
def llm_judge_content(prompt_text, file_content):
|
| 21 |
+
# 此函数为检测非结构化文本的统一接口
|
| 22 |
+
try:
|
| 23 |
+
response = client.chat.completions.create(
|
| 24 |
+
model=MOCK_MODEL_NAME,
|
| 25 |
+
messages=[
|
| 26 |
+
{"role": "system", "content": "You are a strict data validation assistant. Answer ONLY with 'YES' or 'NO'."},
|
| 27 |
+
{"role": "user", "content": f"{prompt_text}\n\n[File Content]:\n{file_content}"}
|
| 28 |
+
],
|
| 29 |
+
temperature=0
|
| 30 |
+
)
|
| 31 |
+
return "yes" in response.choices[0].message.content.strip().lower()
|
| 32 |
+
except Exception as e:
|
| 33 |
+
print(f"LLM API Error: {e}")
|
| 34 |
+
return False
|
| 35 |
+
|
| 36 |
+
def get_ground_truth(workspace):
|
| 37 |
+
"""
|
| 38 |
+
沙盒内探针自己执行硬核逻辑,重新解析数据计算 Ground Truth,避免假阴性/假阳性。
|
| 39 |
+
"""
|
| 40 |
+
can_log = os.path.join(workspace, "chassis_can.log")
|
| 41 |
+
radar_json = os.path.join(workspace, "sensor_data", "radar_track.json")
|
| 42 |
+
|
| 43 |
+
if not os.path.exists(can_log) or not os.path.exists(radar_json):
|
| 44 |
+
return set()
|
| 45 |
+
|
| 46 |
+
aeb_timestamps = []
|
| 47 |
+
with open(can_log, "r", encoding="utf-8") as f:
|
| 48 |
+
for line in f:
|
| 49 |
+
# 必须满足双重条件: 刹车CAN ID = 0x2B0, PAYLOAD 前两字节 = FF 01
|
| 50 |
+
if "MSG_ID:0x2B0" in line and "PAYLOAD:[FF 01" in line:
|
| 51 |
+
m = re.search(r"<(\d+)>", line)
|
| 52 |
+
if m:
|
| 53 |
+
aeb_timestamps.append(int(m.group(1)))
|
| 54 |
+
|
| 55 |
+
truth_ids = set()
|
| 56 |
+
with open(radar_json, "r", encoding="utf-8") as f:
|
| 57 |
+
radar_data = json.load(f)
|
| 58 |
+
|
| 59 |
+
frames = radar_data.get("data_stream", {}).get("radar_front_center", {}).get("frames", [])
|
| 60 |
+
for frame in frames:
|
| 61 |
+
stamp_ms = frame.get("header", {}).get("stamp_ms", 0)
|
| 62 |
+
# 严密的时间戳对齐:雷达比底盘快 1500ms
|
| 63 |
+
if (stamp_ms - 1500) in aeb_timestamps:
|
| 64 |
+
objects = frame.get("payload", {}).get("tracked_entities", {}).get("radar_objects", [])
|
| 65 |
+
for obj in objects:
|
| 66 |
+
rcs = obj.get("attributes", {}).get("rcs_dbsm", 999.0)
|
| 67 |
+
conf = obj.get("attributes", {}).get("track_confidence", 999)
|
| 68 |
+
# 必须满足 rcs < 5.0 且 confidence < 60
|
| 69 |
+
if rcs < 5.0 and conf < 60:
|
| 70 |
+
tid = obj.get("metadata", {}).get("track_id", "")
|
| 71 |
+
if tid:
|
| 72 |
+
truth_ids.add(tid)
|
| 73 |
+
|
| 74 |
+
return truth_ids
|
| 75 |
+
|
| 76 |
+
def main():
|
| 77 |
+
workspace = sys.argv[1] if len(sys.argv) > 1 else "."
|
| 78 |
+
target_file = os.path.join(workspace, "analysis", "ghost_ids.json")
|
| 79 |
+
|
| 80 |
+
details = []
|
| 81 |
+
total_score = 0
|
| 82 |
+
|
| 83 |
+
# 1. 验证目标文件存在性 (10分)
|
| 84 |
+
if os.path.exists(target_file):
|
| 85 |
+
total_score += 10
|
| 86 |
+
details.append({"item": "检查目标文件是否存在", "score": 10, "max_score": 10, "passed": True, "reason": "文件 analysis/ghost_ids.json 存在"})
|
| 87 |
+
else:
|
| 88 |
+
details.append({"item": "检查目标文件是否存在", "score": 0, "max_score": 10, "passed": False, "reason": "文件 analysis/ghost_ids.json 不存在"})
|
| 89 |
+
|
| 90 |
+
# 2. 验证结构纯净性 (20分)
|
| 91 |
+
# 绝对禁止使用正则去匹配结构化结果,必须使用 json 库严格解析
|
| 92 |
+
agent_ids = []
|
| 93 |
+
is_valid_format = False
|
| 94 |
+
if os.path.exists(target_file):
|
| 95 |
+
try:
|
| 96 |
+
with open(target_file, "r", encoding="utf-8") as f:
|
| 97 |
+
data = json.load(f)
|
| 98 |
+
if isinstance(data, list) and all(isinstance(i, str) for i in data):
|
| 99 |
+
is_valid_format = True
|
| 100 |
+
agent_ids = data
|
| 101 |
+
total_score += 20
|
| 102 |
+
details.append({"item": "JSON格式规范性验证", "score": 20, "max_score": 20, "passed": True, "reason": "是一个纯净的字符串数组"})
|
| 103 |
+
else:
|
| 104 |
+
details.append({"item": "JSON格式规范性验证", "score": 0, "max_score": 20, "passed": False, "reason": "结构错误,不是纯净的字符串数组"})
|
| 105 |
+
except json.JSONDecodeError:
|
| 106 |
+
details.append({"item": "JSON格式规范性验证", "score": 0, "max_score": 20, "passed": False, "reason": "非法的JSON文件"})
|
| 107 |
+
else:
|
| 108 |
+
details.append({"item": "JSON格式规范性验证", "score": 0, "max_score": 20, "passed": False, "reason": "文件缺失,无法验证"})
|
| 109 |
+
|
| 110 |
+
# 3. 数据精准度 (70分)
|
| 111 |
+
if is_valid_format:
|
| 112 |
+
truth_ids = get_ground_truth(workspace)
|
| 113 |
+
agent_set = set(agent_ids)
|
| 114 |
+
|
| 115 |
+
if not truth_ids:
|
| 116 |
+
# 如果极端��况环境加载异常,这里进行容错
|
| 117 |
+
details.append({"item": "验证提取的 ID 准确性", "score": 0, "max_score": 70, "passed": False, "reason": "Ground Truth 数据生成错误,请检查环境"})
|
| 118 |
+
else:
|
| 119 |
+
intersection = agent_set.intersection(truth_ids)
|
| 120 |
+
false_positives = agent_set - truth_ids
|
| 121 |
+
false_negatives = truth_ids - agent_set
|
| 122 |
+
|
| 123 |
+
union_len = len(agent_set.union(truth_ids))
|
| 124 |
+
# 使用严格的 Jaccard 相似度来反映 F1 维度的惩罚机制,有捏造、漏报均会急剧降分
|
| 125 |
+
data_score = int(70 * (len(intersection) / union_len)) if union_len > 0 else 0
|
| 126 |
+
|
| 127 |
+
total_score += data_score
|
| 128 |
+
passed = (data_score == 70)
|
| 129 |
+
reason = f"精准度检查完成。正确提取: {len(intersection)}项, 漏报: {len(false_negatives)}项, 误报(幻觉/条件错误): {len(false_positives)}项"
|
| 130 |
+
details.append({"item": "验证提取的 ID 准确性", "score": data_score, "max_score": 70, "passed": passed, "reason": reason})
|
| 131 |
+
else:
|
| 132 |
+
details.append({"item": "验证提取的 ID 准确性", "score": 0, "max_score": 70, "passed": False, "reason": "由于文件不存在或格式不合规,跳过数据校验"})
|
| 133 |
+
|
| 134 |
+
# 统分写入
|
| 135 |
+
with open(os.path.join(workspace, "workplace_score.json"), "w", encoding="utf-8") as f:
|
| 136 |
+
json.dump({
|
| 137 |
+
"total_score": total_score,
|
| 138 |
+
"details": details
|
| 139 |
+
}, f, indent=2, ensure_ascii=False)
|
| 140 |
+
|
| 141 |
+
if __name__ == "__main__":
|
| 142 |
+
main()
|
persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0019/verify_workplace.py
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
import json
|
| 4 |
+
import httpx
|
| 5 |
+
from openai import OpenAI
|
| 6 |
+
|
| 7 |
+
MOCK_API_KEY = os.environ.get("MOCK_API_KEY", "dummy_key")
|
| 8 |
+
MOCK_API_BASE = os.environ.get("MOCK_API_BASE", "http://localhost/v1")
|
| 9 |
+
MOCK_MODEL_NAME = os.environ.get("MOCK_MODEL_NAME", "gpt-5.4")
|
| 10 |
+
|
| 11 |
+
# 初始化客户端,必须关闭 SSL 验证
|
| 12 |
+
http_client = httpx.Client(verify=False)
|
| 13 |
+
client = OpenAI(
|
| 14 |
+
api_key=MOCK_API_KEY,
|
| 15 |
+
base_url=MOCK_API_BASE,
|
| 16 |
+
http_client=http_client
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
def llm_judge_content(prompt_text, file_content):
|
| 20 |
+
# 此函数为检测非结构化文本的统一接口
|
| 21 |
+
try:
|
| 22 |
+
response = client.chat.completions.create(
|
| 23 |
+
model=MOCK_MODEL_NAME,
|
| 24 |
+
messages=[
|
| 25 |
+
{"role": "system", "content": "You are a strict data validation assistant. Answer ONLY with 'YES' or 'NO'."},
|
| 26 |
+
{"role": "user", "content": f"{prompt_text}\n\n[File Content]:\n{file_content}"}
|
| 27 |
+
],
|
| 28 |
+
temperature=0
|
| 29 |
+
)
|
| 30 |
+
return "yes" in response.choices[0].message.content.strip().lower()
|
| 31 |
+
except Exception as e:
|
| 32 |
+
print(f"LLM API Error: {e}")
|
| 33 |
+
return False
|
| 34 |
+
|
| 35 |
+
def verify_target(workspace):
|
| 36 |
+
score = 0
|
| 37 |
+
details = []
|
| 38 |
+
|
| 39 |
+
# 1. 检查目标目录是否存在 (10 分)
|
| 40 |
+
fix_list_dir = os.path.join(workspace, "fix_list")
|
| 41 |
+
if os.path.isdir(fix_list_dir):
|
| 42 |
+
score += 10
|
| 43 |
+
details.append({"item": "检查 fix_list 目录是否存在", "score": 10, "max_score": 10, "passed": True, "reason": "目录 fix_list 成功创建"})
|
| 44 |
+
else:
|
| 45 |
+
details.append({"item": "检查 fix_list 目录是否存在", "score": 0, "max_score": 10, "passed": False, "reason": "目录 fix_list 不存在"})
|
| 46 |
+
|
| 47 |
+
# 2. 检查结果文件是否存在 (20 分)
|
| 48 |
+
target_file = os.path.join(workspace, "fix_list", "target.json")
|
| 49 |
+
if os.path.isfile(target_file):
|
| 50 |
+
score += 20
|
| 51 |
+
details.append({"item": "检查 target.json 文件是否存在", "score": 20, "max_score": 20, "passed": True, "reason": "文件 target.json 存在"})
|
| 52 |
+
|
| 53 |
+
# 3. 检查 JSON 格式是否合法 (20 分)
|
| 54 |
+
try:
|
| 55 |
+
with open(target_file, "r", encoding="utf-8") as f:
|
| 56 |
+
data = json.load(f)
|
| 57 |
+
score += 20
|
| 58 |
+
details.append({"item": "检查 target.json 格式是否合法", "score": 20, "max_score": 20, "passed": True, "reason": "JSON 格式完全合法且可解析"})
|
| 59 |
+
|
| 60 |
+
if isinstance(data, dict):
|
| 61 |
+
keys = list(data.keys())
|
| 62 |
+
|
| 63 |
+
# 4. 检查字段完整性及防止作弊冗余 (10 分)
|
| 64 |
+
if "culprit_asset" in keys:
|
| 65 |
+
if len(keys) > 1:
|
| 66 |
+
score += 5
|
| 67 |
+
details.append({"item": "检查是否仅包含 culprit_asset 字段", "score": 5, "max_score": 10, "passed": False, "reason": "包含 culprit_asset,但捏造/附带了冗余多余的字段,扣除 5 分"})
|
| 68 |
+
else:
|
| 69 |
+
score += 10
|
| 70 |
+
details.append({"item": "检查是否仅包含 culprit_asset 字段", "score": 10, "max_score": 10, "passed": True, "reason": "有且仅有 culprit_asset 字段,非常干净"})
|
| 71 |
+
|
| 72 |
+
# 5. 精准比对最终找到的资产路径值 (40 分)
|
| 73 |
+
expected_value = "environments/ruins/statue_shattered_piece_04_cinematic.mesh"
|
| 74 |
+
if data["culprit_asset"] == expected_value:
|
| 75 |
+
score += 40
|
| 76 |
+
details.append({"item": "比对 culprit_asset 值是否准确无误", "score": 40, "max_score": 40, "passed": True, "reason": "成功揪出了性能毛刺对应的超高顶点过场静态网格体"})
|
| 77 |
+
else:
|
| 78 |
+
details.append({"item": "比对 culprit_asset 值是否准确无误", "score": 0, "max_score": 40, "passed": False, "reason": f"资产路径不匹配。期望: {expected_value},实际: {data['culprit_asset']}"})
|
| 79 |
+
else:
|
| 80 |
+
details.append({"item": "检查是否仅包含 culprit_asset 字段", "score": 0, "max_score": 10, "passed": False, "reason": "完全缺失必须的 culprit_asset 键"})
|
| 81 |
+
details.append({"item": "比对 culprit_asset 值是否准确无误", "score": 0, "max_score": 40, "passed": False, "reason": "因为键缺失,无法验证具体值"})
|
| 82 |
+
else:
|
| 83 |
+
details.append({"item": "检查 JSON 的根节点是否为字典结构", "score": 0, "max_score": 10, "passed": False, "reason": "目标 JSON 不是 Key-Value 格式的字典"})
|
| 84 |
+
details.append({"item": "比对 culprit_asset 值是否准确无误", "score": 0, "max_score": 40, "passed": False, "reason": "数据结构错误,无法获取对应键值"})
|
| 85 |
+
|
| 86 |
+
except json.JSONDecodeError as e:
|
| 87 |
+
details.append({"item": "检查 target.json 格式是否合法", "score": 0, "max_score": 20, "passed": False, "reason": f"JSON 解析失败或包含非法字符: {e}"})
|
| 88 |
+
details.append({"item": "检查是否仅包含 culprit_asset 字段", "score": 0, "max_score": 10, "passed": False, "reason": "JSON 无法解析,中止验证"})
|
| 89 |
+
details.append({"item": "比对 culprit_asset 值是否准确无误", "score": 0, "max_score": 40, "passed": False, "reason": "JSON 无法解析,中止验证"})
|
| 90 |
+
|
| 91 |
+
else:
|
| 92 |
+
details.append({"item": "检查 target.json 文件是否存在", "score": 0, "max_score": 20, "passed": False, "reason": "文件 target.json 未找到"})
|
| 93 |
+
details.append({"item": "检查 target.json 格式是否合法", "score": 0, "max_score": 20, "passed": False, "reason": "文件缺失,中止验证"})
|
| 94 |
+
details.append({"item": "检查是否仅包含 culprit_asset 字段", "score": 0, "max_score": 10, "passed": False, "reason": "文件缺失,中止验证"})
|
| 95 |
+
details.append({"item": "比对 culprit_asset 值是否准确无误", "score": 0, "max_score": 40, "passed": False, "reason": "文件缺失,中止验证"})
|
| 96 |
+
|
| 97 |
+
# 输出结果记录
|
| 98 |
+
result = {
|
| 99 |
+
"total_score": score,
|
| 100 |
+
"details": details
|
| 101 |
+
}
|
| 102 |
+
with open(os.path.join(workspace, "workplace_score.json"), "w", encoding="utf-8") as f:
|
| 103 |
+
json.dump(result, f, indent=2, ensure_ascii=False)
|
| 104 |
+
|
| 105 |
+
if __name__ == "__main__":
|
| 106 |
+
workspace_dir = sys.argv[1] if len(sys.argv) > 1 else "."
|
| 107 |
+
verify_target(workspace_dir)
|
persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0020/verify_workplace.py
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
import json
|
| 4 |
+
import httpx
|
| 5 |
+
from openai import OpenAI
|
| 6 |
+
|
| 7 |
+
# ----------------- 强制 API 规范 -----------------
|
| 8 |
+
MOCK_API_KEY = os.environ.get("MOCK_API_KEY", "dummy_key")
|
| 9 |
+
MOCK_API_BASE = os.environ.get("MOCK_API_BASE", "http://localhost/v1")
|
| 10 |
+
MOCK_MODEL_NAME = os.environ.get("MOCK_MODEL_NAME", "gpt-5.4")
|
| 11 |
+
|
| 12 |
+
# 初始化客户端,必须关闭 SSL 验证
|
| 13 |
+
http_client = httpx.Client(verify=False)
|
| 14 |
+
client = OpenAI(
|
| 15 |
+
api_key=MOCK_API_KEY,
|
| 16 |
+
base_url=MOCK_API_BASE,
|
| 17 |
+
http_client=http_client
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
def llm_judge_content(prompt_text, file_content):
|
| 21 |
+
"""大模型语义检测接口,只用于检测自然语言语义/格式外废话"""
|
| 22 |
+
try:
|
| 23 |
+
response = client.chat.completions.create(
|
| 24 |
+
model=MOCK_MODEL_NAME,
|
| 25 |
+
messages=[
|
| 26 |
+
{"role": "system", "content": "You are a strict data validation assistant. Answer ONLY with 'YES' or 'NO'."},
|
| 27 |
+
{"role": "user", "content": f"{prompt_text}\n\n[File Content]:\n{file_content}"}
|
| 28 |
+
],
|
| 29 |
+
temperature=0
|
| 30 |
+
)
|
| 31 |
+
return "yes" in response.choices[0].message.content.strip().lower()
|
| 32 |
+
except Exception as e:
|
| 33 |
+
print(f"LLM API Error: {e}")
|
| 34 |
+
return False
|
| 35 |
+
# -------------------------------------------------
|
| 36 |
+
|
| 37 |
+
def verify():
|
| 38 |
+
workspace = sys.argv[1] if len(sys.argv) > 1 else "."
|
| 39 |
+
target_file = os.path.join(workspace, "hotfix_target.json")
|
| 40 |
+
|
| 41 |
+
score_details = []
|
| 42 |
+
total_score = 0
|
| 43 |
+
|
| 44 |
+
# Check 1: 检查物理文件是否存在 (15分)
|
| 45 |
+
if os.path.exists(target_file):
|
| 46 |
+
total_score += 15
|
| 47 |
+
score_details.append({
|
| 48 |
+
"item": "检查 hotfix_target.json 文件是否存在",
|
| 49 |
+
"score": 15, "max_score": 15, "passed": True,
|
| 50 |
+
"reason": "目标文件 hotfix_target.json 存在"
|
| 51 |
+
})
|
| 52 |
+
else:
|
| 53 |
+
score_details.append({
|
| 54 |
+
"item": "检查 hotfix_target.json 文件是否存在",
|
| 55 |
+
"score": 0, "max_score": 15, "passed": False,
|
| 56 |
+
"reason": "未找到 hotfix_target.json 文件"
|
| 57 |
+
})
|
| 58 |
+
with open(os.path.join(workspace, "workplace_score.json"), "w", encoding="utf-8") as f:
|
| 59 |
+
json.dump({"total_score": total_score, "details": score_details}, f, indent=2, ensure_ascii=False)
|
| 60 |
+
return
|
| 61 |
+
|
| 62 |
+
# Check 2: 检查文件格式及其内容结构 (15分)
|
| 63 |
+
try:
|
| 64 |
+
with open(target_file, "r", encoding="utf-8") as f:
|
| 65 |
+
data = json.load(f)
|
| 66 |
+
|
| 67 |
+
total_score += 15
|
| 68 |
+
score_details.append({
|
| 69 |
+
"item": "检查文件是否为合法 JSON",
|
| 70 |
+
"score": 15, "max_score": 15, "passed": True,
|
| 71 |
+
"reason": "成功以 JSON 格式解析文件"
|
| 72 |
+
})
|
| 73 |
+
except json.JSONDecodeError:
|
| 74 |
+
score_details.append({
|
| 75 |
+
"item": "检查文件是否为合法 JSON",
|
| 76 |
+
"score": 0, "max_score": 15, "passed": False,
|
| 77 |
+
"reason": "JSON 格式非法或存在语法错误"
|
| 78 |
+
})
|
| 79 |
+
with open(os.path.join(workspace, "workplace_score.json"), "w", encoding="utf-8") as f:
|
| 80 |
+
json.dump({"total_score": total_score, "details": score_details}, f, indent=2, ensure_ascii=False)
|
| 81 |
+
return
|
| 82 |
+
|
| 83 |
+
# 附加语义检测:检查是否违背“不要废话内存管理原理”的指令
|
| 84 |
+
# 提取多余的文本字段或过长的注释值交由 LLM 判别
|
| 85 |
+
has_waste_talk = False
|
| 86 |
+
for key, value in data.items():
|
| 87 |
+
if isinstance(value, str) and len(value) > 30 and key not in ["archetype_id", "memory_address"]:
|
| 88 |
+
prompt = "Does the following text contain unsolicited textbook-style explanations or tutorials about computer memory management or ECS principles? If yes, answer 'YES', else 'NO'."
|
| 89 |
+
if llm_judge_content(prompt, value):
|
| 90 |
+
has_waste_talk = True
|
| 91 |
+
break
|
| 92 |
+
|
| 93 |
+
if has_waste_talk:
|
| 94 |
+
# 一票否决性质的倒扣分
|
| 95 |
+
total_score = max(0, total_score - 10)
|
| 96 |
+
score_details.append({
|
| 97 |
+
"item": "严格遵守禁止说教的要求",
|
| 98 |
+
"score": -10, "max_score": 0, "passed": False,
|
| 99 |
+
"reason": "检测到多余的内存管理教科书原理解释(幻觉或违背 Persona),倒扣 10 分"
|
| 100 |
+
})
|
| 101 |
+
else:
|
| 102 |
+
score_details.append({
|
| 103 |
+
"item": "严格遵守禁止说教的要求",
|
| 104 |
+
"score": 0, "max_score": 0, "passed": True,
|
| 105 |
+
"reason": "输出干净简洁,未包含啰嗦的原理解释"
|
| 106 |
+
})
|
| 107 |
+
|
| 108 |
+
# Check 3: 精准检查 archetype_id 提取结果 (30分)
|
| 109 |
+
arch_id = str(data.get("archetype_id", "")).strip()
|
| 110 |
+
if arch_id == "ARCH_E7_DYNAMIC_MESH":
|
| 111 |
+
total_score += 30
|
| 112 |
+
score_details.append({
|
| 113 |
+
"item": "检查 archetype_id 定位是否精准",
|
| 114 |
+
"score": 30, "max_score": 30, "passed": True,
|
| 115 |
+
"reason": "成功分析日志并提取出发生高延迟的 ARCH_E7_DYNAMIC_MESH"
|
| 116 |
+
})
|
| 117 |
+
else:
|
| 118 |
+
score_details.append({
|
| 119 |
+
"item": "检查 archetype_id 定位是否精准",
|
| 120 |
+
"score": 0, "max_score": 30, "passed": False,
|
| 121 |
+
"reason": f"提取错误。期望为 ARCH_E7_DYNAMIC_MESH,实际为: '{arch_id}'"
|
| 122 |
+
})
|
| 123 |
+
|
| 124 |
+
# Check 4: 精准检查 memory_address 提取结果并排查诱饵陷阱 (40分)
|
| 125 |
+
mem_addr = str(data.get("memory_address", "")).strip().upper()
|
| 126 |
+
if mem_addr == "0X000002B47C90F000":
|
| 127 |
+
total_score += 40
|
| 128 |
+
score_details.append({
|
| 129 |
+
"item": "检查 memory_address 定位是否精准并避开诱饵",
|
| 130 |
+
"score": 40, "max_score": 40, "passed": True,
|
| 131 |
+
"reason": "成功定位具有最多碎片的正确内存块 0x000002B47C90F000,且没有掉入诱饵陷阱"
|
| 132 |
+
})
|
| 133 |
+
elif mem_addr == "0X000001FA88000000":
|
| 134 |
+
# 掉入了 Decoy 陷阱:找到了 F 最多的块,但没验证这个块是不是属于前面的 archetype
|
| 135 |
+
total_score += 10
|
| 136 |
+
score_details.append({
|
| 137 |
+
"item": "检查 memory_address 定位是否精准并避开诱饵",
|
| 138 |
+
"score": 10, "max_score": 40, "passed": False,
|
| 139 |
+
"reason": "错误!定位到了包含大量碎片的诱饵块 0x000001FA88000000,但在多表关联时未验证它的 ArchID 是否一致!"
|
| 140 |
+
})
|
| 141 |
+
else:
|
| 142 |
+
score_details.append({
|
| 143 |
+
"item": "检查 memory_address 定位是否精准并避开诱饵",
|
| 144 |
+
"score": 0, "max_score": 40, "passed": False,
|
| 145 |
+
"reason": f"内存地址定位完全错误,实际提取值为: '{mem_addr}'"
|
| 146 |
+
})
|
| 147 |
+
|
| 148 |
+
# Ensure total limits
|
| 149 |
+
total_score = max(0, min(100, total_score))
|
| 150 |
+
|
| 151 |
+
# Output to workplace_score.json
|
| 152 |
+
with open(os.path.join(workspace, "workplace_score.json"), "w", encoding="utf-8") as f:
|
| 153 |
+
json.dump({"total_score": total_score, "details": score_details}, f, indent=2, ensure_ascii=False)
|
| 154 |
+
|
| 155 |
+
if __name__ == "__main__":
|
| 156 |
+
verify()
|
persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0021/verify_workplace.py
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
import json
|
| 4 |
+
import httpx
|
| 5 |
+
import re
|
| 6 |
+
from openai import OpenAI
|
| 7 |
+
|
| 8 |
+
MOCK_API_KEY = os.environ.get("MOCK_API_KEY", "dummy_key")
|
| 9 |
+
MOCK_API_BASE = os.environ.get("MOCK_API_BASE", "http://localhost/v1")
|
| 10 |
+
MOCK_MODEL_NAME = os.environ.get("MOCK_MODEL_NAME", "gpt-5.4")
|
| 11 |
+
|
| 12 |
+
# 初始化客户端,强制关闭 SSL 验证
|
| 13 |
+
http_client = httpx.Client(verify=False)
|
| 14 |
+
client = OpenAI(
|
| 15 |
+
api_key=MOCK_API_KEY,
|
| 16 |
+
base_url=MOCK_API_BASE,
|
| 17 |
+
http_client=http_client
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
def llm_judge_content(prompt_text, file_content):
|
| 21 |
+
"""用于对非结构化文本内容进行兜底或辅助语义判定"""
|
| 22 |
+
try:
|
| 23 |
+
response = client.chat.completions.create(
|
| 24 |
+
model=MOCK_MODEL_NAME,
|
| 25 |
+
messages=[
|
| 26 |
+
{"role": "system", "content": "You are a strict data validation assistant. Answer ONLY with 'YES' or 'NO'."},
|
| 27 |
+
{"role": "user", "content": f"{prompt_text}\n\n[File Content]:\n{file_content}"}
|
| 28 |
+
],
|
| 29 |
+
temperature=0
|
| 30 |
+
)
|
| 31 |
+
return "yes" in response.choices[0].message.content.strip().lower()
|
| 32 |
+
except Exception as e:
|
| 33 |
+
print(f"LLM API Error: {e}")
|
| 34 |
+
return False
|
| 35 |
+
|
| 36 |
+
def verify():
|
| 37 |
+
# 动态获取沙盒挂载的工作区路径
|
| 38 |
+
workspace = sys.argv[1] if len(sys.argv) > 1 else "."
|
| 39 |
+
target_json_path = os.path.join(workspace, "debug", "root_cause.json")
|
| 40 |
+
|
| 41 |
+
total_score = 0
|
| 42 |
+
details = []
|
| 43 |
+
|
| 44 |
+
# 1. 检查物理文件是否存在 (10 分)
|
| 45 |
+
if not os.path.exists(target_json_path):
|
| 46 |
+
details.append({
|
| 47 |
+
"item": "检查目标文件是否存在",
|
| 48 |
+
"score": 0,
|
| 49 |
+
"max_score": 10,
|
| 50 |
+
"passed": False,
|
| 51 |
+
"reason": "未找到 debug/root_cause.json 文件,Agent 未能在指定路径输出结果"
|
| 52 |
+
})
|
| 53 |
+
with open(os.path.join(workspace, "workplace_score.json"), "w", encoding="utf-8") as f:
|
| 54 |
+
json.dump({"total_score": 0, "details": details}, f, indent=2, ensure_ascii=False)
|
| 55 |
+
return
|
| 56 |
+
else:
|
| 57 |
+
details.append({
|
| 58 |
+
"item": "检查目标文件是否存在",
|
| 59 |
+
"score": 10,
|
| 60 |
+
"max_score": 10,
|
| 61 |
+
"passed": True,
|
| 62 |
+
"reason": "文件 debug/root_cause.json 存在"
|
| 63 |
+
})
|
| 64 |
+
total_score += 10
|
| 65 |
+
|
| 66 |
+
# 2. 检查 JSON 语法合法性 (10 分)
|
| 67 |
+
try:
|
| 68 |
+
with open(target_json_path, "r", encoding="utf-8") as f:
|
| 69 |
+
data = json.load(f)
|
| 70 |
+
details.append({
|
| 71 |
+
"item": "JSON 格式解析",
|
| 72 |
+
"score": 10,
|
| 73 |
+
"max_score": 10,
|
| 74 |
+
"passed": True,
|
| 75 |
+
"reason": "JSON 格式合法且可被标准库解析"
|
| 76 |
+
})
|
| 77 |
+
total_score += 10
|
| 78 |
+
except Exception as e:
|
| 79 |
+
details.append({
|
| 80 |
+
"item": "JSON 格式解析",
|
| 81 |
+
"score": 0,
|
| 82 |
+
"max_score": 10,
|
| 83 |
+
"passed": False,
|
| 84 |
+
"reason": f"解析失败,可能混入了多余字符或 markdown 格式: {e}"
|
| 85 |
+
})
|
| 86 |
+
with open(os.path.join(workspace, "workplace_score.json"), "w", encoding="utf-8") as f:
|
| 87 |
+
json.dump({"total_score": total_score, "details": details}, f, indent=2, ensure_ascii=False)
|
| 88 |
+
return
|
| 89 |
+
|
| 90 |
+
# 3. 检查 JSON Schema 完整性与数据类型 (20 分)
|
| 91 |
+
# 不允许少任何一个键,也不允许多出胡编乱造的键
|
| 92 |
+
expected_keys = {"device_addr", "reg_addr", "bad_value"}
|
| 93 |
+
actual_keys = set(data.keys()) if isinstance(data, dict) else set()
|
| 94 |
+
|
| 95 |
+
if actual_keys == expected_keys:
|
| 96 |
+
if all(isinstance(data[k], str) for k in expected_keys):
|
| 97 |
+
# 严格检查值是否为 "0x" 加上两个十六进制字符(大小写均可)
|
| 98 |
+
format_pass = all(re.match(r"^0x[0-9a-fA-F]{2}$", data[k]) for k in expected_keys)
|
| 99 |
+
if format_pass:
|
| 100 |
+
details.append({
|
| 101 |
+
"item": "Schema 完整性与类型验证",
|
| 102 |
+
"score": 20,
|
| 103 |
+
"max_score": 20,
|
| 104 |
+
"passed": True,
|
| 105 |
+
"reason": "所有必填键均存在,无幻觉字段,且值严格遵循标准的 0xXX 字符串格式"
|
| 106 |
+
})
|
| 107 |
+
total_score += 20
|
| 108 |
+
else:
|
| 109 |
+
details.append({
|
| 110 |
+
"item": "Schema 完整性与类型验证",
|
| 111 |
+
"score": 10,
|
| 112 |
+
"max_score": 20,
|
| 113 |
+
"passed": False,
|
| 114 |
+
"reason": "键正确且为字符串,但值未严格遵循 0xXX 的标准两位十六进制格式"
|
| 115 |
+
})
|
| 116 |
+
total_score += 10
|
| 117 |
+
else:
|
| 118 |
+
details.append({
|
| 119 |
+
"item": "Schema 完整性与类型验证",
|
| 120 |
+
"score": 5,
|
| 121 |
+
"max_score": 20,
|
| 122 |
+
"passed": False,
|
| 123 |
+
"reason": "键正确,但部分数据不是纯字符串类型(如被写为整数或包含其它嵌套结构)"
|
| 124 |
+
})
|
| 125 |
+
total_score += 5
|
| 126 |
+
else:
|
| 127 |
+
missing = expected_keys - actual_keys
|
| 128 |
+
extra = actual_keys - expected_keys
|
| 129 |
+
reason_parts = []
|
| 130 |
+
if missing: reason_parts.append(f"缺少必填键: {missing}")
|
| 131 |
+
if extra: reason_parts.append(f"捏造或多余键: {extra}")
|
| 132 |
+
details.append({
|
| 133 |
+
"item": "Schema 完整性与类型验证",
|
| 134 |
+
"score": 0,
|
| 135 |
+
"max_score": 20,
|
| 136 |
+
"passed": False,
|
| 137 |
+
"reason": " | ".join(reason_parts)
|
| 138 |
+
})
|
| 139 |
+
|
| 140 |
+
# 4. 严格值校验: device_addr (20 分)
|
| 141 |
+
device_addr = str(data.get("device_addr", "")).strip().lower()
|
| 142 |
+
if device_addr == "0x68":
|
| 143 |
+
details.append({
|
| 144 |
+
"item": "校验设备地址(device_addr)",
|
| 145 |
+
"score": 20,
|
| 146 |
+
"max_score": 20,
|
| 147 |
+
"passed": True,
|
| 148 |
+
"reason": "准确提取 I2C 基地址 0x68"
|
| 149 |
+
})
|
| 150 |
+
total_score += 20
|
| 151 |
+
elif device_addr == "0xd0":
|
| 152 |
+
details.append({
|
| 153 |
+
"item": "校验设备地址(device_addr)",
|
| 154 |
+
"score": 10,
|
| 155 |
+
"max_score": 20,
|
| 156 |
+
"passed": False,
|
| 157 |
+
"reason": "提取到 0xD0 (这是带 Write 位偏移后的传输地址),虽然对应了抓包字节,但规范的 Base Addr 应为 0x68"
|
| 158 |
+
})
|
| 159 |
+
total_score += 10
|
| 160 |
+
else:
|
| 161 |
+
details.append({
|
| 162 |
+
"item": "校验设备地址(device_addr)",
|
| 163 |
+
"score": 0,
|
| 164 |
+
"max_score": 20,
|
| 165 |
+
"passed": False,
|
| 166 |
+
"reason": f"提取错误: {device_addr}"
|
| 167 |
+
})
|
| 168 |
+
|
| 169 |
+
# 5. 严格值校验: reg_addr (20 分)
|
| 170 |
+
reg_addr = str(data.get("reg_addr", "")).strip().lower()
|
| 171 |
+
if reg_addr == "0x6b":
|
| 172 |
+
details.append({
|
| 173 |
+
"item": "校验寄存器地址(reg_addr)",
|
| 174 |
+
"score": 20,
|
| 175 |
+
"max_score": 20,
|
| 176 |
+
"passed": True,
|
| 177 |
+
"reason": "准确提取触发死锁的 PWR_MGMT_1 寄存器地址 0x6B"
|
| 178 |
+
})
|
| 179 |
+
total_score += 20
|
| 180 |
+
else:
|
| 181 |
+
details.append({
|
| 182 |
+
"item": "校验寄存器地址(reg_addr)",
|
| 183 |
+
"score": 0,
|
| 184 |
+
"max_score": 20,
|
| 185 |
+
"passed": False,
|
| 186 |
+
"reason": f"寄存器地址提取错误: {reg_addr}"
|
| 187 |
+
})
|
| 188 |
+
|
| 189 |
+
# 6. 严格值校验: bad_value (20 分)
|
| 190 |
+
bad_value = str(data.get("bad_value", "")).strip().lower()
|
| 191 |
+
if bad_value == "0x80":
|
| 192 |
+
details.append({
|
| 193 |
+
"item": "校验致死错值(bad_value)",
|
| 194 |
+
"score": 20,
|
| 195 |
+
"max_score": 20,
|
| 196 |
+
"passed": True,
|
| 197 |
+
"reason": "准确提取触发 Errata 并导致看门狗复位的脏值 0x80"
|
| 198 |
+
})
|
| 199 |
+
total_score += 20
|
| 200 |
+
else:
|
| 201 |
+
details.append({
|
| 202 |
+
"item": "校验致死错值(bad_value)",
|
| 203 |
+
"score": 0,
|
| 204 |
+
"max_score": 20,
|
| 205 |
+
"passed": False,
|
| 206 |
+
"reason": f"错误值提取错误: {bad_value}"
|
| 207 |
+
})
|
| 208 |
+
|
| 209 |
+
# 写入最终判卷结果
|
| 210 |
+
with open(os.path.join(workspace, "workplace_score.json"), "w", encoding="utf-8") as f:
|
| 211 |
+
json.dump({"total_score": total_score, "details": details}, f, indent=2, ensure_ascii=False)
|
| 212 |
+
|
| 213 |
+
if __name__ == "__main__":
|
| 214 |
+
verify()
|
persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0022/verify_workplace.py
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
import json
|
| 4 |
+
import httpx
|
| 5 |
+
from openai import OpenAI
|
| 6 |
+
|
| 7 |
+
MOCK_API_KEY = os.environ.get("MOCK_API_KEY", "dummy_key")
|
| 8 |
+
MOCK_API_BASE = os.environ.get("MOCK_API_BASE", "http://localhost/v1")
|
| 9 |
+
MOCK_MODEL_NAME = os.environ.get("MOCK_MODEL_NAME", "gpt-5.4")
|
| 10 |
+
|
| 11 |
+
# 初始化客户端,必须关闭 SSL 验证
|
| 12 |
+
http_client = httpx.Client(verify=False)
|
| 13 |
+
client = OpenAI(
|
| 14 |
+
api_key=MOCK_API_KEY,
|
| 15 |
+
base_url=MOCK_API_BASE,
|
| 16 |
+
http_client=http_client
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
def llm_judge_content(prompt_text, file_content):
|
| 20 |
+
# 此函数为检测非结构化文本的统一接口
|
| 21 |
+
try:
|
| 22 |
+
response = client.chat.completions.create(
|
| 23 |
+
model=MOCK_MODEL_NAME,
|
| 24 |
+
messages=[
|
| 25 |
+
{"role": "system", "content": "You are a strict data validation assistant. Answer ONLY with 'YES' or 'NO'."},
|
| 26 |
+
{"role": "user", "content": f"{prompt_text}\n\n[File Content]:\n{file_content}"}
|
| 27 |
+
],
|
| 28 |
+
temperature=0
|
| 29 |
+
)
|
| 30 |
+
return "yes" in response.choices[0].message.content.strip().lower()
|
| 31 |
+
except Exception as e:
|
| 32 |
+
print(f"LLM API Error: {e}")
|
| 33 |
+
return False
|
| 34 |
+
|
| 35 |
+
def verify_workplace(workspace):
|
| 36 |
+
score = 0
|
| 37 |
+
details = []
|
| 38 |
+
|
| 39 |
+
# 目标路径配置
|
| 40 |
+
target_dir = os.path.join(workspace, "pipeline_fixes")
|
| 41 |
+
target_file = os.path.join(target_dir, "patch.json")
|
| 42 |
+
|
| 43 |
+
# 真实数据源(防止基于大模型的幻觉或模糊匹配,必须通过精准代码强校验)
|
| 44 |
+
truth_node = "SHD_Flesh_Subsurface_09"
|
| 45 |
+
truth_texture = "/prod/show/SC043/assets/chars/mutant/tex/v003/diffuse_UDIM_1001.tx"
|
| 46 |
+
|
| 47 |
+
# 1. 验证目标目录是否存在 (10分)
|
| 48 |
+
if os.path.isdir(target_dir):
|
| 49 |
+
score += 10
|
| 50 |
+
details.append({"item": "检查 pipeline_fixes 目录是否存在", "score": 10, "max_score": 10, "passed": True, "reason": "成功创建 pipeline_fixes 目录"})
|
| 51 |
+
else:
|
| 52 |
+
details.append({"item": "检查 pipeline_fixes 目录是否存在", "score": 0, "max_score": 10, "passed": False, "reason": "未找到 pipeline_fixes 目录"})
|
| 53 |
+
|
| 54 |
+
# 2. 验证热修复文件是否存在 (10分)
|
| 55 |
+
file_exists = os.path.isfile(target_file)
|
| 56 |
+
if file_exists:
|
| 57 |
+
score += 10
|
| 58 |
+
details.append({"item": "检查 patch.json 文件是否存在", "score": 10, "max_score": 10, "passed": True, "reason": "成功找到 patch.json 文件"})
|
| 59 |
+
else:
|
| 60 |
+
details.append({"item": "检查 patch.json 文件是否存在", "score": 0, "max_score": 10, "passed": False, "reason": "未找到 patch.json 文件"})
|
| 61 |
+
|
| 62 |
+
# 3. 严格验证 JSON 格式合法性及 Schema 字段约束 (20分)
|
| 63 |
+
data = None
|
| 64 |
+
if file_exists:
|
| 65 |
+
try:
|
| 66 |
+
with open(target_file, "r", encoding="utf-8") as f:
|
| 67 |
+
data = json.load(f)
|
| 68 |
+
|
| 69 |
+
# 使用强代码检查,严查任何画蛇添足的解释字段
|
| 70 |
+
if isinstance(data, dict):
|
| 71 |
+
keys = set(data.keys())
|
| 72 |
+
expected_keys = {"broken_node", "missing_texture"}
|
| 73 |
+
if keys == expected_keys:
|
| 74 |
+
score += 20
|
| 75 |
+
details.append({"item": "检查 JSON 格式与 Schema 合法性", "score": 20, "max_score": 20, "passed": True, "reason": "JSON 解析成功,且仅包含题目严格约束的两个字段,无冗余内容"})
|
| 76 |
+
else:
|
| 77 |
+
details.append({"item": "检查 JSON 格式与 Schema 合法性", "score": 0, "max_score": 20, "passed": False, "reason": f"格式违规:包含预期外的字段或缺失字段,当前键集合:{list(keys)}"})
|
| 78 |
+
else:
|
| 79 |
+
details.append({"item": "检查 JSON 格式与 Schema 合法性", "score": 0, "max_score": 20, "passed": False, "reason": "JSON 根节点非字典(Object)类型"})
|
| 80 |
+
except json.JSONDecodeError:
|
| 81 |
+
details.append({"item": "检查 JSON 格式与 Schema 合法性", "score": 0, "max_score": 20, "passed": False, "reason": "文件不是合法的 JSON 格式,无法解析"})
|
| 82 |
+
else:
|
| 83 |
+
details.append({"item": "检查 JSON 格式与 Schema 合法性", "score": 0, "max_score": 20, "passed": False, "reason": "因文件不存在,无法进行格式校验"})
|
| 84 |
+
|
| 85 |
+
# 4. 验证核心数据:故障节点名的精准提取 (30分)
|
| 86 |
+
if data and isinstance(data, dict):
|
| 87 |
+
node_val = data.get("broken_node", "")
|
| 88 |
+
if node_val == truth_node:
|
| 89 |
+
score += 30
|
| 90 |
+
details.append({"item": "校验 broken_node 提取准确度", "score": 30, "max_score": 30, "passed": True, "reason": "成功在海量渲染日志的栈转储与十六进制报错中提取出真正的崩溃节点名"})
|
| 91 |
+
else:
|
| 92 |
+
details.append({"item": "校验 broken_node 提取准确度", "score": 0, "max_score": 30, "passed": False, "reason": f"节点提取错误,期望 [{truth_node}],实际得到 [{node_val}]"})
|
| 93 |
+
|
| 94 |
+
# 5. 验证核心数据:丢失贴图路径的精准解析与追踪 (30分)
|
| 95 |
+
if data and isinstance(data, dict):
|
| 96 |
+
tex_val = data.get("missing_texture", "")
|
| 97 |
+
if tex_val == truth_texture:
|
| 98 |
+
score += 30
|
| 99 |
+
details.append({"item": "校验 missing_texture 提取准确度", "score": 30, "max_score": 30, "passed": True, "reason": "成功在深层嵌套(拓扑极度复杂)的场景树中穿透干扰项,定位到了关联的贴图绝对路径"})
|
| 100 |
+
else:
|
| 101 |
+
details.append({"item": "校验 missing_texture 提取准确度", "score": 0, "max_score": 30, "passed": False, "reason": f"贴图路径追踪失败,期望 [{truth_texture}],实际得到 [{tex_val}]"})
|
| 102 |
+
|
| 103 |
+
if not data or not isinstance(data, dict):
|
| 104 |
+
details.append({"item": "校验 broken_node 提取准确度", "score": 0, "max_score": 30, "passed": False, "reason": "JSON 结构无效,无法校验提取准确度"})
|
| 105 |
+
details.append({"item": "校验 missing_texture 提取准确度", "score": 0, "max_score": 30, "passed": False, "reason": "JSON 结构无效,无法校验提取准确度"})
|
| 106 |
+
|
| 107 |
+
result = {
|
| 108 |
+
"total_score": score,
|
| 109 |
+
"details": details
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
with open("workplace_score.json", "w", encoding="utf-8") as f:
|
| 113 |
+
json.dump(result, f, ensure_ascii=False, indent=2)
|
| 114 |
+
|
| 115 |
+
if __name__ == "__main__":
|
| 116 |
+
workspace_dir = sys.argv[1] if len(sys.argv) > 1 else "."
|
| 117 |
+
verify_workplace(workspace_dir)
|
persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0023/verify_workplace.py
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
import json
|
| 4 |
+
import httpx
|
| 5 |
+
from openai import OpenAI
|
| 6 |
+
|
| 7 |
+
MOCK_API_KEY = os.environ.get("MOCK_API_KEY", "dummy_key")
|
| 8 |
+
MOCK_API_BASE = os.environ.get("MOCK_API_BASE", "http://localhost/v1")
|
| 9 |
+
MOCK_MODEL_NAME = os.environ.get("MOCK_MODEL_NAME", "gpt-5.4")
|
| 10 |
+
|
| 11 |
+
# 初始化客户端,必须关闭 SSL 验证
|
| 12 |
+
http_client = httpx.Client(verify=False)
|
| 13 |
+
client = OpenAI(
|
| 14 |
+
api_key=MOCK_API_KEY,
|
| 15 |
+
base_url=MOCK_API_BASE,
|
| 16 |
+
http_client=http_client
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
def llm_judge_content(prompt_text, file_content):
|
| 20 |
+
try:
|
| 21 |
+
response = client.chat.completions.create(
|
| 22 |
+
model=MOCK_MODEL_NAME,
|
| 23 |
+
messages=[
|
| 24 |
+
{"role": "system", "content": "You are a strict data validation assistant. Answer ONLY with 'YES' or 'NO'."},
|
| 25 |
+
{"role": "user", "content": f"{prompt_text}\n\n[File Content]:\n{file_content}"}
|
| 26 |
+
],
|
| 27 |
+
temperature=0
|
| 28 |
+
)
|
| 29 |
+
return "yes" in response.choices[0].message.content.strip().lower()
|
| 30 |
+
except Exception as e:
|
| 31 |
+
print(f"LLM API Error: {e}")
|
| 32 |
+
return False
|
| 33 |
+
|
| 34 |
+
def verify_workplace(workspace):
|
| 35 |
+
score = 0
|
| 36 |
+
details = []
|
| 37 |
+
|
| 38 |
+
intel_dir = os.path.join(workspace, "intel")
|
| 39 |
+
iocs_file = os.path.join(intel_dir, "iocs.json")
|
| 40 |
+
|
| 41 |
+
# 1. 检查目录与文件是否存在 (10 分)
|
| 42 |
+
if os.path.isdir(intel_dir) and os.path.isfile(iocs_file):
|
| 43 |
+
details.append({"item": "检查结果目录与目标文件是否存在", "score": 10, "max_score": 10, "passed": True, "reason": "文件 intel/iocs.json 存在"})
|
| 44 |
+
score += 10
|
| 45 |
+
else:
|
| 46 |
+
details.append({"item": "检查结果目录与目标文件是否存在", "score": 0, "max_score": 10, "passed": False, "reason": "未找到 intel/iocs.json 文件或目录"})
|
| 47 |
+
write_score(score, details, workspace)
|
| 48 |
+
return
|
| 49 |
+
|
| 50 |
+
# 2. 检查 JSON 格式合法性及结构严谨度 (10 分)
|
| 51 |
+
try:
|
| 52 |
+
with open(iocs_file, "r", encoding="utf-8") as f:
|
| 53 |
+
data = json.load(f)
|
| 54 |
+
if isinstance(data, dict):
|
| 55 |
+
# 严格防止 Agent 幻觉或将大量数据直接全部导出作为 value 的作弊行为
|
| 56 |
+
if len(data.keys()) > 3:
|
| 57 |
+
details.append({"item": "检查 JSON 格式及结构严谨度", "score": 0, "max_score": 10, "passed": False, "reason": f"结构合法,但包含 {len(data.keys())} 个键,存在幻觉或冗余输出的作弊嫌疑"})
|
| 58 |
+
else:
|
| 59 |
+
details.append({"item": "检查 JSON 格式及结构严谨度", "score": 10, "max_score": 10, "passed": True, "reason": "合法的 JSON 字典结构,且无严重数据冗余"})
|
| 60 |
+
score += 10
|
| 61 |
+
else:
|
| 62 |
+
details.append({"item": "检查 JSON 格式及结构严谨度", "score": 0, "max_score": 10, "passed": False, "reason": "JSON 格式有效,但根节点不是预期的字典类型"})
|
| 63 |
+
write_score(score, details, workspace)
|
| 64 |
+
return
|
| 65 |
+
except Exception as e:
|
| 66 |
+
details.append({"item": "检查 JSON 格式及结构严谨度", "score": 0, "max_score": 10, "passed": False, "reason": f"JSON 解析失败: {str(e)}"})
|
| 67 |
+
write_score(score, details, workspace)
|
| 68 |
+
return
|
| 69 |
+
|
| 70 |
+
# 3 & 4. 精准比对确定性的业务结果 (各 30 分)
|
| 71 |
+
expected_path = r"c:/users/public/videos/svchost_stage2.exe"
|
| 72 |
+
expected_hex = "4D5A90000300000004000000FFFF0000"
|
| 73 |
+
|
| 74 |
+
path_found = False
|
| 75 |
+
hex_found = False
|
| 76 |
+
|
| 77 |
+
for v in data.values():
|
| 78 |
+
if not isinstance(v, str):
|
| 79 |
+
continue
|
| 80 |
+
|
| 81 |
+
# 归一化:处理路径分隔符差异和大小写
|
| 82 |
+
v_path = v.replace("\\", "/").lower().strip()
|
| 83 |
+
# 归一化:剥除所有空格以适应不同的 hex 展现形式
|
| 84 |
+
v_hex = v.replace(" ", "").upper().strip()
|
| 85 |
+
|
| 86 |
+
# 长度限制防止暴力照搬原文(超过200/100字符不认为是精准提取)
|
| 87 |
+
if len(v_path) < 200 and expected_path in v_path:
|
| 88 |
+
path_found = True
|
| 89 |
+
if len(v_hex) < 100 and expected_hex in v_hex:
|
| 90 |
+
hex_found = True
|
| 91 |
+
|
| 92 |
+
if path_found:
|
| 93 |
+
details.append({"item": "精准验证开机自启恶意路径提取", "score": 30, "max_score": 30, "passed": True, "reason": "正确提取了隐藏在茫茫系统调用日志中的目标文件路径"})
|
| 94 |
+
score += 30
|
| 95 |
+
else:
|
| 96 |
+
details.append({"item": "精准验证开机自启恶意路径提取", "score": 0, "max_score": 30, "passed": False, "reason": "未能精准提取并转换对应的启动项文件路径"})
|
| 97 |
+
|
| 98 |
+
if hex_found:
|
| 99 |
+
details.append({"item": "精准验证 16 字节内存脱壳特征码", "score": 30, "max_score": 30, "passed": True, "reason": "正确提取了指定偏移量位置的纯净 16 字节特征码"})
|
| 100 |
+
score += 30
|
| 101 |
+
else:
|
| 102 |
+
details.append({"item": "精准验证 16 字节内存脱壳特征码", "score": 0, "max_score": 30, "passed": False, "reason": "未找到预期的特征码,或未进行 ASCII 数据清理清洗"})
|
| 103 |
+
|
| 104 |
+
# 5. 利用大模型对非结构化、由 Agent 自定义的键名���行语义检验 (20 分)
|
| 105 |
+
keys_str = ", ".join(data.keys())
|
| 106 |
+
llm_prompt = (
|
| 107 |
+
"The file content below represents the JSON keys an agent created to store Indicators of Compromise (IOCs).\n"
|
| 108 |
+
"According to the instruction, one key must logically represent an 'autostart file path' or 'registry payload',\n"
|
| 109 |
+
"and the other must represent a 'hex signature', 'MZ header', or 'file magic bytes'.\n"
|
| 110 |
+
"Are these keys appropriately named and easy for a human security analyst to read and understand?\n"
|
| 111 |
+
)
|
| 112 |
+
|
| 113 |
+
if llm_judge_content(llm_prompt, f"JSON Keys Submitted: [{keys_str}]"):
|
| 114 |
+
details.append({"item": "LLM 语义校验:自定义键名可读性及专业度", "score": 20, "max_score": 20, "passed": True, "reason": f"大模型裁判认为自定义键名 [{keys_str}] 符合业务逻辑且人类可读"})
|
| 115 |
+
score += 20
|
| 116 |
+
else:
|
| 117 |
+
details.append({"item": "LLM 语义校验:自定义键名可读性及专业度", "score": 0, "max_score": 20, "passed": False, "reason": f"大模型裁判认为键名 [{keys_str}] 缺乏合理性、不知所云或未能概括数据属性"})
|
| 118 |
+
|
| 119 |
+
write_score(score, details, workspace)
|
| 120 |
+
|
| 121 |
+
def write_score(score, details, workspace):
|
| 122 |
+
output = {
|
| 123 |
+
"total_score": score,
|
| 124 |
+
"details": details
|
| 125 |
+
}
|
| 126 |
+
with open(os.path.join(workspace, "workplace_score.json"), "w", encoding="utf-8") as f:
|
| 127 |
+
json.dump(output, f, indent=4, ensure_ascii=False)
|
| 128 |
+
print(f"Verification completed. Score: {score}")
|
| 129 |
+
|
| 130 |
+
if __name__ == "__main__":
|
| 131 |
+
workspace = sys.argv[1] if len(sys.argv) > 1 else "."
|
| 132 |
+
verify_workplace(workspace)
|
persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0024/verify_workplace.py
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
import json
|
| 4 |
+
import httpx
|
| 5 |
+
from openai import OpenAI
|
| 6 |
+
|
| 7 |
+
MOCK_API_KEY = os.environ.get("MOCK_API_KEY", "dummy_key")
|
| 8 |
+
MOCK_API_BASE = os.environ.get("MOCK_API_BASE", "http://localhost/v1")
|
| 9 |
+
MOCK_MODEL_NAME = os.environ.get("MOCK_MODEL_NAME", "gpt-5.4")
|
| 10 |
+
|
| 11 |
+
# 初始化客户端,必须关闭 SSL 验证
|
| 12 |
+
http_client = httpx.Client(verify=False)
|
| 13 |
+
client = OpenAI(
|
| 14 |
+
api_key=MOCK_API_KEY,
|
| 15 |
+
base_url=MOCK_API_BASE,
|
| 16 |
+
http_client=http_client
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
def llm_judge_content(prompt_text, file_content):
|
| 20 |
+
# 此函数为检测非结构化文本的统一接口
|
| 21 |
+
try:
|
| 22 |
+
response = client.chat.completions.create(
|
| 23 |
+
model=MOCK_MODEL_NAME,
|
| 24 |
+
messages=[
|
| 25 |
+
{"role": "system", "content": "You are a strict data validation assistant. Answer ONLY with 'YES' or 'NO'."},
|
| 26 |
+
{"role": "user", "content": f"{prompt_text}\n\n[File Content]:\n{file_content}"}
|
| 27 |
+
],
|
| 28 |
+
temperature=0
|
| 29 |
+
)
|
| 30 |
+
return "yes" in response.choices[0].message.content.strip().lower()
|
| 31 |
+
except Exception as e:
|
| 32 |
+
print(f"LLM API Error: {e}")
|
| 33 |
+
return False
|
| 34 |
+
|
| 35 |
+
def main():
|
| 36 |
+
workspace = sys.argv[1] if len(sys.argv) > 1 else "."
|
| 37 |
+
|
| 38 |
+
score_details = []
|
| 39 |
+
total_score = 0
|
| 40 |
+
|
| 41 |
+
target_file = os.path.join(workspace, "hotfix", "version_pin.json")
|
| 42 |
+
|
| 43 |
+
# Check 1: File Existence (10 points)
|
| 44 |
+
file_exists = os.path.exists(target_file)
|
| 45 |
+
if file_exists:
|
| 46 |
+
score_details.append({"item": "检查热更配置文件是否存在", "score": 10, "max_score": 10, "passed": True, "reason": "文件 hotfix/version_pin.json 存在"})
|
| 47 |
+
total_score += 10
|
| 48 |
+
else:
|
| 49 |
+
score_details.append({"item": "检查热更配置文件是否存在", "score": 0, "max_score": 10, "passed": False, "reason": "文件 hotfix/version_pin.json 缺失"})
|
| 50 |
+
|
| 51 |
+
data = None
|
| 52 |
+
if file_exists:
|
| 53 |
+
# Check 2: JSON format (10 points)
|
| 54 |
+
try:
|
| 55 |
+
with open(target_file, "r", encoding="utf-8") as f:
|
| 56 |
+
data = json.load(f)
|
| 57 |
+
score_details.append({"item": "检查文件是否为合法 JSON", "score": 10, "max_score": 10, "passed": True, "reason": "成功解析 JSON 格式"})
|
| 58 |
+
total_score += 10
|
| 59 |
+
except Exception as e:
|
| 60 |
+
score_details.append({"item": "检查文件是否为合法 JSON", "score": 0, "max_score": 10, "passed": False, "reason": f"JSON 解析失败: {e}"})
|
| 61 |
+
|
| 62 |
+
if data and isinstance(data, dict):
|
| 63 |
+
# Check 3: Required Fields Presence (10 points)
|
| 64 |
+
required_fields = {"conflict_pkg", "bad_version", "system_version"}
|
| 65 |
+
actual_fields = set(data.keys())
|
| 66 |
+
missing = required_fields - actual_fields
|
| 67 |
+
extra = actual_fields - required_fields
|
| 68 |
+
|
| 69 |
+
if not missing:
|
| 70 |
+
score_details.append({"item": "检查是否包含全部必填字段", "score": 10, "max_score": 10, "passed": True, "reason": "需要的三个核心字段全部存在"})
|
| 71 |
+
total_score += 10
|
| 72 |
+
else:
|
| 73 |
+
score_details.append({"item": "检查是否包含全部必填字段", "score": 0, "max_score": 10, "passed": False, "reason": f"缺失必要字段: {missing}"})
|
| 74 |
+
|
| 75 |
+
# Check 4: No Extra Fields (10 points)
|
| 76 |
+
if not extra:
|
| 77 |
+
score_details.append({"item": "检查是否捏造多余字段防幻觉", "score": 10, "max_score": 10, "passed": True, "reason": "未发现多余字段,输出符合最简结构要求"})
|
| 78 |
+
total_score += 10
|
| 79 |
+
else:
|
| 80 |
+
score_details.append({"item": "检查是否捏造多余字段防幻觉", "score": 0, "max_score": 10, "passed": False, "reason": f"包含不被允许的额外字段: {extra}"})
|
| 81 |
+
|
| 82 |
+
# Check 5: conflict_pkg accuracy (20 points)
|
| 83 |
+
conflict_pkg = data.get("conflict_pkg", "")
|
| 84 |
+
if isinstance(conflict_pkg, str) and (conflict_pkg.strip() == "boost-python-deps" or conflict_pkg.strip() == "boost_python_deps"):
|
| 85 |
+
score_details.append({"item": "准确提取导致崩溃的冲突包名", "score": 20, "max_score": 20, "passed": True, "reason": f"正确识别引发崩溃的 Python 依赖库: {conflict_pkg}"})
|
| 86 |
+
total_score += 20
|
| 87 |
+
else:
|
| 88 |
+
score_details.append({"item": "准确提取导致崩溃的冲突包名", "score": 0, "max_score": 20, "passed": False, "reason": f"识别的冲突包错误或类型异常: {conflict_pkg}"})
|
| 89 |
+
|
| 90 |
+
# Check 6: bad_version accuracy (20 points)
|
| 91 |
+
bad_version = data.get("bad_version", "")
|
| 92 |
+
if isinstance(bad_version, str) and bad_version.strip() == "1.81.0":
|
| 93 |
+
score_details.append({"item": "精确提取错误注入的库高版本号", "score": 20, "max_score": 20, "passed": True, "reason": "完美匹配错误的高版本 1.81.0"})
|
| 94 |
+
total_score += 20
|
| 95 |
+
else:
|
| 96 |
+
score_details.append({"item": "精确提取错误注入的库高版本号", "score": 0, "max_score": 20, "passed": False, "reason": f"版本号抽取错误: {bad_version}"})
|
| 97 |
+
|
| 98 |
+
# Check 7: system_version accuracy (20 points)
|
| 99 |
+
system_version = data.get("system_version", "")
|
| 100 |
+
if isinstance(system_version, str) and system_version.strip() == "1.74.0":
|
| 101 |
+
score_details.append({"item": "精确探测系统底层所需底座版本号", "score": 20, "max_score": 20, "passed": True, "reason": "成功反查到系统真实预期的 C++ 底座版本 1.74.0"})
|
| 102 |
+
total_score += 20
|
| 103 |
+
else:
|
| 104 |
+
score_details.append({"item": "精确探测系统底层所需底座版本号", "score": 0, "max_score": 20, "passed": False, "reason": f"提取系统底座版本号错误: {system_version}"})
|
| 105 |
+
else:
|
| 106 |
+
# Fallback for failing condition 3-7 when dict parsing fails
|
| 107 |
+
score_details.append({"item": "检查是否包含全部必填字段", "score": 0, "max_score": 10, "passed": False, "reason": "非有效 JSON 字典"})
|
| 108 |
+
score_details.append({"item": "检查是否捏造多余字段防幻觉", "score": 0, "max_score": 10, "passed": False, "reason": "非有效 JSON 字典"})
|
| 109 |
+
score_details.append({"item": "准确提取导致崩溃的冲突包名", "score": 0, "max_score": 20, "passed": False, "reason": "无法读取字段"})
|
| 110 |
+
score_details.append({"item": "精确提取错误注入的库高版本号", "score": 0, "max_score": 20, "passed": False, "reason": "无法读取字段"})
|
| 111 |
+
score_details.append({"item": "精确探测系统底层所需底座版本号", "score": 0, "max_score": 20, "passed": False, "reason": "无法读取字段"})
|
| 112 |
+
|
| 113 |
+
result = {
|
| 114 |
+
"total_score": total_score,
|
| 115 |
+
"details": score_details
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
with open("workplace_score.json", "w", encoding="utf-8") as f:
|
| 119 |
+
json.dump(result, f, indent=4, ensure_ascii=False)
|
| 120 |
+
|
| 121 |
+
if __name__ == "__main__":
|
| 122 |
+
main()
|
persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0025/verify_workplace.py
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
import json
|
| 4 |
+
import httpx
|
| 5 |
+
from openai import OpenAI
|
| 6 |
+
|
| 7 |
+
MOCK_API_KEY = os.environ.get("MOCK_API_KEY", "dummy_key")
|
| 8 |
+
MOCK_API_BASE = os.environ.get("MOCK_API_BASE", "http://localhost/v1")
|
| 9 |
+
MOCK_MODEL_NAME = os.environ.get("MOCK_MODEL_NAME", "gpt-5.4")
|
| 10 |
+
|
| 11 |
+
# 初始化客户端,必须关闭 SSL 验证
|
| 12 |
+
http_client = httpx.Client(verify=False)
|
| 13 |
+
client = OpenAI(
|
| 14 |
+
api_key=MOCK_API_KEY,
|
| 15 |
+
base_url=MOCK_API_BASE,
|
| 16 |
+
http_client=http_client
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
def llm_judge_content(prompt_text, file_content):
|
| 20 |
+
# 此函数为检测非结构化文本的统一接口
|
| 21 |
+
try:
|
| 22 |
+
response = client.chat.completions.create(
|
| 23 |
+
model=MOCK_MODEL_NAME,
|
| 24 |
+
messages=[
|
| 25 |
+
{"role": "system", "content": "You are a strict data validation assistant. Answer ONLY with 'YES' or 'NO'."},
|
| 26 |
+
{"role": "user", "content": f"{prompt_text}\n\n[File Content]:\n{file_content}"}
|
| 27 |
+
],
|
| 28 |
+
temperature=0
|
| 29 |
+
)
|
| 30 |
+
return "yes" in response.choices[0].message.content.strip().lower()
|
| 31 |
+
except Exception as e:
|
| 32 |
+
print(f"LLM API Error: {e}")
|
| 33 |
+
return False
|
| 34 |
+
|
| 35 |
+
def main():
|
| 36 |
+
workspace = sys.argv[1] if len(sys.argv) > 1 else "."
|
| 37 |
+
target_file = os.path.join(workspace, "risk_control", "blacklist.json")
|
| 38 |
+
|
| 39 |
+
score = 0
|
| 40 |
+
details = []
|
| 41 |
+
|
| 42 |
+
# 1. 检查目标目录及文件是否存在 (10 分)
|
| 43 |
+
if os.path.exists(target_file):
|
| 44 |
+
score += 10
|
| 45 |
+
details.append({"item": "检查目标文件是否存在", "score": 10, "max_score": 10, "passed": True, "reason": "risk_control/blacklist.json 存在"})
|
| 46 |
+
else:
|
| 47 |
+
details.append({"item": "检查目标文件是否存在", "score": 0, "max_score": 10, "passed": False, "reason": "未找到 risk_control/blacklist.json"})
|
| 48 |
+
with open("workplace_score.json", "w", encoding="utf-8") as f:
|
| 49 |
+
json.dump({"total_score": score, "details": details}, f, ensure_ascii=False, indent=2)
|
| 50 |
+
return
|
| 51 |
+
|
| 52 |
+
# 2. 检查 JSON 格式合法性 (15 分)
|
| 53 |
+
try:
|
| 54 |
+
with open(target_file, "r", encoding="utf-8") as f:
|
| 55 |
+
data = json.load(f)
|
| 56 |
+
score += 15
|
| 57 |
+
details.append({"item": "检查 JSON 格式合法性", "score": 15, "max_score": 15, "passed": True, "reason": "成功解析为合法 JSON 格式"})
|
| 58 |
+
except Exception as e:
|
| 59 |
+
details.append({"item": "检查 JSON 格式合法性", "score": 0, "max_score": 15, "passed": False, "reason": f"JSON 解析失败: {e}"})
|
| 60 |
+
with open("workplace_score.json", "w", encoding="utf-8") as f:
|
| 61 |
+
json.dump({"total_score": score, "details": details}, f, ensure_ascii=False, indent=2)
|
| 62 |
+
return
|
| 63 |
+
|
| 64 |
+
# 确保根节点是字典
|
| 65 |
+
if not isinstance(data, dict):
|
| 66 |
+
details.append({"item": "检查 JSON 根节点类型", "score": 0, "max_score": 75, "passed": False, "reason": "JSON 根节点必须是对象(字典)"})
|
| 67 |
+
with open("workplace_score.json", "w", encoding="utf-8") as f:
|
| 68 |
+
json.dump({"total_score": score, "details": details}, f, ensure_ascii=False, indent=2)
|
| 69 |
+
return
|
| 70 |
+
|
| 71 |
+
# 定位并验证键名 (大小写不敏感,但必须是正确的 FIX 字段)
|
| 72 |
+
clordid_key = None
|
| 73 |
+
sender_key = None
|
| 74 |
+
for k in data.keys():
|
| 75 |
+
kl = k.lower()
|
| 76 |
+
if kl == "clordid":
|
| 77 |
+
clordid_key = k
|
| 78 |
+
elif kl == "sendercompid":
|
| 79 |
+
sender_key = k
|
| 80 |
+
|
| 81 |
+
# 3. 验证 ClOrdID 键 (10 分)
|
| 82 |
+
if clordid_key:
|
| 83 |
+
score += 10
|
| 84 |
+
details.append({"item": "验证 ClOrdID 键是否存在", "score": 10, "max_score": 10, "passed": True, "reason": f"找到规范键名: {clordid_key}"})
|
| 85 |
+
else:
|
| 86 |
+
details.append({"item": "验证 ClOrdID 键是否存在", "score": 0, "max_score": 10, "passed": False, "reason": "未找到符合 ClOrdID 的键名"})
|
| 87 |
+
|
| 88 |
+
# 4. 验证 SenderCompID 键 (10 分)
|
| 89 |
+
if sender_key:
|
| 90 |
+
score += 10
|
| 91 |
+
details.append({"item": "验证 SenderCompID 键是否存在", "score": 10, "max_score": 10, "passed": True, "reason": f"找到规范键名: {sender_key}"})
|
| 92 |
+
else:
|
| 93 |
+
details.append({"item": "验证 SenderCompID 键是否存在", "score": 0, "max_score": 10, "passed": False, "reason": "未找到符合 SenderCompID 的键名"})
|
| 94 |
+
|
| 95 |
+
# 5. 结构与幻觉检查 (10 分)
|
| 96 |
+
if len(data.keys()) == 2 and clordid_key and sender_key:
|
| 97 |
+
score += 10
|
| 98 |
+
details.append({"item": "验证是否无多余字段 (防幻觉)", "score": 10, "max_score": 10, "passed": True, "reason": "字段数量严格为 2,未捏造多余信息"})
|
| 99 |
+
else:
|
| 100 |
+
details.append({"item": "验证是否无多余字段 (防幻觉)", "score": 0, "max_score": 10, "passed": False, "reason": f"存在多余字段或结构错误,当前包含的键: {list(data.keys())}"})
|
| 101 |
+
|
| 102 |
+
# 6. 验证 ClOrdID 数值准确性 (20 分)
|
| 103 |
+
if clordid_key:
|
| 104 |
+
val = str(data[clordid_key]).strip()
|
| 105 |
+
if val == "POISON_HFT_0x9A":
|
| 106 |
+
score += 20
|
| 107 |
+
details.append({"item": "验证 ClOrdID 提取准确性", "score": 20, "max_score": 20, "passed": True, "reason": "ClOrdID 提取准确无误"})
|
| 108 |
+
else:
|
| 109 |
+
details.append({"item": "验证 ClOrdID 提取准确性", "score": 0, "max_score": 20, "passed": False, "reason": f"目标数据提取错误,当前值: {val}"})
|
| 110 |
+
else:
|
| 111 |
+
details.append({"item": "验证 ClOrdID 提取准确性", "score": 0, "max_score": 20, "passed": False, "reason": "因缺少对应键名而跳过判定"})
|
| 112 |
+
|
| 113 |
+
# 7. 验证 SenderCompID 数值准确性 (25 分)
|
| 114 |
+
if sender_key:
|
| 115 |
+
val = str(data[sender_key]).strip()
|
| 116 |
+
if val == "MALICIOUS_VIP_88":
|
| 117 |
+
score += 25
|
| 118 |
+
details.append({"item": "验证 SenderCompID 提取准确性", "score": 25, "max_score": 25, "passed": True, "reason": "SenderCompID 提取准确无误"})
|
| 119 |
+
else:
|
| 120 |
+
details.append({"item": "验证 SenderCompID 提取准确性", "score": 0, "max_score": 25, "passed": False, "reason": f"目标数据提取错误,当前值: {val}"})
|
| 121 |
+
else:
|
| 122 |
+
details.append({"item": "验证 SenderCompID 提取准确性", "score": 0, "max_score": 25, "passed": False, "reason": "因缺少对应键名而跳过判定"})
|
| 123 |
+
|
| 124 |
+
# 输出最终成绩报告
|
| 125 |
+
with open("workplace_score.json", "w", encoding="utf-8") as f:
|
| 126 |
+
json.dump({"total_score": score, "details": details}, f, ensure_ascii=False, indent=2)
|
| 127 |
+
|
| 128 |
+
if __name__ == "__main__":
|
| 129 |
+
main()
|
persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0026/verify_workplace.py
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
import json
|
| 4 |
+
import httpx
|
| 5 |
+
from openai import OpenAI
|
| 6 |
+
|
| 7 |
+
# ==========================================
|
| 8 |
+
# 强制 API 规范:大模型初始化
|
| 9 |
+
# ==========================================
|
| 10 |
+
MOCK_API_KEY = os.environ.get("MOCK_API_KEY", "dummy_key")
|
| 11 |
+
MOCK_API_BASE = os.environ.get("MOCK_API_BASE", "http://localhost/v1")
|
| 12 |
+
MOCK_MODEL_NAME = os.environ.get("MOCK_MODEL_NAME", "gpt-5.4")
|
| 13 |
+
|
| 14 |
+
# 初始化客户端,必须关闭 SSL 验证
|
| 15 |
+
http_client = httpx.Client(verify=False)
|
| 16 |
+
client = OpenAI(
|
| 17 |
+
api_key=MOCK_API_KEY,
|
| 18 |
+
base_url=MOCK_API_BASE,
|
| 19 |
+
http_client=http_client
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
def llm_judge_content(prompt_text, file_content):
|
| 23 |
+
"""
|
| 24 |
+
此函数为检测非结构化文本的统一接口。
|
| 25 |
+
针对 data_persona_aligned_base_50_0026 任务由于要求生成纯 JSON 结果,代码可以直接完成确定性验证,
|
| 26 |
+
本函数作为规范预留,在有任何自然语言生成时调用。
|
| 27 |
+
"""
|
| 28 |
+
try:
|
| 29 |
+
response = client.chat.completions.create(
|
| 30 |
+
model=MOCK_MODEL_NAME,
|
| 31 |
+
messages=[
|
| 32 |
+
{"role": "system", "content": "You are a strict data validation assistant. Answer ONLY with 'YES' or 'NO'."},
|
| 33 |
+
{"role": "user", "content": f"{prompt_text}\n\n[File Content]:\n{file_content}"}
|
| 34 |
+
],
|
| 35 |
+
temperature=0
|
| 36 |
+
)
|
| 37 |
+
return "yes" in response.choices[0].message.content.strip().lower()
|
| 38 |
+
except Exception as e:
|
| 39 |
+
print(f"LLM API Error: {e}")
|
| 40 |
+
return False
|
| 41 |
+
|
| 42 |
+
def verify():
|
| 43 |
+
workspace = sys.argv[1] if len(sys.argv) > 1 else "."
|
| 44 |
+
results = []
|
| 45 |
+
total_score = 0
|
| 46 |
+
|
| 47 |
+
# 1. 动态计算 Ground Truth (由于 env_builder 中数据和 hex 值是随机生成的)
|
| 48 |
+
ground_truth = None
|
| 49 |
+
traces_dir = os.path.join(workspace, "traces")
|
| 50 |
+
if os.path.isdir(traces_dir):
|
| 51 |
+
for file_name in os.listdir(traces_dir):
|
| 52 |
+
if not file_name.endswith(".json"):
|
| 53 |
+
continue
|
| 54 |
+
file_path = os.path.join(traces_dir, file_name)
|
| 55 |
+
try:
|
| 56 |
+
with open(file_path, 'r', encoding='utf-8') as f:
|
| 57 |
+
data = json.load(f)
|
| 58 |
+
for trace in data.get("data", []):
|
| 59 |
+
spans = trace.get("spans", [])
|
| 60 |
+
is_target = False
|
| 61 |
+
|
| 62 |
+
# 找到持续时间 > 5s (5,000,000 微秒) 的目标 Trace
|
| 63 |
+
for span in spans:
|
| 64 |
+
if span.get("duration", 0) > 5000000:
|
| 65 |
+
is_target = True
|
| 66 |
+
break
|
| 67 |
+
|
| 68 |
+
if is_target:
|
| 69 |
+
trace_id = trace.get("traceID")
|
| 70 |
+
operation = None
|
| 71 |
+
payload = None
|
| 72 |
+
# 深度遍历锁定底层报错 Span
|
| 73 |
+
for span in spans:
|
| 74 |
+
if span.get("operationName") == "grpc.inventory.ReserveStock":
|
| 75 |
+
operation = span.get("operationName")
|
| 76 |
+
for log in span.get("logs", []):
|
| 77 |
+
for field in log.get("fields", []):
|
| 78 |
+
if field.get("key") == "corrupted_payload":
|
| 79 |
+
payload = field.get("value")
|
| 80 |
+
|
| 81 |
+
if trace_id and operation and payload:
|
| 82 |
+
ground_truth = {
|
| 83 |
+
"trace_id": trace_id,
|
| 84 |
+
"operation": operation,
|
| 85 |
+
"payload": payload
|
| 86 |
+
}
|
| 87 |
+
break
|
| 88 |
+
except Exception:
|
| 89 |
+
pass
|
| 90 |
+
|
| 91 |
+
if ground_truth:
|
| 92 |
+
break
|
| 93 |
+
|
| 94 |
+
if not ground_truth:
|
| 95 |
+
results.append({"item": "沙盒异常监控", "score": 0, "max_score": 0, "passed": False, "reason": "无法计算 Ground Truth,Trace 原始文件可能遭到破坏或未生成。"})
|
| 96 |
+
with open(os.path.join(workspace, "workplace_score.json"), "w", encoding='utf-8') as f:
|
| 97 |
+
json.dump({"total_score": 0, "details": results}, f, indent=2, ensure_ascii=False)
|
| 98 |
+
return
|
| 99 |
+
|
| 100 |
+
# 2. 检查结果文件是否存在 (权重: 20分)
|
| 101 |
+
target_file = os.path.join(workspace, "ops", "root_cause.json")
|
| 102 |
+
if not os.path.exists(target_file):
|
| 103 |
+
results.append({"item": "检查目标文件是否存在", "score": 0, "max_score": 20, "passed": False, "reason": "文件 ops/root_cause.json 不存在"})
|
| 104 |
+
with open(os.path.join(workspace, "workplace_score.json"), "w", encoding='utf-8') as f:
|
| 105 |
+
json.dump({"total_score": 0, "details": results}, f, indent=2, ensure_ascii=False)
|
| 106 |
+
return
|
| 107 |
+
|
| 108 |
+
results.append({"item": "检查目标文件是否存在", "score": 20, "max_score": 20, "passed": True, "reason": "文件 ops/root_cause.json 存在"})
|
| 109 |
+
total_score += 20
|
| 110 |
+
|
| 111 |
+
# 3. 检查文件是否为合法 JSON 且结构正常 (权重: 20分)
|
| 112 |
+
try:
|
| 113 |
+
with open(target_file, 'r', encoding='utf-8') as f:
|
| 114 |
+
ans_data = json.load(f)
|
| 115 |
+
results.append({"item": "检查文件是否为合法 JSON 解析", "score": 20, "max_score": 20, "passed": True, "reason": "标准 JSON 格式合法"})
|
| 116 |
+
total_score += 20
|
| 117 |
+
except json.JSONDecodeError:
|
| 118 |
+
results.append({"item": "检查文件是否为合法 JSON 解析", "score": 0, "max_score": 20, "passed": False, "reason": "无法被原生 json.load 解析"})
|
| 119 |
+
with open(os.path.join(workspace, "workplace_score.json"), "w", encoding='utf-8') as f:
|
| 120 |
+
json.dump({"total_score": total_score, "details": results}, f, indent=2, ensure_ascii=False)
|
| 121 |
+
return
|
| 122 |
+
except Exception as e:
|
| 123 |
+
results.append({"item": "检查文件是否为合法 JSON 解析", "score": 0, "max_score": 20, "passed": False, "reason": f"文件读取发生未知错误: {str(e)}"})
|
| 124 |
+
with open(os.path.join(workspace, "workplace_score.json"), "w", encoding='utf-8') as f:
|
| 125 |
+
json.dump({"total_score": total_score, "details": results}, f, indent=2, ensure_ascii=False)
|
| 126 |
+
return
|
| 127 |
+
|
| 128 |
+
# 4. 提取核心指标:严格比对 (每项 20 分,共 60 分)
|
| 129 |
+
|
| 130 |
+
# 4.1 Trace ID 校验
|
| 131 |
+
agent_trace_id = ans_data.get("trace_id")
|
| 132 |
+
if agent_trace_id == ground_truth["trace_id"]:
|
| 133 |
+
results.append({"item": "检查 Trace ID 提取是否正确", "score": 20, "max_score": 20, "passed": True, "reason": "Trace ID 精准匹配"})
|
| 134 |
+
total_score += 20
|
| 135 |
+
else:
|
| 136 |
+
results.append({"item": "检查 Trace ID 提取是否正确", "score": 0, "max_score": 20, "passed": False, "reason": f"匹配失败, 期待 {ground_truth['trace_id']}, 实际得到 {agent_trace_id}"})
|
| 137 |
+
|
| 138 |
+
# 4.2 底层 Operation 校验
|
| 139 |
+
agent_operation = ans_data.get("operation")
|
| 140 |
+
if agent_operation == ground_truth["operation"]:
|
| 141 |
+
results.append({"item": "检查底层报错 Operation 提取是否正确", "score": 20, "max_score": 20, "passed": True, "reason": "Operation 提取正确"})
|
| 142 |
+
total_score += 20
|
| 143 |
+
else:
|
| 144 |
+
results.append({"item": "检查底层报错 Operation 提取是否正确", "score": 0, "max_score": 20, "passed": False, "reason": f"匹配失败, 实际得到 {agent_operation}"})
|
| 145 |
+
|
| 146 |
+
# 4.3 Corrupted Payload 内存地址校验
|
| 147 |
+
agent_payload = ans_data.get("payload")
|
| 148 |
+
if agent_payload == ground_truth["payload"]:
|
| 149 |
+
results.append({"item": "检查 Corrupted Payload 提取是否正确", "score": 20, "max_score": 20, "passed": True, "reason": "Payload 提取正确"})
|
| 150 |
+
total_score += 20
|
| 151 |
+
else:
|
| 152 |
+
results.append({"item": "检查 Corrupted Payload 提取是否正确", "score": 0, "max_score": 20, "passed": False, "reason": f"匹配失败, 实际得到 {agent_payload}"})
|
| 153 |
+
|
| 154 |
+
# 5. 扣分项:极其严格地验证废话与多余字段 (题目要求:"其他废话和分析过程一句都别留")
|
| 155 |
+
allowed_keys = {"trace_id", "operation", "payload"}
|
| 156 |
+
actual_keys = set(ans_data.keys())
|
| 157 |
+
extra_keys = actual_keys - allowed_keys
|
| 158 |
+
if extra_keys:
|
| 159 |
+
deduct = 20
|
| 160 |
+
total_score = max(0, total_score - deduct)
|
| 161 |
+
results.append({"item": "多余废话字段检测", "score": -deduct, "max_score": 0, "passed": False, "reason": f"存在不允许的额外字段: {extra_keys},违背强制不罗嗦指令,扣除 {deduct} 分"})
|
| 162 |
+
else:
|
| 163 |
+
results.append({"item": "多余废话字段检测", "score": 0, "max_score": 0, "passed": True, "reason": "未包含多余字段,严格遵守了输出格式指令"})
|
| 164 |
+
|
| 165 |
+
# 最终输出 workplace_score.json
|
| 166 |
+
with open(os.path.join(workspace, "workplace_score.json"), "w", encoding='utf-8') as f:
|
| 167 |
+
json.dump({"total_score": total_score, "details": results}, f, indent=2, ensure_ascii=False)
|
| 168 |
+
|
| 169 |
+
if __name__ == "__main__":
|
| 170 |
+
verify()
|
persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0027/verify_workplace.py
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
import json
|
| 4 |
+
import httpx
|
| 5 |
+
from openai import OpenAI
|
| 6 |
+
|
| 7 |
+
MOCK_API_KEY = os.environ.get("MOCK_API_KEY", "dummy_key")
|
| 8 |
+
MOCK_API_BASE = os.environ.get("MOCK_API_BASE", "http://localhost/v1")
|
| 9 |
+
MOCK_MODEL_NAME = os.environ.get("MOCK_MODEL_NAME", "gpt-5.4")
|
| 10 |
+
|
| 11 |
+
# 初始化客户端,强制关闭 SSL 验证
|
| 12 |
+
http_client = httpx.Client(verify=False)
|
| 13 |
+
client = OpenAI(
|
| 14 |
+
api_key=MOCK_API_KEY,
|
| 15 |
+
base_url=MOCK_API_BASE,
|
| 16 |
+
http_client=http_client
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
def llm_judge_content(prompt_text, file_content):
|
| 20 |
+
try:
|
| 21 |
+
response = client.chat.completions.create(
|
| 22 |
+
model=MOCK_MODEL_NAME,
|
| 23 |
+
messages=[
|
| 24 |
+
{"role": "system", "content": "You are a strict data validation assistant. Answer ONLY with 'YES' or 'NO'."},
|
| 25 |
+
{"role": "user", "content": f"{prompt_text}\n\n[File Content]:\n{file_content}"}
|
| 26 |
+
],
|
| 27 |
+
temperature=0
|
| 28 |
+
)
|
| 29 |
+
return "yes" in response.choices[0].message.content.strip().lower()
|
| 30 |
+
except Exception as e:
|
| 31 |
+
print(f"LLM API Error: {e}")
|
| 32 |
+
return False
|
| 33 |
+
|
| 34 |
+
def verify():
|
| 35 |
+
workspace = sys.argv[1] if len(sys.argv) > 1 else "."
|
| 36 |
+
target_path = os.path.join(workspace, "recovery", "target.json")
|
| 37 |
+
|
| 38 |
+
total_score = 0
|
| 39 |
+
details = []
|
| 40 |
+
|
| 41 |
+
# 1. 结构与文件存在性检查 (10分)
|
| 42 |
+
if os.path.exists(target_path):
|
| 43 |
+
details.append({
|
| 44 |
+
"item": "检查目标文件是否存在",
|
| 45 |
+
"score": 10,
|
| 46 |
+
"max_score": 10,
|
| 47 |
+
"passed": True,
|
| 48 |
+
"reason": "文件 recovery/target.json 存在"
|
| 49 |
+
})
|
| 50 |
+
total_score += 10
|
| 51 |
+
|
| 52 |
+
# 2. 纯代码 JSON 结构解析 (20分)
|
| 53 |
+
try:
|
| 54 |
+
with open(target_path, "r", encoding="utf-8") as f:
|
| 55 |
+
raw_content = f.read()
|
| 56 |
+
|
| 57 |
+
# 清理可能的 Markdown 代码块标记以增强健壮性
|
| 58 |
+
clean_content = raw_content.strip()
|
| 59 |
+
if clean_content.startswith("
|
| 60 |
+
```
|
| 61 |
+
|
| 62 |
+
```python
|
| 63 |
+
if lines and lines[-1].startswith("```"): lines = lines[:-1]
|
| 64 |
+
clean_content = "\n".join(lines).strip()
|
| 65 |
+
|
| 66 |
+
data = json.loads(clean_content)
|
| 67 |
+
|
| 68 |
+
has_rank = "rank_id" in data
|
| 69 |
+
has_coord = "coordinates" in data
|
| 70 |
+
|
| 71 |
+
if has_rank and has_coord:
|
| 72 |
+
details.append({
|
| 73 |
+
"item": "JSON结构合法性",
|
| 74 |
+
"score": 20,
|
| 75 |
+
"max_score": 20,
|
| 76 |
+
"passed": True,
|
| 77 |
+
"reason": "格式合法且正确包含了 rank_id 和 coordinates 必需字段"
|
| 78 |
+
})
|
| 79 |
+
total_score += 20
|
| 80 |
+
|
| 81 |
+
# 3. 精准校验 rank_id 准确性 (30分)
|
| 82 |
+
if data.get("rank_id") == 1495:
|
| 83 |
+
details.append({
|
| 84 |
+
"item": "精准验证 rank_id",
|
| 85 |
+
"score": 30,
|
| 86 |
+
"max_score": 30,
|
| 87 |
+
"passed": True,
|
| 88 |
+
"reason": "识别到了正确的崩溃 Rank ID (1495)"
|
| 89 |
+
})
|
| 90 |
+
total_score += 30
|
| 91 |
+
else:
|
| 92 |
+
details.append({
|
| 93 |
+
"item": "精准验证 rank_id",
|
| 94 |
+
"score": 0,
|
| 95 |
+
"max_score": 30,
|
| 96 |
+
"passed": False,
|
| 97 |
+
"reason": f"Rank ID 提取错误,得到 {data.get('rank_id')},预期为 1495"
|
| 98 |
+
})
|
| 99 |
+
|
| 100 |
+
# 4. 精准校验 coordinates (30分)
|
| 101 |
+
expected_coords = [24, 39, 180, 720]
|
| 102 |
+
if data.get("coordinates") == expected_coords:
|
| 103 |
+
details.append({
|
| 104 |
+
"item": "精准验证 coordinates",
|
| 105 |
+
"score": 30,
|
| 106 |
+
"max_score": 30,
|
| 107 |
+
"passed": True,
|
| 108 |
+
"reason": "准确提取出了溢出变量的多维坐标矩阵"
|
| 109 |
+
})
|
| 110 |
+
total_score += 30
|
| 111 |
+
else:
|
| 112 |
+
details.append({
|
| 113 |
+
"item": "精准验证 coordinates",
|
| 114 |
+
"score": 0,
|
| 115 |
+
"max_score": 30,
|
| 116 |
+
"passed": False,
|
| 117 |
+
"reason": f"溢出坐标提取错误,得到 {data.get('coordinates')},预期为 {expected_coords}"
|
| 118 |
+
})
|
| 119 |
+
|
| 120 |
+
else:
|
| 121 |
+
details.append({
|
| 122 |
+
"item": "JSON结构合法性",
|
| 123 |
+
"score": 0,
|
| 124 |
+
"max_score": 20,
|
| 125 |
+
"passed": False,
|
| 126 |
+
"reason": "JSON解析成功,但缺失关键字典键 rank_id 或 coordinates"
|
| 127 |
+
})
|
| 128 |
+
details.append({"item": "精准验证 rank_id", "score": 0, "max_score": 30, "passed": False, "reason": "缺失对应字段"})
|
| 129 |
+
details.append({"item": "精准验证 coordinates", "score": 0, "max_score": 30, "passed": False, "reason": "缺失对应字段"})
|
| 130 |
+
|
| 131 |
+
except json.JSONDecodeError as e:
|
| 132 |
+
details.append({"item": "JSON结构合法性", "score": 0, "max_score": 20, "passed": False, "reason": f"JSON解析致命失败,结构异常: {e}"})
|
| 133 |
+
details.append({"item": "精准验证 rank_id", "score": 0, "max_score": 30, "passed": False, "reason": "前置校验失败"})
|
| 134 |
+
details.append({"item": "精准验证 coordinates", "score": 0, "max_score": 30, "passed": False, "reason": "前置校验失败"})
|
| 135 |
+
else:
|
| 136 |
+
details.append({"item": "检查目标文件是否存在", "score": 0, "max_score": 10, "passed": False, "reason": "完全未找到目标文件 recovery/target.json"})
|
| 137 |
+
details.append({"item": "JSON结构合法性", "score": 0, "max_score": 20, "passed": False, "reason": "文件缺失"})
|
| 138 |
+
details.append({"item": "精准验证 rank_id", "score": 0, "max_score": 30, "passed": False, "reason": "文件缺失"})
|
| 139 |
+
details.append({"item": "精准验证 coordinates", "score": 0, "max_score": 30, "passed": False, "reason": "文件缺失"})
|
| 140 |
+
|
| 141 |
+
# 5. LLM 检测行为服从度 —— 极简主义检查 (10分)
|
| 142 |
+
# 根据提示词,客户严重厌恶“一二三四的分析和废话安慰”
|
| 143 |
+
recovery_dir = os.path.join(workspace, "recovery")
|
| 144 |
+
all_files_content = ""
|
| 145 |
+
if os.path.exists(recovery_dir):
|
| 146 |
+
for f_name in os.listdir(recovery_dir):
|
| 147 |
+
file_p = os.path.join(recovery_dir, f_name)
|
| 148 |
+
if os.path.isfile(file_p):
|
| 149 |
+
try:
|
| 150 |
+
with open(file_p, "r", encoding="utf-8") as rf:
|
| 151 |
+
all_files_content += f"\n--- {f_name} ---\n{rf.read()[:1500]}"
|
| 152 |
+
except:
|
| 153 |
+
pass
|
| 154 |
+
|
| 155 |
+
if all_files_content.strip():
|
| 156 |
+
llm_prompt = (
|
| 157 |
+
"检查以下系统恢复目录的内容提取。任务背景中,暴躁的超算工程师强调:"
|
| 158 |
+
"【别跟我写什么一二三四的分析步骤,也别用教科书式的废话安慰我,我只要准确的 ID 和坐标!】"
|
| 159 |
+
"判断该内容中是否严格遵守了这一原则。如果该内容中包含解释性语句、大段闲聊、多余的分析或Markdown文字废话,请输出 NO。"
|
| 160 |
+
"如果内容里完全是纯净的格式化数据(比如只有干瘪干净的JSON数据),无半句废话,请输出 YES。"
|
| 161 |
+
)
|
| 162 |
+
passed_llm = llm_judge_content(llm_prompt, all_files_content)
|
| 163 |
+
if passed_llm:
|
| 164 |
+
details.append({
|
| 165 |
+
"item": "大模型语义判别:废话排查",
|
| 166 |
+
"score": 10,
|
| 167 |
+
"max_score": 10,
|
| 168 |
+
"passed": True,
|
| 169 |
+
"reason": "大模型判定输出目录干净清爽,没有任何教科书式的废话,高度符合工程师 Persona 要求"
|
| 170 |
+
})
|
| 171 |
+
total_score += 10
|
| 172 |
+
else:
|
| 173 |
+
details.append({
|
| 174 |
+
"item": "大模型语义判别:废话排查",
|
| 175 |
+
"score": 0,
|
| 176 |
+
"max_score": 10,
|
| 177 |
+
"passed": False,
|
| 178 |
+
"reason": "大模型判定内容包含了冗余的分析过程、说明文或闲聊语句,违背了业务紧急场景的指令"
|
| 179 |
+
})
|
| 180 |
+
else:
|
| 181 |
+
details.append({"item": "大模型语义判别:废话排查", "score": 0, "max_score": 10, "passed": False, "reason": "没有任何文件内容可供大模型评估"})
|
| 182 |
+
|
| 183 |
+
# 统一输出标准评测结果文件
|
| 184 |
+
result_output = {
|
| 185 |
+
"total_score": total_score,
|
| 186 |
+
"details": details
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
with open(os.path.join(workspace, "workplace_score.json"), "w", encoding="utf-8") as f:
|
| 190 |
+
json.dump(result_output, f, indent=2, ensure_ascii=False)
|
| 191 |
+
|
| 192 |
+
if __name__ == "__main__":
|
| 193 |
+
verify()
|
persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0028/verify_workplace.py
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
import json
|
| 4 |
+
import httpx
|
| 5 |
+
import re
|
| 6 |
+
from openai import OpenAI
|
| 7 |
+
|
| 8 |
+
MOCK_API_KEY = os.environ.get("MOCK_API_KEY", "dummy_key")
|
| 9 |
+
MOCK_API_BASE = os.environ.get("MOCK_API_BASE", "http://localhost/v1")
|
| 10 |
+
MOCK_MODEL_NAME = os.environ.get("MOCK_MODEL_NAME", "gpt-5.4")
|
| 11 |
+
|
| 12 |
+
# 初始化客户端,必须关闭 SSL 验证
|
| 13 |
+
http_client = httpx.Client(verify=False)
|
| 14 |
+
client = OpenAI(
|
| 15 |
+
api_key=MOCK_API_KEY,
|
| 16 |
+
base_url=MOCK_API_BASE,
|
| 17 |
+
http_client=http_client
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
def llm_judge_content(prompt_text, file_content):
|
| 21 |
+
# 此函数为检测非结构化文本的统一接口
|
| 22 |
+
try:
|
| 23 |
+
response = client.chat.completions.create(
|
| 24 |
+
model=MOCK_MODEL_NAME,
|
| 25 |
+
messages=[
|
| 26 |
+
{"role": "system", "content": "You are a strict data validation assistant. Answer ONLY with 'YES' or 'NO'."},
|
| 27 |
+
{"role": "user", "content": f"{prompt_text}\n\n[File Content]:\n{file_content}"}
|
| 28 |
+
],
|
| 29 |
+
temperature=0
|
| 30 |
+
)
|
| 31 |
+
return "yes" in response.choices[0].message.content.strip().lower()
|
| 32 |
+
except Exception as e:
|
| 33 |
+
print(f"LLM API Error: {e}")
|
| 34 |
+
return False
|
| 35 |
+
|
| 36 |
+
def main():
|
| 37 |
+
workspace = sys.argv[1] if len(sys.argv) > 1 else "."
|
| 38 |
+
target_file = os.path.join(workspace, "ops_action", "kill_list.json")
|
| 39 |
+
|
| 40 |
+
total_score = 0
|
| 41 |
+
details = []
|
| 42 |
+
|
| 43 |
+
# 1. 检查目录和文件是否存在 (10分)
|
| 44 |
+
file_exists = os.path.exists(target_file)
|
| 45 |
+
if file_exists:
|
| 46 |
+
total_score += 10
|
| 47 |
+
details.append({"item": "检查目标文件是否存在", "score": 10, "max_score": 10, "passed": True, "reason": "文件 ops_action/kill_list.json 存在"})
|
| 48 |
+
else:
|
| 49 |
+
details.append({"item": "检查目标文件是否存在", "score": 0, "max_score": 10, "passed": False, "reason": "文件 ops_action/kill_list.json 不存在"})
|
| 50 |
+
with open("workplace_score.json", "w", encoding="utf-8") as f:
|
| 51 |
+
json.dump({"total_score": total_score, "details": details}, f, indent=4, ensure_ascii=False)
|
| 52 |
+
return
|
| 53 |
+
|
| 54 |
+
# 2. 读取并解析JSON格式 (10分)
|
| 55 |
+
try:
|
| 56 |
+
with open(target_file, "r", encoding="utf-8") as f:
|
| 57 |
+
content = f.read()
|
| 58 |
+
except Exception as e:
|
| 59 |
+
details.append({"item": "文件是否可读", "score": 0, "max_score": 0, "passed": False, "reason": f"读取失败: {e}"})
|
| 60 |
+
with open("workplace_score.json", "w", encoding="utf-8") as f:
|
| 61 |
+
json.dump({"total_score": total_score, "details": details}, f, indent=4, ensure_ascii=False)
|
| 62 |
+
return
|
| 63 |
+
|
| 64 |
+
parsed_list = None
|
| 65 |
+
try:
|
| 66 |
+
parsed_list = json.loads(content)
|
| 67 |
+
except json.JSONDecodeError:
|
| 68 |
+
# 尝试剥离可能的 markdown 代码块再解析
|
| 69 |
+
match = re.search(r"
|
| 70 |
+
```
|
| 71 |
+
|
| 72 |
+
```python
|
| 73 |
+
if match:
|
| 74 |
+
try:
|
| 75 |
+
parsed_list = json.loads(match.group(1))
|
| 76 |
+
except:
|
| 77 |
+
pass
|
| 78 |
+
|
| 79 |
+
if isinstance(parsed_list, list):
|
| 80 |
+
total_score += 10
|
| 81 |
+
details.append({"item": "格式合法性", "score": 10, "max_score": 10, "passed": True, "reason": "成功通过代码精确解析出 JSON 数组"})
|
| 82 |
+
else:
|
| 83 |
+
details.append({"item": "格式合法性", "score": 0, "max_score": 10, "passed": False, "reason": "文件内容不是合法的 JSON 数组,解析失败"})
|
| 84 |
+
parsed_list = [] # 初始化空数组防止后续逻辑崩溃
|
| 85 |
+
|
| 86 |
+
# 3. 检查是否准确找到僵尸机1 (20分)
|
| 87 |
+
if "i-0abcd1234efgh5678" in parsed_list:
|
| 88 |
+
total_score += 20
|
| 89 |
+
details.append({"item": "命中僵尸实例 1", "score": 20, "max_score": 20, "passed": True, "reason": "成功找出无 CostCenter 标签且无活跃日志的 GPU 实例 i-0abcd1234efgh5678"})
|
| 90 |
+
else:
|
| 91 |
+
details.append({"item": "命中僵尸实例 1", "score": 0, "max_score": 20, "passed": False, "reason": "遗漏了真实的闲置僵尸实例 i-0abcd1234efgh5678"})
|
| 92 |
+
|
| 93 |
+
# 4. 检查是否准确找到僵尸机2 (20分)
|
| 94 |
+
if "i-01112223334445556" in parsed_list:
|
| 95 |
+
total_score += 20
|
| 96 |
+
details.append({"item": "命中僵尸实例 2", "score": 20, "max_score": 20, "passed": True, "reason": "成功找出无 CostCenter 标签且无活跃日志的 GPU 实例 i-01112223334445556"})
|
| 97 |
+
else:
|
| 98 |
+
details.append({"item": "命中僵尸实例 2", "score": 0, "max_score": 20, "passed": False, "reason": "遗漏了真实的闲置僵尸实例 i-01112223334445556"})
|
| 99 |
+
|
| 100 |
+
# 5. 检查是否误杀正在运行业务的活跃机器 (20分)
|
| 101 |
+
if "i-0deadbeefdeadbeef" not in parsed_list:
|
| 102 |
+
total_score += 20
|
| 103 |
+
details.append({"item": "排除活跃实例", "score": 20, "max_score": 20, "passed": True, "reason": "成功排除了 CloudTrail 中有 SubmitTrainingJob 等业务级操作的活跃机器 i-0deadbeefdeadbeef"})
|
| 104 |
+
else:
|
| 105 |
+
details.append({"item": "排除活跃实例", "score": 0, "max_score": 20, "passed": False, "reason": "致命错误!误杀了在日志中有模型训练和更新等活跃业务的实例 i-0deadbeefdeadbeef"})
|
| 106 |
+
|
| 107 |
+
# 6. 检查是否有误杀正常机器或捏造不存在的 ID (10分)
|
| 108 |
+
false_positives = [
|
| 109 |
+
"i-0987654321fedcba0", # t3.micro (非 GPU)
|
| 110 |
+
"i-0aaabbbcccdddeee1", # p4d (有 CostCenter 标签)
|
| 111 |
+
"i-02222222222222222" # g4dn (已停止,状态不符合)
|
| 112 |
+
]
|
| 113 |
+
|
| 114 |
+
found_fp = [i for i in parsed_list if i in false_positives]
|
| 115 |
+
hallucinated = [i for i in parsed_list if i not in false_positives and i not in ["i-0abcd1234efgh5678", "i-01112223334445556", "i-0deadbeefdeadbeef"]]
|
| 116 |
+
|
| 117 |
+
if len(found_fp) == 0 and len(hallucinated) == 0:
|
| 118 |
+
total_score += 10
|
| 119 |
+
details.append({"item": "排除干扰项与零幻觉验证", "score": 10, "max_score": 10, "passed": True, "reason": "未包含任何不符合条件的机器,也未捏造虚假的实例 ID"})
|
| 120 |
+
else:
|
| 121 |
+
details.append({"item": "排除干扰项与零幻觉验证", "score": 0, "max_score": 10, "passed": False, "reason": f"名单中包含了错误的干扰机器或幻觉捏造的数据: {found_fp + hallucinated}"})
|
| 122 |
+
|
| 123 |
+
# 7. LLM 语义检测:检查是否严格遵守“不要长篇大论”的无废话原则 (10分)
|
| 124 |
+
prompt_text = "Does the following file content consist strictly and ONLY of a JSON data structure (e.g., an array of strings), without ANY human-like conversational text, greetings, apologies, or long analytical explanations? Answer 'YES' if it is perfectly pure data. Answer 'NO' if it contains conversational text like 'Here is the list of zombie instances', 'I found these', etc."
|
| 125 |
+
is_pure = llm_judge_content(prompt_text, content)
|
| 126 |
+
if is_pure:
|
| 127 |
+
total_score += 10
|
| 128 |
+
details.append({"item": "大模型内容纯净度验证", "score": 10, "max_score": 10, "passed": True, "reason": "文件内容纯净,无冗余对话,符合脚本自动化挂载的需求"})
|
| 129 |
+
else:
|
| 130 |
+
details.append({"item": "大模型内容纯净度验证", "score": 0, "max_score": 10, "passed": False, "reason": "大模型判定文件中包含了冗余的交互对话或分析报告,违反了纯粹输出的要求"})
|
| 131 |
+
|
| 132 |
+
with open("workplace_score.json", "w", encoding="utf-8") as f:
|
| 133 |
+
json.dump({"total_score": total_score, "details": details}, f, indent=4, ensure_ascii=False)
|
| 134 |
+
|
| 135 |
+
if __name__ == "__main__":
|
| 136 |
+
main()
|
persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0029/verify_workplace.py
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
import json
|
| 4 |
+
import httpx
|
| 5 |
+
from openai import OpenAI
|
| 6 |
+
|
| 7 |
+
MOCK_API_KEY = os.environ.get("MOCK_API_KEY", "dummy_key")
|
| 8 |
+
MOCK_API_BASE = os.environ.get("MOCK_API_BASE", "http://localhost/v1")
|
| 9 |
+
MOCK_MODEL_NAME = os.environ.get("MOCK_MODEL_NAME", "gpt-5.4")
|
| 10 |
+
|
| 11 |
+
# 初始化客户端,必须关闭 SSL 验证
|
| 12 |
+
http_client = httpx.Client(verify=False)
|
| 13 |
+
client = OpenAI(
|
| 14 |
+
api_key=MOCK_API_KEY,
|
| 15 |
+
base_url=MOCK_API_BASE,
|
| 16 |
+
http_client=http_client
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
def llm_judge_content(prompt_text, file_content):
|
| 20 |
+
# 此函数为检测非结构化文本的统一接口
|
| 21 |
+
try:
|
| 22 |
+
response = client.chat.completions.create(
|
| 23 |
+
model=MOCK_MODEL_NAME,
|
| 24 |
+
messages=[
|
| 25 |
+
{"role": "system", "content": "You are a strict data validation assistant. Answer ONLY with 'YES' or 'NO'."},
|
| 26 |
+
{"role": "user", "content": f"{prompt_text}\n\n[File Content]:\n{file_content}"}
|
| 27 |
+
],
|
| 28 |
+
temperature=0
|
| 29 |
+
)
|
| 30 |
+
return "yes" in response.choices[0].message.content.strip().lower()
|
| 31 |
+
except Exception as e:
|
| 32 |
+
print(f"LLM API Error: {e}")
|
| 33 |
+
return False
|
| 34 |
+
|
| 35 |
+
def main():
|
| 36 |
+
workspace = sys.argv[1] if len(sys.argv) > 1 else "."
|
| 37 |
+
total_score = 0
|
| 38 |
+
details = []
|
| 39 |
+
|
| 40 |
+
target_file = os.path.join(workspace, "action_items", "kill_list.json")
|
| 41 |
+
|
| 42 |
+
# 1. 检查目标文件是否存在 (10 分)
|
| 43 |
+
if os.path.exists(target_file):
|
| 44 |
+
details.append({
|
| 45 |
+
"item": "检查结果文件是否存在",
|
| 46 |
+
"score": 10,
|
| 47 |
+
"max_score": 10,
|
| 48 |
+
"passed": True,
|
| 49 |
+
"reason": "目标文件 action_items/kill_list.json 已创建"
|
| 50 |
+
})
|
| 51 |
+
total_score += 10
|
| 52 |
+
else:
|
| 53 |
+
details.append({
|
| 54 |
+
"item": "检查结果文件是否存在",
|
| 55 |
+
"score": 0,
|
| 56 |
+
"max_score": 10,
|
| 57 |
+
"passed": False,
|
| 58 |
+
"reason": "目标文件 action_items/kill_list.json 未找到"
|
| 59 |
+
})
|
| 60 |
+
# 文件不存在直接输出结果
|
| 61 |
+
with open("workplace_score.json", "w", encoding="utf-8") as f:
|
| 62 |
+
json.dump({"total_score": total_score, "details": details}, f, ensure_ascii=False, indent=2)
|
| 63 |
+
return
|
| 64 |
+
|
| 65 |
+
# 2. 检查 JSON 格式合法性与 Schema (20 分)
|
| 66 |
+
# 利用原生的 json.load 严查 Markdown 包裹、废话及格式错误
|
| 67 |
+
data = None
|
| 68 |
+
try:
|
| 69 |
+
with open(target_file, "r", encoding="utf-8") as f:
|
| 70 |
+
data = json.load(f)
|
| 71 |
+
|
| 72 |
+
if isinstance(data, dict) and "idle_ebs" in data and "zombie_gpu" in data:
|
| 73 |
+
if isinstance(data["idle_ebs"], list) and isinstance(data["zombie_gpu"], list):
|
| 74 |
+
details.append({
|
| 75 |
+
"item": "检查 JSON 格式与 Schema 合法性",
|
| 76 |
+
"score": 20,
|
| 77 |
+
"max_score": 20,
|
| 78 |
+
"passed": True,
|
| 79 |
+
"reason": "JSON 文件可以被原生解析器成功加载,没有包含多余的废话和 Markdown 代码块,且 Schema 正确"
|
| 80 |
+
})
|
| 81 |
+
total_score += 20
|
| 82 |
+
else:
|
| 83 |
+
details.append({
|
| 84 |
+
"item": "检查 JSON 格式与 Schema 合法性",
|
| 85 |
+
"score": 0,
|
| 86 |
+
"max_score": 20,
|
| 87 |
+
"passed": False,
|
| 88 |
+
"reason": "JSON 格式有效,但 idle_ebs 或 zombie_gpu 不是列表"
|
| 89 |
+
})
|
| 90 |
+
data = None
|
| 91 |
+
else:
|
| 92 |
+
details.append({
|
| 93 |
+
"item": "检查 JSON 格式与 Schema 合法性",
|
| 94 |
+
"score": 0,
|
| 95 |
+
"max_score": 20,
|
| 96 |
+
"passed": False,
|
| 97 |
+
"reason": "JSON 格式有效,但缺少要求的 idle_ebs 或 zombie_gpu 字段"
|
| 98 |
+
})
|
| 99 |
+
data = None
|
| 100 |
+
except json.JSONDecodeError as e:
|
| 101 |
+
details.append({
|
| 102 |
+
"item": "检查 JSON 格式与 Schema 合法性",
|
| 103 |
+
"score": 0,
|
| 104 |
+
"max_score": 20,
|
| 105 |
+
"passed": False,
|
| 106 |
+
"reason": f"JSON 解析失败(Agent 未遵循要求,可能包裹了 Markdown、包含了废话说明或语法错误):{str(e)}"
|
| 107 |
+
})
|
| 108 |
+
|
| 109 |
+
# 如果无法解析,后续计分均跳过
|
| 110 |
+
if data:
|
| 111 |
+
# 定义期望的答案集
|
| 112 |
+
expected_ebs = {"vol-09a8b7c6d5e4f3a21", "vol-00001111222233334", "vol-0ffeeddccbbaa9988"}
|
| 113 |
+
# 定义一定存在于文件中但不应该被提取的干扰项(用于校验是否存在提取条件过滤错误)
|
| 114 |
+
invalid_ebs = {"vol-01122334455667788", "vol-0a1b2c3d4e5f60708"}
|
| 115 |
+
|
| 116 |
+
expected_gpu = {"i-0987654321abcdef0", "i-55556666777788889", "i-deadbeefdeadbeef0", "i-9876543210fedcba9"}
|
| 117 |
+
invalid_gpu = {"i-11112222333344445", "i-99990000aaaaabbbb", "i-abcdef12345678900"}
|
| 118 |
+
|
| 119 |
+
actual_ebs_set = set(data.get("idle_ebs", []))
|
| 120 |
+
actual_gpu_set = set(data.get("zombie_gpu", []))
|
| 121 |
+
|
| 122 |
+
# 3. 检查 idle_ebs 提取准确度 (满分 35 分)
|
| 123 |
+
ebs_score = 0
|
| 124 |
+
ebs_reason = ""
|
| 125 |
+
|
| 126 |
+
# 严查作弊与逻辑错误:一旦包���了不符合条件的数据或幻觉伪造数据,一票否决
|
| 127 |
+
if any(x in invalid_ebs for x in actual_ebs_set) or not actual_ebs_set.issubset(expected_ebs | invalid_ebs):
|
| 128 |
+
ebs_reason = "在 idle_ebs 结果中混入了 in-use 的 EBS 或无中生有的幻觉 ID,触发强杀脚本报警规则,该项得分清零。"
|
| 129 |
+
else:
|
| 130 |
+
if "vol-09a8b7c6d5e4f3a21" in actual_ebs_set: ebs_score += 10
|
| 131 |
+
if "vol-00001111222233334" in actual_ebs_set: ebs_score += 10
|
| 132 |
+
if "vol-0ffeeddccbbaa9988" in actual_ebs_set: ebs_score += 15 # 提取单引号伪 JSON 数据的难度稍高
|
| 133 |
+
ebs_reason = f"成功提取了 {len(actual_ebs_set)} 个符合要求的可用 EBS 卷。"
|
| 134 |
+
|
| 135 |
+
details.append({
|
| 136 |
+
"item": "检查 idle_ebs 数据准确性",
|
| 137 |
+
"score": ebs_score,
|
| 138 |
+
"max_score": 35,
|
| 139 |
+
"passed": ebs_score == 35,
|
| 140 |
+
"reason": ebs_reason
|
| 141 |
+
})
|
| 142 |
+
total_score += ebs_score
|
| 143 |
+
|
| 144 |
+
# 4. 检查 zombie_gpu 提取准确度 (满分 35 分)
|
| 145 |
+
gpu_score = 0
|
| 146 |
+
gpu_reason = ""
|
| 147 |
+
|
| 148 |
+
# 同样严查:如果提取出利用率大于2%的节点,或者把非GPU实例拿进来,一票否决
|
| 149 |
+
if any(x in invalid_gpu for x in actual_gpu_set) or not actual_gpu_set.issubset(expected_gpu | invalid_gpu):
|
| 150 |
+
gpu_reason = "在 zombie_gpu 中包含了利用率大于2%的实例、非 GPU 实例(如t3)或幻觉 ID,触发报警,该项得分清零。"
|
| 151 |
+
else:
|
| 152 |
+
if "i-0987654321abcdef0" in actual_gpu_set: gpu_score += 8
|
| 153 |
+
if "i-55556666777788889" in actual_gpu_set: gpu_score += 9
|
| 154 |
+
if "i-deadbeefdeadbeef0" in actual_gpu_set: gpu_score += 9
|
| 155 |
+
if "i-9876543210fedcba9" in actual_gpu_set: gpu_score += 9
|
| 156 |
+
gpu_reason = f"成功提取了 {len(actual_gpu_set)} 个符合要求的僵尸 GPU 实例。"
|
| 157 |
+
|
| 158 |
+
details.append({
|
| 159 |
+
"item": "检查 zombie_gpu 数据准确性",
|
| 160 |
+
"score": gpu_score,
|
| 161 |
+
"max_score": 35,
|
| 162 |
+
"passed": gpu_score == 35,
|
| 163 |
+
"reason": gpu_reason
|
| 164 |
+
})
|
| 165 |
+
total_score += gpu_score
|
| 166 |
+
|
| 167 |
+
# 输出结果
|
| 168 |
+
with open("workplace_score.json", "w", encoding="utf-8") as f:
|
| 169 |
+
json.dump({"total_score": total_score, "details": details}, f, ensure_ascii=False, indent=2)
|
| 170 |
+
|
| 171 |
+
if __name__ == "__main__":
|
| 172 |
+
main()
|
persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0030/verify_workplace.py
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
import json
|
| 4 |
+
import httpx
|
| 5 |
+
from openai import OpenAI
|
| 6 |
+
|
| 7 |
+
# ==========================================
|
| 8 |
+
# 强制环境与 LLM 初始化规范
|
| 9 |
+
# ==========================================
|
| 10 |
+
MOCK_API_KEY = os.environ.get("MOCK_API_KEY", "dummy_key")
|
| 11 |
+
MOCK_API_BASE = os.environ.get("MOCK_API_BASE", "http://localhost/v1")
|
| 12 |
+
MOCK_MODEL_NAME = os.environ.get("MOCK_MODEL_NAME", "gpt-5.4")
|
| 13 |
+
|
| 14 |
+
http_client = httpx.Client(verify=False)
|
| 15 |
+
client = OpenAI(
|
| 16 |
+
api_key=MOCK_API_KEY,
|
| 17 |
+
base_url=MOCK_API_BASE,
|
| 18 |
+
http_client=http_client
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
def llm_judge_content(prompt_text, file_content):
|
| 22 |
+
"""大模型语义检测统一接口"""
|
| 23 |
+
try:
|
| 24 |
+
response = client.chat.completions.create(
|
| 25 |
+
model=MOCK_MODEL_NAME,
|
| 26 |
+
messages=[
|
| 27 |
+
{"role": "system", "content": "You are a strict data validation assistant. Answer ONLY with 'YES' or 'NO'."},
|
| 28 |
+
{"role": "user", "content": f"{prompt_text}\n\n[File Content]:\n{file_content}"}
|
| 29 |
+
],
|
| 30 |
+
temperature=0
|
| 31 |
+
)
|
| 32 |
+
return "yes" in response.choices[0].message.content.strip().lower()
|
| 33 |
+
except Exception as e:
|
| 34 |
+
print(f"LLM API Error: {e}")
|
| 35 |
+
return False
|
| 36 |
+
|
| 37 |
+
# ==========================================
|
| 38 |
+
# 辅助函数:深度遍历 JSON 数据
|
| 39 |
+
# ==========================================
|
| 40 |
+
def find_in_json(obj, target):
|
| 41 |
+
"""在 JSON 反序列化后的结构中,纯代码方式确切查找键或值中是否包含目标字符串"""
|
| 42 |
+
if isinstance(obj, dict):
|
| 43 |
+
for k, v in obj.items():
|
| 44 |
+
if target in str(k) or find_in_json(v, target):
|
| 45 |
+
return True
|
| 46 |
+
elif isinstance(obj, list):
|
| 47 |
+
for item in obj:
|
| 48 |
+
if find_in_json(item, target):
|
| 49 |
+
return True
|
| 50 |
+
else:
|
| 51 |
+
if target in str(obj):
|
| 52 |
+
return True
|
| 53 |
+
return False
|
| 54 |
+
|
| 55 |
+
# ==========================================
|
| 56 |
+
# 核心验证逻辑
|
| 57 |
+
# ==========================================
|
| 58 |
+
def main():
|
| 59 |
+
workspace = sys.argv[1] if len(sys.argv) > 1 else "."
|
| 60 |
+
report_path = os.path.join(workspace, "dv_reports", "culprit_signal.json")
|
| 61 |
+
score_file = os.path.join(workspace, "workplace_score.json")
|
| 62 |
+
|
| 63 |
+
total_score = 0
|
| 64 |
+
details = []
|
| 65 |
+
|
| 66 |
+
def write_score_and_exit():
|
| 67 |
+
with open(score_file, "w", encoding="utf-8") as f:
|
| 68 |
+
json.Tape_out_reports = {"total_score": total_score, "details": details}
|
| 69 |
+
json.dump(json.Tape_out_reports, f, indent=2, ensure_ascii=False)
|
| 70 |
+
sys.exit(0)
|
| 71 |
+
|
| 72 |
+
# 【检测项 1】检查结果文件及其所在目录是否存在 (10分)
|
| 73 |
+
if os.path.exists(report_path):
|
| 74 |
+
details.append({"item": "检查目标文件 culprit_signal.json 是否存在", "score": 10, "max_score": 10, "passed": True, "reason": "结果文件存在"})
|
| 75 |
+
total_score += 10
|
| 76 |
+
else:
|
| 77 |
+
details.append({"item": "检查目标文件 culprit_signal.json 是否存在", "score": 0, "max_score": 10, "passed": False, "reason": "结果文件不存在"})
|
| 78 |
+
write_score_and_exit()
|
| 79 |
+
|
| 80 |
+
# 【检测项 2】结构化文件格式强制验证 (10分)
|
| 81 |
+
with open(report_path, "r", encoding="utf-8") as f:
|
| 82 |
+
content = f.read().strip()
|
| 83 |
+
|
| 84 |
+
try:
|
| 85 |
+
data = json.loads(content)
|
| 86 |
+
details.append({"item": "检查文件是否为合法规范的 JSON", "score": 10, "max_score": 10, "passed": True, "reason": "JSON 格式合法且可解析"})
|
| 87 |
+
total_score += 10
|
| 88 |
+
except json.JSONDecodeError:
|
| 89 |
+
details.append({"item": "检查文件是否为合法规范的 JSON", "score": 0, "max_score": 10, "passed": False, "reason": "并非合法的 JSON 格式,存在语法错误或包含混杂文本"})
|
| 90 |
+
write_score_and_exit()
|
| 91 |
+
|
| 92 |
+
# 【检测项 3】真实信号名的原生代码提取 (30分)
|
| 93 |
+
# 严格杜绝正则模糊匹配,直接从 dict 的层级数据结构中寻找信号数据
|
| 94 |
+
has_real_name = find_in_json(data, "axi_wdata")
|
| 95 |
+
has_raw_symbol = find_in_json(data, "$")
|
| 96 |
+
has_wrong_signal = find_in_json(data, "axi_wstrb")
|
| 97 |
+
|
| 98 |
+
score_3 = 0
|
| 99 |
+
reason_3 = ""
|
| 100 |
+
if has_real_name and not has_raw_symbol and not has_wrong_signal:
|
| 101 |
+
score_3 = 30
|
| 102 |
+
reason_3 = "成功定位真实信号名 axi_wdata,且剔除了 VCD 原始 ASCII 代号,没有包含其他干扰信号"
|
| 103 |
+
elif has_real_name and (has_raw_symbol or has_wrong_signal):
|
| 104 |
+
score_3 = 10
|
| 105 |
+
reason_3 = "包含了真实信号名,但未清洗干净(带入 VCD 代号 $ 或误抓取了干扰信号 axi_wstrb),视为不严谨"
|
| 106 |
+
else:
|
| 107 |
+
score_3 = 0
|
| 108 |
+
reason_3 = "在 JSON 数据结构中未找到引发异常的确切真实信号名 'axi_wdata'"
|
| 109 |
+
|
| 110 |
+
details.append({"item": "利用原生解析器验证真实信号名的提取纯度", "score": score_3, "max_score": 30, "passed": score_3 == 30, "reason": reason_3})
|
| 111 |
+
total_score += score_3
|
| 112 |
+
|
| 113 |
+
# 【检测项 4】时钟周期与异常注入点的时间戳判定 (30分)
|
| 114 |
+
has_exact_time = find_in_json(data, "1424500")
|
| 115 |
+
has_fatal_time = find_in_json(data, "1425000")
|
| 116 |
+
has_z_time = find_in_json(data, "1385000")
|
| 117 |
+
|
| 118 |
+
score_4 = 0
|
| 119 |
+
reason_4 = ""
|
| 120 |
+
if has_exact_time and not has_fatal_time and not has_z_time:
|
| 121 |
+
score_4 = 30
|
| 122 |
+
reason_4 = "成功追溯并提取了确切的异常灌入时间点 1424500 ps,完美避开后续 Fatal 点与其他高阻态跳变点"
|
| 123 |
+
elif has_exact_time:
|
| 124 |
+
score_4 = 15
|
| 125 |
+
reason_4 = "找到了确切时间戳 1424500,但数据中存在 Fatal 时间等混淆项,未剔除干净"
|
| 126 |
+
elif has_fatal_time:
|
| 127 |
+
score_4 = 0
|
| 128 |
+
reason_4 = "严重误判:将 UVM_FATAL 的断言时刻 1425000 当成了引发问题的原始时间点"
|
| 129 |
+
elif has_z_time:
|
| 130 |
+
score_4 = 0
|
| 131 |
+
reason_4 = "被干扰波形误导:错误锁定了与此 Fatal 无关的高阻态跳变时间点 1385000"
|
| 132 |
+
else:
|
| 133 |
+
score_4 = 0
|
| 134 |
+
reason_4 = "在 JSON 数据中完全没有找到正确的异常时间戳"
|
| 135 |
+
|
| 136 |
+
details.append({"item": "验证波形逆推导致的源头异常时间戳", "score": score_4, "max_score": 30, "passed": score_4 == 30, "reason": reason_4})
|
| 137 |
+
total_score += score_4
|
| 138 |
+
|
| 139 |
+
# 【检测项 5】基于 LLM 的非结构化/语义职业素养检测 (20分)
|
| 140 |
+
# 场景剧本提示"铁证直接去敲主管的门",意味着需要极其简练,纯粹的键值对,杜绝大段无意义解释
|
| 141 |
+
llm_prompt = (
|
| 142 |
+
"The user provided a JSON output to act as hard evidence for a critical chip tape-out error. "
|
| 143 |
+
"The instructions demanded a JSON output containing ONLY the culprit signal and its timestamp. "
|
| 144 |
+
"Does the provided JSON file text contain ONLY technical data (keys and numbers), WITHOUT any redundant "
|
| 145 |
+
"conversational text, verbose explanations, or excuses? "
|
| 146 |
+
"(Answer 'YES' if it is purely an extremely concise technical JSON, 'NO' if it contains conversational words or verbose string explanations)."
|
| 147 |
+
)
|
| 148 |
+
|
| 149 |
+
is_concise = llm_judge_content(llm_prompt, content)
|
| 150 |
+
if is_concise:
|
| 151 |
+
details.append({"item": "大模型验证:报告是否足够干净利落,符合流片紧急事件的铁证要求", "score": 20, "max_score": 20, "passed": True, "reason": "大模型判定 JSON 极其精炼,只包含信号数据,没有多余的废话和推脱解释"})
|
| 152 |
+
total_score += 20
|
| 153 |
+
else:
|
| 154 |
+
details.append({"item": "大模型验证:报告是否足够干净利落,符合流片紧急事件的铁证要求", "score": 0, "max_score": 20, "passed": False, "reason": "大模型判定文件中包含了冗余的解释文本或推诿语句,不够专业与精炼"})
|
| 155 |
+
|
| 156 |
+
write_score_and_exit()
|
| 157 |
+
|
| 158 |
+
if __name__ == "__main__":
|
| 159 |
+
main()
|
persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0031/verify_workplace.py
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
import json
|
| 4 |
+
import re
|
| 5 |
+
import httpx
|
| 6 |
+
from openai import OpenAI
|
| 7 |
+
|
| 8 |
+
MOCK_API_KEY = os.environ.get("MOCK_API_KEY", "dummy_key")
|
| 9 |
+
MOCK_API_BASE = os.environ.get("MOCK_API_BASE", "http://localhost/v1")
|
| 10 |
+
MOCK_MODEL_NAME = os.environ.get("MOCK_MODEL_NAME", "gpt-5.4")
|
| 11 |
+
|
| 12 |
+
# 强制关闭 SSL 验证并初始化客户端
|
| 13 |
+
http_client = httpx.Client(verify=False)
|
| 14 |
+
client = OpenAI(
|
| 15 |
+
api_key=MOCK_API_KEY,
|
| 16 |
+
base_url=MOCK_API_BASE,
|
| 17 |
+
http_client=http_client
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
def llm_judge_content(prompt_text, file_content):
|
| 21 |
+
"""大模型语义检查接口,确保无废话和自然语言包装"""
|
| 22 |
+
try:
|
| 23 |
+
response = client.chat.completions.create(
|
| 24 |
+
model=MOCK_MODEL_NAME,
|
| 25 |
+
messages=[
|
| 26 |
+
{"role": "system", "content": "You are a strict data validation assistant. Answer ONLY with 'YES' or 'NO'."},
|
| 27 |
+
{"role": "user", "content": f"{prompt_text}\n\n[File Content]:\n{file_content}"}
|
| 28 |
+
],
|
| 29 |
+
temperature=0
|
| 30 |
+
)
|
| 31 |
+
return "yes" in response.choices[0].message.content.strip().lower()
|
| 32 |
+
except Exception as e:
|
| 33 |
+
print(f"LLM API Error: {e}")
|
| 34 |
+
return False
|
| 35 |
+
|
| 36 |
+
def main():
|
| 37 |
+
workspace = sys.argv[1] if len(sys.argv) > 1 else "."
|
| 38 |
+
config_dir = os.path.join(workspace, "config")
|
| 39 |
+
blacklist_file = os.path.join(config_dir, "blacklist.json")
|
| 40 |
+
|
| 41 |
+
score_details = []
|
| 42 |
+
total_score = 0
|
| 43 |
+
|
| 44 |
+
# 1. 检查目录 (10分)
|
| 45 |
+
if os.path.exists(config_dir) and os.path.isdir(config_dir):
|
| 46 |
+
score_details.append({"item": "检查 config 目录是否存在", "score": 10, "max_score": 10, "passed": True, "reason": "目录 config 存在"})
|
| 47 |
+
total_score += 10
|
| 48 |
+
else:
|
| 49 |
+
score_details.append({"item": "检查 config 目录是否存在", "score": 0, "max_score": 10, "passed": False, "reason": "目录 config 不存在"})
|
| 50 |
+
|
| 51 |
+
# 2. 检查文件 (10分)
|
| 52 |
+
if os.path.exists(blacklist_file) and os.path.isfile(blacklist_file):
|
| 53 |
+
score_details.append({"item": "检查 blacklist.json 是否存在", "score": 10, "max_score": 10, "passed": True, "reason": "文件 blacklist.json 存在"})
|
| 54 |
+
total_score += 10
|
| 55 |
+
|
| 56 |
+
with open(blacklist_file, "r", encoding="utf-8") as f:
|
| 57 |
+
content = f.read().strip()
|
| 58 |
+
|
| 59 |
+
# 3. 解析与格式纯粹度 (20分)
|
| 60 |
+
parsed_data = None
|
| 61 |
+
is_pure_json = True
|
| 62 |
+
|
| 63 |
+
try:
|
| 64 |
+
parsed_data = json.loads(content)
|
| 65 |
+
except json.JSONDecodeError:
|
| 66 |
+
# 尝试做梯度容错:去掉 Agent 可能会写错的 Markdown 包装
|
| 67 |
+
stripped = re.sub(r"^
|
| 68 |
+
```
|
| 69 |
+
|
| 70 |
+
```python
|
| 71 |
+
try:
|
| 72 |
+
parsed_data = json.loads(stripped)
|
| 73 |
+
is_pure_json = False # 触发容错说明格式不纯粹
|
| 74 |
+
except json.JSONDecodeError:
|
| 75 |
+
pass
|
| 76 |
+
|
| 77 |
+
if parsed_data is not None and isinstance(parsed_data, list):
|
| 78 |
+
if is_pure_json:
|
| 79 |
+
score_details.append({"item": "检查文件是否为纯粹合法的 JSON 数组", "score": 20, "max_score": 20, "passed": True, "reason": "文件是原生、无冗余的合法 JSON 列表结构"})
|
| 80 |
+
total_score += 20
|
| 81 |
+
else:
|
| 82 |
+
score_details.append({"item": "检查文件是否为纯粹合法的 JSON 数组", "score": 10, "max_score": 20, "passed": False, "reason": "内容需剥离 Markdown 代码块包装后才能解析为 JSON,格式不纯粹,扣除部分分数"})
|
| 83 |
+
total_score += 10
|
| 84 |
+
else:
|
| 85 |
+
score_details.append({"item": "检查文件是否为纯粹合法的 JSON 数组", "score": 0, "max_score": 20, "passed": False, "reason": "文件无法被解析为 JSON 数组(尝试容错后依然失败,或非列表结构)"})
|
| 86 |
+
|
| 87 |
+
# 4. 数据准确度与无幻觉测试 (50分)
|
| 88 |
+
expected_ips = {"120.44.55.66", "45.33.22.11", "10.0.5.200"}
|
| 89 |
+
if parsed_data is not None and isinstance(parsed_data, list):
|
| 90 |
+
extracted_ips = set(str(item).strip() for item in parsed_data)
|
| 91 |
+
missing_ips = expected_ips - extracted_ips
|
| 92 |
+
extra_ips = extracted_ips - expected_ips
|
| 93 |
+
|
| 94 |
+
content_score = 50
|
| 95 |
+
passed_content = True
|
| 96 |
+
|
| 97 |
+
if missing_ips:
|
| 98 |
+
content_score -= len(missing_ips) * 15
|
| 99 |
+
passed_content = False
|
| 100 |
+
if extra_ips:
|
| 101 |
+
# 严惩冗余幻觉(可能包含了正常包或 RateLimit包)
|
| 102 |
+
content_score -= len(extra_ips) * 15
|
| 103 |
+
passed_content = False
|
| 104 |
+
|
| 105 |
+
if content_score < 0:
|
| 106 |
+
content_score = 0
|
| 107 |
+
|
| 108 |
+
reason_content = "精确提取出所有恶毒 IP,无幻觉、无冗余数据" if passed_content else f"提取数据有误。缺失: {missing_ips}, 冗余(幻觉): {extra_ips}"
|
| 109 |
+
score_details.append({"item": "检查提取的恶意源 IP 是否精准完整", "score": content_score, "max_score": 50, "passed": passed_content, "reason": reason_content})
|
| 110 |
+
total_score += content_score
|
| 111 |
+
else:
|
| 112 |
+
score_details.append({"item": "检查提取的恶意源 IP 是否精准完整", "score": 0, "max_score": 50, "passed": False, "reason": "因结构解析彻底失败,跳过内容比对环节"})
|
| 113 |
+
|
| 114 |
+
# 5. LLM 把控自然语言纯粹性 (10分)
|
| 115 |
+
if content:
|
| 116 |
+
prompt_text = "Does the following file content contain ONLY computer-readable code/JSON/data, completely FREE OF ANY natural language explanations, pleasantries (like 'Here is the result'), or conversational text? Answer YES if it is strictly pure data/code, NO if there is any conversational text."
|
| 117 |
+
is_pure_llm = llm_judge_content(prompt_text, content)
|
| 118 |
+
|
| 119 |
+
if is_pure_llm and is_pure_json:
|
| 120 |
+
score_details.append({"item": "利用大模型检查文件自然语言污染", "score": 10, "max_score": 10, "passed": True, "reason": "大模型及原生代码双重判定文件无任何人类对话式废话或外部包装"})
|
| 121 |
+
total_score += 10
|
| 122 |
+
else:
|
| 123 |
+
score_details.append({"item": "利用大模型检查文件自然语言污染", "score": 0, "max_score": 10, "passed": False, "reason": "大模型判定文件中包含多余的自然语言解释或被前置步骤发现存在格式污染"})
|
| 124 |
+
else:
|
| 125 |
+
score_details.append({"item": "利用大模型检查文件自然语言污染", "score": 0, "max_score": 10, "passed": False, "reason": "文件内容为空"})
|
| 126 |
+
|
| 127 |
+
else:
|
| 128 |
+
score_details.append({"item": "检查 blacklist.json 是否存在", "score": 0, "max_score": 10, "passed": False, "reason": "文件 blacklist.json 不存在"})
|
| 129 |
+
score_details.append({"item": "检查文件是否为纯粹合法的 JSON 数组", "score": 0, "max_score": 20, "passed": False, "reason": "文件不存在"})
|
| 130 |
+
score_details.append({"item": "检查提取的恶意源 IP 是否精准完整", "score": 0, "max_score": 50, "passed": False, "reason": "文件不存在"})
|
| 131 |
+
score_details.append({"item": "利用大模型检查文件自然语言污染", "score": 0, "max_score": 10, "passed": False, "reason": "文件不存在"})
|
| 132 |
+
|
| 133 |
+
# 输出标准评测记录
|
| 134 |
+
with open(os.path.join(workspace, "workplace_score.json"), "w", encoding="utf-8") as f:
|
| 135 |
+
json.dump({"total_score": total_score, "details": score_details}, f, indent=2, ensure_ascii=False)
|
| 136 |
+
|
| 137 |
+
if __name__ == "__main__":
|
| 138 |
+
main()
|
persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0032/verify_workplace.py
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
import json
|
| 4 |
+
import httpx
|
| 5 |
+
from openai import OpenAI
|
| 6 |
+
|
| 7 |
+
MOCK_API_KEY = os.environ.get("MOCK_API_KEY", "dummy_key")
|
| 8 |
+
MOCK_API_BASE = os.environ.get("MOCK_API_BASE", "http://localhost/v1")
|
| 9 |
+
MOCK_MODEL_NAME = os.environ.get("MOCK_MODEL_NAME", "gpt-5.4")
|
| 10 |
+
|
| 11 |
+
# 初始化客户端,必须关闭 SSL 验证
|
| 12 |
+
http_client = httpx.Client(verify=False)
|
| 13 |
+
client = OpenAI(
|
| 14 |
+
api_key=MOCK_API_KEY,
|
| 15 |
+
base_url=MOCK_API_BASE,
|
| 16 |
+
http_client=http_client
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
def llm_judge_content(prompt_text, file_content):
|
| 20 |
+
# 此函数为检测非结构化文本的统一接口
|
| 21 |
+
try:
|
| 22 |
+
response = client.chat.completions.create(
|
| 23 |
+
model=MOCK_MODEL_NAME,
|
| 24 |
+
messages=[
|
| 25 |
+
{"role": "system", "content": "You are a strict data validation assistant. Answer ONLY with 'YES' or 'NO'."},
|
| 26 |
+
{"role": "user", "content": f"{prompt_text}\n\n[File Content]:\n{file_content}"}
|
| 27 |
+
],
|
| 28 |
+
temperature=0
|
| 29 |
+
)
|
| 30 |
+
return "yes" in response.choices[0].message.content.strip().lower()
|
| 31 |
+
except Exception as e:
|
| 32 |
+
print(f"LLM API Error: {e}")
|
| 33 |
+
return False
|
| 34 |
+
|
| 35 |
+
def get_ground_truth(outcar_path):
|
| 36 |
+
steps_data = []
|
| 37 |
+
current_step = None
|
| 38 |
+
current_energy = None
|
| 39 |
+
current_max_force = 0.0
|
| 40 |
+
in_force_block = False
|
| 41 |
+
|
| 42 |
+
with open(outcar_path, 'r', encoding='utf-8') as f:
|
| 43 |
+
for line in f:
|
| 44 |
+
# 提取 ionic step 步数
|
| 45 |
+
if "Iteration" in line and "(" in line:
|
| 46 |
+
parts = line.split()
|
| 47 |
+
if len(parts) >= 2 and parts[0] == "Iteration":
|
| 48 |
+
s_str = parts[1].split('(')[0]
|
| 49 |
+
if s_str.isdigit():
|
| 50 |
+
s = int(s_str)
|
| 51 |
+
if current_step is not None and current_energy is not None:
|
| 52 |
+
steps_data.append({
|
| 53 |
+
'step': current_step,
|
| 54 |
+
'energy': current_energy,
|
| 55 |
+
'max_force': current_max_force
|
| 56 |
+
})
|
| 57 |
+
current_step = s
|
| 58 |
+
current_energy = None
|
| 59 |
+
current_max_force = 0.0
|
| 60 |
+
in_force_block = False
|
| 61 |
+
|
| 62 |
+
# 提取 TOTEN 能量
|
| 63 |
+
if "free energy TOTEN" in line:
|
| 64 |
+
parts = line.split('=')
|
| 65 |
+
if len(parts) == 2:
|
| 66 |
+
val_str = parts[1].replace('eV', '').strip()
|
| 67 |
+
try:
|
| 68 |
+
current_energy = float(val_str)
|
| 69 |
+
except ValueError:
|
| 70 |
+
pass
|
| 71 |
+
|
| 72 |
+
# 提取 受力
|
| 73 |
+
if "TOTAL-FORCE (eV/Angst)" in line:
|
| 74 |
+
in_force_block = True
|
| 75 |
+
continue
|
| 76 |
+
|
| 77 |
+
if in_force_block:
|
| 78 |
+
if "---" in line:
|
| 79 |
+
continue
|
| 80 |
+
elif "timing for ionic step" in line or "BRION:" in line:
|
| 81 |
+
in_force_block = False
|
| 82 |
+
else:
|
| 83 |
+
parts = line.split()
|
| 84 |
+
if len(parts) == 6:
|
| 85 |
+
try:
|
| 86 |
+
fx, fy, fz = float(parts[3]), float(parts[4]), float(parts[5])
|
| 87 |
+
max_f = max(abs(fx), abs(fy), abs(fz))
|
| 88 |
+
if max_f > current_max_force:
|
| 89 |
+
current_max_force = max_f
|
| 90 |
+
except ValueError:
|
| 91 |
+
pass
|
| 92 |
+
|
| 93 |
+
# 扫尾
|
| 94 |
+
if current_step is not None and current_energy is not None:
|
| 95 |
+
steps_data.append({
|
| 96 |
+
'step': current_step,
|
| 97 |
+
'energy': current_energy,
|
| 98 |
+
'max_force': current_max_force
|
| 99 |
+
})
|
| 100 |
+
|
| 101 |
+
# 计算滑动窗口 (5步)
|
| 102 |
+
trap_step = -1
|
| 103 |
+
for i in range(4, len(steps_data)):
|
| 104 |
+
window = steps_data[i-4:i+1]
|
| 105 |
+
energies = [x['energy'] for x in window]
|
| 106 |
+
diff = max(energies) - min(energies)
|
| 107 |
+
last_max_force = window[-1]['max_force']
|
| 108 |
+
|
| 109 |
+
if diff < 0.05 and last_max_force > 0.05:
|
| 110 |
+
trap_step = window[-1]['step']
|
| 111 |
+
break
|
| 112 |
+
|
| 113 |
+
if trap_step == -1:
|
| 114 |
+
return None, None
|
| 115 |
+
|
| 116 |
+
energies_up_to_trap = [x['energy'] for x in steps_data if x['step'] <= trap_step]
|
| 117 |
+
return trap_step, energies_up_to_trap
|
| 118 |
+
|
| 119 |
+
def evaluate(workspace):
|
| 120 |
+
total_score = 0
|
| 121 |
+
details = []
|
| 122 |
+
|
| 123 |
+
result_dir = os.path.join(workspace, "result")
|
| 124 |
+
json_path = os.path.join(result_dir, "trap_report.json")
|
| 125 |
+
outcar_path = os.path.join(workspace, "sim_data", "OUTCAR_fragment.log")
|
| 126 |
+
|
| 127 |
+
# [1] 检查文件存在及合法性 (20分)
|
| 128 |
+
file_exists = os.path.exists(json_path)
|
| 129 |
+
if not file_exists:
|
| 130 |
+
details.append({"item": "检查目标文件 trap_report.json 是否存在并合法", "score": 0, "max_score": 20, "passed": False, "reason": "文件不存在"})
|
| 131 |
+
return 0, details
|
| 132 |
+
|
| 133 |
+
try:
|
| 134 |
+
with open(json_path, 'r', encoding='utf-8') as f:
|
| 135 |
+
agent_data = json.load(f)
|
| 136 |
+
total_score += 20
|
| 137 |
+
details.append({"item": "检查目标文件 trap_report.json 是否存在并合法", "score": 20, "max_score": 20, "passed": True, "reason": "文件存在且为合法JSON"})
|
| 138 |
+
except Exception as e:
|
| 139 |
+
details.append({"item": "检查目标文件 trap_report.json 是否存在并合法", "score": 0, "max_score": 20, "passed": False, "reason": f"文件解析为JSON失败: {e}"})
|
| 140 |
+
return total_score, details
|
| 141 |
+
|
| 142 |
+
# [2] JSON 键名合理性检测 (10分,大模型兜底)
|
| 143 |
+
keys_str = ", ".join(agent_data.keys()) if isinstance(agent_data, dict) else ""
|
| 144 |
+
prompt = (
|
| 145 |
+
"Are the following JSON keys intuitively clear to distinguish which key represents a single 'step number' "
|
| 146 |
+
"(e.g. trap_step, trapped_iteration, step, etc.) and which key represents a sequence/list of 'energies' "
|
| 147 |
+
"(e.g. energies, energy_list, sequence, etc.)? "
|
| 148 |
+
"Any reasonable names that separate a singular concept and a plural/list concept are perfectly acceptable. "
|
| 149 |
+
"Only answer 'NO' if they are extremely confusing, completely irrelevant, or identical."
|
| 150 |
+
)
|
| 151 |
+
is_keys_good = llm_judge_content(prompt, keys_str)
|
| 152 |
+
if is_keys_good:
|
| 153 |
+
total_score += 10
|
| 154 |
+
details.append({"item": "利用大模型检查JSON键名是否具有可读性", "score": 10, "max_score": 10, "passed": True, "reason": "键名清晰易懂"})
|
| 155 |
+
else:
|
| 156 |
+
details.append({"item": "利用大模型检查JSON键名是否具有可读性", "score": 0, "max_score": 10, "passed": False, "reason": f"键名难以辨别: {keys_str}"})
|
| 157 |
+
|
| 158 |
+
# [3] 从Agent的JSON提取核心内容 (5分)
|
| 159 |
+
agent_step = None
|
| 160 |
+
agent_energies = None
|
| 161 |
+
if isinstance(agent_data, dict):
|
| 162 |
+
for k, v in agent_data.items():
|
| 163 |
+
if isinstance(v, (int, float)):
|
| 164 |
+
agent_step = int(v)
|
| 165 |
+
elif isinstance(v, str) and v.isdigit():
|
| 166 |
+
agent_step = int(v)
|
| 167 |
+
elif isinstance(v, list) and all(isinstance(x, (int, float)) for x in v):
|
| 168 |
+
agent_energies = v
|
| 169 |
+
|
| 170 |
+
if agent_step is not None and agent_energies is not None:
|
| 171 |
+
total_score += 5
|
| 172 |
+
details.append({"item": "结构解析识别成功", "score": 5, "max_score": 5, "passed": True, "reason": "成功提取出步数标量和能量数组"})
|
| 173 |
+
else:
|
| 174 |
+
details.append({"item": "结构解析识别成功", "score": 0, "max_score": 5, "passed": False, "reason": "无法通过类型映射出核心字段"})
|
| 175 |
+
return total_score, details
|
| 176 |
+
|
| 177 |
+
# 获取 GT
|
| 178 |
+
gt_step, gt_energies = get_ground_truth(outcar_path)
|
| 179 |
+
if gt_step is None:
|
| 180 |
+
details.append({"item": "环境GT自检", "score": 0, "max_score": 0, "passed": False, "reason": "沙盒异常,未解析出预期卡死现象"})
|
| 181 |
+
return total_score, details
|
| 182 |
+
|
| 183 |
+
# [4] 对比卡死步数 (30分)
|
| 184 |
+
if agent_step == gt_step:
|
| 185 |
+
total_score += 30
|
| 186 |
+
details.append({"item": "陷阱节点(卡死步数)的精确匹配", "score": 30, "max_score": 30, "passed": True, "reason": f"成功匹配真实陷阱节点: {gt_step}"})
|
| 187 |
+
else:
|
| 188 |
+
details.append({"item": "陷阱节点(卡死步数)的精确匹配", "score": 0, "max_score": 30, "passed": False, "reason": f"Agent提取节点为 {agent_step}, 但正确答案应为 {gt_step}"})
|
| 189 |
+
|
| 190 |
+
# [5] 检查能量序列长度 (10分)
|
| 191 |
+
if len(agent_energies) == len(gt_energies):
|
| 192 |
+
total_score += 10
|
| 193 |
+
details.append({"item": "检查能量序列的长度是否匹配", "score": 10, "max_score": 10, "passed": True, "reason": f"序列长度完全一致 ({len(gt_energies)} 步)"})
|
| 194 |
+
else:
|
| 195 |
+
details.append({"item": "检查能量序列的长度是否匹配", "score": 0, "max_score": 10, "passed": False, "reason": f"长度不匹配,Agent包含 {len(agent_energies)} 步,应为 {len(gt_energies)} 步"})
|
| 196 |
+
# 长度不对后续全错直接返回
|
| 197 |
+
return total_score, details
|
| 198 |
+
|
| 199 |
+
# [6] 检查能量序列具体数值的正确性 (25分)
|
| 200 |
+
error_count = 0
|
| 201 |
+
for a, g in zip(agent_energies, gt_energies):
|
| 202 |
+
if abs(a - g) > 1e-4:
|
| 203 |
+
error_count += 1
|
| 204 |
+
|
| 205 |
+
if error_count == 0:
|
| 206 |
+
total_score += 25
|
| 207 |
+
details.append({"item": "能量序列数值精确度校验", "score": 25, "max_score": 25, "passed": True, "reason": "所有能量数据提取均无误"})
|
| 208 |
+
else:
|
| 209 |
+
penalty = min(25, error_count * 5)
|
| 210 |
+
earned = 25 - penalty
|
| 211 |
+
total_score += earned
|
| 212 |
+
details.append({"item": "能量序列数值精确度校验", "score": earned, "max_score": 25, "passed": False, "reason": f"存在 {error_count} 处数值与源文件不符(允许绝对误差 1e-4),扣除 {penalty} 分"})
|
| 213 |
+
|
| 214 |
+
return total_score, details
|
| 215 |
+
|
| 216 |
+
if __name__ == "__main__":
|
| 217 |
+
workspace_path = sys.argv[1] if len(sys.argv) > 1 else "."
|
| 218 |
+
final_score, report_details = evaluate(workspace_path)
|
| 219 |
+
|
| 220 |
+
result_json = {
|
| 221 |
+
"total_score": final_score,
|
| 222 |
+
"details": report_details
|
| 223 |
+
}
|
| 224 |
+
|
| 225 |
+
with open(os.path.join(workspace_path, "workplace_score.json"), 'w', encoding='utf-8') as f:
|
| 226 |
+
json.dump(result_json, f, ensure_ascii=False, indent=2)
|
persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0033/verify_workplace.py
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
import json
|
| 4 |
+
import math
|
| 5 |
+
import httpx
|
| 6 |
+
from openai import OpenAI
|
| 7 |
+
|
| 8 |
+
MOCK_API_KEY = os.environ.get("MOCK_API_KEY", "dummy_key")
|
| 9 |
+
MOCK_API_BASE = os.environ.get("MOCK_API_BASE", "http://localhost/v1")
|
| 10 |
+
MOCK_MODEL_NAME = os.environ.get("MOCK_MODEL_NAME", "gpt-5.4")
|
| 11 |
+
|
| 12 |
+
http_client = httpx.Client(verify=False)
|
| 13 |
+
client = OpenAI(
|
| 14 |
+
api_key=MOCK_API_KEY,
|
| 15 |
+
base_url=MOCK_API_BASE,
|
| 16 |
+
http_client=http_client
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
def llm_judge_content(prompt_text, file_content):
|
| 20 |
+
try:
|
| 21 |
+
response = client.chat.completions.create(
|
| 22 |
+
model=MOCK_MODEL_NAME,
|
| 23 |
+
messages=[
|
| 24 |
+
{"role": "system", "content": "You are a strict data validation assistant. Answer ONLY with 'YES' or 'NO'."},
|
| 25 |
+
{"role": "user", "content": f"{prompt_text}\n\n[File Content]:\n{file_content}"}
|
| 26 |
+
],
|
| 27 |
+
temperature=0
|
| 28 |
+
)
|
| 29 |
+
return "yes" in response.choices[0].message.content.strip().lower()
|
| 30 |
+
except Exception as e:
|
| 31 |
+
print(f"LLM API Error: {e}")
|
| 32 |
+
return False
|
| 33 |
+
|
| 34 |
+
def extract_quaternions(json_obj):
|
| 35 |
+
"""
|
| 36 |
+
通过结构遍历,严格从任意层级的嵌套 JSON 中提取出类似 [float, float, float, float] 的记录,
|
| 37 |
+
规避纯正则表达式可能引发的假阳性匹配。
|
| 38 |
+
"""
|
| 39 |
+
extracted = []
|
| 40 |
+
|
| 41 |
+
def traverse(obj):
|
| 42 |
+
if isinstance(obj, dict):
|
| 43 |
+
nums = [v for v in obj.values() if isinstance(v, (int, float))]
|
| 44 |
+
if len(nums) == 4:
|
| 45 |
+
# 优先尝试根据 w, x, y, z 键名提取
|
| 46 |
+
keys = list(obj.keys())
|
| 47 |
+
w_v = next((obj[k] for k in keys if 'w' in k.lower()), None)
|
| 48 |
+
x_v = next((obj[k] for k in keys if 'x' in k.lower()), None)
|
| 49 |
+
y_v = next((obj[k] for k in keys if 'y' in k.lower()), None)
|
| 50 |
+
z_v = next((obj[k] for k in keys if 'z' in k.lower()), None)
|
| 51 |
+
if all(v is not None for v in [w_v, x_v, y_v, z_v]):
|
| 52 |
+
extracted.append((float(w_v), float(x_v), float(y_v), float(z_v)))
|
| 53 |
+
else:
|
| 54 |
+
# 降级:按数值顺序提取
|
| 55 |
+
extracted.append(tuple(float(n) for n in nums[:4]))
|
| 56 |
+
else:
|
| 57 |
+
for v in obj.values():
|
| 58 |
+
traverse(v)
|
| 59 |
+
elif isinstance(obj, list):
|
| 60 |
+
# 检查当前列表是否恰好为一组四元数
|
| 61 |
+
nums = [x for x in obj if isinstance(x, (int, float))]
|
| 62 |
+
if len(nums) == 4 and len(obj) == 4:
|
| 63 |
+
extracted.append(tuple(float(n) for n in nums))
|
| 64 |
+
else:
|
| 65 |
+
for v in obj:
|
| 66 |
+
traverse(v)
|
| 67 |
+
|
| 68 |
+
traverse(json_obj)
|
| 69 |
+
return extracted
|
| 70 |
+
|
| 71 |
+
def match_quaternions(extracted, expected):
|
| 72 |
+
matched_flags = [False] * len(expected)
|
| 73 |
+
score = 0
|
| 74 |
+
for ex in extracted:
|
| 75 |
+
best_match_idx = -1
|
| 76 |
+
for i, exp in enumerate(expected):
|
| 77 |
+
if not matched_flags[i]:
|
| 78 |
+
# 允许极小的浮点数误差
|
| 79 |
+
if all(math.isclose(a, b, abs_tol=1e-3) for a, b in zip(ex, exp)):
|
| 80 |
+
best_match_idx = i
|
| 81 |
+
break
|
| 82 |
+
if best_match_idx != -1:
|
| 83 |
+
matched_flags[best_match_idx] = True
|
| 84 |
+
score += 10
|
| 85 |
+
|
| 86 |
+
return score, matched_flags
|
| 87 |
+
|
| 88 |
+
def main():
|
| 89 |
+
workspace = sys.argv[1] if len(sys.argv) > 1 else "."
|
| 90 |
+
target_file = os.path.join(workspace, "flight_dynamics", "quaternions.json")
|
| 91 |
+
|
| 92 |
+
score_details = []
|
| 93 |
+
total_score = 0
|
| 94 |
+
|
| 95 |
+
# 1. 物理探针:检查文件是否存在
|
| 96 |
+
if os.path.exists(target_file):
|
| 97 |
+
score_details.append({"item": "检查目标结果文件是否存在", "score": 10, "max_score": 10, "passed": True, "reason": "文件 flight_dynamics/quaternions.json 存在"})
|
| 98 |
+
total_score += 10
|
| 99 |
+
else:
|
| 100 |
+
score_details.append({"item": "检查目标结果文件是否存在", "score": 0, "max_score": 10, "passed": False, "reason": "文件 flight_dynamics/quaternions.json 不存在"})
|
| 101 |
+
result = {"total_score": 0, "details": score_details}
|
| 102 |
+
with open("workplace_score.json", "w") as f:
|
| 103 |
+
json.dump(result, f, indent=2, ensure_ascii=False)
|
| 104 |
+
return
|
| 105 |
+
|
| 106 |
+
# 2. 结构探针:检查 JSON 合法性
|
| 107 |
+
with open(target_file, "r") as f:
|
| 108 |
+
content = f.read()
|
| 109 |
+
|
| 110 |
+
json_data = None
|
| 111 |
+
try:
|
| 112 |
+
json_data = json.loads(content)
|
| 113 |
+
score_details.append({"item": "验证 JSON 语法格式", "score": 10, "max_score": 10, "passed": True, "reason": "文件是合法的 JSON"})
|
| 114 |
+
total_score += 10
|
| 115 |
+
except Exception as e:
|
| 116 |
+
score_details.append({"item": "验证 JSON 语法格式", "score": 0, "max_score": 10, "passed": False, "reason": f"解析 JSON 失败: {e}"})
|
| 117 |
+
|
| 118 |
+
# 3. LLM 语义探针:判断 Key 命名是否具可读性
|
| 119 |
+
if json_data is not None:
|
| 120 |
+
prompt = "Does the following JSON content clearly express quaternion components using explicit keys like q_w, q_x, q_y, q_z, or have an extremely clear and unambiguous array structure for quaternions?"
|
| 121 |
+
is_clear = llm_judge_content(prompt, content)
|
| 122 |
+
if is_clear:
|
| 123 |
+
score_details.append({"item": "利用大模型检查数据字段表达是否清晰", "score": 10, "max_score": 10, "passed": True, "reason": "大模型判定 JSON 结构中包含清晰的四元数表达或键名"})
|
| 124 |
+
total_score += 10
|
| 125 |
+
else:
|
| 126 |
+
score_details.append({"item": "利用大模型检查数据字段表达是否清晰", "score": 0, "max_score": 10, "passed": False, "reason": "大模型认为数据字段不够直观或缺失相关标记"})
|
| 127 |
+
else:
|
| 128 |
+
score_details.append({"item": "利用大模型检查数据字段表达是否清晰", "score": 0, "max_score": 10, "passed": False, "reason": "JSON无法解析,跳过大模型检测"})
|
| 129 |
+
|
| 130 |
+
# 4 & 5. 核心计算探针:防幻觉与精度验证
|
| 131 |
+
expected_data = [
|
| 132 |
+
(0.9990, 0.0100, 0.0200, -0.0400),
|
| 133 |
+
(0.9950, 0.0250, 0.0350, -0.0890),
|
| 134 |
+
(0.9800, 0.0500, 0.0700, -0.1790),
|
| 135 |
+
(0.9500, 0.0900, 0.1200, -0.2700),
|
| 136 |
+
(0.9000, 0.1500, 0.1800, -0.3700)
|
| 137 |
+
]
|
| 138 |
+
|
| 139 |
+
if json_data is not None:
|
| 140 |
+
extracted = extract_quaternions(json_data)
|
| 141 |
+
if len(extracted) == 0:
|
| 142 |
+
score_details.append({"item": "防幻觉及数据完整性检测", "score": 0, "max_score": 20, "passed": False, "reason": "未能在 JSON 中找到四元数数据组"})
|
| 143 |
+
score_details.append({"item": "验证四元数数值提取精度", "score": 0, "max_score": 50, "passed": False, "reason": "无数据可校验"})
|
| 144 |
+
else:
|
| 145 |
+
acc_score, matched_flags = match_quaternions(extracted, expected_data)
|
| 146 |
+
|
| 147 |
+
# 计算幻觉与遗漏扣分
|
| 148 |
+
extra_items = len(extracted) - sum(matched_flags) # 找到了但无法匹配上的伪造数据
|
| 149 |
+
missing_items = len(expected_data) - sum(matched_flags) # 漏找的数据
|
| 150 |
+
|
| 151 |
+
penalty = min(extra_items * 5, 20)
|
| 152 |
+
hal_score = 20 - penalty - (missing_items * 4)
|
| 153 |
+
hal_score = max(0, hal_score)
|
| 154 |
+
|
| 155 |
+
if hal_score == 20:
|
| 156 |
+
score_details.append({"item": "防幻觉及数据完整性检测", "score": 20, "max_score": 20, "passed": True, "reason": "精准提取了所有5组数据,且无任何冗余错漏数据"})
|
| 157 |
+
total_score += 20
|
| 158 |
+
else:
|
| 159 |
+
score_details.append({"item": "防幻觉及数据完整性检测", "score": hal_score, "max_score": 20, "passed": False, "reason": f"提取存在漏掉或冗余: 漏掉 {missing_items} 组,多出 {extra_items} 组无法对齐的数据"})
|
| 160 |
+
total_score += hal_score
|
| 161 |
+
|
| 162 |
+
# 精度分
|
| 163 |
+
score_details.append({"item": "验证四元数数值提取精度", "score": acc_score, "max_score": 50, "passed": acc_score == 50, "reason": f"成功匹配 {sum(matched_flags)}/5 组四元数,每组 10 分"})
|
| 164 |
+
total_score += acc_score
|
| 165 |
+
else:
|
| 166 |
+
score_details.append({"item": "防幻觉及数据完整性检测", "score": 0, "max_score": 20, "passed": False, "reason": "无有效 JSON 供检查"})
|
| 167 |
+
score_details.append({"item": "验证四元数数值提取精度", "score": 0, "max_score": 50, "passed": False, "reason": "无有效 JSON 供检查"})
|
| 168 |
+
|
| 169 |
+
result = {"total_score": total_score, "details": score_details}
|
| 170 |
+
with open("workplace_score.json", "w") as f:
|
| 171 |
+
json.dump(result, f, indent=2, ensure_ascii=False)
|
| 172 |
+
|
| 173 |
+
if __name__ == "__main__":
|
| 174 |
+
main()
|
persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0034/verify_workplace.py
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
import json
|
| 4 |
+
import httpx
|
| 5 |
+
from openai import OpenAI
|
| 6 |
+
|
| 7 |
+
# 强制 API 规范:从环境变量读取配置,关闭 SSL 验证
|
| 8 |
+
MOCK_API_KEY = os.environ.get("MOCK_API_KEY", "dummy_key")
|
| 9 |
+
MOCK_API_BASE = os.environ.get("MOCK_API_BASE", "http://localhost/v1")
|
| 10 |
+
MOCK_MODEL_NAME = os.environ.get("MOCK_MODEL_NAME", "gpt-5.4")
|
| 11 |
+
|
| 12 |
+
http_client = httpx.Client(verify=False)
|
| 13 |
+
client = OpenAI(
|
| 14 |
+
api_key=MOCK_API_KEY,
|
| 15 |
+
base_url=MOCK_API_BASE,
|
| 16 |
+
http_client=http_client
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
def llm_judge_content(prompt_text, file_content):
|
| 20 |
+
"""
|
| 21 |
+
统一的非结构化文本大模型验证接口。
|
| 22 |
+
用于验证 Agent 生成的结构化数据的键名是否符合自然语言描述的“清晰直观”。
|
| 23 |
+
"""
|
| 24 |
+
try:
|
| 25 |
+
response = client.chat.completions.create(
|
| 26 |
+
model=MOCK_MODEL_NAME,
|
| 27 |
+
messages=[
|
| 28 |
+
{"role": "system", "content": "You are a strict data validation assistant. Answer ONLY with 'YES' or 'NO'."},
|
| 29 |
+
{"role": "user", "content": f"{prompt_text}\n\n[File Content]:\n{file_content}"}
|
| 30 |
+
],
|
| 31 |
+
temperature=0
|
| 32 |
+
)
|
| 33 |
+
return "yes" in response.choices[0].message.content.strip().lower()
|
| 34 |
+
except Exception as e:
|
| 35 |
+
print(f"LLM API Error: {e}")
|
| 36 |
+
return False
|
| 37 |
+
|
| 38 |
+
def verify_workplace(workspace):
|
| 39 |
+
score_details = []
|
| 40 |
+
total_score = 0
|
| 41 |
+
|
| 42 |
+
file_path = os.path.join(workspace, "analysis", "culprit.json")
|
| 43 |
+
|
| 44 |
+
# 1. 检查目标文件及其目录结构的存在性
|
| 45 |
+
exists = os.path.isfile(file_path)
|
| 46 |
+
if exists:
|
| 47 |
+
score_details.append({"item": "检查目标分析文件是否存在", "score": 10, "max_score": 10, "passed": True, "reason": "文件 analysis/culprit.json 存在"})
|
| 48 |
+
total_score += 10
|
| 49 |
+
else:
|
| 50 |
+
score_details.append({"item": "检查目标分析文件是否存在", "score": 0, "max_score": 10, "passed": False, "reason": "未找到 analysis/culprit.json,目录或文件未建立"})
|
| 51 |
+
|
| 52 |
+
# 如果文件不存在,后续所有基于文件内容的验证均得0分
|
| 53 |
+
if not exists:
|
| 54 |
+
for item in ["JSON格式合法性验证", "防作弊与幻觉检查(字段数<=5)", "精确提取源码位置", "精确提取受害者符号名", "精确提取去优化核心原因", "LLM评估数据字段命名语义"]:
|
| 55 |
+
score_details.append({"item": item, "score": 0, "max_score": 15, "passed": False, "reason": "依赖的分析文件不存在"})
|
| 56 |
+
return score_details, total_score
|
| 57 |
+
|
| 58 |
+
# 2. 原生代码验证:JSON 格式绝对合法性
|
| 59 |
+
data = None
|
| 60 |
+
try:
|
| 61 |
+
with open(file_path, "r", encoding="utf-8") as f:
|
| 62 |
+
data = json.load(f)
|
| 63 |
+
if isinstance(data, dict):
|
| 64 |
+
score_details.append({"item": "JSON格式合法性验证", "score": 15, "max_score": 15, "passed": True, "reason": "文件解析成功,且最外层为标准的 JSON Object (字典) 结构"})
|
| 65 |
+
total_score += 15
|
| 66 |
+
else:
|
| 67 |
+
score_details.append({"item": "JSON格式合法性验证", "score": 0, "max_score": 15, "passed": False, "reason": "最外层格式非 JSON Object (可能为 Array 或裸字串)"})
|
| 68 |
+
data = None
|
| 69 |
+
except Exception as e:
|
| 70 |
+
score_details.append({"item": "JSON格式合法性验证", "score": 0, "max_score": 15, "passed": False, "reason": f"结构化解析失败,不符合 JSON Schema:{str(e)}"})
|
| 71 |
+
|
| 72 |
+
if data is None:
|
| 73 |
+
for item in ["防作弊与幻觉检查(字段数<=5)", "精确提取源码位置", "精确提取受害者符号名", "精确提取去优化核心原因", "LLM评估数据字段命名语义"]:
|
| 74 |
+
score_details.append({"item": item, "score": 0, "max_score": 15, "passed": False, "reason": "非法的 JSON 数据导致无法检测值"})
|
| 75 |
+
return score_details, total_score
|
| 76 |
+
|
| 77 |
+
# 3. 防作弊与幻觉检查 (严格限制 Agent 捏造冗余节点或全量 Dump)
|
| 78 |
+
if len(data.keys()) <= 5:
|
| 79 |
+
score_details.append({"item": "防作弊与幻觉检查(字段数<=5)", "score": 15, "max_score": 15, "passed": True, "reason": f"当前键值对数量为 {len(data.keys())},符合针对性提取特征,未触发暴力 Dump 防御"})
|
| 80 |
+
total_score += 15
|
| 81 |
+
else:
|
| 82 |
+
score_details.append({"item": "防作弊与幻觉检查(字段数<=5)", "score": 0, "max_score": 15, "passed": False, "reason": f"当前键值对数量 {len(data.keys())} 超过阈值,疑似暴力写入全部信息而非特定提炼"})
|
| 83 |
+
|
| 84 |
+
# 将所有的 Value 转化为字符串,去除非结构化空格,执行原生代码全等严密对比
|
| 85 |
+
values_str = [str(v).strip() for v in data.values()]
|
| 86 |
+
|
| 87 |
+
# 4. 精确提取:源码物理位置
|
| 88 |
+
if any(v == "/app/src/core/hot_path_router.js" for v in values_str):
|
| 89 |
+
score_details.append({"item": "精确提取源码位置", "score": 15, "max_score": 15, "passed": True, "reason": "准确地映射出了反人类 JSON 下的 source_loc"})
|
| 90 |
+
total_score += 15
|
| 91 |
+
else:
|
| 92 |
+
score_details.append({"item": "精确提取源码位置", "score": 0, "max_score": 15, "passed": False, "reason": "未能精准提取到正确的文件路径 /app/src/core/hot_path_router.js,存在幻觉或混淆"})
|
| 93 |
+
|
| 94 |
+
# 5. 精确提取:函数符号名
|
| 95 |
+
if any(v == "processRequestFastPath" for v in values_str):
|
| 96 |
+
score_details.append({"item": "精确提取受害者符号名", "score": 15, "max_score": 15, "passed": True, "reason": "准确地锁定了触发 deoptimization 的热点函数名"})
|
| 97 |
+
total_score += 15
|
| 98 |
+
else:
|
| 99 |
+
score_details.append({"item": "精确提取受害者符号名", "score": 0, "max_score": 15, "passed": False, "reason": "未能精准提取到目标 symbol_name:processRequestFastPath"})
|
| 100 |
+
|
| 101 |
+
# 6. 精确提取:Bailout (去优化) 原因
|
| 102 |
+
if any(v == "wrong map" for v in values_str):
|
| 103 |
+
score_details.append({"item": "精确提取去优化核心原因", "score": 15, "max_score": 15, "passed": True, "reason": "成功从十六进制与噪音中提取了 bailout reason"})
|
| 104 |
+
total_score += 15
|
| 105 |
+
else:
|
| 106 |
+
score_details.append({"item": "精确提取去优化核心原因", "score": 0, "max_score": 15, "passed": False, "reason": "未能精准匹配原因 'wrong map',或是带入了额外干扰文本"})
|
| 107 |
+
|
| 108 |
+
# 7. LLM 非结构化检测:由于 Prompt 允许 Agent 自由决定字段名,故调用 LLM 查验字段命名是否直观清晰
|
| 109 |
+
keys_str = ", ".join(data.keys())
|
| 110 |
+
prompt_text = "The user dynamically generated JSON keys to identify the following three variables for an automated script: 'source code file path', 'function symbol name', and 'deoptimization bailout reason'. Are these provided key names intuitively descriptive, reasonable and free of random gibberish? Return YES if they make sense, or NO if they are vague or meaningless."
|
| 111 |
+
|
| 112 |
+
llm_result = llm_judge_content(prompt_text, keys_str)
|
| 113 |
+
if llm_result:
|
| 114 |
+
score_details.append({"item": "LLM评估数据字段命名语义", "score": 15, "max_score": 15, "passed": True, "reason": f"Agent 创建的键名 [{keys_str}] 被判定为具备清晰语义,有利于下游自动化修复脚本接入"})
|
| 115 |
+
total_score += 15
|
| 116 |
+
else:
|
| 117 |
+
score_details.append({"item": "LLM评估数据字段命名语义", "score": 0, "max_score": 15, "passed": False, "reason": f"Agent 创建的键名 [{keys_str}] 缺乏合理描述性,下游脚本难以识别"})
|
| 118 |
+
|
| 119 |
+
return score_details, total_score
|
| 120 |
+
|
| 121 |
+
if __name__ == "__main__":
|
| 122 |
+
workspace = sys.argv[1] if len(sys.argv) > 1 else "."
|
| 123 |
+
details, score = verify_workplace(workspace)
|
| 124 |
+
|
| 125 |
+
result = {
|
| 126 |
+
"total_score": score,
|
| 127 |
+
"details": details
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
out_path = os.path.join(workspace, "workplace_score.json")
|
| 131 |
+
with open(out_path, "w", encoding="utf-8") as f:
|
| 132 |
+
json.dump(result, f, indent=2, ensure_ascii=False)
|
persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0035/verify_workplace.py
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
import json
|
| 4 |
+
import httpx
|
| 5 |
+
from openai import OpenAI
|
| 6 |
+
|
| 7 |
+
MOCK_API_KEY = os.environ.get("MOCK_API_KEY", "dummy_key")
|
| 8 |
+
MOCK_API_BASE = os.environ.get("MOCK_API_BASE", "http://localhost/v1")
|
| 9 |
+
MOCK_MODEL_NAME = os.environ.get("MOCK_MODEL_NAME", "gpt-5.4")
|
| 10 |
+
|
| 11 |
+
# 初始化客户端,必须关闭 SSL 验证
|
| 12 |
+
http_client = httpx.Client(verify=False)
|
| 13 |
+
client = OpenAI(
|
| 14 |
+
api_key=MOCK_API_KEY,
|
| 15 |
+
base_url=MOCK_API_BASE,
|
| 16 |
+
http_client=http_client
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
def llm_judge_content(prompt_text, file_content):
|
| 20 |
+
"""大模型用于判断非结构化文本的语义或风格属性,严查啰嗦的分析报告"""
|
| 21 |
+
try:
|
| 22 |
+
response = client.chat.completions.create(
|
| 23 |
+
model=MOCK_MODEL_NAME,
|
| 24 |
+
messages=[
|
| 25 |
+
{"role": "system", "content": "You are a strict data validation assistant. Answer ONLY with 'YES' or 'NO'."},
|
| 26 |
+
{"role": "user", "content": f"{prompt_text}\n\n[File Content]:\n{file_content}"}
|
| 27 |
+
],
|
| 28 |
+
temperature=0
|
| 29 |
+
)
|
| 30 |
+
return "yes" in response.choices[0].message.content.strip().lower()
|
| 31 |
+
except Exception as e:
|
| 32 |
+
print(f"LLM API Error: {e}")
|
| 33 |
+
return False
|
| 34 |
+
|
| 35 |
+
def get_ground_truth(workspace):
|
| 36 |
+
"""严格使用原生代码从沙盒生成的环境文件中提取事实真值,拒绝模糊匹配"""
|
| 37 |
+
gt_supernode_id = None
|
| 38 |
+
gt_leak_address = None
|
| 39 |
+
|
| 40 |
+
# 提取 Supernode ID
|
| 41 |
+
try:
|
| 42 |
+
coordinator_dir = os.path.join(workspace, "coordinator")
|
| 43 |
+
if os.path.exists(coordinator_dir):
|
| 44 |
+
for f_name in os.listdir(coordinator_dir):
|
| 45 |
+
if f_name.endswith(".log"):
|
| 46 |
+
with open(os.path.join(coordinator_dir, f_name), "r", encoding="utf-8") as f:
|
| 47 |
+
for line in f:
|
| 48 |
+
if "FRAG_SPLIT_OVERFLOW" in line:
|
| 49 |
+
parts = line.split("expand_vertex: ")
|
| 50 |
+
if len(parts) > 1:
|
| 51 |
+
gt_supernode_id = parts[1].split(" |")[0].strip()
|
| 52 |
+
break
|
| 53 |
+
except Exception:
|
| 54 |
+
pass
|
| 55 |
+
|
| 56 |
+
# 提取 Leak Address
|
| 57 |
+
try:
|
| 58 |
+
trace_file = os.path.join(workspace, "dumps", "worker_alloc_heap.trace")
|
| 59 |
+
if os.path.exists(trace_file):
|
| 60 |
+
with open(trace_file, "r", encoding="utf-8") as f:
|
| 61 |
+
lines = f.readlines()
|
| 62 |
+
for i, line in enumerate(lines):
|
| 63 |
+
if "CIRCULAR_DETECTED" in line:
|
| 64 |
+
for j in range(i, -1, -1):
|
| 65 |
+
if lines[j].startswith("Alloc:"):
|
| 66 |
+
gt_leak_address = lines[j].split("@")[1].strip()
|
| 67 |
+
break
|
| 68 |
+
break
|
| 69 |
+
except Exception:
|
| 70 |
+
pass
|
| 71 |
+
|
| 72 |
+
# Fallback 到环境构建器中的默认种子真值,以防异常
|
| 73 |
+
if not gt_supernode_id:
|
| 74 |
+
gt_supernode_id = "V_0x8f9e_77b21"
|
| 75 |
+
if not gt_leak_address:
|
| 76 |
+
gt_leak_address = "0x7fa1b2c4e000"
|
| 77 |
+
|
| 78 |
+
return gt_supernode_id, gt_leak_address
|
| 79 |
+
|
| 80 |
+
def main():
|
| 81 |
+
workspace = sys.argv[1] if len(sys.argv) > 1 else "."
|
| 82 |
+
gt_supernode_id, gt_leak_address = get_ground_truth(workspace)
|
| 83 |
+
|
| 84 |
+
total_score = 0
|
| 85 |
+
score_details = []
|
| 86 |
+
|
| 87 |
+
target_file = os.path.join(workspace, "hotfix", "target_fix.json")
|
| 88 |
+
|
| 89 |
+
# 检测项 1 & 2 & 3 & 4: 存在性、Schema 合法性与精准值校验 (90分)
|
| 90 |
+
if os.path.exists(target_file):
|
| 91 |
+
score_details.append({"item": "黑名单修复文件生成", "score": 10, "max_score": 10, "passed": True, "reason": "成功在预期位置生成了 hotfix/target_fix.json"})
|
| 92 |
+
total_score += 10
|
| 93 |
+
|
| 94 |
+
try:
|
| 95 |
+
with open(target_file, "r", encoding="utf-8") as f:
|
| 96 |
+
data = json.load(f)
|
| 97 |
+
|
| 98 |
+
keys = list(data.keys())
|
| 99 |
+
if "supernode_id" in keys and "leak_address" in keys:
|
| 100 |
+
if len(keys) == 2:
|
| 101 |
+
score_details.append({"item": "JSON Schema 规范度", "score": 10, "max_score": 10, "passed": True, "reason": "包含所需字段且无冗余垃圾属性"})
|
| 102 |
+
total_score += 10
|
| 103 |
+
else:
|
| 104 |
+
score_details.append({"item": "JSON Schema 规范度", "score": 0, "max_score": 10, "passed": False, "reason": "包含所需字段,但私自捏造了额外的键值,破坏了极简规范"})
|
| 105 |
+
|
| 106 |
+
# 严密检测 Supernode ID
|
| 107 |
+
ans_supernode = str(data.get("supernode_id", "")).strip()
|
| 108 |
+
if ans_supernode == gt_supernode_id:
|
| 109 |
+
score_details.append({"item": "超级节点 ID 精准度", "score": 35, "max_score": 35, "passed": True, "reason": f"成功锁定正确超节点: {gt_supernode_id}"})
|
| 110 |
+
total_score += 35
|
| 111 |
+
else:
|
| 112 |
+
score_details.append({"item": "超级节点 ID 精准度", "score": 0, "max_score": 35, "passed": False, "reason": f"节点 ID 解析错误,预期 {gt_supernode_id},实际返回 {ans_supernode}"})
|
| 113 |
+
|
| 114 |
+
# 严密检测 Leak Address
|
| 115 |
+
ans_leak = str(data.get("leak_address", "")).strip()
|
| 116 |
+
if ans_leak == gt_leak_address:
|
| 117 |
+
score_details.append({"item": "泄漏内存地址精准度", "score": 35, "max_score": 35, "passed": True, "reason": f"成功捕获触发环形引用的根地址: {gt_leak_address}"})
|
| 118 |
+
total_score += 35
|
| 119 |
+
else:
|
| 120 |
+
score_details.append({"item": "泄漏内存地址精准度", "score": 0, "max_score": 35, "passed": False, "reason": f"泄漏地址解析错误,预期 {gt_leak_address},实际返回 {ans_leak}"})
|
| 121 |
+
|
| 122 |
+
else:
|
| 123 |
+
score_details.append({"item": "JSON Schema 规范度", "score": 0, "max_score": 10, "passed": False, "reason": "缺失必备的 supernode_id 或 leak_address 字段"})
|
| 124 |
+
score_details.append({"item": "超级节点 ID 精准度", "score": 0, "max_score": 35, "passed": False, "reason": "因结构缺失无法比对"})
|
| 125 |
+
score_details.append({"item": "泄漏内存地址精准度", "score": 0, "max_score": 35, "passed": False, "reason": "因结构缺失无法比对"})
|
| 126 |
+
|
| 127 |
+
except json.JSONDecodeError:
|
| 128 |
+
score_details.append({"item": "JSON Schema 规范度", "score": 0, "max_score": 10, "passed": False, "reason": "文件内容不符合合法 JSON 标准"})
|
| 129 |
+
score_details.append({"item": "超级节点 ID 精准度", "score": 0, "max_score": 35, "passed": False, "reason": "文件解析崩溃"})
|
| 130 |
+
score_details.append({"item": "泄漏内存地址精准度", "score": 0, "max_score": 35, "passed": False, "reason": "文件解析崩溃"})
|
| 131 |
+
else:
|
| 132 |
+
score_details.append({"item": "黑名单修复文件生成", "score": 0, "max_score": 10, "passed": False, "reason": "未能找到预期文件 hotfix/target_fix.json"})
|
| 133 |
+
score_details.append({"item": "JSON Schema 规范度", "score": 0, "max_score": 10, "passed": False, "reason": "文件不存在"})
|
| 134 |
+
score_details.append({"item": "超级节点 ID 精准度", "score": 0, "max_score": 35, "passed": False, "reason": "文件不存在"})
|
| 135 |
+
score_details.append({"item": "泄漏内存地址精准度", "score": 0, "max_score": 35, "passed": False, "reason": "文件不存在"})
|
| 136 |
+
|
| 137 |
+
# 检测项 5: 人设一致性与幻觉报告严查 (10分) - 借由 LLM 处理非结构化文本语义
|
| 138 |
+
extra_text_candidates = []
|
| 139 |
+
|
| 140 |
+
# 读取可能多写的 JSON 冗余内容
|
| 141 |
+
if os.path.exists(target_file):
|
| 142 |
+
try:
|
| 143 |
+
with open(target_file, "r", encoding="utf-8") as f:
|
| 144 |
+
d = json.load(f)
|
| 145 |
+
for k in d.keys():
|
| 146 |
+
if k not in ("supernode_id", "leak_address"):
|
| 147 |
+
extra_text_candidates.append(str(d[k]))
|
| 148 |
+
except:
|
| 149 |
+
pass
|
| 150 |
+
|
| 151 |
+
# 探查目录下有没有乱写的文本报告
|
| 152 |
+
for root, _, files in os.walk(workspace):
|
| 153 |
+
for file in files:
|
| 154 |
+
if file.endswith((".md", ".txt", ".log")) and "plan_fragments" not in file and "worker_01" not in file and "worker_alloc" not in file:
|
| 155 |
+
try:
|
| 156 |
+
with open(os.path.join(root, file), "r", encoding="utf-8", errors="ignore") as f:
|
| 157 |
+
content = f.read(2000).strip()
|
| 158 |
+
if len(content) > 20:
|
| 159 |
+
extra_text_candidates.append(content)
|
| 160 |
+
except:
|
| 161 |
+
pass
|
| 162 |
+
|
| 163 |
+
extra_text = "\n".join(extra_text_candidates).strip()
|
| 164 |
+
if len(extra_text) > 10:
|
| 165 |
+
prompt = "Does the following text contain a verbose troubleshooting analysis, explanatory report, or chatty conversational filler? The business user explicitly forbade long reports. If it contains such redundant explanation instead of concise raw variables, answer YES. Otherwise answer NO."
|
| 166 |
+
is_verbose = llm_judge_content(prompt, extra_text[:2000])
|
| 167 |
+
if is_verbose:
|
| 168 |
+
score_details.append({"item": "指令绝对服从性与零废话检验", "score": 0, "max_score": 10, "passed": False, "reason": "大模型判定 Agent 违反 '别长篇大论' 指令,擅自生成了冗余的解释性排查报告"})
|
| 169 |
+
else:
|
| 170 |
+
score_details.append({"item": "指令绝对服从性与零废话检验", "score": 10, "max_score": 10, "passed": True, "reason": "存在部分额外文本,但经大模型确认不构成长篇大论,可宽恕"})
|
| 171 |
+
total_score += 10
|
| 172 |
+
else:
|
| 173 |
+
score_details.append({"item": "指令绝对服从性与零废话检验", "score": 10, "max_score": 10, "passed": True, "reason": "彻底遵循极简输出指令,未检测到任何多余废话或报告文件"})
|
| 174 |
+
total_score += 10
|
| 175 |
+
|
| 176 |
+
# 写入最终结果
|
| 177 |
+
result = {
|
| 178 |
+
"total_score": total_score,
|
| 179 |
+
"details": score_details
|
| 180 |
+
}
|
| 181 |
+
with open(os.path.join(workspace, "workplace_score.json"), "w", encoding="utf-8") as f:
|
| 182 |
+
json.dump(result, f, indent=4, ensure_ascii=False)
|
| 183 |
+
|
| 184 |
+
if __name__ == "__main__":
|
| 185 |
+
main()
|
persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0036/verify_workplace.py
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
import json
|
| 4 |
+
import httpx
|
| 5 |
+
from openai import OpenAI
|
| 6 |
+
|
| 7 |
+
MOCK_API_KEY = os.environ.get("MOCK_API_KEY", "dummy_key")
|
| 8 |
+
MOCK_API_BASE = os.environ.get("MOCK_API_BASE", "http://localhost/v1")
|
| 9 |
+
MOCK_MODEL_NAME = os.environ.get("MOCK_MODEL_NAME", "gpt-5.4")
|
| 10 |
+
|
| 11 |
+
# 初始化客户端,必须关闭 SSL 验证
|
| 12 |
+
http_client = httpx.Client(verify=False)
|
| 13 |
+
client = OpenAI(
|
| 14 |
+
api_key=MOCK_API_KEY,
|
| 15 |
+
base_url=MOCK_API_BASE,
|
| 16 |
+
http_client=http_client
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
def llm_judge_content(prompt_text, file_content):
|
| 20 |
+
# 此函数为检测非结构化文本的统一接口
|
| 21 |
+
try:
|
| 22 |
+
response = client.chat.completions.create(
|
| 23 |
+
model=MOCK_MODEL_NAME,
|
| 24 |
+
messages=[
|
| 25 |
+
{"role": "system", "content": "You are a strict data validation assistant. Answer ONLY with 'YES' or 'NO'."},
|
| 26 |
+
{"role": "user", "content": f"{prompt_text}\n\n[File Content]:\n{file_content}"}
|
| 27 |
+
],
|
| 28 |
+
temperature=0
|
| 29 |
+
)
|
| 30 |
+
return "yes" in response.choices[0].message.content.strip().lower()
|
| 31 |
+
except Exception as e:
|
| 32 |
+
print(f"LLM API Error: {e}")
|
| 33 |
+
return False
|
| 34 |
+
|
| 35 |
+
def extract_ints(obj):
|
| 36 |
+
res = []
|
| 37 |
+
if isinstance(obj, int):
|
| 38 |
+
res.append(obj)
|
| 39 |
+
elif isinstance(obj, str) and obj.isdigit():
|
| 40 |
+
res.append(int(obj))
|
| 41 |
+
elif isinstance(obj, list):
|
| 42 |
+
for item in obj:
|
| 43 |
+
res.extend(extract_ints(item))
|
| 44 |
+
elif isinstance(obj, dict):
|
| 45 |
+
for item in obj.values():
|
| 46 |
+
res.extend(extract_ints(item))
|
| 47 |
+
return res
|
| 48 |
+
|
| 49 |
+
def extract_coords(obj):
|
| 50 |
+
coords = []
|
| 51 |
+
if isinstance(obj, list):
|
| 52 |
+
if len(obj) == 2 and isinstance(obj[0], (int, float)) and isinstance(obj[1], (int, float)):
|
| 53 |
+
coords.append([int(obj[0]), int(obj[1])])
|
| 54 |
+
else:
|
| 55 |
+
for item in obj:
|
| 56 |
+
coords.extend(extract_coords(item))
|
| 57 |
+
elif isinstance(obj, dict):
|
| 58 |
+
if 'x' in obj and 'y' in obj and isinstance(obj['x'], (int, float)) and isinstance(obj['y'], (int, float)):
|
| 59 |
+
coords.append([int(obj['x']), int(obj['y'])])
|
| 60 |
+
else:
|
| 61 |
+
for item in obj.values():
|
| 62 |
+
coords.extend(extract_coords(item))
|
| 63 |
+
return coords
|
| 64 |
+
|
| 65 |
+
def verify_workplace(workspace):
|
| 66 |
+
score = 0
|
| 67 |
+
details = []
|
| 68 |
+
|
| 69 |
+
# 1. 检查目标目录 (10分)
|
| 70 |
+
triage_dir = os.path.join(workspace, "triage")
|
| 71 |
+
if os.path.exists(triage_dir) and os.path.isdir(triage_dir):
|
| 72 |
+
score += 10
|
| 73 |
+
details.append({"item": "检查目标目录 triage", "score": 10, "max_score": 10, "passed": True, "reason": "triage 目录存在"})
|
| 74 |
+
else:
|
| 75 |
+
details.append({"item": "检查目标目录 triage", "score": 0, "max_score": 10, "passed": False, "reason": "triage 目录不存在"})
|
| 76 |
+
|
| 77 |
+
# 2. 检查 JSON 文件合法性 (10分)
|
| 78 |
+
json_path = os.path.join(triage_dir, "root_cause.json")
|
| 79 |
+
json_obj = None
|
| 80 |
+
content = ""
|
| 81 |
+
if os.path.exists(json_path):
|
| 82 |
+
try:
|
| 83 |
+
with open(json_path, 'r', encoding='utf-8') as f:
|
| 84 |
+
content = f.read()
|
| 85 |
+
json_obj = json.loads(content)
|
| 86 |
+
score += 10
|
| 87 |
+
details.append({"item": "检查 root_cause.json 合法性", "score": 10, "max_score": 10, "passed": True, "reason": "JSON 文件合法且可通过原生 json.loads 解析"})
|
| 88 |
+
except Exception as e:
|
| 89 |
+
details.append({"item": "检查 root_cause.json 合法性", "score": 0, "max_score": 10, "passed": False, "reason": f"JSON 解析失败或格式非法: {e}"})
|
| 90 |
+
else:
|
| 91 |
+
details.append({"item": "检查 root_cause.json 合法性", "score": 0, "max_score": 10, "passed": False, "reason": "文件 root_cause.json 不存在"})
|
| 92 |
+
|
| 93 |
+
# 内容确定性检查
|
| 94 |
+
if json_obj is not None:
|
| 95 |
+
all_ints = extract_ints(json_obj)
|
| 96 |
+
target_pts = 824672800 # (824050000 + 173 * 3600)
|
| 97 |
+
|
| 98 |
+
# 3. PTS 精准定位 (20分)
|
| 99 |
+
if target_pts in all_ints:
|
| 100 |
+
score += 20
|
| 101 |
+
details.append({"item": "提取目标致命 PTS", "score": 20, "max_score": 20, "passed": True, "reason": f"成功在结构化数据中提取到引发下溢的精准 PTS: {target_pts}"})
|
| 102 |
+
else:
|
| 103 |
+
details.append({"item": "提取目标致命 PTS", "score": 0, "max_score": 20, "passed": False, "reason": "未在结果数据中找到致命故障瞬间对应的准确 PTS 戳"})
|
| 104 |
+
|
| 105 |
+
# 4. 坐标精准提取 (30分)
|
| 106 |
+
extracted_coords = extract_coords(json_obj)
|
| 107 |
+
target_coords = [[114, 52], [115, 52], [115, 53]]
|
| 108 |
+
matched_coords = []
|
| 109 |
+
for c in target_coords:
|
| 110 |
+
if c in extracted_coords:
|
| 111 |
+
matched_coords.append(c)
|
| 112 |
+
|
| 113 |
+
coord_score = 0
|
| 114 |
+
if len(matched_coords) == 3:
|
| 115 |
+
coord_score = 30
|
| 116 |
+
details.append({"item": "提取受影响宏块坐标", "score": 30, "max_score": 30, "passed": True, "reason": "成功提取受影响的全部 3 个宏块坐标"})
|
| 117 |
+
else:
|
| 118 |
+
coord_score = len(matched_coords) * 10
|
| 119 |
+
details.append({"item": "提取受影响宏���坐标", "score": coord_score, "max_score": 30, "passed": coord_score > 0, "reason": f"部分匹配,提取了 {len(matched_coords)}/3 个宏块坐标"})
|
| 120 |
+
score += coord_score
|
| 121 |
+
|
| 122 |
+
# 5. 检查数据纯净度,严查幻觉 (20分)
|
| 123 |
+
# 将超过8亿的数字视为 PTS 戳候选,如果有其他不属于目标 PTS 的时间戳混入,视为数据冗余。
|
| 124 |
+
redundant_pts = [v for v in all_ints if v > 800000000 and v != target_pts]
|
| 125 |
+
# 判断是否包含捏造的坐标
|
| 126 |
+
redundant_coords = [c for c in extracted_coords if c not in target_coords]
|
| 127 |
+
|
| 128 |
+
penalty_reasons = []
|
| 129 |
+
if redundant_pts:
|
| 130 |
+
penalty_reasons.append("混入了非致错瞬间的冗余 PTS")
|
| 131 |
+
if redundant_coords:
|
| 132 |
+
penalty_reasons.append("捏造或包含了未报错的宏块坐标数据")
|
| 133 |
+
|
| 134 |
+
if not penalty_reasons:
|
| 135 |
+
score += 20
|
| 136 |
+
details.append({"item": "结构化幻觉及冗余审查", "score": 20, "max_score": 20, "passed": True, "reason": "数据极度纯净,无任何伪造节点或多余不相关参数"})
|
| 137 |
+
else:
|
| 138 |
+
details.append({"item": "结构化幻觉及冗余审查", "score": 0, "max_score": 20, "passed": False, "reason": f"严厉扣分:{';'.join(penalty_reasons)}"})
|
| 139 |
+
|
| 140 |
+
# 6. 利用大模型判断非结构化文字的“无废话”原则遵从度 (10分)
|
| 141 |
+
prompt_text = "Does the following file strictly contain only necessary structured data elements without ANY conversational filler, textbook-style explanation, or redundant natural language narrative?"
|
| 142 |
+
llm_passed = llm_judge_content(prompt_text, content)
|
| 143 |
+
if llm_passed:
|
| 144 |
+
score += 10
|
| 145 |
+
details.append({"item": "LLM语义法官:无废话指令检查", "score": 10, "max_score": 10, "passed": True, "reason": "文件纯粹且未包含冗长啰嗦的自然语言推导"})
|
| 146 |
+
else:
|
| 147 |
+
details.append({"item": "LLM语义法官:无废话指令检查", "score": 0, "max_score": 10, "passed": False, "reason": "严重违背了暴躁工程师的『别废话』Persona,包含了教科书式推导内容"})
|
| 148 |
+
|
| 149 |
+
else:
|
| 150 |
+
details.append({"item": "提取目标致命 PTS", "score": 0, "max_score": 20, "passed": False, "reason": "JSON 解析失败,依赖结构化的数值提取无法进行"})
|
| 151 |
+
details.append({"item": "提取受影响宏块坐标", "score": 0, "max_score": 30, "passed": False, "reason": "JSON 解析失败,无法提取确定的坐标信息"})
|
| 152 |
+
details.append({"item": "结构化幻觉及冗余审查", "score": 0, "max_score": 20, "passed": False, "reason": "JSON 解析失败"})
|
| 153 |
+
details.append({"item": "LLM语义法官:无废话指令检查", "score": 0, "max_score": 10, "passed": False, "reason": "JSON 格式非法无法评估"})
|
| 154 |
+
|
| 155 |
+
result = {
|
| 156 |
+
"total_score": score,
|
| 157 |
+
"details": details
|
| 158 |
+
}
|
| 159 |
+
with open(os.path.join(workspace, "workplace_score.json"), "w", encoding="utf-8") as f:
|
| 160 |
+
json.dump(result, f, indent=2, ensure_ascii=False)
|
| 161 |
+
|
| 162 |
+
if __name__ == "__main__":
|
| 163 |
+
workspace = sys.argv[1] if len(sys.argv) > 1 else "."
|
| 164 |
+
verify_workplace(workspace)
|
persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0037/verify_workplace.py
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
import json
|
| 4 |
+
import struct
|
| 5 |
+
import httpx
|
| 6 |
+
from openai import OpenAI
|
| 7 |
+
|
| 8 |
+
MOCK_API_KEY = os.environ.get("MOCK_API_KEY", "dummy_key")
|
| 9 |
+
MOCK_API_BASE = os.environ.get("MOCK_API_BASE", "http://localhost/v1")
|
| 10 |
+
MOCK_MODEL_NAME = os.environ.get("MOCK_MODEL_NAME", "gpt-5.4")
|
| 11 |
+
|
| 12 |
+
# 初始化客户端,必须关闭 SSL 验证
|
| 13 |
+
http_client = httpx.Client(verify=False)
|
| 14 |
+
client = OpenAI(
|
| 15 |
+
api_key=MOCK_API_KEY,
|
| 16 |
+
base_url=MOCK_API_BASE,
|
| 17 |
+
http_client=http_client
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
def llm_judge_content(prompt_text, file_content):
|
| 21 |
+
# 此函数为检测非结构化文本的统一接口(本题验证以结构化原生代码判定为主,保留此防御性调用接口)
|
| 22 |
+
try:
|
| 23 |
+
response = client.chat.completions.create(
|
| 24 |
+
model=MOCK_MODEL_NAME,
|
| 25 |
+
messages=[
|
| 26 |
+
{"role": "system", "content": "You are a strict data validation assistant. Answer ONLY with 'YES' or 'NO'."},
|
| 27 |
+
{"role": "user", "content": f"{prompt_text}\n\n[File Content]:\n{file_content}"}
|
| 28 |
+
],
|
| 29 |
+
temperature=0
|
| 30 |
+
)
|
| 31 |
+
return "yes" in response.choices[0].message.content.strip().lower()
|
| 32 |
+
except Exception as e:
|
| 33 |
+
print(f"LLM API Error: {e}")
|
| 34 |
+
return False
|
| 35 |
+
|
| 36 |
+
def parse_ground_truth(workspace):
|
| 37 |
+
"""
|
| 38 |
+
原生验证探针核心逻辑:完全复原并解析遥测数据的 Ground Truth
|
| 39 |
+
"""
|
| 40 |
+
log_path = os.path.join(workspace, "telemetry_dumps", "downlink_pass_critical.log")
|
| 41 |
+
if not os.path.exists(log_path):
|
| 42 |
+
return {}
|
| 43 |
+
|
| 44 |
+
gt_data = {}
|
| 45 |
+
with open(log_path, 'r', encoding='utf-8') as f:
|
| 46 |
+
for line in f:
|
| 47 |
+
if "RAW_PAYLOAD:" not in line:
|
| 48 |
+
continue
|
| 49 |
+
# 提取 payload 部分的 hex
|
| 50 |
+
hex_str = line.split("RAW_PAYLOAD:")[1].strip()
|
| 51 |
+
try:
|
| 52 |
+
raw_bytes = bytes.fromhex(hex_str)
|
| 53 |
+
except ValueError:
|
| 54 |
+
continue
|
| 55 |
+
|
| 56 |
+
# 查找帧头同步字
|
| 57 |
+
sync_idx = raw_bytes.find(b'\x1a\xcf\xfc\x1d')
|
| 58 |
+
while sync_idx != -1:
|
| 59 |
+
# 检查截断:帧头(4) + ts(4) + q(16) + crc(2) = 26 bytes
|
| 60 |
+
if sync_idx + 26 <= len(raw_bytes):
|
| 61 |
+
packet = raw_bytes[sync_idx:sync_idx+26]
|
| 62 |
+
# 解析时间戳和四元数浮点(必须大端序)
|
| 63 |
+
ts = struct.unpack('>I', packet[4:8])[0]
|
| 64 |
+
q1, q2, q3, q4 = struct.unpack('>ffff', packet[8:24])
|
| 65 |
+
# 验证值合理范围
|
| 66 |
+
if all(-1.0 <= q <= 1.0 for q in (q1, q2, q3, q4)):
|
| 67 |
+
gt_data[str(ts)] = [q1, q2, q3, q4]
|
| 68 |
+
break # 一行理论上只包含一条完整有效数据
|
| 69 |
+
# 寻找下一个潜在的帧头
|
| 70 |
+
sync_idx = raw_bytes.find(b'\x1a\xcf\xfc\x1d', sync_idx + 1)
|
| 71 |
+
return gt_data
|
| 72 |
+
|
| 73 |
+
def main():
|
| 74 |
+
workspace = sys.argv[1] if len(sys.argv) > 1 else "."
|
| 75 |
+
score_details = []
|
| 76 |
+
total_score = 0
|
| 77 |
+
|
| 78 |
+
# [1] 检查工作区目录和文件产生情况 (10分)
|
| 79 |
+
target_dir = os.path.join(workspace, "recovery")
|
| 80 |
+
target_file = os.path.join(target_dir, "attitude_quaternions.json")
|
| 81 |
+
|
| 82 |
+
dir_exists = os.path.isdir(target_dir)
|
| 83 |
+
file_exists = os.path.isfile(target_file)
|
| 84 |
+
|
| 85 |
+
if dir_exists and file_exists:
|
| 86 |
+
score_details.append({"item": "检查目标目录和文件是否存在", "score": 10, "max_score": 10, "passed": True, "reason": "成功创建 recovery 目录及 attitude_quaternions.json"})
|
| 87 |
+
total_score += 10
|
| 88 |
+
else:
|
| 89 |
+
score_details.append({"item": "检查目标目录和文件是否存在", "score": 0, "max_score": 10, "passed": False, "reason": "未找到要求的目录或文件输出"})
|
| 90 |
+
|
| 91 |
+
# [2] 检查文件是否为合法 JSON (10分)
|
| 92 |
+
agent_data = None
|
| 93 |
+
if file_exists:
|
| 94 |
+
try:
|
| 95 |
+
with open(target_file, "r", encoding="utf-8") as f:
|
| 96 |
+
agent_data = json.load(f)
|
| 97 |
+
score_details.append({"item": "检查 JSON 格式合法性", "score": 10, "max_score": 10, "passed": True, "reason": "JSON 文件能被成功解析"})
|
| 98 |
+
total_score += 10
|
| 99 |
+
except Exception as e:
|
| 100 |
+
score_details.append({"item": "检查 JSON 格式合法性", "score": 0, "max_score": 10, "passed": False, "reason": f"JSON 解析失败: {e}"})
|
| 101 |
+
else:
|
| 102 |
+
score_details.append({"item": "检查 JSON 格式合法性", "score": 0, "max_score": 10, "passed": False, "reason": "依赖文件不存在,跳过检查"})
|
| 103 |
+
|
| 104 |
+
# [3] 数据结构层级和类型合法性 (20分)
|
| 105 |
+
format_passed = False
|
| 106 |
+
if agent_data is not None:
|
| 107 |
+
if isinstance(agent_data, dict):
|
| 108 |
+
all_valid = True
|
| 109 |
+
for k, v in agent_data.items():
|
| 110 |
+
try:
|
| 111 |
+
int(k) # key必须能转为整型时间戳
|
| 112 |
+
except ValueError:
|
| 113 |
+
all_valid = False
|
| 114 |
+
break
|
| 115 |
+
|
| 116 |
+
if not isinstance(v, list) or len(v) != 4:
|
| 117 |
+
all_valid = False
|
| 118 |
+
break
|
| 119 |
+
|
| 120 |
+
for val in v:
|
| 121 |
+
if not isinstance(val, (int, float)) or val < -1.0 or val > 1.0:
|
| 122 |
+
all_valid = False
|
| 123 |
+
break
|
| 124 |
+
|
| 125 |
+
if all_valid and len(agent_data) > 0:
|
| 126 |
+
format_passed = True
|
| 127 |
+
score_details.append({"item": "检查数据结构和值边界的合法性", "score": 20, "max_score": 20, "passed": True, "reason": "数据结构正确(字符串映射到4元素数组),并且所有浮点数均在[-1.0, 1.0]边界内"})
|
| 128 |
+
total_score += 20
|
| 129 |
+
elif not all_valid:
|
| 130 |
+
score_details.append({"item": "检查数据结构和值边界的合法性", "score": 0, "max_score": 20, "passed": False, "reason": "存在数据节点异常: 键非数字/数组长度不符/浮点数值越界"})
|
| 131 |
+
else:
|
| 132 |
+
score_details.append({"item": "检查数据结构和值边界的合法性", "score": 0, "max_score": 20, "passed": False, "reason": "提取出的 JSON 数据字典为空"})
|
| 133 |
+
else:
|
| 134 |
+
score_details.append({"item": "检查数据结构和值边界的合法性", "score": 0, "max_score": 20, "passed": False, "reason": "根节点应当是一个 JSON Object(字典)"})
|
| 135 |
+
else:
|
| 136 |
+
score_details.append({"item": "检查数据结构和值边界的合法性", "score": 0, "max_score": 20, "passed": False, "reason": "无可用 JSON 对象数据"})
|
| 137 |
+
|
| 138 |
+
# [4] 精度与召回率的严格对比探针 (60分)
|
| 139 |
+
if format_passed:
|
| 140 |
+
gt_data = parse_ground_truth(workspace)
|
| 141 |
+
if not gt_data:
|
| 142 |
+
score_details.append({"item": "数据精准对比测试", "score": 0, "max_score": 60, "passed": False, "reason": "未能从沙盒环境中提取到 ground truth,验证无法继续"})
|
| 143 |
+
else:
|
| 144 |
+
correct_count = 0
|
| 145 |
+
for k, v in agent_data.items():
|
| 146 |
+
if k in gt_data:
|
| 147 |
+
gt_v = gt_data[k]
|
| 148 |
+
# 考虑到浮点数序列化的微小偏差,设置 1e-4 的容忍度
|
| 149 |
+
if all(abs(a - b) < 1e-4 for a, b in zip(v, gt_v)):
|
| 150 |
+
correct_count += 1
|
| 151 |
+
|
| 152 |
+
# 使用 F1 分数来严惩产生幻觉数据或丢失数据的行为
|
| 153 |
+
precision = correct_count / len(agent_data) if len(agent_data) > 0 else 0.0
|
| 154 |
+
recall = correct_count / len(gt_data) if len(gt_data) > 0 else 0.0
|
| 155 |
+
|
| 156 |
+
if precision + recall > 0:
|
| 157 |
+
f1 = 2 * precision * recall / (precision + recall)
|
| 158 |
+
else:
|
| 159 |
+
f1 = 0.0
|
| 160 |
+
|
| 161 |
+
data_score = int(round(f1 * 60))
|
| 162 |
+
passed = (data_score == 60)
|
| 163 |
+
|
| 164 |
+
score_details.append({
|
| 165 |
+
"item": "数据精准对比测试 (F1-Score评估)",
|
| 166 |
+
"score": data_score,
|
| 167 |
+
"max_score": 60,
|
| 168 |
+
"passed": passed,
|
| 169 |
+
"reason": f"正确提取了 {correct_count}/{len(gt_data)} 条有效记录。Precision: {precision:.2f}, Recall: {recall:.2f}, 综合F1评定: {f1:.3f}"
|
| 170 |
+
})
|
| 171 |
+
total_score += data_score
|
| 172 |
+
else:
|
| 173 |
+
score_details.append({"item": "数据精准对比测试", "score": 0, "max_score": 60, "passed": False, "reason": "前置的数据结构和边界校验未通过,一票否决不执行对比逻辑"})
|
| 174 |
+
|
| 175 |
+
# 输出统一规范的验证结果
|
| 176 |
+
with open(os.path.join(workspace, "workplace_score.json"), "w", encoding="utf-8") as f:
|
| 177 |
+
json.dump({
|
| 178 |
+
"total_score": total_score,
|
| 179 |
+
"details": score_details
|
| 180 |
+
}, f, indent=2, ensure_ascii=False)
|
| 181 |
+
|
| 182 |
+
if __name__ == "__main__":
|
| 183 |
+
main()
|
persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0038/verify_workplace.py
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
import json
|
| 4 |
+
import httpx
|
| 5 |
+
from openai import OpenAI
|
| 6 |
+
|
| 7 |
+
MOCK_API_KEY = os.environ.get("MOCK_API_KEY", "dummy_key")
|
| 8 |
+
MOCK_API_BASE = os.environ.get("MOCK_API_BASE", "http://localhost/v1")
|
| 9 |
+
MOCK_MODEL_NAME = os.environ.get("MOCK_MODEL_NAME", "gpt-5.4")
|
| 10 |
+
|
| 11 |
+
# 初始化客户端,必须关闭 SSL 验证
|
| 12 |
+
http_client = httpx.Client(verify=False)
|
| 13 |
+
client = OpenAI(
|
| 14 |
+
api_key=MOCK_API_KEY,
|
| 15 |
+
base_url=MOCK_API_BASE,
|
| 16 |
+
http_client=http_client
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
def llm_judge_content(prompt_text, file_content):
|
| 20 |
+
# 此函数为检测非结构化文本的统一接口
|
| 21 |
+
try:
|
| 22 |
+
response = client.chat.completions.create(
|
| 23 |
+
model=MOCK_MODEL_NAME,
|
| 24 |
+
messages=[
|
| 25 |
+
{"role": "system", "content": "You are a strict data validation assistant. Answer ONLY with 'YES' or 'NO'."},
|
| 26 |
+
{"role": "user", "content": f"{prompt_text}\n\n[File Content]:\n{file_content}"}
|
| 27 |
+
],
|
| 28 |
+
temperature=0
|
| 29 |
+
)
|
| 30 |
+
return "yes" in response.choices[0].message.content.strip().lower()
|
| 31 |
+
except Exception as e:
|
| 32 |
+
print(f"LLM API Error: {e}")
|
| 33 |
+
return False
|
| 34 |
+
|
| 35 |
+
def clean_json_string(s):
|
| 36 |
+
"""移除可能的 Markdown 语法以便严格解析"""
|
| 37 |
+
s = s.strip()
|
| 38 |
+
if s.startswith("
|
| 39 |
+
```
|
| 40 |
+
|
| 41 |
+
```python
|
| 42 |
+
return "\n".join(lines[1:-1]).strip()
|
| 43 |
+
return s
|
| 44 |
+
|
| 45 |
+
def write_score(total_score, details):
|
| 46 |
+
res = {
|
| 47 |
+
"total_score": total_score,
|
| 48 |
+
"details": details
|
| 49 |
+
}
|
| 50 |
+
with open("workplace_score.json", "w", encoding="utf-8") as f:
|
| 51 |
+
json.dump(res, f, indent=2, ensure_ascii=False)
|
| 52 |
+
|
| 53 |
+
def main():
|
| 54 |
+
workspace = sys.argv[1] if len(sys.argv) > 1 else "."
|
| 55 |
+
report_file = os.path.join(workspace, "reports", "violation_root.json")
|
| 56 |
+
|
| 57 |
+
total_score = 0
|
| 58 |
+
details = []
|
| 59 |
+
|
| 60 |
+
# 1. 检查结果文件是否存在 (20分)
|
| 61 |
+
if os.path.exists(report_file):
|
| 62 |
+
total_score += 20
|
| 63 |
+
details.append({"item": "检查目标文件是否存在", "score": 20, "max_score": 20, "passed": True, "reason": "文件 reports/violation_root.json 已成功创建"})
|
| 64 |
+
else:
|
| 65 |
+
details.append({"item": "检查目标文件是否存在", "score": 0, "max_score": 20, "passed": False, "reason": "文件 reports/violation_root.json 不存在,Agent可能未能生成结果文件"})
|
| 66 |
+
write_score(0, details)
|
| 67 |
+
return
|
| 68 |
+
|
| 69 |
+
# 2. 检查 JSON 格式的合法性 (20分)
|
| 70 |
+
with open(report_file, 'r', encoding='utf-8') as f:
|
| 71 |
+
content = f.read()
|
| 72 |
+
|
| 73 |
+
cleaned_content = clean_json_string(content)
|
| 74 |
+
try:
|
| 75 |
+
data = json.loads(cleaned_content)
|
| 76 |
+
total_score += 20
|
| 77 |
+
details.append({"item": "解析并校验 JSON 格式", "score": 20, "max_score": 20, "passed": True, "reason": "文件内容是合法的 JSON 格式,解析成功"})
|
| 78 |
+
except json.JSONDecodeError:
|
| 79 |
+
details.append({"item": "解析并校验 JSON 格式", "score": 0, "max_score": 20, "passed": False, "reason": "文件不是合法的 JSON 格式,无法被严格解析"})
|
| 80 |
+
write_score(total_score, details)
|
| 81 |
+
return
|
| 82 |
+
|
| 83 |
+
# 3. 校验必需的键及防废话策略 (10分)
|
| 84 |
+
has_module = "module_instance" in data
|
| 85 |
+
has_time = "timestamp_ps" in data
|
| 86 |
+
|
| 87 |
+
if has_module and has_time:
|
| 88 |
+
# 如果存在额外字段,则使用 LLM 检查是否是冗长的废话分析(题目要求:别给我整什么长篇大论)
|
| 89 |
+
if len(data.keys()) > 2:
|
| 90 |
+
is_verbose = llm_judge_content(
|
| 91 |
+
"Check if this JSON contains verbose analysis, detailed reasoning, or long descriptive text violating the instruction 'no long analysis, just exact data'. If it contains extra long analysis, return YES. If the extra keys are just simple metadata, return NO.",
|
| 92 |
+
cleaned_content
|
| 93 |
+
)
|
| 94 |
+
if is_verbose:
|
| 95 |
+
details.append({"item": "检查多余内容(防废话)", "score": 0, "max_score": 10, "passed": False, "reason": "找到了核心键,但通过大模型判定包含了违反设定的长篇大论字段,本项被扣分"})
|
| 96 |
+
else:
|
| 97 |
+
total_score += 10
|
| 98 |
+
details.append({"item": "检查多余内容(防废话)", "score": 10, "max_score": 10, "passed": True, "reason": "包含所需键,且附加字段经大模型判定并非长篇大论,给予满分"})
|
| 99 |
+
else:
|
| 100 |
+
total_score += 10
|
| 101 |
+
details.append({"item": "检查多余内容(防废话)", "score": 10, "max_score": 10, "passed": True, "reason": "严格遵守要求,JSON 仅包含预期的核心键 module_instance 和 timestamp_ps"})
|
| 102 |
+
else:
|
| 103 |
+
details.append({"item": "核心键校验", "score": 0, "max_score": 10, "passed": False, "reason": f"缺失了核心要求的数据键。module_instance:{has_module}, timestamp_ps:{has_time}"})
|
| 104 |
+
# 无法继续验证具体值
|
| 105 |
+
write_score(total_score, details)
|
| 106 |
+
return
|
| 107 |
+
|
| 108 |
+
# 4. 精确校验时间戳提取结果 (25分)
|
| 109 |
+
try:
|
| 110 |
+
ts_val = int(data["timestamp_ps"])
|
| 111 |
+
if ts_val == 478230:
|
| 112 |
+
total_score += 25
|
| 113 |
+
details.append({"item": "时间戳数值的精准匹配", "score": 25, "max_score": 25, "passed": True, "reason": "精准锁定了 X 态发生的第一个时间戳 478230"})
|
| 114 |
+
else:
|
| 115 |
+
details.append({"item": "时间戳数值的精准匹配", "score": 0, "max_score": 25, "passed": False, "reason": f"时间戳不匹配,计算得出的值是 {ts_val},与期望值不符"})
|
| 116 |
+
except (ValueError, TypeError):
|
| 117 |
+
details.append({"item": "时间戳数值的精准匹配", "score": 0, "max_score": 25, "passed": False, "reason": "timestamp_ps 的值不是有效的整数格式"})
|
| 118 |
+
|
| 119 |
+
# 5. 精确校验底层模块实例全路径 (25分)
|
| 120 |
+
mod_val = str(data["module_instance"]).strip()
|
| 121 |
+
if mod_val == "sys_top.bus_matrix.u_axi_interconnect_m0":
|
| 122 |
+
total_score += 25
|
| 123 |
+
details.append({"item": "底层实例路径的精准匹配", "score": 25, "max_score": 25, "passed": True, "reason": "成功通过混淆的 db 文件溯源到了完全准确的实例路径"})
|
| 124 |
+
else:
|
| 125 |
+
details.append({"item": "底层实例路径的精准匹配", "score": 0, "max_score": 25, "passed": False, "reason": f"路径溯源错误,提取的值是: {mod_val}"})
|
| 126 |
+
|
| 127 |
+
write_score(total_score, details)
|
| 128 |
+
|
| 129 |
+
if __name__ == "__main__":
|
| 130 |
+
main()
|
persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0039/verify_workplace.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
|
persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0040/verify_workplace.py
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
import json
|
| 4 |
+
import httpx
|
| 5 |
+
from openai import OpenAI
|
| 6 |
+
|
| 7 |
+
# 强制 API 规范:获取环境变量配置
|
| 8 |
+
MOCK_API_KEY = os.environ.get("MOCK_API_KEY", "dummy_key")
|
| 9 |
+
MOCK_API_BASE = os.environ.get("MOCK_API_BASE", "http://localhost/v1")
|
| 10 |
+
MOCK_MODEL_NAME = os.environ.get("MOCK_MODEL_NAME", "gpt-5.4")
|
| 11 |
+
|
| 12 |
+
# 初始化客户端,必须关闭 SSL 验证以支持某些沙盒环境的本地 Mock 代理
|
| 13 |
+
http_client = httpx.Client(verify=False)
|
| 14 |
+
client = OpenAI(
|
| 15 |
+
api_key=MOCK_API_KEY,
|
| 16 |
+
base_url=MOCK_API_BASE,
|
| 17 |
+
http_client=http_client
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
def llm_judge_content(prompt_text, file_content):
|
| 21 |
+
"""大模型语义检测接口,仅用于验证非结构化/不可确定形式的内容意图"""
|
| 22 |
+
try:
|
| 23 |
+
response = client.chat.completions.create(
|
| 24 |
+
model=MOCK_MODEL_NAME,
|
| 25 |
+
messages=[
|
| 26 |
+
{"role": "system", "content": "You are a strict data validation assistant. Answer ONLY with 'YES' or 'NO'."},
|
| 27 |
+
{"role": "user", "content": f"{prompt_text}\n\n[File Content]:\n{file_content}"}
|
| 28 |
+
],
|
| 29 |
+
temperature=0
|
| 30 |
+
)
|
| 31 |
+
return "yes" in response.choices[0].message.content.strip().lower()
|
| 32 |
+
except Exception as e:
|
| 33 |
+
print(f"LLM API Error: {e}")
|
| 34 |
+
return False
|
| 35 |
+
|
| 36 |
+
def verify(workspace):
|
| 37 |
+
score = 0
|
| 38 |
+
details = []
|
| 39 |
+
|
| 40 |
+
# 1. 验证目标目录是否存在 (10分)
|
| 41 |
+
reports_dir = os.path.join(workspace, "reports")
|
| 42 |
+
if os.path.isdir(reports_dir):
|
| 43 |
+
score += 10
|
| 44 |
+
details.append({"item": "检查目标结果目录 reports 是否存在", "score": 10, "max_score": 10, "passed": True, "reason": "reports 目录存在"})
|
| 45 |
+
else:
|
| 46 |
+
details.append({"item": "检查目标结果目录 reports 是否存在", "score": 0, "max_score": 10, "passed": False, "reason": "reports 目录不存在"})
|
| 47 |
+
|
| 48 |
+
# 2. 验证目标 JSON 文件是否存在 (10分)
|
| 49 |
+
json_path = os.path.join(reports_dir, "bottleneck.json")
|
| 50 |
+
json_exists = os.path.isfile(json_path)
|
| 51 |
+
if json_exists:
|
| 52 |
+
score += 10
|
| 53 |
+
details.append({"item": "检查 bottleneck.json 文件是否存在", "score": 10, "max_score": 10, "passed": True, "reason": "bottleneck.json 文件存在"})
|
| 54 |
+
else:
|
| 55 |
+
details.append({"item": "检查 bottleneck.json 文件是否存在", "score": 0, "max_score": 10, "passed": False, "reason": "bottleneck.json 文件不存在"})
|
| 56 |
+
|
| 57 |
+
# 发生缺失则无法进入内容校验
|
| 58 |
+
if not json_exists:
|
| 59 |
+
details.append({"item": "检查 JSON 格式合法性", "score": 0, "max_score": 10, "passed": False, "reason": "文件缺失,无法校验格式"})
|
| 60 |
+
details.append({"item": "精确提取并验证 Entity ID (0x7C9A)", "score": 0, "max_score": 25, "passed": False, "reason": "文件缺失,无法提取验证"})
|
| 61 |
+
details.append({"item": "精确提取并验证 Block Size (16384)", "score": 0, "max_score": 25, "passed": False, "reason": "文件缺失,无法提取验证"})
|
| 62 |
+
details.append({"item": "严查结构化数据作弊/幻觉生成", "score": 0, "max_score": 10, "passed": False, "reason": "文件缺失,无法检查结构"})
|
| 63 |
+
details.append({"item": "利用大模型验证 JSON 键名的业务语义", "score": 0, "max_score": 10, "passed": False, "reason": "文件缺失,无法校验"})
|
| 64 |
+
return score, details
|
| 65 |
+
|
| 66 |
+
# 3. 解析验证 JSON 格式的合法性 (10分)
|
| 67 |
+
try:
|
| 68 |
+
with open(json_path, "r", encoding="utf-8") as f:
|
| 69 |
+
content = f.read()
|
| 70 |
+
data = json.loads(content)
|
| 71 |
+
score += 10
|
| 72 |
+
details.append({"item": "检查 JSON 格式合法性", "score": 10, "max_score": 10, "passed": True, "reason": "JSON 格式完全合法并成功解析"})
|
| 73 |
+
except Exception as e:
|
| 74 |
+
details.append({"item": "检查 JSON 格式合法性", "score": 0, "max_score": 10, "passed": False, "reason": f"JSON 解析失败: {e}"})
|
| 75 |
+
details.append({"item": "精确提取并验证 Entity ID (0x7C9A)", "score": 0, "max_score": 25, "passed": False, "reason": "解析失败,无法提取"})
|
| 76 |
+
details.append({"item": "精确提取并验证 Block Size (16384)", "score": 0, "max_score": 25, "passed": False, "reason": "解析失败,无法提取"})
|
| 77 |
+
details.append({"item": "严查结构化数据作弊/幻觉生成", "score": 0, "max_score": 10, "passed": False, "reason": "解析失败,无法检查"})
|
| 78 |
+
details.append({"item": "利用大模型验证 JSON 键名的业务语义", "score": 0, "max_score": 10, "passed": False, "reason": "解析失败,无法检查"})
|
| 79 |
+
return score, details
|
| 80 |
+
|
| 81 |
+
# 递归提取 JSON 中所有基本元素(键及值),以应对各种未约定的嵌套格式
|
| 82 |
+
primitives = []
|
| 83 |
+
def extract_all(d):
|
| 84 |
+
if isinstance(d, dict):
|
| 85 |
+
for k, v in d.items():
|
| 86 |
+
primitives.append(str(k))
|
| 87 |
+
extract_all(v)
|
| 88 |
+
elif isinstance(d, list):
|
| 89 |
+
for item in d:
|
| 90 |
+
extract_all(item)
|
| 91 |
+
else:
|
| 92 |
+
primitives.append(str(d))
|
| 93 |
+
|
| 94 |
+
extract_all(data)
|
| 95 |
+
|
| 96 |
+
# 4. 精确提取并验证 Entity ID (25分)
|
| 97 |
+
eid_found = False
|
| 98 |
+
for p in primitives:
|
| 99 |
+
if p.strip().upper() == "0X7C9A":
|
| 100 |
+
eid_found = True
|
| 101 |
+
break
|
| 102 |
+
if eid_found:
|
| 103 |
+
score += 25
|
| 104 |
+
details.append({"item": "精确提取并验证 Entity ID (0x7C9A)", "score": 25, "max_score": 25, "passed": True, "reason": "使用代码精确在 JSON 结构中匹配到目标 Entity ID"})
|
| 105 |
+
else:
|
| 106 |
+
details.append({"item": "精确提取并验证 Entity ID (0x7C9A)", "score": 0, "max_score": 25, "passed": False, "reason": "严格代码解析下,未发现异常的 Entity ID 数据项"})
|
| 107 |
+
|
| 108 |
+
# 5. 精确提取并验证 Block Size (25分)
|
| 109 |
+
size_found = False
|
| 110 |
+
for p in primitives:
|
| 111 |
+
if p.strip() == "16384":
|
| 112 |
+
size_found = True
|
| 113 |
+
break
|
| 114 |
+
if size_found:
|
| 115 |
+
score += 25
|
| 116 |
+
details.append({"item": "精确提取并验证 Block Size (16384)", "score": 25, "max_score": 25, "passed": True, "reason": "使用代码精确在 JSON 结构中匹配到异常的内存大小数值 16384"})
|
| 117 |
+
else:
|
| 118 |
+
details.append({"item": "精确提取并验证 Block Size (16384)", "score": 0, "max_score": 25, "passed": False, "reason": "严格代码解析下,未发现目标的内存快照大小数值"})
|
| 119 |
+
|
| 120 |
+
# 6. 幻觉与敷衍全量抓取限制惩罚 (10分)
|
| 121 |
+
# 若元素个数大于 15 则可能是直接把整个段落当 string 放进去或者包含大量多余的数据点
|
| 122 |
+
if len(primitives) <= 15:
|
| 123 |
+
score += 10
|
| 124 |
+
details.append({"item": "严查结构化数据作弊/幻觉生成", "score": 10, "max_score": 10, "passed": True, "reason": f"JSON 结构精简专注 (总元素数 {len(primitives)}),无冗余无用捏造"})
|
| 125 |
+
else:
|
| 126 |
+
details.append({"item": "严查结构化数据作弊/幻觉生成", "score": 0, "max_score": 10, "passed": False, "reason": f"JSON 规模过于冗杂 (总元素数 {len(primitives)}),可能含有大模型推诿词及未提取的全量内容映射"})
|
| 127 |
+
|
| 128 |
+
# 7. LLM 检查非约定语义:键名的业务合理性 (10分)
|
| 129 |
+
keys = []
|
| 130 |
+
if isinstance(data, dict):
|
| 131 |
+
keys = list(data.keys())
|
| 132 |
+
elif isinstance(data, list) and len(data) > 0 and isinstance(data[0], dict):
|
| 133 |
+
keys = list(data[0].keys())
|
| 134 |
+
|
| 135 |
+
if keys:
|
| 136 |
+
prompt = "判断以下的 JSON 键名是否合理地传达了 'Entity ID / EID' 和 'Memory Size / Block Size' 的含义。只要键名能看出来是在表示这两个概念(允许缩写或近义词),回答 YES。如果都是毫无意义的字母(如 a, b, key1, data)或是在答非所问抱怨,回答 NO。"
|
| 137 |
+
keys_str = ", ".join([str(k) for k in keys])
|
| 138 |
+
is_semantic_ok = llm_judge_content(prompt, keys_str)
|
| 139 |
+
if is_semantic_ok:
|
| 140 |
+
score += 10
|
| 141 |
+
details.append({"item": "利用大模型验证 JSON 键名的业务语义", "score": 10, "max_score": 10, "passed": True, "reason": f"大模型认为字典键名 ['{keys_str}'] 符合专业且明确的语义"})
|
| 142 |
+
else:
|
| 143 |
+
details.append({"item": "利用大模型验证 JSON 键名的业务语义", "score": 0, "max_score": 10, "passed": False, "reason": f"大模型认为生成的键名 ['{keys_str}'] 未能有效传达 'Entity ID' 和 '内存大小' 的业务概念"})
|
| 144 |
+
else:
|
| 145 |
+
details.append({"item": "利用大模型验证 JSON 键名的业务语义", "score": 0, "max_score": 10, "passed": False, "reason": "文件结构非标准键值对对象,无法提取 Keys 给 LLM 进行语义判定"})
|
| 146 |
+
|
| 147 |
+
return score, details
|
| 148 |
+
|
| 149 |
+
def main():
|
| 150 |
+
workspace = sys.argv[1] if len(sys.argv) > 1 else "."
|
| 151 |
+
score, details = verify(workspace)
|
| 152 |
+
|
| 153 |
+
result = {
|
| 154 |
+
"total_score": score,
|
| 155 |
+
"details": details
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
with open(os.path.join(workspace, "workplace_score.json"), "w", encoding="utf-8") as f:
|
| 159 |
+
json.dump(result, f, indent=2, ensure_ascii=False)
|
| 160 |
+
|
| 161 |
+
if __name__ == "__main__":
|
| 162 |
+
main()
|
persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0041/verify_workplace.py
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
import json
|
| 4 |
+
import re
|
| 5 |
+
|
| 6 |
+
def verify():
|
| 7 |
+
workspace = sys.argv[1] if len(sys.argv) > 1 else "."
|
| 8 |
+
score = 0
|
| 9 |
+
details = []
|
| 10 |
+
|
| 11 |
+
ioc_file_path = os.path.join(workspace, "report/ioc.json")
|
| 12 |
+
|
| 13 |
+
# 1. 检查文件是否存在 (10分)
|
| 14 |
+
if os.path.exists(ioc_file_path):
|
| 15 |
+
score += 10
|
| 16 |
+
details.append({"item": "检查 report/ioc.json 物理文件", "score": 10, "max_score": 10, "passed": True, "reason": "文件已生成"})
|
| 17 |
+
|
| 18 |
+
# 2. 检查 JSON 格式合法性 (10分)
|
| 19 |
+
try:
|
| 20 |
+
with open(ioc_file_path, 'r', encoding='utf-8') as f:
|
| 21 |
+
data = json.load(f)
|
| 22 |
+
score += 10
|
| 23 |
+
details.append({"item": "检查 JSON 语法合法性", "score": 10, "max_score": 10, "passed": True, "reason": "JSON 解析成功"})
|
| 24 |
+
|
| 25 |
+
# 3. 检查持久化恶意路径 (40分)
|
| 26 |
+
# 期待路径: C:\ProgramData\Intel\telemetry_srv.exe
|
| 27 |
+
expected_path = r"C:\ProgramData\Intel\telemetry_srv.exe".lower()
|
| 28 |
+
|
| 29 |
+
found_path = False
|
| 30 |
+
actual_path_val = ""
|
| 31 |
+
# 遍历 JSON 寻找类似路径的字符串
|
| 32 |
+
def find_path_recursive(obj):
|
| 33 |
+
nonlocal found_path, actual_path_val
|
| 34 |
+
if isinstance(obj, str):
|
| 35 |
+
if "telemetry_srv.exe" in obj.lower():
|
| 36 |
+
actual_path_val = obj
|
| 37 |
+
if obj.lower().replace("/", "\\") == expected_path:
|
| 38 |
+
found_path = True
|
| 39 |
+
elif isinstance(obj, dict):
|
| 40 |
+
for v in obj.values(): find_path_recursive(v)
|
| 41 |
+
elif isinstance(obj, list):
|
| 42 |
+
for i in obj: find_path_recursive(i)
|
| 43 |
+
|
| 44 |
+
find_path_recursive(data)
|
| 45 |
+
|
| 46 |
+
if found_path:
|
| 47 |
+
score += 40
|
| 48 |
+
details.append({"item": "恶意程序持久化路径匹配", "score": 40, "max_score": 40, "passed": True, "reason": f"成功提取并匹配路径: {actual_path_val}"})
|
| 49 |
+
elif "telemetry_srv.exe" in actual_path_val.lower():
|
| 50 |
+
score += 20
|
| 51 |
+
details.append({"item": "恶意程序持久化路径匹配", "score": 20, "max_score": 40, "passed": False, "reason": f"提取到的路径不完整或不准确: {actual_path_val}"})
|
| 52 |
+
else:
|
| 53 |
+
details.append({"item": "恶意程序持久化路径匹配", "score": 0, "max_score": 40, "passed": False, "reason": "未找到正确的恶意程序路径"})
|
| 54 |
+
|
| 55 |
+
# 4. 检查脱壳特征码 (40分)
|
| 56 |
+
# 期待特征码: 5C7A8E1F2B3D4C5A6B7C8D9EAFB0C1D2 (16字节)
|
| 57 |
+
expected_sig = "5c7a8e1f2b3d4c5a6b7c8d9eafb0c1d2"
|
| 58 |
+
|
| 59 |
+
found_sig = False
|
| 60 |
+
actual_sig_val = ""
|
| 61 |
+
|
| 62 |
+
def find_sig_recursive(obj):
|
| 63 |
+
nonlocal found_sig, actual_sig_val
|
| 64 |
+
if isinstance(obj, str):
|
| 65 |
+
# 移除空格、破折号、0x等干扰项进行匹配
|
| 66 |
+
clean_str = re.sub(r'[^a-fA-F0-9]', '', obj).lower()
|
| 67 |
+
if expected_sig in clean_str:
|
| 68 |
+
actual_sig_val = obj
|
| 69 |
+
found_sig = True
|
| 70 |
+
elif isinstance(obj, dict):
|
| 71 |
+
for v in obj.values(): find_sig_recursive(v)
|
| 72 |
+
elif isinstance(obj, list):
|
| 73 |
+
for i in obj: find_sig_recursive(i)
|
| 74 |
+
|
| 75 |
+
find_sig_recursive(data)
|
| 76 |
+
|
| 77 |
+
if found_sig:
|
| 78 |
+
score += 40
|
| 79 |
+
details.append({"item": "16字节脱壳特征码匹配", "score": 40, "max_score": 40, "passed": True, "reason": f"成功匹配特征码: {actual_sig_val}"})
|
| 80 |
+
else:
|
| 81 |
+
details.append({"item": "16字节脱壳特征码匹配", "score": 0, "max_score": 40, "passed": False, "reason": "未找到或特征码错误"})
|
| 82 |
+
|
| 83 |
+
except json.JSONDecodeError:
|
| 84 |
+
details.append({"item": "检查 JSON 语法合法性", "score": 0, "max_score": 10, "passed": False, "reason": "JSON 格式错误,无法解析"})
|
| 85 |
+
details.append({"item": "数据内容检查", "score": 0, "max_score": 80, "passed": False, "reason": "由于 JSON 无法解析,跳过内容检查"})
|
| 86 |
+
else:
|
| 87 |
+
details.append({"item": "检查 report/ioc.json 物理文件", "score": 0, "max_score": 10, "passed": False, "reason": "文件未生成"})
|
| 88 |
+
details.append({"item": "后续所有检查", "score": 0, "max_score": 90, "passed": False, "reason": "基础文件缺失"})
|
| 89 |
+
|
| 90 |
+
# 最终输出结果
|
| 91 |
+
result = {
|
| 92 |
+
"total_score": score,
|
| 93 |
+
"details": details
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
with open("workplace_score.json", "w", encoding="utf-8") as f:
|
| 97 |
+
json.dump(result, f, indent=2, ensure_ascii=False)
|
| 98 |
+
|
| 99 |
+
if __name__ == "__main__":
|
| 100 |
+
verify()
|
persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0042/verify_workplace.py
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
import json
|
| 4 |
+
import re
|
| 5 |
+
import httpx
|
| 6 |
+
from openai import OpenAI
|
| 7 |
+
|
| 8 |
+
MOCK_API_KEY = os.environ.get("MOCK_API_KEY", "dummy_key")
|
| 9 |
+
MOCK_API_BASE = os.environ.get("MOCK_API_BASE", "http://localhost/v1")
|
| 10 |
+
MOCK_MODEL_NAME = os.environ.get("MOCK_MODEL_NAME", "gpt-5.4")
|
| 11 |
+
|
| 12 |
+
# 初始化客户端,必须关闭 SSL 验证
|
| 13 |
+
http_client = httpx.Client(verify=False)
|
| 14 |
+
client = OpenAI(
|
| 15 |
+
api_key=MOCK_API_KEY,
|
| 16 |
+
base_url=MOCK_API_BASE,
|
| 17 |
+
http_client=http_client
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
def llm_judge_content(prompt_text, file_content):
|
| 21 |
+
# 此函数为检测非结构化文本的统一接口
|
| 22 |
+
try:
|
| 23 |
+
response = client.chat.completions.create(
|
| 24 |
+
model=MOCK_MODEL_NAME,
|
| 25 |
+
messages=[
|
| 26 |
+
{"role": "system", "content": "You are a strict data validation assistant. Answer ONLY with 'YES' or 'NO'."},
|
| 27 |
+
{"role": "user", "content": f"{prompt_text}\n\n[File Content]:\n{file_content}"}
|
| 28 |
+
],
|
| 29 |
+
temperature=0
|
| 30 |
+
)
|
| 31 |
+
return "yes" in response.choices[0].message.content.strip().lower()
|
| 32 |
+
except Exception as e:
|
| 33 |
+
print(f"LLM API Error: {e}")
|
| 34 |
+
return False
|
| 35 |
+
|
| 36 |
+
def normalize_hex_string(s):
|
| 37 |
+
"""去除干扰字符,纯化十六进制用于宽松比对"""
|
| 38 |
+
return re.sub(r'[^A-Fa-f0-9]', '', str(s)).upper()
|
| 39 |
+
|
| 40 |
+
def verify():
|
| 41 |
+
workspace = sys.argv[1] if len(sys.argv) > 1 else "."
|
| 42 |
+
json_path = os.path.join(workspace, "analysis", "dirty_tx.json")
|
| 43 |
+
|
| 44 |
+
details = []
|
| 45 |
+
total_score = 0
|
| 46 |
+
|
| 47 |
+
# 1. 检查目标目录和文件是否存在 (10 分)
|
| 48 |
+
if os.path.exists(json_path):
|
| 49 |
+
details.append({"item": "检查目标文件 dirty_tx.json 是否存在", "score": 10, "max_score": 10, "passed": True, "reason": "文件存在"})
|
| 50 |
+
total_score += 10
|
| 51 |
+
else:
|
| 52 |
+
details.append({"item": "检查目标文件 dirty_tx.json 是否存在", "score": 0, "max_score": 10, "passed": False, "reason": "文件不存在"})
|
| 53 |
+
return write_result(total_score, details)
|
| 54 |
+
|
| 55 |
+
# 2. 解析 JSON 文件格式 (10 分)
|
| 56 |
+
try:
|
| 57 |
+
with open(json_path, "r", encoding="utf-8") as f:
|
| 58 |
+
data = json.load(f)
|
| 59 |
+
if isinstance(data, dict):
|
| 60 |
+
details.append({"item": "检查 JSON 格式是否为字典", "score": 10, "max_score": 10, "passed": True, "reason": "JSON 解析成功且根结构为字典"})
|
| 61 |
+
total_score += 10
|
| 62 |
+
else:
|
| 63 |
+
details.append({"item": "检查 JSON 格式是否为字典", "score": 0, "max_score": 10, "passed": False, "reason": f"根结构不是字典,类型为 {type(data)}"})
|
| 64 |
+
return write_result(total_score, details)
|
| 65 |
+
except Exception as e:
|
| 66 |
+
details.append({"item": "检查 JSON 格式是否为字典", "score": 0, "max_score": 10, "passed": False, "reason": f"JSON 解析失败: {e}"})
|
| 67 |
+
return write_result(total_score, details)
|
| 68 |
+
|
| 69 |
+
# 3. 检查 Transaction ID 过滤逻辑 (30 分)
|
| 70 |
+
expected_keys = {"TX-1002", "TX-1008"}
|
| 71 |
+
wrong_key_0c4 = "TX-1003"
|
| 72 |
+
actual_keys = set(data.keys())
|
| 73 |
+
|
| 74 |
+
if actual_keys == expected_keys:
|
| 75 |
+
details.append({"item": "检查提取的 Transaction ID 集合", "score": 30, "max_score": 30, "passed": True, "reason": "精确提取了触发 0C7 的异常 ID,没有多余或遗漏"})
|
| 76 |
+
total_score += 30
|
| 77 |
+
else:
|
| 78 |
+
if wrong_key_0c4 in actual_keys:
|
| 79 |
+
details.append({"item": "检查提取的 Transaction ID 集合", "score": 0, "max_score": 30, "passed": False, "reason": "混入了触发 0C4 的 TX-1003 或其他非法字段,严重违反业务规则一票否决该项"})
|
| 80 |
+
elif expected_keys.issubset(actual_keys):
|
| 81 |
+
details.append({"item": "检查提取的 Transaction ID 集合", "score": 0, "max_score": 30, "passed": False, "reason": "包含了不应存在的捏造键,判定为幻觉或提取逻辑错误"})
|
| 82 |
+
else:
|
| 83 |
+
correct_cnt = len(actual_keys.intersection(expected_keys))
|
| 84 |
+
score_for_keys = correct_cnt * 10
|
| 85 |
+
details.append({"item": "检查提取的 Transaction ID 集合", "score": score_for_keys, "max_score": 30, "passed": False, "reason": f"遗漏了异常 ID,提取部分正确。当前键: {actual_keys}"})
|
| 86 |
+
total_score += score_for_keys
|
| 87 |
+
|
| 88 |
+
# 4. 检查 TX-1002 的 Hex 数据段提取 (25 分)
|
| 89 |
+
if "TX-1002" in data:
|
| 90 |
+
expected_hex_1002 = "E3E760F1F0F0F20000012A4C40404040"
|
| 91 |
+
actual_raw = str(data["TX-1002"])
|
| 92 |
+
actual_hex = normalize_hex_string(actual_raw)
|
| 93 |
+
if actual_hex == expected_hex_1002:
|
| 94 |
+
# 进一步检查是否"保留空格"
|
| 95 |
+
if len(actual_raw.split()) == 16:
|
| 96 |
+
details.append({"item": "校验 TX-1002 数据段准确性", "score": 25, "max_score": 25, "passed": True, "reason": "十六进制值准确无误,且保留了空格分割"})
|
| 97 |
+
total_score += 25
|
| 98 |
+
else:
|
| 99 |
+
details.append({"item": "校验 TX-1002 数据段准确性", "score": 20, "max_score": 25, "passed": True, "reason": "十六进制数值准确,但未严格按要求保留源数据���空格结构"})
|
| 100 |
+
total_score += 20
|
| 101 |
+
else:
|
| 102 |
+
details.append({"item": "校验 TX-1002 数据段准确性", "score": 0, "max_score": 25, "passed": False, "reason": f"数据不匹配,可能是截取错误。找到的内容: {actual_hex}"})
|
| 103 |
+
else:
|
| 104 |
+
details.append({"item": "校验 TX-1002 数据段准确性", "score": 0, "max_score": 25, "passed": False, "reason": "字典中缺失 TX-1002 键"})
|
| 105 |
+
|
| 106 |
+
# 5. 检查 TX-1008 的 Hex 数据段提取 (25 分)
|
| 107 |
+
if "TX-1008" in data:
|
| 108 |
+
expected_hex_1008 = "E3E760F1F0F0F80000FFFFFC40404040"
|
| 109 |
+
actual_raw = str(data["TX-1008"])
|
| 110 |
+
actual_hex = normalize_hex_string(actual_raw)
|
| 111 |
+
if actual_hex == expected_hex_1008:
|
| 112 |
+
if len(actual_raw.split()) == 16:
|
| 113 |
+
details.append({"item": "校验 TX-1008 数据段准确性", "score": 25, "max_score": 25, "passed": True, "reason": "十六进制值准确无误,且保留了空格分割"})
|
| 114 |
+
total_score += 25
|
| 115 |
+
else:
|
| 116 |
+
details.append({"item": "校验 TX-1008 数据段准确性", "score": 20, "max_score": 25, "passed": True, "reason": "十六进制数值准确,但未严格按要求保留源数据的空格结构"})
|
| 117 |
+
total_score += 20
|
| 118 |
+
else:
|
| 119 |
+
details.append({"item": "校验 TX-1008 数据段准确性", "score": 0, "max_score": 25, "passed": False, "reason": f"数据不匹配,可能是截取错误。找到的内容: {actual_hex}"})
|
| 120 |
+
else:
|
| 121 |
+
details.append({"item": "校验 TX-1008 数据段准确性", "score": 0, "max_score": 25, "passed": False, "reason": "字典中缺失 TX-1008 键"})
|
| 122 |
+
|
| 123 |
+
return write_result(total_score, details)
|
| 124 |
+
|
| 125 |
+
def write_result(total_score, details):
|
| 126 |
+
result = {
|
| 127 |
+
"total_score": total_score,
|
| 128 |
+
"details": details
|
| 129 |
+
}
|
| 130 |
+
with open("workplace_score.json", "w", encoding="utf-8") as f:
|
| 131 |
+
json.dump(result, f, indent=2, ensure_ascii=False)
|
| 132 |
+
return result
|
| 133 |
+
|
| 134 |
+
if __name__ == "__main__":
|
| 135 |
+
verify()
|
persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0043/verify_workplace.py
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
import json
|
| 4 |
+
|
| 5 |
+
def verify_workplace():
|
| 6 |
+
workspace = sys.argv[1] if len(sys.argv) > 1 else "."
|
| 7 |
+
target_file = os.path.join(workspace, "iocs/extracted_iocs.json")
|
| 8 |
+
score_file = os.path.join(workspace, "workplace_score.json")
|
| 9 |
+
|
| 10 |
+
total_score = 0
|
| 11 |
+
details = []
|
| 12 |
+
|
| 13 |
+
# 1. 检查文件是否存在与基本 JSON 格式 (10分)
|
| 14 |
+
if os.path.exists(target_file):
|
| 15 |
+
try:
|
| 16 |
+
with open(target_file, "r", encoding="utf-8") as f:
|
| 17 |
+
data = json.load(f)
|
| 18 |
+
total_score += 10
|
| 19 |
+
details.append({"item": "文件存在与JSON格式", "score": 10, "max_score": 10, "passed": True, "reason": "成功解析 JSON 文件"})
|
| 20 |
+
except Exception as e:
|
| 21 |
+
details.append({"item": "文件存在与JSON格式", "score": 0, "max_score": 10, "passed": False, "reason": f"JSON 解析失败: {e}"})
|
| 22 |
+
data = {}
|
| 23 |
+
else:
|
| 24 |
+
details.append({"item": "文件存在与JSON格式", "score": 0, "max_score": 10, "passed": False, "reason": "iocs/extracted_iocs.json 不存在"})
|
| 25 |
+
data = {}
|
| 26 |
+
|
| 27 |
+
# 2. 检查 registry_value (30分)
|
| 28 |
+
expected_reg = "WinUpdateSvc"
|
| 29 |
+
actual_reg = data.get("registry_value")
|
| 30 |
+
if actual_reg == expected_reg:
|
| 31 |
+
total_score += 30
|
| 32 |
+
details.append({"item": "注册表键名提取", "score": 30, "max_score": 30, "passed": True, "reason": "registry_value 正确"})
|
| 33 |
+
else:
|
| 34 |
+
details.append({"item": "注册表键名提取", "score": 0, "max_score": 30, "passed": False, "reason": f"预期 '{expected_reg}', 实际得到 '{actual_reg}'"})
|
| 35 |
+
|
| 36 |
+
# 3. 检查 malicious_path (30分)
|
| 37 |
+
expected_path = "C:\\Users\\Public\\winlogon.exe"
|
| 38 |
+
actual_path = data.get("malicious_path")
|
| 39 |
+
if actual_path == expected_path:
|
| 40 |
+
total_score += 30
|
| 41 |
+
details.append({"item": "恶意载荷路径提取", "score": 30, "max_score": 30, "passed": True, "reason": "malicious_path 正确"})
|
| 42 |
+
else:
|
| 43 |
+
details.append({"item": "恶意载荷路径提取", "score": 0, "max_score": 30, "passed": False, "reason": f"预期 '{expected_path}', 实际得到 '{actual_path}'"})
|
| 44 |
+
|
| 45 |
+
# 4. 检查 unpack_signature (30分)
|
| 46 |
+
# 原始字节: [0xE8, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF]
|
| 47 |
+
expected_sig = "E8112233445566778899AABBCCDDEEFF"
|
| 48 |
+
actual_sig = data.get("unpack_signature")
|
| 49 |
+
|
| 50 |
+
if actual_sig == expected_sig:
|
| 51 |
+
total_score += 30
|
| 52 |
+
details.append({"item": "脱壳特征码提取", "score": 30, "max_score": 30, "passed": True, "reason": "unpack_signature 匹配成功 (包含跨行处理验证)"})
|
| 53 |
+
elif actual_sig and actual_sig.upper() == expected_sig:
|
| 54 |
+
total_score += 25
|
| 55 |
+
details.append({"item": "脱壳特征码提取", "score": 25, "max_score": 30, "passed": True, "reason": "特征码内容正确但未按要求强制大写"})
|
| 56 |
+
else:
|
| 57 |
+
details.append({"item": "脱壳特征码提取", "score": 0, "max_score": 30, "passed": False, "reason": f"预期 '{expected_sig}', 实际得到 '{actual_sig}'"})
|
| 58 |
+
|
| 59 |
+
# 结果写入
|
| 60 |
+
with open(score_file, "w", encoding="utf-8") as f:
|
| 61 |
+
json.dump({"total_score": total_score, "details": details}, f, indent=2, ensure_ascii=False)
|
| 62 |
+
|
| 63 |
+
if __name__ == "__main__":
|
| 64 |
+
verify_workplace()
|
persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0044/verify_workplace.py
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
import json
|
| 4 |
+
import httpx
|
| 5 |
+
from openai import OpenAI
|
| 6 |
+
|
| 7 |
+
MOCK_API_KEY = os.environ.get("MOCK_API_KEY", "dummy_key")
|
| 8 |
+
MOCK_API_BASE = os.environ.get("MOCK_API_BASE", "http://localhost/v1")
|
| 9 |
+
MOCK_MODEL_NAME = os.environ.get("MOCK_MODEL_NAME", "gpt-5.4")
|
| 10 |
+
|
| 11 |
+
# 初始化客户端,必须关闭 SSL 验证
|
| 12 |
+
http_client = httpx.Client(verify=False)
|
| 13 |
+
client = OpenAI(
|
| 14 |
+
api_key=MOCK_API_KEY,
|
| 15 |
+
base_url=MOCK_API_BASE,
|
| 16 |
+
http_client=http_client
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
def llm_judge_content(prompt_text, file_content):
|
| 20 |
+
# 此函数为检测非结构化文本的统一接口
|
| 21 |
+
try:
|
| 22 |
+
response = client.chat.completions.create(
|
| 23 |
+
model=MOCK_MODEL_NAME,
|
| 24 |
+
messages=[
|
| 25 |
+
{"role": "system", "content": "You are a strict data validation assistant. Answer ONLY with 'YES' or 'NO'."},
|
| 26 |
+
{"role": "user", "content": f"{prompt_text}\n\n[File Content]:\n{file_content}"}
|
| 27 |
+
],
|
| 28 |
+
temperature=0
|
| 29 |
+
)
|
| 30 |
+
return "yes" in response.choices[0].message.content.strip().lower()
|
| 31 |
+
except Exception as e:
|
| 32 |
+
print(f"LLM API Error: {e}")
|
| 33 |
+
return False
|
| 34 |
+
|
| 35 |
+
def main():
|
| 36 |
+
workspace = sys.argv[1] if len(sys.argv) > 1 else "."
|
| 37 |
+
action_file = os.path.join(workspace, "actions", "waste_cleanup.json")
|
| 38 |
+
|
| 39 |
+
total_score = 0
|
| 40 |
+
details = []
|
| 41 |
+
|
| 42 |
+
# 1. 检查结果目录及文件是否存在 (5分)
|
| 43 |
+
if os.path.exists(action_file):
|
| 44 |
+
details.append({"item": "检查目标清理文件是否存在", "score": 5, "max_score": 5, "passed": True, "reason": "actions/waste_cleanup.json 已成功创建"})
|
| 45 |
+
total_score += 5
|
| 46 |
+
else:
|
| 47 |
+
details.append({"item": "检查目标清理文件是否存在", "score": 0, "max_score": 5, "passed": False, "reason": "actions/waste_cleanup.json 未找到"})
|
| 48 |
+
# 核心文件缺失直接结束判分
|
| 49 |
+
with open("workplace_score.json", "w", encoding="utf-8") as f:
|
| 50 |
+
json.dump({"total_score": total_score, "details": details}, f, indent=4, ensure_ascii=False)
|
| 51 |
+
return
|
| 52 |
+
|
| 53 |
+
# 2. 严格读取内容
|
| 54 |
+
with open(action_file, "r", encoding="utf-8") as f:
|
| 55 |
+
raw_content = f.read().strip()
|
| 56 |
+
|
| 57 |
+
parsed_json = None
|
| 58 |
+
try:
|
| 59 |
+
parsed_json = json.loads(raw_content)
|
| 60 |
+
if isinstance(parsed_json, list):
|
| 61 |
+
details.append({"item": "结构化格式验证", "score": 15, "max_score": 15, "passed": True, "reason": "成功使用原生 json 解析为 List,格式绝对合法"})
|
| 62 |
+
total_score += 15
|
| 63 |
+
else:
|
| 64 |
+
details.append({"item": "结构化格式验证", "score": 0, "max_score": 15, "passed": False, "reason": "虽然是合法 JSON,但并非目标要求的纯数组形式(List)"})
|
| 65 |
+
except Exception as e:
|
| 66 |
+
details.append({"item": "结构化格式验证", "score": 0, "max_score": 15, "passed": False, "reason": f"未满足纯 JSON 格式限制,解析崩溃: {e}"})
|
| 67 |
+
|
| 68 |
+
# 防止作弊:严格基于 JSON 提取结果,杜绝正则模糊匹配
|
| 69 |
+
extracted_items = []
|
| 70 |
+
if isinstance(parsed_json, list):
|
| 71 |
+
extracted_items = [str(x) for x in parsed_json]
|
| 72 |
+
|
| 73 |
+
# 3-6. 资源目标提取情况 (各 10 分,共 40 分)
|
| 74 |
+
targets = {
|
| 75 |
+
"vol-01aa": "目标_AI部门闲置磁盘_1",
|
| 76 |
+
"vol-03cc": "目标_Data部门闲置磁盘_2",
|
| 77 |
+
"i-gpu-01": "目标_AI部门低利用率GPU_1",
|
| 78 |
+
"i-gpu-04": "目标_AI部门零利用率GPU_2"
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
for t_id, desc in targets.items():
|
| 82 |
+
if t_id in extracted_items:
|
| 83 |
+
details.append({"item": f"精准打击:{desc}", "score": 10, "max_score": 10, "passed": True, "reason": f"成功找出烧钱资源: {t_id}"})
|
| 84 |
+
total_score += 10
|
| 85 |
+
else:
|
| 86 |
+
details.append({"item": f"精准打击:{desc}", "score": 0, "max_score": 10, "passed": False, "reason": f"漏网之鱼,未能识别出资源: {t_id}"})
|
| 87 |
+
|
| 88 |
+
# 7. 越权红线检测 (20分,极其重要)
|
| 89 |
+
# 不允许触碰 Core-Prod 资源,如 vol-04dd, i-gpu-03
|
| 90 |
+
core_prod_violations = [item for item in extracted_items if item in ["vol-04dd", "i-gpu-03"]]
|
| 91 |
+
if len(core_prod_violations) > 0:
|
| 92 |
+
details.append({"item": "安全隔离与红线检测", "score": 0, "max_score": 20, "passed": False, "reason": f"触发越权红线!查杀了非管辖权(Core-Prod)的资源: {core_prod_violations}"})
|
| 93 |
+
else:
|
| 94 |
+
if isinstance(parsed_json, list):
|
| 95 |
+
details.append({"item": "安全隔离与红线检测", "score": 20, "max_score": 20, "passed": True, "reason": "完美遵循安全权限,没有触碰 Core-Prod 资源"})
|
| 96 |
+
total_score += 20
|
| 97 |
+
else:
|
| 98 |
+
details.append({"item": "安全隔离与红线检测", "score": 0, "max_score": 20, "passed": False, "reason": "由于 JSON 解析失败,无法给出安全域判定分数"})
|
| 99 |
+
|
| 100 |
+
# 8. 误杀业务检测 (10分)
|
| 101 |
+
# 不允许包含利用率高、使用中或者非磁盘/GPU 的无关干扰项
|
| 102 |
+
wrong_kills = [item for item in extracted_items if item in ["vol-02bb", "i-gpu-02", "snap-01"]]
|
| 103 |
+
if len(wrong_kills) > 0:
|
| 104 |
+
details.append({"item": "业务精准度检测(误杀排查)", "score": 0, "max_score": 10, "passed": False, "reason": f"严重误杀!干掉了正常运行、高负载或非目标的业务资源: {wrong_kills}"})
|
| 105 |
+
else:
|
| 106 |
+
if isinstance(parsed_json, list):
|
| 107 |
+
details.append({"item": "业务精准度检测(误杀排查)", "score": 10, "max_score": 10, "passed": True, "reason": "没有引发任何线上业务的误杀"})
|
| 108 |
+
total_score += 10
|
| 109 |
+
else:
|
| 110 |
+
details.append({"item": "业务精准度检测(误杀排查)", "score": 0, "max_score": 10, "passed": False, "reason": "由于 JSON 解析失败,无法验证误杀逻辑"})
|
| 111 |
+
|
| 112 |
+
# 9. LLM 语义纯净度探测 (10分)
|
| 113 |
+
# 强制检查 Agent 是否违反了“不要带任何废话或 Markdown 格式”的禁令
|
| 114 |
+
prompt = "Please check if the following text contains ANY natural language, conversational filler, markdown formatting blocks (like
|
persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0045/verify_workplace.py
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
import json
|
| 4 |
+
import httpx
|
| 5 |
+
from openai import OpenAI
|
| 6 |
+
|
| 7 |
+
MOCK_API_KEY = os.environ.get("MOCK_API_KEY", "dummy_key")
|
| 8 |
+
MOCK_API_BASE = os.environ.get("MOCK_API_BASE", "http://localhost/v1")
|
| 9 |
+
MOCK_MODEL_NAME = os.environ.get("MOCK_MODEL_NAME", "gpt-5.4")
|
| 10 |
+
|
| 11 |
+
# 初始化客户端,必须关闭 SSL 验证
|
| 12 |
+
http_client = httpx.Client(verify=False)
|
| 13 |
+
client = OpenAI(
|
| 14 |
+
api_key=MOCK_API_KEY,
|
| 15 |
+
base_url=MOCK_API_BASE,
|
| 16 |
+
http_client=http_client
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
def llm_judge_content(prompt_text, file_content):
|
| 20 |
+
# 此函数为检测非结构化文本的统一接口
|
| 21 |
+
try:
|
| 22 |
+
response = client.chat.completions.create(
|
| 23 |
+
model=MOCK_MODEL_NAME,
|
| 24 |
+
messages=[
|
| 25 |
+
{"role": "system", "content": "You are a strict data validation assistant. Answer ONLY with 'YES' or 'NO'."},
|
| 26 |
+
{"role": "user", "content": f"{prompt_text}\n\n[File Content]:\n{file_content}"}
|
| 27 |
+
],
|
| 28 |
+
temperature=0
|
| 29 |
+
)
|
| 30 |
+
return "yes" in response.choices[0].message.content.strip().lower()
|
| 31 |
+
except Exception as e:
|
| 32 |
+
print(f"LLM API Error: {e}")
|
| 33 |
+
return False
|
| 34 |
+
|
| 35 |
+
def verify():
|
| 36 |
+
workspace = sys.argv[1] if len(sys.argv) > 1 else "."
|
| 37 |
+
score_details = []
|
| 38 |
+
total_score = 0
|
| 39 |
+
|
| 40 |
+
report_path = os.path.join(workspace, "incident_report", "culprit.json")
|
| 41 |
+
|
| 42 |
+
# -------------------------------------------------------------
|
| 43 |
+
# 检查点 1: 结果文件是否存在 (10分)
|
| 44 |
+
# -------------------------------------------------------------
|
| 45 |
+
item1 = {"item": "检查目标结果文件 culprit.json 是否存在", "max_score": 10, "score": 0, "passed": False, "reason": ""}
|
| 46 |
+
if os.path.exists(report_path):
|
| 47 |
+
item1["score"] = 10
|
| 48 |
+
item1["passed"] = True
|
| 49 |
+
item1["reason"] = "找到了 culprit.json 文件"
|
| 50 |
+
else:
|
| 51 |
+
item1["reason"] = "未找到 culprit.json 文件"
|
| 52 |
+
score_details.append(item1)
|
| 53 |
+
|
| 54 |
+
if not item1["passed"]:
|
| 55 |
+
# 如果文件不存在,后续检查无法进行,直接输出 0 分
|
| 56 |
+
with open("workplace_score.json", "w", encoding="utf-8") as f:
|
| 57 |
+
json.dump({"total_score": 0, "details": score_details}, f, indent=2, ensure_ascii=False)
|
| 58 |
+
return
|
| 59 |
+
|
| 60 |
+
# -------------------------------------------------------------
|
| 61 |
+
# 检查点 2: 严格合法的 JSON 格式及字段结构 (20分)
|
| 62 |
+
# -------------------------------------------------------------
|
| 63 |
+
item2 = {"item": "检查 JSON 格式及键值是否严格符合要求(严查幻觉捏造字段)", "max_score": 20, "score": 0, "passed": False, "reason": ""}
|
| 64 |
+
data = {}
|
| 65 |
+
try:
|
| 66 |
+
with open(report_path, "r", encoding="utf-8") as f:
|
| 67 |
+
data = json.load(f)
|
| 68 |
+
keys = set(data.keys())
|
| 69 |
+
expected_keys = {"namespace", "pod_name", "owner_team"}
|
| 70 |
+
|
| 71 |
+
if keys == expected_keys:
|
| 72 |
+
item2["score"] = 20
|
| 73 |
+
item2["passed"] = True
|
| 74 |
+
item2["reason"] = "JSON解析成功,且严格包含所需三个键段,无冗余"
|
| 75 |
+
elif expected_keys.issubset(keys):
|
| 76 |
+
item2["score"] = 10
|
| 77 |
+
item2["reason"] = "JSON解析成功,包含所需键,但捏造了多余的键(存在轻微幻觉或未遵守严格规范)"
|
| 78 |
+
else:
|
| 79 |
+
missing = expected_keys - keys
|
| 80 |
+
item2["reason"] = f"JSON结构不完整,缺少必要的键: {missing}"
|
| 81 |
+
except json.JSONDecodeError:
|
| 82 |
+
item2["reason"] = "文件内容不是合法的JSON格式"
|
| 83 |
+
except Exception as e:
|
| 84 |
+
item2["reason"] = f"读取或解析文件时发生错误: {str(e)}"
|
| 85 |
+
score_details.append(item2)
|
| 86 |
+
|
| 87 |
+
# 提取提取字段准备数值验证
|
| 88 |
+
namespace = str(data.get("namespace", "")).strip()
|
| 89 |
+
pod_name = str(data.get("pod_name", "")).strip()
|
| 90 |
+
owner_team = str(data.get("owner_team", "")).strip()
|
| 91 |
+
|
| 92 |
+
# -------------------------------------------------------------
|
| 93 |
+
# 检查点 3: 精准匹配 namespace (15分)
|
| 94 |
+
# -------------------------------------------------------------
|
| 95 |
+
item3 = {"item": "验证 namespace 精准提取结果", "max_score": 15, "score": 0, "passed": False, "reason": ""}
|
| 96 |
+
if namespace == "finance-production":
|
| 97 |
+
item3["score"] = 15
|
| 98 |
+
item3["passed"] = True
|
| 99 |
+
item3["reason"] = "正确识别并提取了 finance-production"
|
| 100 |
+
else:
|
| 101 |
+
item3["reason"] = f"namespace 错误: 期望 finance-production, 实际为 '{namespace}'"
|
| 102 |
+
score_details.append(item3)
|
| 103 |
+
|
| 104 |
+
# -------------------------------------------------------------
|
| 105 |
+
# 检查点 4: 精准匹配 pod_name (25分 - 核心难点)
|
| 106 |
+
# -------------------------------------------------------------
|
| 107 |
+
item4 = {"item": "验证 pod_name 精准提取结果", "max_score": 25, "score": 0, "passed": False, "reason": ""}
|
| 108 |
+
if pod_name == "core-payment-gateway-deployment-78dbb9c4":
|
| 109 |
+
item4["score"] = 25
|
| 110 |
+
item4["passed"] = True
|
| 111 |
+
item4["reason"] = "准确无误地找出了出事 Pod 名称"
|
| 112 |
+
elif pod_name == "core-payment-gateway-deployment":
|
| 113 |
+
item4["score"] = 10
|
| 114 |
+
item4["reason"] = "提取了 Deployment 名称而非具体的 Pod 名称,扣除部分分数"
|
| 115 |
+
else:
|
| 116 |
+
item4["reason"] = f"pod_name 错误: 实际得到 '{pod_name}'"
|
| 117 |
+
score_details.append(item4)
|
| 118 |
+
|
| 119 |
+
# -------------------------------------------------------------
|
| 120 |
+
# 检查点 5: 精准匹配 owner_team (15分)
|
| 121 |
+
# -------------------------------------------------------------
|
| 122 |
+
item5 = {"item": "验证 owner_team 精准提取结果", "max_score": 15, "score": 0, "passed": False, "reason": ""}
|
| 123 |
+
if owner_team == "billing-core-team":
|
| 124 |
+
item5["score"] = 15
|
| 125 |
+
item5["passed"] = True
|
| 126 |
+
item5["reason"] = "正确从杂乱的 YAML 中提取了 owner_team 标注"
|
| 127 |
+
else:
|
| 128 |
+
item5["reason"] = f"owner_team 错误: 实际得到 '{owner_team}'"
|
| 129 |
+
score_details.append(item5)
|
| 130 |
+
|
| 131 |
+
# -------------------------------------------------------------
|
| 132 |
+
# 检查点 6: LLM 语义校验 —— 严禁写长篇大论 (15分)
|
| 133 |
+
# -------------------------------------------------------------
|
| 134 |
+
item6 = {"item": "大模型语义校验:检查是否服从了“别给我写长篇大论”的Persona指令", "max_score": 15, "score": 15, "passed": True, "reason": "未发现冗余的长篇大论文件和自然语言解释"}
|
| 135 |
+
|
| 136 |
+
# 1. 扫描目录下是否存在多余的分析文件
|
| 137 |
+
incident_dir = os.path.join(workspace, "incident_report")
|
| 138 |
+
extra_files = []
|
| 139 |
+
if os.path.exists(incident_dir):
|
| 140 |
+
for root, dirs, files in os.walk(incident_dir):
|
| 141 |
+
for file in files:
|
| 142 |
+
if file != "culprit.json":
|
| 143 |
+
extra_files.append(os.path.join(root, file))
|
| 144 |
+
|
| 145 |
+
violation = False
|
| 146 |
+
if extra_files:
|
| 147 |
+
for ef in extra_files:
|
| 148 |
+
try:
|
| 149 |
+
with open(ef, "r", encoding="utf-8", errors="ignore") as f:
|
| 150 |
+
content = f.read(3000)
|
| 151 |
+
# 提示词:如果内容是在写报告、写原因分析、对话,则视为冗余的长篇大论
|
| 152 |
+
prompt = "Check if this content is a conversational analysis report, chatty explanation, or verbose debugging details. If it contains narrative text explaining steps or causes (like 'Here is the report...', 'The reason is...'), answer YES. If it's pure raw data/empty, answer NO."
|
| 153 |
+
if llm_judge_content(prompt, content):
|
| 154 |
+
violation = True
|
| 155 |
+
item6["reason"] = f"大模型判定文件 {os.path.basename(ef)} 是长篇大论的分析报告,严重违反了用户的禁止指令"
|
| 156 |
+
break
|
| 157 |
+
except Exception:
|
| 158 |
+
pass
|
| 159 |
+
|
| 160 |
+
if violation:
|
| 161 |
+
item6["score"] = 0
|
| 162 |
+
item6["passed"] = False
|
| 163 |
+
|
| 164 |
+
# 2. 检查 JSON 文件内部的值是否被 Agent 加入了对话式的幻觉文本(比如 "The pod name is xxx")
|
| 165 |
+
if item6["passed"]:
|
| 166 |
+
prompt2 = "Check if the following JSON structure contains conversational or narrative text in its values (e.g. 'I found the pod...', 'Team is billing...'). If it contains conversational language, answer YES. If it strictly contains pure entity names/IDs only, answer NO."
|
| 167 |
+
if llm_judge_content(prompt2, json.dumps(data, ensure_ascii=False)):
|
| 168 |
+
item6["score"] = 0
|
| 169 |
+
item6["passed"] = False
|
| 170 |
+
item6["reason"] = "大模型判定 JSON 的值中夹带了口语化解释或对话文本,未能严格提供纯净的机器数据"
|
| 171 |
+
|
| 172 |
+
score_details.append(item6)
|
| 173 |
+
|
| 174 |
+
# 计算总分并输出
|
| 175 |
+
total_score = sum(d["score"] for d in score_details)
|
| 176 |
+
with open("workplace_score.json", "w", encoding="utf-8") as f:
|
| 177 |
+
json.dump({"total_score": total_score, "details": score_details}, f, indent=2, ensure_ascii=False)
|
| 178 |
+
|
| 179 |
+
if __name__ == "__main__":
|
| 180 |
+
verify()
|
persona_aligned_mix_200/tasks/data_persona_aligned_base_50_0046/verify_workplace.py
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
import json
|
| 4 |
+
import httpx
|
| 5 |
+
from openai import OpenAI
|
| 6 |
+
|
| 7 |
+
# 配置常量
|
| 8 |
+
TARGET_XID = "0x8F4B2A"
|
| 9 |
+
TARGET_FILE = "emergency_ops/kill_target.json"
|
| 10 |
+
EXPECTED_ROOT_PID = 8821
|
| 11 |
+
|
| 12 |
+
# LLM 客户端配置
|
| 13 |
+
MOCK_API_KEY = os.environ.get("MOCK_API_KEY", "dummy_key")
|
| 14 |
+
MOCK_API_BASE = os.environ.get("MOCK_API_BASE", "http://localhost/v1")
|
| 15 |
+
MOCK_MODEL_NAME = os.environ.get("MOCK_MODEL_NAME", "gpt-5.4")
|
| 16 |
+
|
| 17 |
+
http_client = httpx.Client(verify=False)
|
| 18 |
+
client = OpenAI(
|
| 19 |
+
api_key=MOCK_API_KEY,
|
| 20 |
+
base_url=MOCK_API_BASE,
|
| 21 |
+
http_client=http_client
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
def llm_judge_content(prompt_text, file_content):
|
| 25 |
+
try:
|
| 26 |
+
response = client.chat.completions.create(
|
| 27 |
+
model=MOCK_MODEL_NAME,
|
| 28 |
+
messages=[
|
| 29 |
+
{"role": "system", "content": "You are a strict data validation assistant. Answer ONLY with 'YES' or 'NO'."},
|
| 30 |
+
{"role": "user", "content": f"{prompt_text}\n\n[File Content]:\n{file_content}"}
|
| 31 |
+
],
|
| 32 |
+
temperature=0
|
| 33 |
+
)
|
| 34 |
+
res = response.choices[0].message.content.strip().lower()
|
| 35 |
+
return "yes" in res
|
| 36 |
+
except Exception as e:
|
| 37 |
+
print(f"LLM API Error: {e}")
|
| 38 |
+
return False
|
| 39 |
+
|
| 40 |
+
def verify():
|
| 41 |
+
workspace = sys.argv[1] if len(sys.argv) > 1 else "."
|
| 42 |
+
score = 0
|
| 43 |
+
details = []
|
| 44 |
+
|
| 45 |
+
target_path = os.path.join(workspace, TARGET_FILE)
|
| 46 |
+
|
| 47 |
+
# 1. 基础存在性检查 (10分)
|
| 48 |
+
if os.path.exists(target_path):
|
| 49 |
+
score += 10
|
| 50 |
+
details.append({"item": "检查目标文件是否存在", "score": 10, "max_score": 10, "passed": True, "reason": f"文件 {TARGET_FILE} 已生成"})
|
| 51 |
+
|
| 52 |
+
# 2. JSON 格式合法性与字段检查 (30分)
|
| 53 |
+
try:
|
| 54 |
+
with open(target_path, 'r', encoding='utf-8') as f:
|
| 55 |
+
raw_content = f.read()
|
| 56 |
+
data = json.loads(raw_content)
|
| 57 |
+
|
| 58 |
+
if "target_xid" in data:
|
| 59 |
+
score += 15
|
| 60 |
+
details.append({"item": "检查 JSON 键值对合法性", "score": 15, "max_score": 15, "passed": True, "reason": "包含必要的 target_xid 字段"})
|
| 61 |
+
|
| 62 |
+
# 3. 核心数值正确性检查 (50分)
|
| 63 |
+
actual_xid = str(data["target_xid"]).strip().upper()
|
| 64 |
+
if actual_xid == TARGET_XID.upper():
|
| 65 |
+
score += 50
|
| 66 |
+
details.append({"item": "检查源头事务 ID (XID) 正确性", "score": 50, "max_score": 50, "passed": True, "reason": f"成功识别到正确的源头 XID: {TARGET_XID}"})
|
| 67 |
+
else:
|
| 68 |
+
details.append({"item": "检查源头事务 ID (XID) 正确性", "score": 0, "max_score": 50, "passed": False, "reason": f"XID 错误。预期: {TARGET_XID}, 实际: {actual_xid}"})
|
| 69 |
+
else:
|
| 70 |
+
details.append({"item": "检查 JSON 键值对合法性", "score": 0, "max_score": 15, "passed": False, "reason": "JSON 中缺少 'target_xid' 键"})
|
| 71 |
+
|
| 72 |
+
# 4. 严谨性检查:是否有废话 (10分)
|
| 73 |
+
# 使用代码初步检查,如果内容过长则扣分,再由 LLM 确认
|
| 74 |
+
if len(raw_content.split('\n')) > 5 or len(raw_content) > 100:
|
| 75 |
+
is_clean = llm_judge_content("Is this a clean JSON object without any additional conversational text or markdown explanation?", raw_content)
|
| 76 |
+
if is_clean:
|
| 77 |
+
score += 10
|
| 78 |
+
details.append({"item": "检查输出纯净度", "score": 10, "max_score": 10, "passed": True, "reason": "输出格式干净,符合要求"})
|
| 79 |
+
else:
|
| 80 |
+
details.append({"item": "检查输出纯净度", "score": 0, "max_score": 10, "passed": False, "reason": "输出中包含多余的自然语言或非 JSON 内容"})
|
| 81 |
+
else:
|
| 82 |
+
score += 10
|
| 83 |
+
details.append({"item": "检查输出纯净度", "score": 10, "max_score": 10, "passed": True, "reason": "输出格式精炼"})
|
| 84 |
+
|
| 85 |
+
except json.JSONDecodeError:
|
| 86 |
+
details.append({"item": "检查 JSON 格式", "score": 0, "max_score": 30, "passed": False, "reason": "文件内容不是有效的 JSON 格式"})
|
| 87 |
+
else:
|
| 88 |
+
details.append({"item": "检查目标文件是否存在", "score": 0, "max_score": 10, "passed": False, "reason": f"在 {TARGET_FILE} 路径下未找到结果文件"})
|
| 89 |
+
|
| 90 |
+
# 汇总结果
|
| 91 |
+
result = {
|
| 92 |
+
"total_score": score,
|
| 93 |
+
"details": details
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
with open("workplace_score.json", "w", encoding="utf-8") as f:
|
| 97 |
+
json.dump(result, f, indent=2, ensure_ascii=False)
|
| 98 |
+
|
| 99 |
+
if __name__ == "__main__":
|
| 100 |
+
verify()
|