pub struct Client { /* private fields */ }Available on crate feature
http only.Expand description
A TypeSafe API client. Cheap to clone; clones share one connection pool.
Implementations§
Source§impl Client
impl Client
Sourcepub fn new(api_key: impl Into<String>) -> Result<Self, Error>
pub fn new(api_key: impl Into<String>) -> Result<Self, Error>
A client with api_key; base URL and default model come from the environment or
the defaults.
Sourcepub fn from_env() -> Result<Self, Error>
pub fn from_env() -> Result<Self, Error>
A client configured entirely from the environment (see API_KEY_ENV).
Sourcepub fn builder() -> ClientBuilder
pub fn builder() -> ClientBuilder
A builder for configuring the client.
Sourcepub fn default_model(&self) -> &str
pub fn default_model(&self) -> &str
The model used when a request does not name one.
Sourcepub fn system_one(
&self,
state: impl Into<Content>,
questions: Questions,
) -> SystemOneCall<Self>
pub fn system_one( &self, state: impl Into<Content>, questions: Questions, ) -> SystemOneCall<Self>
Starts a call that asks questions about state. The call owns a clone of the
client, so it can be spawned or stored:
use typesafe_client::{Client, NoulQuestion, Questions};
let client = Client::from_env()?;
let mut questions = Questions::new();
let urgent = questions.add("is_urgent", NoulQuestion::new("Does this convey urgency?"));
let call = client
.system_one("Payouts failing for 3 days!", questions)
.model("jev-latest")
.timeout(std::time::Duration::from_secs(5));
let response = tokio::spawn(call.send()).await.expect("task ran")?;
println!("urgent: {:.2}", response.answer(&urgent)?.noul);Sourcepub async fn evaluate(
&self,
request: &SystemOneRequest,
) -> Result<SystemOneResponse, Error>
pub async fn evaluate( &self, request: &SystemOneRequest, ) -> Result<SystemOneResponse, Error>
Sends a prepared request with the client’s default timeout and retry policy. Send
the same request repeatedly, changing only request.state, to reuse questions
without cloning them.
Sourcepub async fn list_models(&self) -> Result<ModelList, Error>
pub async fn list_models(&self) -> Result<ModelList, Error>
Lists the models available to the account.
Trait Implementations§
Source§impl SystemOne for Client
impl SystemOne for Client
Source§fn send<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
request: &'life1 SystemOneRequest,
options: &'life2 CallOptions,
) -> Pin<Box<dyn Future<Output = Result<SystemOneResponse, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn send<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
request: &'life1 SystemOneRequest,
options: &'life2 CallOptions,
) -> Pin<Box<dyn Future<Output = Result<SystemOneResponse, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Source§fn list_models<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<ModelList, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn list_models<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<ModelList, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Lists the models available to the account.
Source§fn system_one(
&self,
state: impl Into<Content>,
questions: Questions,
) -> SystemOneCall<Self>
fn system_one( &self, state: impl Into<Content>, questions: Questions, ) -> SystemOneCall<Self>
Starts a call that asks
questions about state.Auto Trait Implementations§
impl !RefUnwindSafe for Client
impl !UnwindSafe for Client
impl Freeze for Client
impl Send for Client
impl Sync for Client
impl Unpin for Client
impl UnsafeUnpin for Client
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