pub struct ChatClient { /* private fields */ }Expand description
Blocking client for OpenAI-compatible /chat/completions.
Implementations§
Source§impl ChatClient
impl ChatClient
Sourcepub fn new(
base_url: impl Into<String>,
model: impl Into<String>,
) -> Result<Self, ChatError>
pub fn new( base_url: impl Into<String>, model: impl Into<String>, ) -> Result<Self, ChatError>
Builds a client targeting base_url with the default timeout.
§Errors
Returns ChatError::Build if the underlying reqwest::Client fails
to build.
Sourcepub fn with_timeout(
base_url: impl Into<String>,
model: impl Into<String>,
timeout: Duration,
) -> Result<Self, ChatError>
pub fn with_timeout( base_url: impl Into<String>, model: impl Into<String>, timeout: Duration, ) -> Result<Self, ChatError>
Builds a client with a custom timeout.
§Errors
Returns ChatError::Build if the underlying reqwest::Client fails
to build.
Sourcepub fn with_max_tokens(
base_url: impl Into<String>,
model: impl Into<String>,
max_tokens: Option<u32>,
) -> Result<Self, ChatError>
pub fn with_max_tokens( base_url: impl Into<String>, model: impl Into<String>, max_tokens: Option<u32>, ) -> Result<Self, ChatError>
Builds a client with the default timeout and optional completion token cap.
§Errors
Returns ChatError::Build if the underlying reqwest::Client fails
to build.
Sourcepub fn with_timeout_and_max_tokens(
base_url: impl Into<String>,
model: impl Into<String>,
timeout: Duration,
max_tokens: Option<u32>,
) -> Result<Self, ChatError>
pub fn with_timeout_and_max_tokens( base_url: impl Into<String>, model: impl Into<String>, timeout: Duration, max_tokens: Option<u32>, ) -> Result<Self, ChatError>
Builds a client with a custom timeout and optional completion token cap.
§Errors
Returns ChatError::Build if the underlying reqwest::Client fails
to build.
Sourcepub fn with_timeout_max_tokens_and_auth(
base_url: impl Into<String>,
model: impl Into<String>,
timeout: Duration,
max_tokens: Option<u32>,
auth: ResolvedAuth,
) -> Result<Self, ChatError>
pub fn with_timeout_max_tokens_and_auth( base_url: impl Into<String>, model: impl Into<String>, timeout: Duration, max_tokens: Option<u32>, auth: ResolvedAuth, ) -> Result<Self, ChatError>
Builds a client with timeout, token cap, and resolved auth material.
§Errors
Returns ChatError::Build if the underlying reqwest::Client fails
to build.
Sourcepub fn with_no_timeout_and_max_tokens(
base_url: impl Into<String>,
model: impl Into<String>,
max_tokens: Option<u32>,
) -> Result<Self, ChatError>
pub fn with_no_timeout_and_max_tokens( base_url: impl Into<String>, model: impl Into<String>, max_tokens: Option<u32>, ) -> Result<Self, ChatError>
Builds a client with no HTTP request timeout and optional completion token cap.
§Errors
Returns ChatError::Build if the underlying reqwest::Client fails
to build.
Sourcepub const fn with_reasoning_effort(self, effort: ReasoningEffort) -> Self
pub const fn with_reasoning_effort(self, effort: ReasoningEffort) -> Self
Sets OpenAI-compatible reasoning effort for the request body.
Sourcepub fn with_chat_template_kwargs(self, value: Value) -> Self
pub fn with_chat_template_kwargs(self, value: Value) -> Self
Sets provider-specific chat-template options.
Sourcepub fn complete(
&self,
messages: Vec<ChatMessage>,
temperature: f32,
) -> Result<String, ChatError>
pub fn complete( &self, messages: Vec<ChatMessage>, temperature: f32, ) -> Result<String, ChatError>
Sends a chat completion request and returns the first message content.
§Errors
Returns ChatError::Http for transport failures or non-2xx statuses.
Returns ChatError::MalformedResponse when the response body cannot be
decoded or the first choice has no content.
Sourcepub fn complete_raw(
&self,
messages: Vec<ChatMessage>,
temperature: f32,
) -> Result<ChatCompletionOutput, ChatError>
pub fn complete_raw( &self, messages: Vec<ChatMessage>, temperature: f32, ) -> Result<ChatCompletionOutput, ChatError>
Sends a chat completion request and returns content plus raw response.
§Errors
Returns ChatError::Http for transport failures or non-2xx statuses.
Returns ChatError::MalformedResponse when the response body cannot be
decoded or the first choice has no visible content.
Trait Implementations§
Source§impl Clone for ChatClient
impl Clone for ChatClient
Source§fn clone(&self) -> ChatClient
fn clone(&self) -> ChatClient
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for ChatClient
impl !RefUnwindSafe for ChatClient
impl Send for ChatClient
impl Sync for ChatClient
impl Unpin for ChatClient
impl UnsafeUnpin for ChatClient
impl !UnwindSafe for ChatClient
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more