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

Function py_annotated_llm_response

crates/python/src/py_api/mod.rs:75–98  ·  view source on GitHub ↗
(
    annotated_response: Option<&Bound<'_, PyAny>>,
)

Source from the content-addressed store, hash-verified

73}
74
75fn py_annotated_llm_response(
76 annotated_response: Option<&Bound<'_, PyAny>>,
77) -> PyResult<Option<Arc<AnnotatedLlmResponse>>> {
78 let Some(annotated_response) = annotated_response else {
79 return Ok(None);
80 };
81 if annotated_response.is_none() {
82 return Ok(None);
83 }
84
85 if let Ok(response) = annotated_response.cast::<PyAnnotatedLLMResponse>() {
86 let response = response.borrow();
87 return Ok(Some(Arc::new(response.inner.clone())));
88 }
89
90 let value = py_to_json(annotated_response)?;
91 serde_json::from_value::<AnnotatedLlmResponse>(value)
92 .map(|response| Some(Arc::new(response)))
93 .map_err(|error| {
94 PyErr::new::<pyo3::exceptions::PyValueError, _>(format!(
95 "invalid annotated_response: {error}"
96 ))
97 })
98}
99
100pub(crate) async fn forward_stream_to_channel(
101 mut stream: RustJsonStream,

Callers 1

llm_call_endFunction · 0.85

Calls 1

py_to_jsonFunction · 0.85

Tested by

no test coverage detected