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

Method build_cache_request_facts

crates/python/src/py_adaptive.rs:172–208  ·  view source on GitHub ↗
(
        &self,
        py: Python<'_>,
        provider: &str,
        request_id: &str,
        annotated_request: &Bound<'_, PyAny>,
        agent_id: &str,
        timestamp: Option<&str>,
    )

Source from the content-addressed store, hash-verified

170 text_signature = "($self, *, provider: str, request_id: str, annotated_request: object, agent_id: str, timestamp: str | None = None) -> dict | None"
171 )]
172 fn build_cache_request_facts(
173 &self,
174 py: Python<'_>,
175 provider: &str,
176 request_id: &str,
177 annotated_request: &Bound<'_, PyAny>,
178 agent_id: &str,
179 timestamp: Option<&str>,
180 ) -> PyResult<Py<PyAny>> {
181 let _request_id = parse_cache_telemetry_request_id(request_id)?;
182 let _timestamp = parse_cache_telemetry_timestamp(timestamp)?;
183 let annotated_request = parse_annotated_request(annotated_request)?;
184 let guard = self.inner.try_lock().map_err(|_| {
185 pyo3::exceptions::PyRuntimeError::new_err(
186 "adaptive runtime is locked by an async operation; try again after await completes",
187 )
188 })?;
189 let state = guard.as_ref().ok_or_else(|| {
190 pyo3::exceptions::PyRuntimeError::new_err("adaptive runtime already shut down")
191 })?;
192 let Some(facts) = (match state {
193 PyAdaptiveRuntimeState::Pending { .. } => {
194 return Err(pyo3::exceptions::PyRuntimeError::new_err(
195 "adaptive runtime must be registered before building cache request facts",
196 ));
197 }
198 PyAdaptiveRuntimeState::Ready(runtime) => {
199 runtime.build_cache_request_facts(agent_id, provider, &annotated_request)
200 }
201 }) else {
202 return Ok(py.None());
203 };
204
205 let facts = serde_json::to_value(&facts)
206 .map_err(|e| pyo3::exceptions::PyRuntimeError::new_err(e.to_string()))?;
207 json_to_py(py, &facts)
208 }
209
210 #[pyo3(signature = (scope_handle), text_signature = "($self, scope_handle: ScopeHandle) -> None")]
211 fn bind_scope(&self, scope_handle: &PyScopeHandle) -> PyResult<()> {

Callers

nothing calls this directly

Calls 4

parse_annotated_requestFunction · 0.85
json_to_pyFunction · 0.85

Tested by

no test coverage detected