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

Method prepare_llm_request

crates/core/src/plugins/nemo_guardrails/python.rs:172–201  ·  view source on GitHub ↗
(
        &self,
        request: LlmRequest,
        enable_input: bool,
    )

Source from the content-addressed store, hash-verified

170 }
171
172 async fn prepare_llm_request(
173 &self,
174 request: LlmRequest,
175 enable_input: bool,
176 ) -> FlowResult<(LlmRequest, Vec<Json>)> {
177 let codec = self.codec()?;
178 let mut current_request = request;
179 let mut annotated = codec.decode(&current_request)?;
180 let mut messages = messages_from_annotated(&annotated)?;
181
182 if enable_input {
183 match self
184 .bridge
185 .check(messages.clone(), LocalRailKind::Input)
186 .await?
187 {
188 LocalCheckOutcome::Passed => {}
189 LocalCheckOutcome::Blocked { rail, .. } => {
190 return Err(blocked_error("input", rail.as_deref()));
191 }
192 LocalCheckOutcome::Modified { content, .. } => {
193 replace_last_role_content(&mut annotated, "user", content)?;
194 current_request = codec.encode(&annotated, &current_request)?;
195 messages = messages_from_annotated(&annotated)?;
196 }
197 }
198 }
199
200 Ok((current_request, messages))
201 }
202
203 async fn check_output_rails(&self, messages: &[Json], response_text: &str) -> FlowResult<()> {
204 let mut output_messages = messages.to_vec();

Callers 2

execute_llmMethod · 0.80
execute_llm_streamMethod · 0.80

Calls 7

messages_from_annotatedFunction · 0.85
blocked_errorFunction · 0.85
codecMethod · 0.80
decodeMethod · 0.65
encodeMethod · 0.65
checkMethod · 0.45

Tested by

no test coverage detected