pub struct Client<B = Hyper> { /* private fields */ }Expand description
A client for one model server.
Cheap to clone; clones share the connection pool and what was learned about the server, such as that it rejects optional fields.
B is the HTTP backend: the built-in Hyper unless the builder is given another. Most code
never names it and writes Client.
use svir::prelude::*;
let client = Client::openai("http://127.0.0.1:1234").build()?;
let request = Request::new("qwen3-27b").user("Explain ownership in one paragraph.");
let mut stream = client.stream(&request).await?;
while let Some(event) = stream.next().await {
if let Event::Text(delta) = event? {
print!("{delta}");
}
}Implementations§
Source§impl<B: Backend> Client<B>
impl<B: Backend> Client<B>
Sourcepub async fn stream(
&self,
request: impl Borrow<Request>,
) -> Result<EventStream<B>, Error>
pub async fn stream( &self, request: impl Borrow<Request>, ) -> Result<EventStream<B>, Error>
Sends request and returns the answer as a stream of events.
Dropping the stream cancels the request and closes the connection.
Sourcepub async fn complete(
&self,
request: impl Borrow<Request>,
) -> Result<Completion, Error>
pub async fn complete( &self, request: impl Borrow<Request>, ) -> Result<Completion, Error>
Sends request and returns the whole answer.
Sourcepub async fn send(
&self,
request: impl Borrow<Request>,
) -> Result<RawStream<B>, Error>
pub async fn send( &self, request: impl Borrow<Request>, ) -> Result<RawStream<B>, Error>
Sends request and returns the server’s bytes unchanged, after status mapping and
compatibility handling: for a proxy that relays the stream and reads it on the way past
with a Decoder. Layers work on events, so they do not apply here.
Trait Implementations§
Auto Trait Implementations§
impl<B = Hyper> !RefUnwindSafe for Client<B>
impl<B = Hyper> !UnwindSafe for Client<B>
impl<B> Freeze for Client<B>
impl<B> Send for Client<B>
impl<B> Sync for Client<B>
impl<B> Unpin for Client<B>
impl<B> UnsafeUnpin for Client<B>where
Arc<Inner<B>>: UnsafeUnpin,
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