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

2 remove dependency on mongodb #8

Merged
merged 8 commits into from
Feb 1, 2025
Merged

Conversation

Zingzy
Copy link
Owner

@Zingzy Zingzy commented Feb 1, 2025

This PR addresses Issue #2

Summary by Sourcery

Remove dependency on MongoDB and refactor image generation.

Enhancements:

  • Refactor error handling and image generation logic.
  • Improve progress reporting during multi-image generation.

@Zingzy Zingzy added the enhancement New feature or request label Feb 1, 2025
@Zingzy Zingzy linked an issue Feb 1, 2025 that may be closed by this pull request
5 tasks
Copy link

sourcery-ai bot commented Feb 1, 2025

Reviewer's Guide by Sourcery

This pull request removes the dependency on MongoDB and refactors the code to use the discord interaction metadata to store the author of the image. It also adds error handling for the image generation process.

Sequence diagram for image generation with new error handling

sequenceDiagram
    participant U as User
    participant B as Bot
    participant A as API
    participant D as Discord
    U->>B: /imagine command
    B->>B: validate_dimensions()
    B->>B: validate_prompt()
    B->>A: generate_image()
    alt Success
        A->>B: Return image
        B->>D: Store author in interaction metadata
        B->>U: Send image with buttons
    else Error
        A->>B: Return error
        B->>B: Handle specific error type
        B->>U: Send error message
    end
Loading

Class diagram showing refactored error handling

classDiagram
    class AppCommandError {
        <<Discord>>
    }
    class PromptTooLongError {
        +message: str
    }
    class DimensionTooSmallError {
        +message: str
    }
    class NoImagesGeneratedError {
        +message: str
    }
    class ImageGenerationError {
        +message: str
        +model_index: int
    }
    class APIError {
        +message: str
    }
    AppCommandError <|-- PromptTooLongError
    AppCommandError <|-- DimensionTooSmallError
    Exception <|-- NoImagesGeneratedError
    Exception <|-- ImageGenerationError
    Exception <|-- APIError
Loading

File-Level Changes

Change Details Files
Removed MongoDB dependency
  • Removed all code related to MongoDB.
  • Removed the pymongo dependency.
cogs/multi_pollinate_cog.py
cogs/imagine_cog.py
main.py
requirements.txt
pyproject.toml
Refactored image generation logic
  • Moved image generation logic to a new file utils/image_gen_utils.py.
  • Added error handling for image generation.
  • Added a new file utils/embed_utils.py to handle embed generation.
  • Added a new file utils/error_handler.py to handle error messages.
  • Added a new file exceptions.py to handle custom exceptions.
  • Added a new file utils/pollinate_utils.py to handle url parsing.
  • Refactored the multi_pollinate command to use the new image generation logic.
  • Refactored the imagine command to use the new image generation logic.
  • Added a new safe parameter to the imagine command.
  • Added a new safe parameter to the generate_image function.
  • Added a new refresh_models task to refresh the models every 5 minutes.
  • Added a new WAITING_GIFS constant to display a random gif while the image is being generated.
cogs/multi_pollinate_cog.py
cogs/imagine_cog.py
utils/image_gen_utils.py
utils/embed_utils.py
utils/error_handler.py
exceptions.py
utils/pollinate_utils.py
Refactored button interactions
  • Refactored the button interactions to use the discord interaction metadata to store the author of the image.
  • Refactored the button interactions to use the new error handling logic.
cogs/multi_pollinate_cog.py
cogs/imagine_cog.py
Added new error handling
  • Added a new file utils/error_handler.py to handle error messages.
  • Added a new file exceptions.py to handle custom exceptions.
  • Added error handling for the multi_pollinate command.
  • Added error handling for the imagine command.
  • Added error handling for the random command.
cogs/multi_pollinate_cog.py
cogs/imagine_cog.py
cogs/random_cog.py
utils/error_handler.py
exceptions.py
Updated dependencies
  • Updated the dependencies in requirements.txt.
  • Updated the dependencies in pyproject.toml.
requirements.txt
pyproject.toml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @Zingzy - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

url += f"&nofeed={private}" if private else ""
url += "&referer=discordbot"

dic = {
Copy link

Choose a reason for hiding this comment

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

issue (code-quality): We've found these issues:

…guration handling, simplify URL construction, and streamline user comment extraction
@Zingzy Zingzy merged commit 2f33ba5 into main Feb 1, 2025
1 check passed
@Zingzy Zingzy deleted the 2-remove-dependency-on-mongodb branch February 1, 2025 23:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove dependency on MongoDB
1 participant