Skip to content

Utilka/CodeReviewAI_ale_test_task

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CodeReviewAI

CodeReviewAI is a FastAPI-based web application that allows users to submit a GitHub repository URL and receive an automated code review generated by OpenAI's GPT API. The application fetches the repository content, processes it, and uses GPT to generate downsides/comments, a rating, and a conclusion about the code.

Features

  • GitHub Integration: Fetches repository contents directly from GitHub.
  • Automated Code Review: Utilizes OpenAI's GPT API to analyze code and generate a detailed review.
  • Candidate Levels: Adjusts the review based on the specified candidate level (Junior, Middle, or Senior).
  • Rate Limiting: Implements rate limiting for both GitHub and OpenAI APIs to comply with usage policies.

Table of Contents

Requirements

  • Python: 3.12
  • OpenAI API Key: Required for accessing the OpenAI GPT API.
  • GitHub Access Token: Optional, but recommended for higher rate limits when accessing the GitHub API.

Installation

Using Docker (Recommended)

Prerequisites

  • Docker
  • Docker Compose

Steps

  1. Clone the Repository

    git clone https://github.com/your_username/your_repository.git
    cd your_repository
  2. Set Environment Variables

    Create a .env file in the project root or export the variables directly in your shell.

    export OPENAI_API_KEY=your_openai_api_key
    export GITHUB_ACCESS_TOKEN=your_github_access_token  # Optional
  3. Build and Run the Docker Container

    docker-compose up --build

    The application will be available at http://localhost:8000.

Manual Installation

Prerequisites

  • Python: 3.12
  • Poetry: Dependency management tool.

Steps

  1. Clone the Repository

    git clone https://github.com/your_username/your_repository.git
    cd your_repository
  2. Install Poetry

    pip install poetry
  3. Install Dependencies

    poetry install
  4. Set Environment Variables

    export OPENAI_API_KEY=your_openai_api_key
    export GITHUB_ACCESS_TOKEN=your_github_access_token  # Optional
  5. Run the Application

    poetry run start

    The application will be available at http://localhost:8000.

Usage

API Endpoint

  • URL: POST /review

  • Description: Generates a code review for the provided GitHub repository URL.

  • Request Body:

    {
      "assignment_description": "string",
      "github_repo_url": "string",
      "candidate_level": "Junior" | "Middle" | "Senior"
    }
  • Response:

    {
      "Found files": ["list", "of", "files"],
      "Downsides/Comments": "string",
      "Rating": "string",
      "Conclusion": "string"
    }

Example Request

curl -X POST "http://localhost:8000/review" \
  -H "Content-Type: application/json" \
  -d '{
    "assignment_description": "Implement a REST API in Python",
    "github_repo_url": "https://github.com/example/repo",
    "candidate_level": "Middle"
  }'

Example Response

{
  "Found files": [
    "app/main.py",
    "app/utils.py",
    "tests/test_main.py"
  ],
  "Downsides/Comments": "The code lacks proper error handling in the API endpoints...",
  "Rating": "Rating: 75/100",
  "Conclusion": "Overall, the candidate shows a good understanding of REST principles but needs to improve..."
}

Environment Variables

  • OPENAI_API_KEY (required): Your OpenAI API key.
  • GITHUB_ACCESS_TOKEN (optional): Your GitHub personal access token for increased rate limits.

Testing

To run the test suite, execute:

pytest

Ensure you have all development dependencies installed:

poetry install --with dev

Project Structure

  • app/: Main application code.
    • main.py: FastAPI application and endpoint definitions.
    • github_fetcher.py: Logic for fetching repository data from GitHub.
    • openAI_reviewer.py: Logic for generating code reviews using OpenAI's GPT API.
    • utils.py: Utility functions.
  • tests/: Test suite for the application.
  • Dockerfile: Dockerfile for containerizing the application.
  • docker-compose.yaml: Docker Compose configuration.
  • pyproject.toml: Project configuration for Poetry.

Notes

  • The application enforces rate limits for both GitHub and OpenAI APIs to comply with their usage policies.
  • Ensure that you comply with OpenAI's Usage Policies when using this application.
  • The application uses asynchronous programming to improve performance when making API calls.

License

This project is licensed under the MIT License.

Contributing

Contributions are welcome! Please open an issue or submit a pull request for any bugs, improvements, or features.


This README was generated to provide comprehensive documentation for the CodeReviewAI application.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors