A Python package that automatically fixes errors in your code using OpenAI's GPT API
Project description
ScriptMonkey 🐒
ScriptMonkey is a Python package that automatically detects and fixes errors in your code using OpenAI's GPT API. It works with any IDE or code editor, analyzing your code at runtime, providing solutions to errors, and even updating the file with the corrected code.
Features
- Automatic error detection: Captures errors during runtime.
- AI-powered fixes: Uses OpenAI's GPT API to understand and resolve errors.
- Code auto-correction: Automatically updates your Python files with the fixes.
- Cross-IDE compatibility: Works with any IDE or code editor.
Installation
To install ScriptMonkey, simply run:
pip install scriptmonkey
Usage
- Import
scriptmonkey
in your Python script. - Call
scriptmonkey.run()
to activate the error handler. - Run your code, and let ScriptMonkey handle any errors that occur.
Example
import scriptmonkey
# Enable Codemonkey's error handler
scriptmonkey.run()
# Intentional error for testing
def add(a, b):
return a + b # This will fail if b is a string
print(add(2, "3")) # Codemonkey will automatically fix this error and update the file
Once an error occurs, ScriptMonkey will:
- Detect the error.
- Send the error and code to OpenAI for analysis.
- Provide a solution and automatically update the file with the correct code.
How It Works
ScriptMonkey replaces Python's default exception handling with a custom handler. When an error is caught, it:
- Collects the traceback and the Python file that caused the error.
- Sends the error message and code to OpenAI.
- Receives the solution as structured JSON.
- Applies the fix directly to the source file.
Requirements
- Python 3.6 or later
- OpenAI API key
Setup
To use ScriptMonkey, you'll need an OpenAI API key. Set it up as follows:
export OPENAI_API_KEY='your-api-key'
Let ScriptMonkey take care of your Python errors so you can focus on building!
Project details
Release history Release notifications | RSS feed
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
Hashes for scriptmonkey-0.1.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fd42b1665efe6ac3a152295456dbc3e8adaa39a962e227717cf87ba404cd4c02 |
|
MD5 | e152fc0bdb6c1f65b6617f8e46da2d7d |
|
BLAKE2b-256 | dabd475f8c63245adfa10b9f5f074e199f53c4453c51d9aa79ad07a40ae6eeef |