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

Method decode_response

crates/python/src/py_callable.rs:959–985  ·  view source on GitHub ↗
(&self, response: &Json)

Source from the content-addressed store, hash-verified

957
958impl LlmResponseCodec for PyLlmResponseCodecWrapper {
959 fn decode_response(&self, response: &Json) -> FlowResult<AnnotatedLLMResponse> {
960 Python::attach(|py| {
961 let py_resp = json_to_py(py, response).map_err(|e| {
962 FlowError::Internal(format!(
963 "Response codec: failed to convert JSON to Python: {e}"
964 ))
965 })?;
966 let result = self
967 .py_codec
968 .call_method1(py, "decode_response", (py_resp,))
969 .map_err(|e| {
970 FlowError::Internal(format!("Response codec decode_response() failed: {e}"))
971 })?;
972 // PyAnnotatedLLMResponse has skip_from_py_object, so use downcast
973 // on the bound reference instead of extract.
974 let bound = result.bind(py);
975 let py_ref: pyo3::PyRef<'_, PyAnnotatedLLMResponse> = bound
976 .cast::<PyAnnotatedLLMResponse>()
977 .map_err(|e| {
978 FlowError::Internal(format!(
979 "Response codec decode_response() returned unexpected type (expected AnnotatedLLMResponse): {e}"
980 ))
981 })?
982 .borrow();
983 Ok(py_ref.inner.clone())
984 })
985 }
986}
987
988#[cfg(test)]

Callers

nothing calls this directly

Calls 1

json_to_pyFunction · 0.85

Tested by

no test coverage detected