Skip to main content

Using GPT 3 to backstop buggy code

Project description

AIGremlins

AI Gremlin - Automatic Error Correction with OpenAI AI Gremlin is a Python module that leverages OpenAI's GPT-3 to automatically fix errors in your Python code. The module contains two main classes, GremlinTest and AIgremlin, which work together to handle exceptions and get suggestions for fixes from OpenAI's API.

Note: Using this code in real applications is a terrible idea for many reasons, including:

  • Creating the machine revolution by given an AI direct possibility to execute functions without anyone chekcing.
  • There's no garantuee that the AI generated function won't break anything else or delete something import.
  • Many other reasons.

Don't even think about using this in production.

Installation

pip install aigremlins

Example usage

from aigremlins import AIGremlin

# Initialize AI Gremlin instance with your OpenAI API key
gremlin = AIgrAIGremlinemlin(api_key="your_openai_api_key", verbose=True)

# Define the function with an error
@gremlin.ai_backstop
def buggy_function(a, b):
    """ This function should always return a value"""
    return a / b

# Call the function with parameters that cause an exception
result = buggy_function(4, 0)

Features

Automatically detects and corrects errors in your Python functions using OpenAI's GPT-3. Tries to stay as close as possible to the intent of the original function. Dynamically adds and executes the new fixed function in the original namespace. Customizable parameters to control the number of iterations, token limit, temperature settings, and verbosity of the output. Ability to add custom instructions for OpenAI's API.

How It Works

The AIgremlin class wraps your target function with a decorator called ai_backstop. When the target function encounters an exception, the ai_backstop decorator captures the error, function code, and parameters. The ai_backstop decorator formats a prompt for OpenAI's API to get a suggestion for fixing the function. The suggestion is received from OpenAI's API, and a new fixed function is generated. The fixed function is added to the original namespace and executed. The process continues until the fixed function executes without errors or the maximum number of iterations is reached.

Usage

  1. Import the AIgremlin class from the module.
  2. Instantiate an AIgremlin object with your OpenAI API key and other optional parameters (e.g., max_iterations, max_tokens, temperature, temperature_escalation, verbose, and instructions).
  3. Define your function and apply the ai_backstop decorator to it.

Call the decorated function as you normally would. If an exception is encountered, the AI Gremlin will automatically attempt to fix it using OpenAI's API.

Options

  1. temperature -> default temperature of the model used.
  2. temperature escalation -> the model can become increasingly creative. Should be somewhere between the range of 0.1-0.4 as the max temperature is 1.
  3. instructions -> you can give additional instructions to the AI to take into consideration.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aigremlins-1.3.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

aigremlins-1.3-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file aigremlins-1.3.tar.gz.

File metadata

  • Download URL: aigremlins-1.3.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.11.2 Darwin/22.1.0

File hashes

Hashes for aigremlins-1.3.tar.gz
Algorithm Hash digest
SHA256 3745a2e5f3a5870e86ad8d64451f66794020b27f9abcc4affdc2b50743c18a59
MD5 9f3e682455778b6382531cef31217d81
BLAKE2b-256 49ac5045292f2b2290d062f138cba8c36509a8def1cfcbf8d6929d411a60bec9

See more details on using hashes here.

File details

Details for the file aigremlins-1.3-py3-none-any.whl.

File metadata

  • Download URL: aigremlins-1.3-py3-none-any.whl
  • Upload date:
  • Size: 4.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.11.2 Darwin/22.1.0

File hashes

Hashes for aigremlins-1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 c2cf10d7481da6a6659084c025b897183a6d0f52ef94c354e77888d80c14ff2f
MD5 5f1ada766e580abf8ec8caed711e8c5b
BLAKE2b-256 d013f8d97be69c892ad6dbccb4b6efb5512b71af7d5a9a169d6798c38a6e954c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page