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

Function split_json_or_future

crates/python/src/py_callable.rs:48–61  ·  view source on GitHub ↗
(
    py: Python<'_>,
    result: Py<PyAny>,
)

Source from the content-addressed store, hash-verified

46type PyValueFuture = Pin<Box<dyn Future<Output = PyResult<Py<PyAny>>> + Send>>;
47
48fn split_json_or_future(
49 py: Python<'_>,
50 result: Py<PyAny>,
51) -> FlowResult<Result<Json, PyValueFuture>> {
52 let bound = result.bind(py);
53 if bound.getattr("__await__").is_ok() {
54 let future = pyo3_async_runtimes::tokio::into_future(result.into_bound(py))
55 .map_err(|e| FlowError::Internal(e.to_string()))?;
56 Ok(Err(Box::pin(future) as PyValueFuture))
57 } else {
58 let json = py_to_json(bound).map_err(|e: PyErr| FlowError::Internal(e.to_string()))?;
59 Ok(Ok(json))
60 }
61}
62
63async fn resolve_json_or_future(
64 outcome: FlowResult<Result<Json, PyValueFuture>>,

Callers 1

wrap_py_llm_exec_fnFunction · 0.85

Calls 1

py_to_jsonFunction · 0.85

Tested by

no test coverage detected