MCPcopy Create free account
hub / github.com/NVIDIA/NeMo-Relay / test_pipeline_with_codec

Method test_pipeline_with_codec

python/tests/test_codecs.py:254–287  ·  view source on GitHub ↗

Full pipeline: pass codec instance directly + annotated intercept, execute LLM call.

(self)

Source from the content-addressed store, hash-verified

252
253class TestCodecPipeline:
254 async def test_pipeline_with_codec(self):
255 """Full pipeline: pass codec instance directly + annotated intercept, execute LLM call."""
256 codec = SimpleCodec()
257
258 intercept_called = []
259
260 def annotated_intercept(name, request, annotated):
261 intercept_called.append(True)
262 assert annotated is not None
263 assert isinstance(annotated, AnnotatedLLMRequest)
264 # Add a system message via the annotated request
265 new_messages = [
266 {"role": "system", "content": "injected by intercept"},
267 *annotated.messages,
268 ]
269 annotated.messages = new_messages
270 return (request, annotated)
271
272 intercepts.register_llm_request("test-annot-intercept-pipeline", 1, False, annotated_intercept)
273
274 try:
275
276 def func(request):
277 return {"messages": request.content.get("messages", []), "model": request.content.get("model")}
278
279 request = make_request()
280 result = await llm.execute("pipeline-llm", request, func, codec=codec)
281
282 assert len(intercept_called) == 1
283 # The encode step should have written modified messages back
284 assert result["messages"][0]["role"] == "system"
285 assert result["messages"][0]["content"] == "injected by intercept"
286 finally:
287 intercepts.deregister_llm_request("test-annot-intercept-pipeline")
288
289 async def test_codec_parameter(self):
290 """codec parameter passes the specified codec instance directly."""

Callers

nothing calls this directly

Calls 3

SimpleCodecClass · 0.70
make_requestFunction · 0.70
executeMethod · 0.45

Tested by

no test coverage detected