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.2.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

aigremlins-1.2-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: aigremlins-1.2.tar.gz
  • Upload date:
  • Size: 4.1 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.2.tar.gz
Algorithm Hash digest
SHA256 cd6b45602f32b153ed6f9b7cca3425b0c554e8254b099852cd6f372da8e9254e
MD5 d452248dbf3f6869aa866b17d57d58b0
BLAKE2b-256 9a87a2a95b199085a97102438ee9dab92cc9ed6343fc3364607c6888974ba8e9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: aigremlins-1.2-py3-none-any.whl
  • Upload date:
  • Size: 4.0 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c26bf753342c0a7c78e5e82708e7e30eb75fd96e3e1e53674ebed997309dc3b3
MD5 86497eda7a2569eb75686e0b7f02ffd1
BLAKE2b-256 0f4c6c29fa07c47338d46029718f914f8f59fdec2550759d5b5ba0930bd38d76

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