bwilkie commited on
Commit
e2a980c
·
verified ·
1 Parent(s): 9ccd162

Update multiagents.py

Browse files
Files changed (1) hide show
  1. multiagents.py +9 -37
multiagents.py CHANGED
@@ -58,52 +58,24 @@ dotenv.load_dotenv()
58
 
59
  # SETUP AND TEST
60
 
61
-
62
-
63
- # Rate limiting decorator
64
- def rate_limit(calls_per_minute=15):
65
- """Rate limiting decorator that limits function calls per minute"""
66
- def decorator(func):
67
- call_times = []
68
-
69
- @wraps(func)
70
- def wrapper(*args, **kwargs):
71
- now = time.time()
72
- # Remove calls older than 1 minute
73
- call_times[:] = [t for t in call_times if now - t < 60]
74
-
75
- if len(call_times) >= calls_per_minute:
76
- sleep_time = 60 - (now - call_times[0])
77
- if sleep_time > 0:
78
- mylog("rate_limit", f"Rate limit reached. Sleeping for {sleep_time:.2f} seconds")
79
- time.sleep(sleep_time)
80
- # Clean up old calls again after sleeping
81
- now = time.time()
82
- call_times[:] = [t for t in call_times if now - t < 60]
83
-
84
- call_times.append(now)
85
- return func(*args, **kwargs)
86
- return wrapper
87
- return decorator
88
-
89
- # Rate-limited model wrapper
90
  class RateLimitedModel:
91
- def __init__(self, model, calls_per_minute=30):
92
  self.model = model
93
- self.calls_per_minute = calls_per_minute
94
- self.call_times = []
95
 
96
  def __call__(self, messages, **kwargs):
97
- return self._rate_limited_call(messages, **kwargs)
98
-
99
- @rate_limit(calls_per_minute=30) # Adjust as needed
100
- def _rate_limited_call(self, messages, **kwargs):
101
  return self.model(messages, **kwargs)
102
 
103
  def __getattr__(self, name):
104
  # Delegate other attributes to the wrapped model
105
  return getattr(self.model, name)
106
 
 
 
 
107
  ###################
108
 
109
  grok_api_key = os.getenv("groq_api")
@@ -117,7 +89,7 @@ base_model = InferenceClientModel(
117
  )
118
 
119
  # Wrap with rate limiting
120
- My_Agent = RateLimitedModel(base_model, calls_per_minute=15)
121
 
122
  def check_final_answer(final_answer, agent_memory) -> bool:
123
  """
 
58
 
59
  # SETUP AND TEST
60
 
61
+ # Simple rate-limited model wrapper
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
  class RateLimitedModel:
63
+ def __init__(self, model, delay_seconds=1):
64
  self.model = model
65
+ self.delay_seconds = delay_seconds
 
66
 
67
  def __call__(self, messages, **kwargs):
68
+ # Simple delay before each API call
69
+ time.sleep(self.delay_seconds)
 
 
70
  return self.model(messages, **kwargs)
71
 
72
  def __getattr__(self, name):
73
  # Delegate other attributes to the wrapped model
74
  return getattr(self.model, name)
75
 
76
+
77
+
78
+
79
  ###################
80
 
81
  grok_api_key = os.getenv("groq_api")
 
89
  )
90
 
91
  # Wrap with rate limiting
92
+ My_Agent = RateLimitedModel(base_model)
93
 
94
  def check_final_answer(final_answer, agent_memory) -> bool:
95
  """