MCPcopy Create free account
hub / github.com/PaddlePaddle/FastDeploy / test_unstream_with_logprobs

Function test_unstream_with_logprobs

tests/ce/server/test_logprobs.py:6–38  ·  view source on GitHub ↗

测试非流式响应开启 logprobs 后,返回的 token 概率信息是否正确。

()

Source from the content-addressed store, hash-verified

4
5
6def test_unstream_with_logprobs():
7 """
8 测试非流式响应开启 logprobs 后,返回的 token 概率信息是否正确。
9 """
10 data = {
11 "stream": False,
12 "messages": [
13 {"role": "system", "content": "You are a helpful assistant."},
14 {"role": "user", "content": "牛顿的三大运动定律是什么?"},
15 ],
16 "max_tokens": 3,
17 }
18
19 # 构建请求并发送
20 payload = build_request_payload(TEMPLATE, data)
21 response = send_request(URL, payload)
22 print(json.dumps(response.json(), indent=2, ensure_ascii=False))
23 resp_json = response.json()
24
25 # 校验返回内容与概率信息
26 assert resp_json["choices"][0]["message"]["content"] == "牛顿的"
27 assert resp_json["choices"][0]["logprobs"]["content"][0]["token"] == "牛顿"
28 assert resp_json["choices"][0]["logprobs"]["content"][0]["logprob"] == -0.031025361269712448
29 assert resp_json["choices"][0]["logprobs"]["content"][0]["top_logprobs"][0] == {
30 "token": "牛顿",
31 "logprob": -0.031025361269712448,
32 "bytes": [231, 137, 155, 233, 161, 191],
33 "top_logprobs": None,
34 }
35
36 assert resp_json["usage"]["prompt_tokens"] == 22
37 assert resp_json["usage"]["completion_tokens"] == 3
38 assert resp_json["usage"]["total_tokens"] == 25
39
40
41def test_unstream_without_logprobs():

Callers 1

test_logprobs.pyFile · 0.85

Calls 3

build_request_payloadFunction · 0.90
send_requestFunction · 0.90
printFunction · 0.85

Tested by

no test coverage detected