Skip to content

Add PR help message functionality and update dependencies#1241

Merged
mrT23 merged 1 commit intomainfrom
tr/help_rag
Sep 21, 2024
Merged

Add PR help message functionality and update dependencies#1241
mrT23 merged 1 commit intomainfrom
tr/help_rag

Conversation

@mrT23
Copy link
Contributor

@mrT23 mrT23 commented Sep 21, 2024

User description

  • Implement PRHelpMessage class to provide AI-powered assistance for pull requests.
  • Add methods for similarity search using local, S3, and Pinecone databases.
  • Update requirements.txt to include new dependencies for langchain and chromadb.
  • Modify configuration.toml to include force_local_db setting for PR help.
  • Update aiohttp and openai package versions.

PR Type

Enhancement


Description

  • Implemented AI-powered PR help functionality in the PRHelpMessage class
  • Added methods for similarity search using local, S3, and Pinecone databases
  • Improved error handling and logging throughout the PR help process
  • Updated PR help message generation to support different Git providers
  • Added 'force_local_db' configuration option in configuration.toml
  • Updated aiohttp and openai package versions in requirements.txt
  • Added new dependencies for langchain, chromadb, and related packages to support AI-powered functionality

Changes walkthrough 📝

Relevant files
Enhancement
pr_help_message.py
Implement AI-powered PR help functionality                             

