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. That being said:
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
- Import the AIgremlin class from the module.
- 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).
- 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.
from AIgremlins import AIgremlin
# Initialize AI Gremlin instance with your OpenAI API key
ai_gremlin = AIgremlin(api_key="your_openai_api_key", verbose=True)
# Define the function with an error
@ai_gremlin.ai_backstop
def buggy_function(a, b):
return a / b
# Call the function with parameters that cause an exception
result = buggy_function(4, 0)
Options
- temperature -> default temperature of the model used.
- 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.
- 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
Built Distribution
File details
Details for the file aigremlins-1.1.tar.gz
.
File metadata
- Download URL: aigremlins-1.1.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.2 CPython/3.11.2 Darwin/22.1.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 72500a2be76d84d3275672ac97fcec5fcb0ce6f80112f46c226774185da9f494 |
|
MD5 | 638b01b33054211fbbef9a382845d7df |
|
BLAKE2b-256 | 3b3d43f284e6dc241ea9a5c85bce033a66e8aa9e4aabfcd68eb5273e3c5dada5 |
File details
Details for the file aigremlins-1.1-py3-none-any.whl
.
File metadata
- Download URL: aigremlins-1.1-py3-none-any.whl
- Upload date:
- Size: 3.9 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 01da390b477c976522e9705887ba301314cbff0b46eb5a9606bfb962055b315f |
|
MD5 | 67fb4cd102ba76a6e84d7ee3bf404b7c |
|
BLAKE2b-256 | 190923a3a0c2a00b47e9bc88b7e901d8384adab2130032a6d6d4626203fcd972 |