ComposioHQ / composio

Composio equip's your AI agents & LLMs with 100+ high-quality integrations via function calling
https://docs.composio.dev
Other
7.47k stars 2.33k forks source link

feat: Added reddit tool and reddit agent example #354

Closed apneduniya closed 1 month ago

apneduniya commented 1 month ago

PR Type

Enhancement, Documentation


Description


Changes walkthrough ๐Ÿ“

Relevant files
Enhancement
6 files
__init__.py
Integrate Reddit tool into local tools module                       

python/composio/tools/local/__init__.py
  • Added import for Reddit tool.
  • Included Reddit in the list of tools.
  • +2/-0     
    __init__.py
    Initialize Reddit tool module                                                       

    python/composio/tools/local/reddit/__init__.py - Added initialization for `Reddit` tool.
    +1/-0     
    __init__.py
    Initialize Reddit actions module                                                 

    python/composio/tools/local/reddit/actions/__init__.py - Added imports for `Filter` and `Comment` actions.
    +2/-0     
    comment.py
    Implement Comment action for Reddit tool                                 

    python/composio/tools/local/reddit/actions/comment.py
  • Implemented Comment action for Reddit tool.
  • Added environment variable checks for Reddit API credentials.
  • Defined request and response schemas for commenting on a post.
  • +84/-0   
    filter.py
    Implement Filter action for Reddit tool                                   

    python/composio/tools/local/reddit/actions/filter.py
  • Implemented Filter action for Reddit tool.
  • Added environment variable checks for Reddit API credentials.
  • Defined request and response schemas for filtering posts in a
    subreddit.
  • +85/-0   
    tool.py
    Define Reddit tool with actions                                                   

    python/composio/tools/local/reddit/tool.py - Defined `Reddit` tool with `Filter` and `Comment` actions.
    +18/-0   
    Documentation
    5 files
    main.py
    Add example script for Reddit agent                                           

    python/examples/reddit_agent/main.py
  • Created example script for Reddit agent.
  • Integrated Reddit tool with ComposioToolSet.
  • Defined tasks for filtering and commenting on Reddit posts.
  • +56/-0   
    setup.sh
    Add setup script for Reddit agent example                               

    python/examples/reddit_agent/setup.sh
  • Added setup script for Reddit agent example.
  • Script includes virtual environment creation and dependency
    installation.
  • +31/-0   
    .env.example
    Add example environment variables file                                     

    python/examples/reddit_agent/.env.example
  • Added example environment variables for Reddit and Google API
    credentials.
  • +12/-0   
    README.md
    Add README for Reddit agent example                                           

    python/examples/reddit_agent/README.md - Added README with instructions to run Reddit agent example.
    +32/-0   
    requirements.txt
    Add requirements file for Reddit agent example                     

    python/examples/reddit_agent/requirements.txt - Added requirements file for Reddit agent example.
    +4/-0     

    ๐Ÿ’ก PR-Agent usage: Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    codiumai-pr-agent-pro[bot] commented 1 month ago

    PR-Agent was enabled for this repository. To continue using it, please link your git user with your CodiumAI identity here.

    PR Reviewer Guide ๐Ÿ”

    โฑ๏ธ Estimated effort to review: 3 ๐Ÿ”ต๐Ÿ”ต๐Ÿ”ตโšชโšช
    ๐Ÿงช No relevant tests
    ๐Ÿ”’ No security concerns identified
    โšก Key issues to review

    Environment Variables
    The code heavily relies on environment variables for configuration, which might not be set. This could lead to runtime errors if not properly handled. It's recommended to provide default values or a more robust configuration management system. Error Handling
    The error handling for missing environment variables could be improved by providing a more descriptive message or a guide on how to set these variables. Code Duplication
    There is significant code duplication in handling environment variables across different files. Consider creating a utility function or class to handle these operations.
    codiumai-pr-agent-pro[bot] commented 1 month ago

    PR-Agent was enabled for this repository. To continue using it, please link your git user with your CodiumAI identity here.

    PR Code Suggestions โœจ

    CategorySuggestion                                                                                                                                    Score
    Error handling
    Add error handling for the post reply operation to enhance application robustness ___ **Add error handling for the post.reply method to manage exceptions that may occur
    during the comment posting process, improving the robustness of the application.** [python/composio/tools/local/reddit/actions/comment.py [82]](https://github.com/ComposioHQ/composio/pull/354/files#diff-8a9bb3ef62f74ffc61b5fe70c5c207724cd52c47d0566a9908f2dd3e851464a4R82-R82) ```diff -post.reply(request_data.message) # Comment on the post +try: + post.reply(request_data.message) # Comment on the post +except Exception as e: + self.logger.error("Failed to post comment:", e) + return CommentToolResponse(success=False, error=str(e)) ``` - [ ] **Apply this suggestion**
    Suggestion importance[1-10]: 10 Why: Adding error handling for the `post.reply` method improves the robustness of the application by managing potential exceptions during the comment posting process. This is crucial for maintaining application stability.
    10
    Maintainability
    Refactor repetitive environment variable checks into a separate method ___ **Refactor the repeated code for checking if environment variables are set into a
    separate method. This will make the execute method cleaner and promote code reuse.** [python/composio/tools/local/reddit/actions/comment.py [38-41]](https://github.com/ComposioHQ/composio/pull/354/files#diff-8a9bb3ef62f74ffc61b5fe70c5c207724cd52c47d0566a9908f2dd3e851464a4R38-R41) ```diff -if client_id is None: - self.logger.error("CLIENT_ID environment variable not set") - raise ValueError("CLIENT_ID environment variable not set") +def check_env_var(var_name): + var_value = os.getenv(var_name) + if var_value is None: + self.logger.error(f"{var_name} environment variable not set") + raise MissingEnvironmentVariableError(f"{var_name} environment variable not set") + return var_value +client_id = check_env_var("CLIENT_ID") + ``` - [ ] **Apply this suggestion**
    Suggestion importance[1-10]: 9 Why: Refactoring repetitive code into a separate method improves code readability and maintainability. It also reduces the risk of errors and makes future updates easier.
    9
    Best practice
    Replace generic exceptions with custom exceptions for better error specificity ___ **Instead of raising a generic ValueError when environment variables are not set,
    consider creating a custom exception class that better describes the error context
    related to missing configuration for the Reddit API. This will improve error
    handling and debugging.** [python/composio/tools/local/reddit/actions/comment.py [41]](https://github.com/ComposioHQ/composio/pull/354/files#diff-8a9bb3ef62f74ffc61b5fe70c5c207724cd52c47d0566a9908f2dd3e851464a4R41-R41) ```diff -raise ValueError("CLIENT_ID environment variable not set") +raise MissingEnvironmentVariableError("CLIENT_ID environment variable not set") ``` - [ ] **Apply this suggestion**
    Suggestion importance[1-10]: 8 Why: Using custom exceptions improves error handling and debugging by providing more specific error messages. This is a best practice and enhances code maintainability.
    8