MCPcopy Create free account
hub / github.com/NVIDIA-NeMo/Switchyard / serve

Method serve

crates/libsy/src/core/algorithm.rs:767–797  ·  view source on GitHub ↗
(call: CallLlmRequest)

Source from the content-addressed store, hash-verified

765 )
766 )]
767 async fn serve(call: CallLlmRequest) -> Result<()> {
768 let span = tracing::Span::current();
769 observability::record_gen_ai_request(&span, &call.get_routed().request.llm_request);
770 if let Some(tier) = call.get_decision().routing_tier() {
771 span.record("switchyard.routing.tier", tier);
772 }
773 if let Some(session_id) = call
774 .get_routed()
775 .request
776 .metadata
777 .as_ref()
778 .and_then(|metadata| metadata.session_id.as_deref())
779 {
780 span.record("gen_ai.conversation.id", session_id);
781 }
782 let routed = call.get_routed().clone();
783 let target = routed.decision.selected_model().to_string();
784 let client =
785 routed
786 .default_client
787 .clone()
788 .ok_or_else(|| LibsyError::MissingClient {
789 target: target.clone(),
790 })?;
791 let result = client
792 .call(routed.ctx, routed.request, routed.decision)
793 .await
794 .map_err(|source| LibsyError::client_call(target, source));
795 let result = observability::observe_client_call(result);
796 call.respond(result)
797 }
798
799 let stream = self.run_stream(ctx, request, observer);
800 tokio::pin!(stream);

Callers

nothing calls this directly

Calls 9

observe_client_callFunction · 0.85
get_routedMethod · 0.80
get_decisionMethod · 0.80
record_gen_ai_requestFunction · 0.50
routing_tierMethod · 0.45
recordMethod · 0.45
selected_modelMethod · 0.45
callMethod · 0.45
respondMethod · 0.45

Tested by

no test coverage detected