MCPcopy Create free account
hub / github.com/AI45Lab/Code / stream_request

Method stream_request

sdk/python/src/lib.rs:1703–1730  ·  view source on GitHub ↗

Stream a request using the long-lived object-shaped API.

(
        &self,
        py: Python<'_>,
        request: &Bound<'_, PyDict>,
    )

Source from the content-addressed store, hash-verified

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 ///

Callers

nothing calls this directly

Calls 7

block_onMethod · 0.80
get_runtimeFunction · 0.70
cloneMethod · 0.45
is_emptyMethod · 0.45
streamMethod · 0.45

Tested by

no test coverage detected