pub struct RateLimiter { /* private fields */ }
Expand description
Rate limiter to prevent API abuse and rate limiting
Implementations§
Source§impl RateLimiter
impl RateLimiter
Sourcepub fn new(requests_per_minute: usize, max_tool_calls: usize) -> Self
pub fn new(requests_per_minute: usize, max_tool_calls: usize) -> Self
Create a new rate limiter
Sourcepub async fn wait_for_api_request(&self) -> Result<()>
pub async fn wait_for_api_request(&self) -> Result<()>
Check if we can make an API request, blocking if necessary
Sourcepub fn can_make_tool_call(&self) -> bool
pub fn can_make_tool_call(&self) -> bool
Check if we can make a tool call
Sourcepub fn increment_tool_call(&self)
pub fn increment_tool_call(&self)
Increment the tool call count
Sourcepub fn get_tool_call_count(&self) -> usize
pub fn get_tool_call_count(&self) -> usize
Get the current tool call count
Sourcepub fn reset_tool_calls(&self)
pub fn reset_tool_calls(&self)
Reset tool call count for new session
Sourcepub fn get_current_request_count(&self) -> usize
pub fn get_current_request_count(&self) -> usize
Get the current request count in the sliding window
Trait Implementations§
Auto Trait Implementations§
impl Freeze for RateLimiter
impl RefUnwindSafe for RateLimiter
impl Send for RateLimiter
impl Sync for RateLimiter
impl Unpin for RateLimiter
impl UnwindSafe for RateLimiter
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
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>
Converts
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>
Converts
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