Skip to content

Commit 13d1e27

Browse files
authored
feat(comments): improve comments and remove unused file (#5)
* improve comments readability * updaste comments in visualize-trace * improve comments and log message * remove unused file * lint code * lint code
1 parent c55486d commit 13d1e27

File tree

24 files changed

+820
-779
lines changed

24 files changed

+820
-779
lines changed

README.bak.md

Lines changed: 0 additions & 17 deletions
This file was deleted.

apps/run-agent/calculate_score_from_log.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212

1313
def extract_score_from_log(run_dir, task_score_dict):
14-
# 遍历所有task_{task_id}_attempt_*.log的文件,提取score
14+
# Traverse all task_{task_id}_attempt_*.log files to extract score
1515
log_files = glob.glob(os.path.join(run_dir, "task_*_attempt_*.json"))
1616
for log_file in log_files:
1717
task_id = log_file.split("/")[-1].split("_")[1]
@@ -35,7 +35,7 @@ def main(results_dir: str, pass_at_k: int = 3):
3535

3636
print(f"Analyzing results from: {results_dir}")
3737

38-
# 遍历所有run_*目录under results_dir
38+
# Traverse all run_* directories under results_dir
3939
run_dirs = glob.glob(os.path.join(results_dir, "run_*"))
4040
task_score_dict = {}
4141
for run_dir in run_dirs:
@@ -50,7 +50,7 @@ def main(results_dir: str, pass_at_k: int = 3):
5050
else:
5151
failed_id.append(task)
5252

53-
# 保存简单的统计结果
53+
# Save simple statistical results
5454
output_file = os.path.join(results_dir, f"average_scores_pass_at_{pass_at_k}.txt")
5555
with open(output_file, "w") as f:
5656
f.write("EVALUATION RESULTS\n")

apps/run-agent/common_benchmark.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ def prepare_task_description(
546546
if path.is_absolute():
547547
return task.task_question, str(path.resolve())
548548

549-
# 构建完整文件路径:数据目录 + 相对路径
549+
# Build complete file path: data directory + relative path
550550
full_file_path = Path(self.data_dir) / path
551551
return task.task_question, str(full_file_path.resolve())
552552

@@ -636,9 +636,9 @@ def main(*args):
636636
with hydra.initialize_config_dir(config_dir=config_path(), version_base=None):
637637
cfg = hydra.compose(config_name=config_name(), overrides=list(args))
638638
_ = bootstrap_logger()
639-
# 默认关闭 tracing, 同时不 set key
639+
# Default to disable tracing, and don't set key
640640
set_tracing_disabled(True)
641641
set_tracing_export_api_key("fake-key")
642-
# 压制 trace provider 的报警
642+
# Suppress trace provider warnings
643643
bootstrap_silent_trace_provider()
644644
asyncio.run(entrypoint(cfg))

apps/visualize-trace/app.py

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,45 +8,45 @@
88

99
app = Flask(__name__)
1010

11-
# 全局变量存储分析器实例
11+
# Global variable to store analyzer instance
1212
analyzer = None
1313

1414

1515
@app.route("/")
1616
def index():
17-
"""主页面"""
17+
"""Main page"""
1818
return render_template("index.html")
1919

2020

2121
@app.route("/api/list_files", methods=["GET"])
2222
def list_files():
23-
"""列出可用的JSON文件"""
23+
"""List available JSON files"""
2424
try:
2525
directory = request.args.get("directory", "")
2626

2727
if not directory:
28-
# 默认行为:检查上级目录
28+
# Default behavior: check parent directory
2929
directory = os.path.abspath("..")
3030

31-
# 扩展路径(处理~等符号)
31+
# Expand path (handle ~ and other symbols)
3232
directory = os.path.expanduser(directory)
3333

34-
# 转换为绝对路径
34+
# Convert to absolute path
3535
directory = os.path.abspath(directory)
3636

3737
if not os.path.exists(directory):
38-
return jsonify({"error": f"目录不存在: {directory}"}), 404
38+
return jsonify({"error": f"Directory does not exist: {directory}"}), 404
3939

4040
if not os.path.isdir(directory):
41-
return jsonify({"error": f"路径不是目录: {directory}"}), 400
41+
return jsonify({"error": f"Path is not a directory: {directory}"}), 400
4242

4343
try:
4444
json_files = []
4545
for file in os.listdir(directory):
4646
if file.endswith(".json"):
4747
file_path = os.path.join(directory, file)
4848
try:
49-
# 获取文件大小和修改时间
49+
# Get file size and modification time
5050
stat = os.stat(file_path)
5151
json_files.append(
5252
{
@@ -61,61 +61,63 @@ def list_files():
6161
{"name": file, "path": file_path, "size": 0, "modified": 0}
6262
)
6363

64-
# 按文件名排序
64+
# Sort by filename
6565
json_files.sort(key=lambda x: x["name"])
6666

6767
return jsonify(
6868
{
6969
"files": json_files,
7070
"directory": directory,
71-
"message": f'在目录 "{directory}" 中找到 {len(json_files)} 个JSON文件',
71+
"message": f'Found {len(json_files)} JSON files in directory "{directory}"',
7272
}
7373
)
7474
except PermissionError:
75-
return jsonify({"error": f"没有权限访问目录: {directory}"}), 403
75+
return jsonify(
76+
{"error": f"No permission to access directory: {directory}"}
77+
), 403
7678
except Exception as e:
77-
return jsonify({"error": f"读取目录失败: {str(e)}"}), 500
79+
return jsonify({"error": f"Failed to read directory: {str(e)}"}), 500
7880

7981
except Exception as e:
8082
return jsonify({"error": str(e)}), 500
8183

8284

8385
@app.route("/api/load_trace", methods=["POST"])
8486
def load_trace():
85-
"""加载trace文件"""
87+
"""Load trace file"""
8688
global analyzer
8789

8890
data = request.get_json()
8991
file_path = data.get("file_path")
9092

9193
if not file_path:
92-
return jsonify({"error": "请提供文件路径"}), 400
94+
return jsonify({"error": "Please provide file path"}), 400
9395

94-
# 如果是相对路径,转换为绝对路径
96+
# If it's a relative path, convert to absolute path
9597
if not os.path.isabs(file_path):
9698
file_path = os.path.abspath(file_path)
9799

98100
if not os.path.exists(file_path):
99-
return jsonify({"error": f"文件不存在: {file_path}"}), 404
101+
return jsonify({"error": f"File does not exist: {file_path}"}), 404
100102

101103
try:
102104
analyzer = TraceAnalyzer(file_path)
103105
return jsonify(
104106
{
105-
"message": "文件加载成功",
107+
"message": "File loaded successfully",
106108
"file_path": file_path,
107109
"file_name": os.path.basename(file_path),
108110
}
109111
)
110112
except Exception as e:
111-
return jsonify({"error": f"加载文件失败: {str(e)}"}), 500
113+
return jsonify({"error": f"Failed to load file: {str(e)}"}), 500
112114

113115

114116
@app.route("/api/basic_info")
115117
def get_basic_info():
116-
"""获取基本信息"""
118+
"""Get basic information"""
117119
if not analyzer:
118-
return jsonify({"error": "请先加载trace文件"}), 400
120+
return jsonify({"error": "Please load trace file first"}), 400
119121

120122
try:
121123
return jsonify(analyzer.get_basic_info())
@@ -125,9 +127,9 @@ def get_basic_info():
125127

126128
@app.route("/api/performance_summary")
127129
def get_performance_summary():
128-
"""获取性能摘要"""
130+
"""Get performance summary"""
129131
if not analyzer:
130-
return jsonify({"error": "请先加载trace文件"}), 400
132+
return jsonify({"error": "Please load trace file first"}), 400
131133

132134
try:
133135
return jsonify(analyzer.get_performance_summary())
@@ -137,9 +139,9 @@ def get_performance_summary():
137139

138140
@app.route("/api/execution_flow")
139141
def get_execution_flow():
140-
"""获取执行流程"""
142+
"""Get execution flow"""
141143
if not analyzer:
142-
return jsonify({"error": "请先加载trace文件"}), 400
144+
return jsonify({"error": "Please load trace file first"}), 400
143145

144146
try:
145147
return jsonify(analyzer.analyze_conversation_flow())
@@ -149,9 +151,9 @@ def get_execution_flow():
149151

150152
@app.route("/api/execution_summary")
151153
def get_execution_summary():
152-
"""获取执行摘要"""
154+
"""Get execution summary"""
153155
if not analyzer:
154-
return jsonify({"error": "请先加载trace文件"}), 400
156+
return jsonify({"error": "Please load trace file first"}), 400
155157

156158
try:
157159
return jsonify(analyzer.get_execution_summary())
@@ -161,9 +163,9 @@ def get_execution_summary():
161163

162164
@app.route("/api/spans_summary")
163165
def get_spans_summary():
164-
"""获取spans摘要"""
166+
"""Get spans summary"""
165167
if not analyzer:
166-
return jsonify({"error": "请先加载trace文件"}), 400
168+
return jsonify({"error": "Please load trace file first"}), 400
167169

168170
try:
169171
return jsonify(analyzer.get_spans_summary())
@@ -173,9 +175,9 @@ def get_spans_summary():
173175

174176
@app.route("/api/step_logs_summary")
175177
def get_step_logs_summary():
176-
"""获取步骤日志摘要"""
178+
"""Get step logs summary"""
177179
if not analyzer:
178-
return jsonify({"error": "请先加载trace文件"}), 400
180+
return jsonify({"error": "Please load trace file first"}), 400
179181

180182
try:
181183
return jsonify(analyzer.get_step_logs_summary())
@@ -185,15 +187,15 @@ def get_step_logs_summary():
185187

186188
@app.route("/api/debug/raw_messages")
187189
def get_raw_messages():
188-
"""获取原始消息数据用于调试"""
190+
"""Get raw message data for debugging"""
189191
if not analyzer:
190-
return jsonify({"error": "请先加载trace文件"}), 400
192+
return jsonify({"error": "Please load trace file first"}), 400
191193

192194
try:
193195
main_history = analyzer.get_main_agent_history()
194196
browser_sessions = analyzer.get_browser_agent_sessions()
195197

196-
# 获取消息结构概览
198+
# Get message structure overview
197199
main_messages = analyzer.get_main_agent_messages()
198200
message_structure = []
199201

@@ -220,7 +222,7 @@ def get_raw_messages():
220222
"raw_main_history": main_history,
221223
"raw_browser_sessions": {
222224
k: v for k, v in list(browser_sessions.items())[:2]
223-
}, # 只显示前两个会话
225+
}, # Only show first two sessions
224226
}
225227
)
226228
except Exception as e:

0 commit comments

Comments
 (0)