42024409
tangwang
评估框架-批量打标
|
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
import pytest
import requests
from scripts.evaluation.eval_framework.clients import DashScopeLabelClient
from scripts.evaluation.eval_framework.utils import build_label_doc_line
def _http_error(status_code: int, body: str) -> requests.exceptions.HTTPError:
response = requests.Response()
response.status_code = status_code
response._content = body.encode("utf-8")
response.url = "https://dashscope-us.aliyuncs.com/compatible-mode/v1/chat/completions"
return requests.exceptions.HTTPError(f"{status_code} error", response=response)
def test_build_label_doc_line_truncates_long_fields():
doc = {
"title": {"en": "Minimalist Top " * 40},
"skus": [
{
"option1_value": "Very Long Color Name " * 10,
"option2_value": "Very Long Size Name " * 10,
"option3_value": "Very Long Material Name " * 10,
}
],
}
line = build_label_doc_line(1, doc)
assert line.startswith("1. ")
assert len(line) <= 260
assert line.endswith("...")
def test_dashscope_chat_does_not_retry_non_transient_400(monkeypatch):
client = DashScopeLabelClient(model="qwen3.5-plus", base_url="https://example.com", api_key="test")
client.retry_attempts = 4
client.retry_delay_sec = 0
calls = {"count": 0}
def fake_chat_sync(prompt: str):
calls["count"] += 1
raise _http_error(400, '{"code":"InvalidParameter"}')
monkeypatch.setattr(client, "_chat_sync", fake_chat_sync)
with pytest.raises(requests.exceptions.HTTPError):
client._chat("prompt", phase="relevance_classify")
assert calls["count"] == 1
def test_dashscope_chat_retries_transient_500(monkeypatch):
client = DashScopeLabelClient(model="qwen3.5-plus", base_url="https://example.com", api_key="test")
client.retry_attempts = 4
client.retry_delay_sec = 0
calls = {"count": 0}
def fake_chat_sync(prompt: str):
calls["count"] += 1
if calls["count"] < 3:
raise _http_error(500, '{"code":"InternalError"}')
|
42024409
tangwang
评估框架-批量打标
|
64
65
66
67
68
|
monkeypatch.setattr(client, "_chat_sync", fake_chat_sync)
content, raw = client._chat("prompt", phase="relevance_classify")
|