dev-gpt, an automated python developer
Currently the best way to use dev-gpt is through the Jupyter notebook called dev-gpt
This command-line interface (CLI) app uses OpenAI's GPT-4 to automatically write Python code based on a given prompt. It allows users to interact with GPT-4, request code snippets, save the code to files, and run the generated code. The app also extracts and installs required dependencies and handles potential code execution errors.
openai
library (install via pip install openai
)git clone https://github.com/username/gpt-4-python-code-generator.git
cd gpt-4-python-code-generator
pip install -r requirements.txt
export OPENAI_API_KEY=your_api_key_here
python cli.py --api_key your_api_key
Enter a new message (or type 'quit' to exit): Write a Python function to find the factorial of a given number.
```bash
(required dependencies)
(Python code)
Provide instructions on how to run the code in the response.
4. The app saves generated code to a file and runs the code. Any output is displayed in the CLI.
5. If there are any errors in the code, the app asks for help to fix the errors and generates a new response.
6. To exit the CLI, type `quit` or `exit`.
7. The session information is saved in a JSON file named `session.json`.
## Example
$ python cli.py --api_key your_api_key Enter a new message (or type 'quit' to exit): Write a Python function to find the factorial of a given number.
GPT-4 Response:
def factorial(n: int) -> int:
if n == 0:
return 1
else:
return n * factorial(n-1)
To run the code, call the factorial
function with an integer argument, like factorial(5)
.
$ python cli.py --api_key your_api_key Enter a new message (or type 'quit' to exit): Run the factorial function with the input 5. I ran the code and this is the output: Factorial of 5 is: 120