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

Function infer

tests/ce/server/test_update_weight.py:60–112  ·  view source on GitHub ↗

发送推理请求 1. 根据 expect_success 参数判断是否预期成功 2. 响应 HTTP 状态码 !=200 或返回 error 时: - expect_success=True -> 抛出断言 - expect_success=False -> 通过 3. 响应正常包含 choices 时: - expect_success=True -> 通过 - expect_success=False -> 抛出断言

(expect_success=True)

Source from the content-addressed store, hash-verified

58
59
60def infer(expect_success=True):
61 """
62 发送推理请求
63 1. 根据 expect_success 参数判断是否预期成功
64 2. 响应 HTTP 状态码 !=200 或返回 error 时:
65 - expect_success=True -> 抛出断言
66 - expect_success=False -> 通过
67 3. 响应正常包含 choices 时:
68 - expect_success=True -> 通过
69 - expect_success=False -> 抛出断言
70 """
71 try:
72 resp = requests.post(
73 f"{BASE_URL}/v1/chat/completions",
74 json={
75 "messages": [{"role": "user", "content": "hello"}],
76 "temperature": 0,
77 "top_p": 0,
78 "seed": 33,
79 "min_tokens": 1366,
80 "max_tokens": 1369,
81 "stream": False,
82 },
83 timeout=16,
84 )
85 print("infer:", resp.status_code, resp.text)
86
87 assert resp.status_code == 200, f"Infer HTTP status not 200: {resp.status_code}"
88
89 data = resp.json()
90
91 if "error" in data:
92 print("infer returned error:", data["error"]["message"])
93 if expect_success:
94 raise AssertionError(f"Infer expected success, but got error: {data['error']['message']}")
95 else:
96 return resp
97
98 if "choices" in data:
99 if not expect_success:
100 raise AssertionError("Infer expected failure, but succeeded")
101 print("infer succeeded as expected")
102 else:
103 raise AssertionError(f"Infer response missing 'choices': {data}")
104
105 return resp
106
107 except Exception as e:
108 if expect_success:
109 raise
110 else:
111 print("infer failed as expected:", e)
112 return None
113
114
115# ---------------------------

Callers 3

test_exception_scenarioFunction · 0.85
test_concurrentFunction · 0.85
test_exception_scenario1Function · 0.85

Calls 1

printFunction · 0.85

Tested by

no test coverage detected