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

feat: add retry logic and improve logging in OpenAIClient #229

Merged
merged 1 commit into from
Dec 6, 2024

Conversation

danielchalef
Copy link
Member

@danielchalef danielchalef commented Dec 6, 2024

Important

Enhance OpenAIClient error handling with retry logic and improved logging in generate_response().

  • Error Handling:
    • Modify generate_response() in openai_client.py to include retry logic for exceptions, with a maximum of 2 retries.
    • Handle RateLimitError, RefusalError, APITimeoutError, APIConnectionError, and InternalServerError differently, with specific exceptions not triggering retries.
  • Logging:
    • Log detailed error messages and retry attempts in generate_response().
    • Update exception message in _generate_response() to include response_object.model_dump() details.
  • Constants:
    • Add MAX_RETRIES as a class-level constant in OpenAIClient.

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

@danielchalef danielchalef marked this pull request as ready for review December 6, 2024 15:27
@ellipsis-dev ellipsis-dev bot changed the title ... feat: add retry logic and improve logging in OpenAIClient Dec 6, 2024
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.

👍 Looks good to me! Reviewed everything up to 769bf5f in 1 minute and 26 seconds

More details
  • Looked at 78 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 4 drafted comments based on config settings.
1. graphiti_core/llm_client/openai_client.py:22
  • Draft comment:
    AsyncOpenAI is imported but not used. Consider removing it to clean up the imports.
  • Reason this comment was not posted:
    Confidence changes required: 10%
    The import of AsyncOpenAI is not used in the code, which is unnecessary and should be removed.
2. graphiti_core/llm_client/openai_client.py:156
  • Draft comment:
    Appending error messages to messages on each retry can lead to an ever-growing list, potentially affecting performance or logic. Consider resetting or managing the list size.
  • Reason this comment was not posted:
    Confidence changes required: 80%
    The retry logic in generate_response appends an error message to the messages list on each retry, which could lead to an ever-growing list and potentially affect performance or logic. This should be addressed.
3. graphiti_core/llm_client/openai_client.py:120
  • Draft comment:
    The generate_response method is handling retries and error logging. Consider breaking it down into smaller methods to adhere to the Single Responsibility Principle.
  • Reason this comment was not posted:
    Confidence changes required: 80%
    The code is mostly well-structured, but there are some areas that could be improved for better readability and maintainability.
4. graphiti_core/llm_client/openai_client.py:108
  • Draft comment:
    The exception message 'Invalid response from LLM' could be more descriptive. Consider including more context about the error.
  • Reason this comment was not posted:
    Confidence changes required: 60%
    The code is mostly well-structured, but there are some areas that could be improved for better readability and maintainability.

Workflow ID: wflow_fzHjZt0cQMCnieDs


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

@danielchalef danielchalef merged commit 06aac18 into main Dec 6, 2024
7 checks passed
@danielchalef danielchalef deleted the fix/retry-failed-inference branch December 6, 2024 15:34
@github-actions github-actions bot locked and limited conversation to collaborators Dec 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants