Stream a request using the long-lived object-shaped API.
(
&self,
py: Python<'_>,
request: &Bound<'_, PyDict>,
)
| 1701 | |
| 1702 | /// Stream a request using the long-lived object-shaped API. |
| 1703 | fn stream_request( |
| 1704 | &self, |
| 1705 | py: Python<'_>, |
| 1706 | request: &Bound<'_, PyDict>, |
| 1707 | ) -> PyResult<PyEventStream> { |
| 1708 | let (prompt, rust_history, rust_attachments) = py_session_request_to_parts(request)?; |
| 1709 | let session = self.inner.clone(); |
| 1710 | |
| 1711 | let (rx, _handle) = if rust_attachments.is_empty() { |
| 1712 | py.allow_threads(move || { |
| 1713 | get_runtime().block_on(session.stream(&prompt, rust_history.as_deref())) |
| 1714 | }) |
| 1715 | } else { |
| 1716 | py.allow_threads(move || { |
| 1717 | get_runtime().block_on(session.stream_with_attachments( |
| 1718 | &prompt, |
| 1719 | &rust_attachments, |
| 1720 | rust_history.as_deref(), |
| 1721 | )) |
| 1722 | }) |
| 1723 | } |
| 1724 | .map_err(|e| PyRuntimeError::new_err(format!("Failed to start stream: {e}")))?; |
| 1725 | |
| 1726 | Ok(PyEventStream { |
| 1727 | rx: Arc::new(Mutex::new(rx)), |
| 1728 | done: Arc::new(AtomicBool::new(false)), |
| 1729 | }) |
| 1730 | } |
| 1731 | |
| 1732 | /// Send a prompt with image attachments and wait for the complete response. |
| 1733 | /// |
nothing calls this directly
no test coverage detected