Class: RCrewAI::RateLimiter::ThrottledClient

Inherits:
Object
  • Object
show all
Defined in:
lib/rcrewai/rate_limiter.rb

Overview

Wraps an LLM client so every #chat acquires a rate-limiter slot first. All other messages delegate to the wrapped client unchanged.

Instance Method Summary collapse

Constructor Details

#initialize(client, limiter) ⇒ ThrottledClient

Returns a new instance of ThrottledClient.



71
72
73
74
# File 'lib/rcrewai/rate_limiter.rb', line 71

def initialize(client, limiter)
  @client = client
  @limiter = limiter
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, **kwargs, &block) ⇒ Object



85
86
87
88
89
90
91
# File 'lib/rcrewai/rate_limiter.rb', line 85

def method_missing(name, *args, **kwargs, &block)
  if @client.respond_to?(name)
    @client.public_send(name, *args, **kwargs, &block)
  else
    super
  end
end

Instance Method Details

#chat(**kwargs, &block) ⇒ Object



76
77
78
79
# File 'lib/rcrewai/rate_limiter.rb', line 76

def chat(**kwargs, &block)
  @limiter.acquire
  @client.chat(**kwargs, &block)
end

#respond_to_missing?(name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/rcrewai/rate_limiter.rb', line 81

def respond_to_missing?(name, include_private = false)
  @client.respond_to?(name, include_private)
end