(
annotated_response: Option<&Bound<'_, PyAny>>,
)
| 73 | } |
| 74 | |
| 75 | fn py_annotated_llm_response( |
| 76 | annotated_response: Option<&Bound<'_, PyAny>>, |
| 77 | ) -> PyResult<Option<Arc<AnnotatedLlmResponse>>> { |
| 78 | let Some(annotated_response) = annotated_response else { |
| 79 | return Ok(None); |
| 80 | }; |
| 81 | if annotated_response.is_none() { |
| 82 | return Ok(None); |
| 83 | } |
| 84 | |
| 85 | if let Ok(response) = annotated_response.cast::<PyAnnotatedLLMResponse>() { |
| 86 | let response = response.borrow(); |
| 87 | return Ok(Some(Arc::new(response.inner.clone()))); |
| 88 | } |
| 89 | |
| 90 | let value = py_to_json(annotated_response)?; |
| 91 | serde_json::from_value::<AnnotatedLlmResponse>(value) |
| 92 | .map(|response| Some(Arc::new(response))) |
| 93 | .map_err(|error| { |
| 94 | PyErr::new::<pyo3::exceptions::PyValueError, _>(format!( |
| 95 | "invalid annotated_response: {error}" |
| 96 | )) |
| 97 | }) |
| 98 | } |
| 99 | |
| 100 | pub(crate) async fn forward_stream_to_channel( |
| 101 | mut stream: RustJsonStream, |
no test coverage detected