Git Product home page Git Product logo

code_analyzer's Introduction

Code Analyzer

This is a simple Python script that uses the OpenAI API to improve the readability and maintainability of your code. It detects the programming language based on the file extension and sends the code to the API for suggestions on how to improve it.

Prerequisites

  1. Python 3.6 or later
  2. An OpenAI API key

Installation

Ubuntu

  1. Install Python 3:
sudo apt-get update
sudo apt-get install python3 python3-pip

Arch Linux

  1. Install python 3:
sudo pacman -Syu
sudo pacman -S python python-pip

Usage

  1. Install the package, inside the project directory, with the following command:
pip install --editable .
  1. Set your OpenAI API key as an environment variable or pass it as an argument:
export OPENAI_API_KEY="your_api_key_here"
  1. Run the script with the input file as the first argument, and optionally, the output file and API key as the second and third arguments:
code-analyzer <input_file> [<output_file>] [<openai_api_key>]

Example:

code-analyzer test_files/bad_code.js test_files/bad_code.ai.js

This will generate an improved version of the code in a file with the same name but with the .ai extension (e.g., bad_code.ai.js).

Notes

  • The script currently supports the following file extensions: .go, .py, .js, .java, .cs, .cpp, .rb, and .php.
  • If the output file is not provided, it will be saved with the same name as the input file but with the .ai-version.{extension}.
  • If the API key is not provided as an argument, the script will look for it in the environment variable OPENAI_API_KEY.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.