Skip to content

Commit

Permalink
Handling the rate limit exception
Browse files Browse the repository at this point in the history
  • Loading branch information
TransformerOptimus committed Jul 20, 2023
1 parent 03442ee commit be7797f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 4 additions & 1 deletion superagi/agent/super_agi.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@ def execute(self, workflow_step: AgentWorkflowStep):
total_tokens = current_tokens + TokenCounter.count_message_tokens(response, self.llm.get_model())

self.update_agent_execution_tokens(current_calls, total_tokens, session)


if 'error' in response and response['error'] == "RATE_LIMIT_EXCEEDED":
return {"result": "RATE_LIMIT_EXCEEDED", "retry": True}

Check warning on line 141 in superagi/agent/super_agi.py

View check run for this annotation

Codecov / codecov/patch

superagi/agent/super_agi.py#L141

Added line #L141 was not covered by tests

if 'content' not in response or response['content'] is None:
raise RuntimeError(f"Failed to get response from llm")
assistant_reply = response['content']
Expand Down
6 changes: 5 additions & 1 deletion superagi/jobs/agent_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,11 @@ def execute_next_action(self, agent_execution_id):
return

if "retry" in response and response["retry"]:
superagi.worker.execute_agent.apply_async((agent_execution_id, datetime.now()), countdown=15)
if "result" in response and response["result"] == "RATE_LIMIT_EXCEEDED":
superagi.worker.execute_agent.apply_async((agent_execution_id, datetime.now()), countdown=60)

Check warning on line 261 in superagi/jobs/agent_executor.py

View check run for this annotation

Codecov / codecov/patch

superagi/jobs/agent_executor.py#L261

Added line #L261 was not covered by tests
else:
superagi.worker.execute_agent.apply_async((agent_execution_id, datetime.now()), countdown=15)

Check warning on line 263 in superagi/jobs/agent_executor.py

View check run for this annotation

Codecov / codecov/patch

superagi/jobs/agent_executor.py#L263

Added line #L263 was not covered by tests

session.close()
return

Expand Down

0 comments on commit be7797f

Please sign in to comment.