pub struct UreqClient { /* private fields */ }Expand description
Blocking TypeSafe client backed by ureq.
use typesafe_ai::{Question, Request, UreqClient};
let client = UreqClient::new(std::env::var("TYPESAFE_API_KEY")?)?;
let request = Request::new("Please refund duplicate charge 1042.")
.with_question("is_billing", Question::noul("Is this a billing request?"));
let response = client.evaluate(&request)?;Implementations§
Source§impl UreqClient
impl UreqClient
Sourcepub fn new(api_key: impl Into<String>) -> Result<Self, UreqError>
pub fn new(api_key: impl Into<String>) -> Result<Self, UreqError>
Creates a client with ClientConfig::default.
The API key is marked sensitive and omitted from the client’s debug output.
Sourcepub fn with_config(
api_key: impl Into<String>,
config: ClientConfig,
) -> Result<Self, UreqError>
pub fn with_config( api_key: impl Into<String>, config: ClientConfig, ) -> Result<Self, UreqError>
Creates a client with explicit shared configuration.
Sourcepub fn with_agent(
api_key: impl Into<String>,
config: ClientConfig,
agent: Agent,
) -> Result<Self, UreqError>
pub fn with_agent( api_key: impl Into<String>, config: ClientConfig, agent: Agent, ) -> Result<Self, UreqError>
Creates a client around an existing ureq agent.
Custom transport and resolver behavior from the agent is preserved. TypeSafe’s status, redirect, and timeout policies are applied to each request.
Sourcepub fn evaluate(&self, request: &Request) -> Result<Response, UreqError>
pub fn evaluate(&self, request: &Request) -> Result<Response, UreqError>
Evaluates every question in request against its shared state.
The request is validated before any HTTP exchange. HTTP 429 and 529 responses are
retried according to ClientConfig::max_retries.
Sourcepub fn evaluate_events(
&self,
request: &Request,
) -> impl Iterator<Item = EvaluationEvent<Error>>
pub fn evaluate_events( &self, request: &Request, ) -> impl Iterator<Item = EvaluationEvent<Error>>
Creates a lazy iterator over attempt failures and the terminal result.
Construction performs no validation, waiting, or HTTP work. Each call to next
drives at most one HTTP attempt and yields failures before any retry delay. See
SyncClient::evaluate_events for retry timing and interruption behavior.
use typesafe_ai::{UreqClient, Request};
for event in client.evaluate_events(request) {
println!("{event:?}");
}