Skip to content

Latest commit

 

History

10 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bug Fixer Using Generative AI

A small SaaS-style web app that explains and fixes errors in code. You paste a code snippet and the error it produces, and a chat model deployed on Azure OpenAI explains what went wrong and returns a corrected version. Each visitor gets a few free requests, after which the app asks for a payment through Stripe.

Features

  • Paste code and its error message to get a plain explanation of the error and a fixed version of the code.
  • Two separate prompts are sent to the model: one explains the error without fixing it, the other returns only the fixed code.
  • Usage is tracked per visitor in a local SQLite database (a SHA-256 hash of the IP address and user agent). Each visitor gets four free requests.
  • When the free requests are used up, a payment page collects card details with Stripe Elements and charges a fixed fee through a Stripe PaymentIntent. A successful payment resets the visitor's counter, which gives them four more requests.

Tech stack

  • Python, Flask, Jinja2 templates
  • Azure OpenAI through the openai Python SDK
  • Stripe (Stripe.js on the page, stripe Python library on the server)
  • SQLite
  • HTML, CSS and a little JavaScript

Project structure

app.py            Flask routes, model calls, usage tracking and payment
config.py         Reads settings from environment variables or a .env file
templates/        Landing, bug fixer, payment and confirmation pages
static/style.css  Page styles
.env.example      Example environment variables
requirements.txt  Python dependencies

Setup

You need Python 3.10 or newer, an Azure OpenAI resource with a chat model deployment, and a Stripe account (test mode is enough).

  1. Clone the repository and install the dependencies:

    git clone https://github.com/Hamza-Tahirr/Bug-Fixer-Using-Generative-AI.git
    cd Bug-Fixer-Using-Generative-AI
    python -m venv venv
    source venv/bin/activate        # on Windows: venv\Scripts\activate
    pip install -r requirements.txt
  2. Copy .env.example to .env and fill in your values:

    Variable Description
    AZURE_OPENAI_API_KEY Key of your Azure OpenAI resource
    AZURE_OPENAI_ENDPOINT Endpoint, for example https://your-resource.openai.azure.com/
    AZURE_OPENAI_DEPLOYMENT Name of your chat model deployment
    AZURE_OPENAI_API_VERSION API version (defaults to 2024-10-21)
    STRIPE_SECRET_KEY Stripe secret key (sk_test_...)
    STRIPE_PUBLISHABLE_KEY Stripe publishable key (pk_test_...)
  3. Start the app:

    python app.py

    Then open http://127.0.0.1:5000. Set FLASK_DEBUG=1 to run with the Flask debugger. The SQLite database app.db is created automatically on first start.

In Stripe test mode you can pay with the card number 4242 4242 4242 4242, any future expiry date and any CVC.

Configuration

  • The price is set by PRICE_CENTS in app.py (500, which is $5.00).
  • The free request limit is checked in the /home route in app.py.

Limitations

  • Visitors are identified only by IP address and user agent, so the free limit is a simple guard and not real authentication.
  • Cards that require extra authentication (3D Secure) are not handled; the payment page shows an error for them.

License

This project is licensed under the MIT License. See LICENSE.

About

Flask web app that explains and fixes code errors with Azure OpenAI, with a per-visitor free limit in SQLite and Stripe payments.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages