forked from trpc-group/trpc-agent-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_pass_at_k.py
More file actions
38 lines (34 loc) · 1.36 KB
/
Copy pathtest_pass_at_k.py
File metadata and controls
38 lines (34 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# -*- coding: utf-8 -*-
#
# Copyright @ 2025 Tencent.com
"""pass@k / pass^k 示例:多轮运行后计算 pass@1、pass@5、pass^2。"""
import os
import pytest
from trpc_agent_sdk.evaluation import AgentEvaluator
@pytest.mark.asyncio
async def test_pass_at_k():
"""多轮运行后解析 (n, c),计算 pass@k 与 pass^k。"""
test_dir = os.path.dirname(os.path.abspath(__file__))
eval_set_path = os.path.join(test_dir, "agent", "weather_agent.evalset.json")
# test_config.json 中已配置 num_runs: 5,会跑 5 轮
executer = AgentEvaluator.get_executer(
agent_module="agent",
agent_name="weather_agent",
eval_dataset_file_path_or_dir=eval_set_path,
print_detailed_results=True,
)
try:
await executer.evaluate()
finally:
result = executer.get_result()
if result is not None:
nc_by_set = AgentEvaluator.parse_pass_nc(result)
for eval_set_id, nc in nc_by_set.items():
n, c = nc.n, nc.c
pass_1 = AgentEvaluator.pass_at_k(n, c, 1)
pass_5 = AgentEvaluator.pass_at_k(n, c, 5)
pass_hat_2 = AgentEvaluator.pass_hat_k(n, c, 2)
print(
f"EvalSet {eval_set_id}: n={n}, c={c}, "
f"pass@1={pass_1:.4f}, pass@5={pass_5:.4f}, pass^2={pass_hat_2:.4f}"
)