pub struct RetryingChatClient<C>where
C: ChatClient,{ /* private fields */ }Expand description
A ChatClient decorator that retries transient failures with exponential
backoff, honoring a server Retry-After when present.
Wraps any inner ChatClient and re-issues the request per its
RetryPolicy. For streaming, only the initial connection is retried:
if establishing the stream (or its very first item, before anything is
yielded to the consumer) fails with a retryable error, the connection is
re-attempted; once the first update flows, later stream errors propagate
unchanged.
let client = RetryingChatClient::new(inner)
.with_policy(RetryPolicy::with_max_retries(5).initial_delay(Duration::from_millis(200)));Implementations§
Source§impl<C> RetryingChatClient<C>where
C: ChatClient,
impl<C> RetryingChatClient<C>where
C: ChatClient,
Sourcepub fn new(inner: C) -> RetryingChatClient<C>
pub fn new(inner: C) -> RetryingChatClient<C>
Wrap inner with the default RetryPolicy.
Sourcepub fn with_policy(self, policy: RetryPolicy) -> RetryingChatClient<C>
pub fn with_policy(self, policy: RetryPolicy) -> RetryingChatClient<C>
Set the retry policy (builder-style).
Sourcepub fn policy(&self) -> &RetryPolicy
pub fn policy(&self) -> &RetryPolicy
A reference to the active retry policy.
Trait Implementations§
Source§impl<C> ChatClient for RetryingChatClient<C>where
C: ChatClient,
impl<C> ChatClient for RetryingChatClient<C>where
C: ChatClient,
Source§fn get_response<'life0, 'async_trait>(
&'life0 self,
messages: Vec<Message>,
options: ChatOptions,
) -> Pin<Box<dyn Future<Output = Result<ChatResponse, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
RetryingChatClient<C>: 'async_trait,
fn get_response<'life0, 'async_trait>(
&'life0 self,
messages: Vec<Message>,
options: ChatOptions,
) -> Pin<Box<dyn Future<Output = Result<ChatResponse, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
RetryingChatClient<C>: 'async_trait,
Get a complete (non-streaming) response.
Source§fn get_streaming_response<'life0, 'async_trait>(
&'life0 self,
messages: Vec<Message>,
options: ChatOptions,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<ChatResponseUpdate, Error>> + Send>>, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
RetryingChatClient<C>: 'async_trait,
fn get_streaming_response<'life0, 'async_trait>(
&'life0 self,
messages: Vec<Message>,
options: ChatOptions,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<ChatResponseUpdate, Error>> + Send>>, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
RetryingChatClient<C>: 'async_trait,
Get a streaming response as a sequence of updates.
Auto Trait Implementations§
impl<C> !RefUnwindSafe for RetryingChatClient<C>
impl<C> !UnwindSafe for RetryingChatClient<C>
impl<C> Freeze for RetryingChatClient<C>where
C: Freeze,
impl<C> Send for RetryingChatClient<C>
impl<C> Sync for RetryingChatClient<C>
impl<C> Unpin for RetryingChatClient<C>where
C: Unpin,
impl<C> UnsafeUnpin for RetryingChatClient<C>where
C: 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