Skip to content

Commit 7f33f08

Browse files
authored
feat(uploadevalset): upload evalset (#244)
* feat(uploadevalset): upload evalset * update(docs): update docs
1 parent 4e950f1 commit 7f33f08

File tree

4 files changed

+142
-0
lines changed

4 files changed

+142
-0
lines changed

docs/content/90.cli/1.overview.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ VeADK 提供如下命令便捷您的操作:
1515
| `veadk web` | 支持长短期记忆、知识库的前端调试界面 | 兼容 Google ADK web |
1616
| `veadk eval` | 支持不同后端的评测 | 评测后端包括 `adk``deepeval`,评测数据集源包括 Google ADK 评测集格式文件,以及 Tracing 文件 |
1717
| `veadk kb` | 知识库相关操作 | 向知识库添加本地文件或目录 |
18+
| `veadk uploadevalset` | 评测集相关操作 | 向Cozeloop推送评测数据集 |

docs/content/90.cli/2.commands.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,17 @@ response = asyncio.run(
126126

127127
print(response) # Your ID is 20250101.
128128
```
129+
130+
## 评测集上传
131+
132+
将评测集上传到 CozeLoop 平台:
133+
134+
```bash
135+
# cozeloop-workspace-id, cozeloop-evalset-id, cozeloop-api-key可从从环境变量中读取
136+
veadk uploadevalset --file <评测集JSON文件路径> ---cozeloop-workspace-id <CozeLoop工作空间ID> --cozeloop-evalset-id <CozeLoop评测集ID> --cozeloop-api-key <CozeLoop API Key>
137+
```
138+
139+
环境变量配置:
140+
- `OBSERVABILITY_OPENTELEMETRY_COZELOOP_SERVICE_NAME`: 工作空间ID
141+
- `OBSERVABILITY_OPENTELEMETRY_COZELOOP_EVALSET_ID`: 评测集ID
142+
- `OBSERVABILITY_OPENTELEMETRY_COZELOOP_API_KEY`: API Key

veadk/cli/cli.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from veadk.cli.cli_pipeline import pipeline
2323
from veadk.cli.cli_prompt import prompt
2424
from veadk.cli.cli_web import web
25+
from veadk.cli.cli_uploadevalset import uploadevalset
2526
from veadk.version import VERSION
2627

2728

@@ -41,6 +42,7 @@ def veadk():
4142
veadk.add_command(pipeline)
4243
veadk.add_command(eval)
4344
veadk.add_command(kb)
45+
veadk.add_command(uploadevalset)
4446

4547
if __name__ == "__main__":
4648
veadk()

veadk/cli/cli_uploadevalset.py

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
# Copyright (c) 2025 Beijing Volcano Engine Technology Co., Ltd. and/or its affiliates.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import click
16+
import json
17+
import requests
18+
from veadk.utils.logger import get_logger
19+
from veadk.config import getenv
20+
from pathlib import Path
21+
22+
logger = get_logger(__name__)
23+
24+
25+
@click.command()
26+
@click.option("--file", required=True, help="JSON file path containing dataset items")
27+
@click.option("--cozeloop-workspace-id", default=None, help="CozeLoop workspace ID")
28+
@click.option("--cozeloop-evalset-id", default=None, help="CozeLoop evaluation set ID")
29+
@click.option(
30+
"--cozeloop-api-key",
31+
default=None,
32+
help="CozeLoop API key (or set COZELOOP_API_KEY env var)",
33+
)
34+
def uploadevalset(
35+
file: str,
36+
cozeloop_workspace_id: str,
37+
cozeloop_evalset_id: str,
38+
cozeloop_api_key: str,
39+
) -> None:
40+
"""Upload dataset items to CozeLoop evaluation set."""
41+
42+
if not cozeloop_workspace_id:
43+
cozeloop_workspace_id = getenv(
44+
"OBSERVABILITY_OPENTELEMETRY_COZELOOP_SERVICE_NAME"
45+
)
46+
if not cozeloop_evalset_id:
47+
cozeloop_evalset_id = getenv("OBSERVABILITY_OPENTELEMETRY_COZELOOP_EVALSET_ID")
48+
if not cozeloop_api_key:
49+
cozeloop_api_key = getenv("OBSERVABILITY_OPENTELEMETRY_COZELOOP_API_KEY")
50+
51+
# Read JSON file
52+
file_path = Path(file)
53+
if not file_path.exists():
54+
logger.error(f"File not found: {file}")
55+
return
56+
57+
logger.info(f"Reading dataset from {file}")
58+
with open(file_path, "r", encoding="utf-8") as f:
59+
data = json.load(f)
60+
61+
# Prepare items
62+
items = []
63+
for case in data.get("eval_cases", []):
64+
conversation = case.get("conversation", [])
65+
for turn in conversation:
66+
user_text = (
67+
turn.get("user_content", {}).get("parts", [{}])[0].get("text", "")
68+
)
69+
output_text = (
70+
turn.get("final_response", {}).get("parts", [{}])[0].get("text", "")
71+
)
72+
73+
items.append(
74+
{
75+
"turns": [
76+
{
77+
"field_datas": [
78+
{
79+
"name": "input",
80+
"content": {
81+
"content_type": "Text",
82+
"text": user_text,
83+
},
84+
},
85+
{
86+
"name": "output",
87+
"content": {
88+
"content_type": "Text",
89+
"text": output_text,
90+
},
91+
},
92+
]
93+
}
94+
]
95+
}
96+
)
97+
98+
# Upload to CozeLoop
99+
url = f"https://api.coze.cn/v1/loop/evaluation/evaluation_sets/{cozeloop_evalset_id}/items"
100+
logger.info(
101+
f"Uploading {len(items)} items to workspace_id={cozeloop_workspace_id} evalset_id={cozeloop_evalset_id}"
102+
)
103+
104+
response = requests.post(
105+
url=url,
106+
headers={
107+
"Authorization": f"Bearer {cozeloop_api_key}",
108+
"Content-Type": "application/json",
109+
"X-TT-ENV": "ppe_eval_openapi",
110+
"x-use-ppe": "1",
111+
},
112+
json={
113+
"workspace_id": cozeloop_workspace_id,
114+
"is_allow_partial_add": True,
115+
"is_skip_invalid_items": True,
116+
"items": items,
117+
},
118+
)
119+
120+
if response.status_code == 200:
121+
logger.info(
122+
f"Successfully uploaded dataset to CozeLoop evalset {cozeloop_evalset_id}"
123+
)
124+
else:
125+
logger.error(f"Failed to upload dataset: {response.text}")

0 commit comments

Comments
 (0)