Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenAI RateLimitError #257

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

sudhakarsingh27
Copy link

@sudhakarsingh27 sudhakarsingh27 commented Jan 27, 2025

It wasn't possible to run this tutorial https://help.getzep.com/graphiti/graphiti/lang-graph-agent consistently without adding this rate limiting API.


Important

Adds rate limiting handling with exponential backoff to generate_response() in openai_client.py.

  • Behavior:
    • Adds rate limiting handling in generate_response() in openai_client.py using exponential backoff.
    • Implements _parse_retry_after() to extract retry time from error messages or fallback to exponential backoff.
    • Logs rate limit hits and retry attempts.
  • Error Handling:
    • Catches RateLimitError and retries with delay.
    • Continues to raise RefusalError without retry.
    • Handles other OpenAI errors by deferring to OpenAI's client retry logic.

This description was created by Ellipsis for 1511121. It will automatically update as commits are pushed.

Copy link


Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.


I have read the CLA Document and I hereby sign the CLA


You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ Changes requested. Reviewed everything up to 1511121 in 1 minute and 43 seconds

More details
  • Looked at 48 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 3 drafted comments based on config settings.
1. graphiti_core/llm_client/openai_client.py:149
  • Draft comment:
    max_delay is not defined. Define max_delay or replace it with a defined variable.
  • Reason this comment was not posted:
    Marked as duplicate.
2. graphiti_core/llm_client/openai_client.py:162
  • Draft comment:
    Convert RateLimitError to string to extract retry time. Use str(e) in _parse_retry_after.
  • Reason this comment was not posted:
    Marked as duplicate.
3. graphiti_core/llm_client/openai_client.py:139
  • Draft comment:
    Define _parse_retry_after as a separate function or a static method for better readability and reusability.
  • Reason this comment was not posted:
    Confidence changes required: 80%
    The _parse_retry_after function is defined inside the generate_response method, which is not idiomatic in Python. It should be defined as a separate method or a static method if it doesn't use any instance variables.

Workflow ID: wflow_vEEQ61N6ZkfozhXO


Want Ellipsis to fix these issues? Tag @ellipsis-dev in a comment. You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

return float(match.group(1)) / 1000 # Convert ms to seconds

# Fallback to exponential backoff if no time found
return min(5 * (2 ** retry_count), max_delay)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

max_delay is not defined. This will cause a NameError. Define max_delay or replace it with a valid variable.

# These errors should not trigger retries
raise
# Handle rate limits with backoff
except RateLimitError as e:
retry_after = _parse_retry_after(e)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_parse_retry_after expects a string, but e is an exception object. Pass str(e) instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant