(
&self,
py: Python<'_>,
prompt: &Bound<'_, PyAny>,
history: Option<&Bound<'_, PyList>>,
)
| 1645 | /// history: Optional conversation history (same format as send) |
| 1646 | #[pyo3(signature = (prompt, history=None))] |
| 1647 | fn stream( |
| 1648 | &self, |
| 1649 | py: Python<'_>, |
| 1650 | prompt: &Bound<'_, PyAny>, |
| 1651 | history: Option<&Bound<'_, PyList>>, |
| 1652 | ) -> PyResult<PyEventStream> { |
| 1653 | let (prompt, rust_history, rust_attachments) = py_session_input_to_parts(prompt, history)?; |
| 1654 | let session = self.inner.clone(); |
| 1655 | let (rx, _handle) = if rust_attachments.is_empty() { |
| 1656 | py.allow_threads(move || { |
| 1657 | get_runtime().block_on(session.stream(&prompt, rust_history.as_deref())) |
| 1658 | }) |
| 1659 | } else { |
| 1660 | py.allow_threads(move || { |
| 1661 | get_runtime().block_on(session.stream_with_attachments( |
| 1662 | &prompt, |
| 1663 | &rust_attachments, |
| 1664 | rust_history.as_deref(), |
| 1665 | )) |
| 1666 | }) |
| 1667 | } |
| 1668 | .map_err(|e| PyRuntimeError::new_err(format!("Failed to start stream: {e}")))?; |
| 1669 | |
| 1670 | Ok(PyEventStream { |
| 1671 | rx: Arc::new(Mutex::new(rx)), |
| 1672 | done: Arc::new(AtomicBool::new(false)), |
| 1673 | }) |
| 1674 | } |
| 1675 | |
| 1676 | /// Send a request using the long-lived object-shaped API. |
| 1677 | /// |
no test coverage detected