pub struct RetryingChatClient<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: ChatClient> RetryingChatClient<C>
impl<C: ChatClient> RetryingChatClient<C>
Sourcepub fn new(inner: C) -> Self
pub fn new(inner: C) -> Self
Wrap inner with the default RetryPolicy.
Sourcepub fn with_policy(self, policy: RetryPolicy) -> Self
pub fn with_policy(self, policy: RetryPolicy) -> Self
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> ChatClient for RetryingChatClient<C>
impl<C: ChatClient> ChatClient for RetryingChatClient<C>
Source§fn get_response<'life0, 'async_trait>(
&'life0 self,
messages: Vec<Message>,
options: ChatOptions,
) -> Pin<Box<dyn Future<Output = Result<ChatResponse>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn get_response<'life0, 'async_trait>(
&'life0 self,
messages: Vec<Message>,
options: ChatOptions,
) -> Pin<Box<dyn Future<Output = Result<ChatResponse>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: '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<ChatStream>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn get_streaming_response<'life0, 'async_trait>(
&'life0 self,
messages: Vec<Message>,
options: ChatOptions,
) -> Pin<Box<dyn Future<Output = Result<ChatStream>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: '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