pub struct ChatStream { /* private fields */ }Expand description
Async stream of ChatResponse events from a streaming chat request.
Each next yields one NDJSON line deserialized as ChatResponse.
When the server closes the body, next returns None.
§Examples
use ollama_oxide::{ChatMessage, ChatRequest, OllamaApiAsync, OllamaClient};
#[tokio::main]
async fn main() -> ollama_oxide::Result<()> {
let client = OllamaClient::default()?;
let request = ChatRequest::new("qwen3:0.6b", [ChatMessage::user("Hi!")]);
let stream = client.chat_stream(&request).await?;
while let Some(event) = stream.next().await {
let chunk = event?;
if let Some(s) = chunk.content() {
print!("{}", s);
}
}
Ok(())
}Implementations§
Source§impl ChatStream
impl ChatStream
Sourcepub async fn next(&self) -> Option<Result<ChatResponse>>
pub async fn next(&self) -> Option<Result<ChatResponse>>
Returns the next event, or None when the stream has ended.
Sourcepub async fn collect(self) -> Result<Vec<ChatResponse>>
pub async fn collect(self) -> Result<Vec<ChatResponse>>
Collects all events into a vector, stopping on the first error.
Auto Trait Implementations§
impl !Freeze for ChatStream
impl !RefUnwindSafe for ChatStream
impl Send for ChatStream
impl Sync for ChatStream
impl Unpin for ChatStream
impl UnsafeUnpin for ChatStream
impl UnwindSafe for ChatStream
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more