pr_agent/tools/pr_help_message.py

  • Implemented PRHelpMessage class with AI-powered assistance for pull
    requests
  • Added methods for similarity search using local, S3, and Pinecone
    databases
  • Improved error handling and logging
  • Updated PR help message generation for different Git providers
  • +340/-96
    Configuration changes
    configuration.toml
    Add force_local_db configuration option                                   

    pr_agent/settings/configuration.toml

    • Added 'force_local_db' option to pr_help section
    +1/-0     
    Dependencies
    requirements.txt
    Update dependencies and add new packages                                 

    requirements.txt

  • Updated aiohttp and openai package versions
  • Added new dependencies for langchain, chromadb, and related packages
  • +8/-2     

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

    - Implement PRHelpMessage class to provide AI-powered assistance for pull requests.
    - Add methods for similarity search using local, S3, and Pinecone databases.
    - Update `requirements.txt` to include new dependencies for langchain and chromadb.
    - Modify `configuration.toml` to include `force_local_db` setting for PR help.
    - Update `aiohttp` and `openai` package versions.
    @mrT23 mrT23 merged commit 1a5835a into main Sep 21, 2024
    @mrT23 mrT23 deleted the tr/help_rag branch September 21, 2024 13:28
    @mrT23
    Copy link
    Contributor Author

    mrT23 commented Sep 21, 2024

    /help "how to change the code suggestion to be commitable ?"

    @qodo-code-review
    Copy link
    Contributor

    Question:

    how to change the code suggestion to be commitable ?

    Answer:

    To make code suggestions commitable, you can use the --pr_code_suggestions.commitable_code_suggestions=true parameter when invoking the improve tool. You can do this manually by commenting on a PR with:

    /improve --pr_code_suggestions.commitable_code_suggestions=true

    For automatic runs, you can set this in the configuration file under the bitbucket_app section:

    [bitbucket_app]
    pr_commands = [
      "/improve --pr_code_suggestions.commitable_code_suggestions=true --pr_code_suggestions.suggestions_score_threshold=7",
    ]
    

    This will present the suggestions as commitable code comments instead of a single table comment.

    Relevant Sources:

    @qodo-ai qodo-ai deleted a comment from qodo-code-review bot Sep 21, 2024
    @Zrmikstri
    Copy link

    /help "how to use pr-agent with self hosted llm"

    @qodo-code-review
    Copy link
    Contributor

    Question:

    how to use pr-agent with self hosted llm

    Answer:

    To use PR-Agent with a self-hosted LLM, you need to self-host PR-Agent itself. Here's how to do it:

    1. Acquire the necessary tokens:

      • An API key for your chosen language model (e.g., OpenAI key with GPT-4 access, or a key for another supported LLM)
      • A personal access token (classic) from your Git provider (GitHub, GitLab, or BitBucket) with repo scope
    2. Choose a deployment method for self-hosting PR-Agent:

      • Locally
      • GitHub
      • GitLab
      • BitBucket
      • Azure DevOps
    3. Follow the installation guide for your chosen deployment method.

    When self-hosting PR-Agent, you use your own API keys, which means the interaction with the LLM provider is directly between you and them. PR-Agent doesn't send your code data to its servers, ensuring better privacy for your code.

    For detailed installation instructions, refer to the PR-Agent documentation for your specific deployment method.

    Relevant Sources:

    @qodo-ai qodo-ai deleted a comment from qodo-code-review bot Sep 30, 2024
    @qodo-ai qodo-ai deleted a comment from qodo-code-review bot Sep 30, 2024
    @mrT23
    Copy link
    Contributor Author

    mrT23 commented Sep 30, 2024

    /improve

    @mrT23
    Copy link
    Contributor Author

    mrT23 commented Sep 30, 2024

    /review

    @qodo-code-review
    Copy link
    Contributor

    qodo-code-review bot commented Sep 30, 2024

    PR Code Suggestions ✨

    CategorySuggestion                                                                                                                                    Score
    Error handling
    Use more specific exception types for better error handling

    Consider using a more specific exception type instead of a bare except clause. This
    will make the error handling more precise and easier to debug.

    pr_agent/tools/pr_help_message.py [58-60]

    -except Exception as e:
    +except (jinja2.TemplateError, ValueError) as e:
         get_logger().error(f"Error while preparing prediction: {e}")
         return ""
    +except Exception as e:
    +    get_logger().error(f"Unexpected error while preparing prediction: {e}")
    +    return ""
    • Apply this suggestion
    Suggestion importance[1-10]: 7

    Why: This suggestion improves error handling by providing more specific exception types. It allows for more precise error identification and handling, which can aid in debugging and maintenance.

    7
    Organization
    best practice
    Avoid using mutable default arguments in function definitions

    Instead of using a mutable default argument (args=None) in the init method, use
    None as the default and assign an empty list in the method body if args is None.
    This aligns with the company's best practice of avoiding mutable default arguments.

    pr_agent/tools/pr_help_message.py [35]

     def __init__(self, pr_url: str, args=None, ai_handler: partial[BaseAiHandler,] = LiteLLMAIHandler):
    +    self.args = [] if args is None else args
    • Apply this suggestion
    Suggestion importance[1-10]: 6

    Why: This is a good practice to avoid potential bugs related to mutable default arguments. While the current code might not cause immediate issues, implementing this change can prevent future problems.

    6
    Import the entire jinja2 module instead of individual components

    Instead of using individual imports from jinja2, consider importing the entire
    module. This aligns with the company's best practice for imports.

    pr_agent/tools/pr_help_message.py [8]

    -from jinja2 import Environment, StrictUndefined
    +import jinja2
    • Apply this suggestion
    Suggestion importance[1-10]: 3

    Why: While this change aligns with some coding practices, it's a minor improvement that doesn't significantly impact functionality or readability. The current import style is also widely used and acceptable.

    3
    Best practice
    Use a context manager for the S3 client to ensure proper resource management

    Consider using a context manager (with statement) for the S3 client to ensure proper
    resource management and cleanup.

    pr_agent/tools/pr_help_message.py [80-85]

    -s3 = boto3.client('s3')
    +with boto3.client('s3') as s3:
    +    # Download the file from S3 to the temporary directory
    +    bucket = 'pr-agent'
    +    file_name = 'chroma_db.zip'
    +    s3.download_file(bucket, file_name, local_file_path)
     
    -# Download the file from S3 to the temporary directory
    -bucket = 'pr-agent'
    -file_name = 'chroma_db.zip'
    -s3.download_file(bucket, file_name, local_file_path)
    -
    • Apply this suggestion
    Suggestion importance[1-10]: 5

    Why: Using a context manager for the S3 client is a good practice for resource management. However, in this case, the improvement is minor as the S3 client doesn't hold significant resources that require explicit cleanup.

    5

    @qodo-code-review
    Copy link
    Contributor

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 4 🔵🔵🔵🔵⚪
    🏅 Score: 85
    🧪 No relevant tests
    🔒 Security concerns

    Sensitive information exposure:
    The code downloads files from an S3 bucket (pr-agent/chroma_db.zip) without any apparent authentication or authorization checks. This could potentially expose sensitive information if the S3 bucket is not properly secured or if the file contains any sensitive data. It's recommended to implement proper access controls and ensure that only authorized users can access this data.

    🔀 Multiple PR themes

    Sub-PR theme: Implement AI-powered PR help functionality

    Relevant files:

    • pr_agent/tools/pr_help_message.py

    Sub-PR theme: Update dependencies and configuration

    Relevant files:

    • pr_agent/settings/configuration.toml
    • requirements.txt

    ⚡ Recommended focus areas for review

    Error Handling
    The error handling in the similarity search methods (get_sim_results_from_s3_db, get_sim_results_from_local_db, get_sim_results_from_pinecone_db) could be improved. Currently, exceptions are caught and logged, but the methods continue execution, potentially with empty results. Consider adding more robust error handling or fallback mechanisms.

    Code Duplication
    There is significant code duplication in the run method when generating the PR comment for different Git providers. Consider refactoring this into separate methods or using a template to reduce duplication and improve maintainability.

    Configuration Management
    The code relies heavily on the global configuration (get_settings()). Consider passing necessary configuration as parameters to methods or using dependency injection to improve testability and reduce global state dependencies.

    @mrT23
    Copy link
    Contributor Author

    mrT23 commented Sep 30, 2024

    /analyze

    @qodo-code-review
    Copy link
    Contributor

    PR Analysis 🔬

    • This screen contains a list of code components that were changed in this PR.
    • You can initiate specific actions for each component, by checking the relevant boxes.
    • After you check a box, the action will be performed automatically by PR-Agent.
    • Results will appear as a comment on the PR, typically after 30-60 seconds.
    fileChanged components
    pr_help_message.py
    • Test
    • Docs
    • Improve
    • Similar
     
    extract_header
    (function)
     
    +12/-0
     
    • Test
    • Docs
    • Improve
    • Similar
     
    __init__
    (method of PRHelpMessage)
     
    +13/-2
     
    • Test
    • Docs
    • Improve
    • Similar
     
    _prepare_prediction
    (method of PRHelpMessage)
     
    +12/-0
     
    • Test
    • Docs
    • Improve
    • Similar
     
    parse_args
    (method of PRHelpMessage)
     
    +6/-0
     
    • Test
    • Docs
    • Improve
    • Similar
     
    get_sim_results_from_s3_db
    (method of PRHelpMessage)
     
    +29/-0
     
    • Test
    • Docs
    • Improve
    • Similar
     
    get_sim_results_from_local_db
    (method of PRHelpMessage)
     
    +22/-0
     
    • Test
    • Docs
    • Improve
    • Similar
     
    get_sim_results_from_pinecone_db
    (method of PRHelpMessage)
     
    +17/-0
     
    • Test
    • Docs
    • Improve
    • Similar
     
    run
    (method of PRHelpMessage)
     
    +152/-87
     
    • Test
    • Docs
    • Improve
    • Similar
     
    prepare_relevant_snippets
    (method of PRHelpMessage)
     
    +28/-0
     
    • Test
    • Docs
    • Improve
    • Similar
     
    generate_bbdc_table
    (function)
     
    +18/-0
     

    💡 Usage guide:

    Using static code analysis capabilities, the analyze tool scans the PR code changes and find the code components (methods, functions, classes) that changed in the PR.

    The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on any PR:

    /analyze
    

    Language that are currently supported: Python, Java, C++, JavaScript, TypeScript, C#.
    See more information about the tool in the docs.

    @moral3jo
    Copy link

    /help "how configure http auth with bitbucket and custom model with ollama in local?"

    @qodo-free-for-open-source-projects
    Copy link
    Contributor

    Question:

    how configure http auth with bitbucket and custom model with ollama in local?

    Answer:

    To configure HTTP auth with Bitbucket and use a custom Ollama model locally, you need to:

    1. For Bitbucket HTTP auth:
    • Add your Bitbucket bearer token in .secrets.toml:
    [bitbucket]
    bearer_token = "<your token>"
    
    • Set git provider to bitbucket in configuration:
    [config]
    git_provider = "bitbucket"
    
    1. For Ollama custom model:
    • Set in configuration file:
    [config]
    model = "ollama/your-model-name"
    fallback_models = ["ollama/your-model-name"]
    custom_model_max_tokens = 128000
    duplicate_examples = true
    
    [ollama]
    api_base = "http://localhost:11434"
    

    Note: While Ollama allows running models locally, commercial models like GPT-4 and Claude are recommended for production-level code analysis tasks as they perform better with complex code analysis.

    Relevant Sources:

    @sparsh-b20
    Copy link

    /help what are the language it supports

    @qodo-free-for-open-source-projects
    Copy link
    Contributor

    Question:

    what are the language it supports

    Answer:

    Qodo Merge/PR-Agent has different levels of language support depending on the tool:

    1. Core tools (describe, review, improve):
    • Support virtually all programming languages since they use advanced language models (Claude 3.5 Sonnet and GPT-4)
    1. Tools requiring static code analysis (analyze, test, add_docs, improve_component):
    • Currently support: Python, Java, C++, JavaScript, TypeScript, C#

    Note that for optimal functionality, it's recommended to use commercial models like GPT-4, Claude Sonnet, or Gemini, as they have demonstrated robust capabilities in generating structured output for code analysis tasks with large input.

    Relevant Sources:

    @sparsh-b20
    Copy link

    /help I am using golang in my projects , is the review and other functionalities available for that
    also , is it require my own open ai key

    @qodo-free-for-open-source-projects
    Copy link
    Contributor

    Question:

    I am using golang in my projects , is the review and other functionalities available for that also , is it require my own open ai key

    Answer:

    For Golang projects:

    1. Core tools (review, describe, improve) support all programming languages since they use GPT-4 and Claude-3.5-sonnet models. You can use these tools with Golang code.

    2. Some specialized tools that require static code analysis (like test generation, documentation generation) currently support only: Python, Java, C++, JavaScript, TypeScript, C#. Golang is not yet supported for these tools.

    3. Regarding OpenAI key:

    • If you self-host PR-Agent: Yes, you need your own OpenAI key (or key from another supported LLM provider)
    • If you use Qodo Merge (hosted version): No, keys are managed by Qodo

    Relevant Sources:

    @sparsh-b20
    Copy link

    /help I am using Golang in my projects , will it qodo.ai will help me
    also , is it require my open ai key

    @qodo-free-for-open-source-projects
    Copy link
    Contributor

    Question:

    I am using Golang in my projects , will it qodo.ai will help me also , is it require my open ai key

    Answer:

    Yes, Qodo Merge can help with Golang projects. The main tools (describe, review, improve) support all programming languages since they use advanced language models like Claude 3.5 Sonnet and GPT-4.

    Regarding the OpenAI key requirement:

    • If you use the self-hosted open-source PR-Agent, you will need your own OpenAI key (or key from another supported LLM provider)
    • If you use Qodo Merge (the hosted version), you don't need to provide any API keys as they are managed by Qodo

    Note that some specialized tools that require static code analysis (like test generation, documentation generation) currently don't support Golang, but the main review and suggestion tools will work fully with Golang code.

    Relevant Sources:

    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.

    6 participants