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

Function test_generate_and_chat_branches

tests/entrypoints/test_llm.py:155–187  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

153
154
155def test_generate_and_chat_branches():
156 llm = _make_llm(_make_engine(is_master=False))
157 llm._check_master = lambda: False
158 with pytest.raises(ValueError, match="master node"):
159 llm.generate("hi")
160
161 llm = _make_llm(_make_engine())
162 llm._check_master = lambda: True
163 llm._run_engine_stream = lambda *_, **__: "streamed"
164 llm._add_request = lambda **_: ["r1"]
165 with pytest.raises(ValueError, match="input dict"):
166 llm.generate({"x": 1}, sampling_params=SamplingParams(max_tokens=1), use_tqdm=False)
167 assert llm.generate("hi", sampling_params=SamplingParams(max_tokens=1), use_tqdm=False, stream=True) == "streamed"
168
169 llm._check_master = lambda: False
170 with pytest.raises(ValueError, match="master node"):
171 llm.chat(messages=[[{"role": "user", "content": "hi"}]], sampling_params=SamplingParams(), use_tqdm=False)
172
173 llm._check_master = lambda: True
174 llm._validate_tools = lambda *_: (_ for _ in ()).throw(ValueError("bad tools"))
175 with pytest.raises(RuntimeError, match="Failed to validate"):
176 llm.chat(
177 messages=[[{"role": "user", "content": "hi"}]], tools=1, sampling_params=SamplingParams(), use_tqdm=False
178 )
179 assert (
180 llm.chat(
181 messages=[[{"role": "user", "content": "hi"}]],
182 sampling_params=SamplingParams(max_tokens=1),
183 use_tqdm=False,
184 stream=True,
185 )
186 == "streamed"
187 )
188
189
190def test_add_request_validations_and_guided_decoding(monkeypatch):

Callers

nothing calls this directly

Calls 5

SamplingParamsClass · 0.90
_make_llmFunction · 0.85
_make_engineFunction · 0.85
chatMethod · 0.80
generateMethod · 0.45

Tested by

no test coverage detected