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

Function llm_call_execute

crates/python/src/py_api/mod.rs:711–762  ·  view source on GitHub ↗
(
    py: Python<'py>,
    name: String,
    request: PyLLMRequest,
    func: Py<PyAny>,
    handle: Option<PyScopeHandle>,
    attributes: Option<PyLLMAttributes>,
    data: Option<&Bound<'py, PyAny>

Source from the content-addressed store, hash-verified

709) -> "object", text_signature = "(name: str, request: LlmRequest, func: object, *, handle: ScopeHandle | None = None, attributes: LlmAttributes | None = None, data: object | None = None, metadata: object | None = None, model_name: str | None = None, codec: object | None = None, response_codec: object | None = None) -> object")]
710#[allow(clippy::too_many_arguments)]
711fn llm_call_execute<'py>(
712 py: Python<'py>,
713 name: String,
714 request: PyLLMRequest,
715 func: Py<PyAny>,
716 handle: Option<PyScopeHandle>,
717 attributes: Option<PyLLMAttributes>,
718 data: Option<&Bound<'py, PyAny>>,
719 metadata: Option<&Bound<'py, PyAny>>,
720 model_name: Option<String>,
721 codec: Option<&Bound<'py, PyAny>>,
722 response_codec: Option<&Bound<'py, PyAny>>,
723) -> PyResult<Bound<'py, PyAny>> {
724 let attrs = attributes
725 .map(|a| a.inner)
726 .unwrap_or(LlmAttributes::empty());
727 let data_json = opt_py_to_json(data)?;
728 let metadata_json = opt_py_to_json(metadata)?;
729 let exec_fn = py_callable::wrap_py_llm_exec_fn(func);
730 let default_fn: LlmExecutionNextFn = Arc::new(move |req| exec_fn(req));
731 let parent_handle = handle.map(|h| h.inner).unwrap_or_else(task_scope_top);
732 let codec_arc: Option<Arc<dyn LlmCodec>> = codec.map(|c| {
733 Arc::new(py_callable::PyLlmCodecWrapper {
734 py_codec: c.clone().unbind(),
735 }) as Arc<dyn LlmCodec>
736 });
737 let response_codec_arc = py_llm_response_codec(response_codec);
738
739 let scope_stack = current_scope_stack_handle();
740 pyo3_async_runtimes::tokio::future_into_py(py, async move {
741 TASK_SCOPE_STACK
742 .scope(scope_stack, async move {
743 let params = core_llm_api::LlmCallExecuteParams::builder()
744 .name(name)
745 .request(request.inner)
746 .func(default_fn)
747 .parent(parent_handle)
748 .attributes(attrs)
749 .data_opt(data_json)
750 .metadata_opt(metadata_json)
751 .model_name_opt(model_name)
752 .codec_opt(codec_arc)
753 .response_codec_opt(response_codec_arc)
754 .build();
755 let result = core_llm_api::llm_call_execute(params)
756 .await
757 .map_err(to_py_err)?;
758 Python::attach(|py| json_to_py(py, &result))
759 })
760 .await
761 })
762}
763
764/// Execute a streaming LLM call through the full middleware pipeline.
765///

Calls 9

opt_py_to_jsonFunction · 0.85
wrap_py_llm_exec_fnFunction · 0.85
py_llm_response_codecFunction · 0.85
json_to_pyFunction · 0.85
requestMethod · 0.80
buildMethod · 0.45
attributesMethod · 0.45
funcMethod · 0.45
nameMethod · 0.45