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

Function llm_call_execute

crates/wasm/src/api/mod.rs:878–943  ·  view source on GitHub ↗
(
    name: &str,
    #[wasm_bindgen(unchecked_param_type = "Json")] request: JsValue,
    #[wasm_bindgen(unchecked_param_type = "(arg: Json) => any")] func: Function,
    #[wasm_bindgen(unchecked_par

Source from the content-addressed store, hash-verified

876#[allow(non_snake_case)]
877#[wasm_bindgen(js_name = "llmCallExecute", unchecked_return_type = "unknown")]
878pub async fn llm_call_execute(
879 name: &str,
880 #[wasm_bindgen(unchecked_param_type = "Json")] request: JsValue,
881 #[wasm_bindgen(unchecked_param_type = "(arg: Json) => any")] func: Function,
882 #[wasm_bindgen(unchecked_param_type = "ScopeHandle | null | undefined")] handle: JsValue,
883 attributes: Option<u32>,
884 #[wasm_bindgen(unchecked_param_type = "Json | null | undefined")] data: JsValue,
885 #[wasm_bindgen(unchecked_param_type = "Json | null | undefined")] metadata: JsValue,
886 #[wasm_bindgen(
887 js_name = "modelName",
888 unchecked_param_type = "string | null | undefined"
889 )]
890 model_name: Option<String>,
891 #[wasm_bindgen(
892 js_name = "codecDecode",
893 unchecked_param_type = "((arg: Json) => any) | null | undefined"
894 )]
895 codec_decode: Option<Function>,
896 #[wasm_bindgen(
897 js_name = "codecEncode",
898 unchecked_param_type = "((arg: Json) => any) | null | undefined"
899 )]
900 codec_encode: Option<Function>,
901 #[wasm_bindgen(
902 js_name = "responseCodecDecode",
903 unchecked_param_type = "((arg: Json) => any) | null | undefined"
904 )]
905 response_codec_decode: Option<Function>,
906) -> Result<JsValue, JsValue> {
907 let request_json = js_to_json(&request)?;
908 let llm_request: CoreLlmRequest = serde_json::from_value(request_json)
909 .map_err(|e| to_js_err(FlowError::Internal(e.to_string())))?;
910 let attrs = LlmAttributes::from_bits_truncate(attributes.unwrap_or(0));
911 let parent_handle = clone_scope_handle_arg(&handle)?.unwrap_or_else(task_scope_top);
912 let exec_fn = callable::wrap_js_llm_exec_fn(func);
913 let default_fn: LlmExecutionNextFn = Arc::new(move |request| exec_fn(request));
914 let codec = match (codec_decode, codec_encode) {
915 (Some(d), Some(e)) => Some(callable::wrap_js_codec(d, e)),
916 _ => None,
917 };
918 let response_codec = response_codec_decode.map(callable::wrap_js_response_codec);
919
920 let scope_stack = current_scope_stack_handle();
921 let data_json = opt_js_to_json(&data)?;
922 let metadata_json = opt_js_to_json(&metadata)?;
923 let result = TASK_SCOPE_STACK
924 .scope(scope_stack, async move {
925 let params = relay_llm_api::LlmCallExecuteParams::builder()
926 .name(name)
927 .request(llm_request)
928 .func(default_fn)
929 .parent(parent_handle)
930 .attributes(attrs)
931 .data_opt(data_json)
932 .metadata_opt(metadata_json)
933 .model_name_opt(model_name)
934 .codec_opt(codec)
935 .response_codec_opt(response_codec)

Calls 12

js_to_jsonFunction · 0.85
to_js_errFunction · 0.85
clone_scope_handle_argFunction · 0.85
opt_js_to_jsonFunction · 0.85
json_to_jsFunction · 0.85
requestMethod · 0.80
wrap_js_llm_exec_fnFunction · 0.50
wrap_js_codecFunction · 0.50
buildMethod · 0.45
attributesMethod · 0.45
funcMethod · 0.45
nameMethod · 0.45