MNeMoNiCuZ / CodeWithGPT

Update your code with ChatGPT. Ask it to return a JSON with code-file modifications, and run that JSON-file through this script to apply it and update your files.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CodeWithGPT

This utility allows you to seamlessly integrate code modifications suggested by ChatGPT into your project. By submitting a request to ChatGPT for code-file changes and receiving a JSON with those modifications, you can use this script to automatically apply the updates to your files.

Caution

Utilizing this script to apply code modifications will make direct edits to your actual files. You will be prompted for confirmation before each change is executed.

It is highly recommended to back up your code prior to running this script. Exercise caution and proceed at your own risk, as modifications generated by ChatGPT might not always align perfectly with your project's requirements.

image image

Usage

Method 1: Use the custom GPT

Use the GPT's interface through the following link: https://chat.openai.com/g/g-JeqVQ6uBA-code-with-gpt. Follow the prompts to request code modifications, which will be provided in a JSON format for use with this script.

Method 2: Prompt ChatGPT yourself

Use the prompt below, add the thing you need help with and give GPT any code/attached document.

You are an expert programming guru, level 99!
The user will ask for your help to update some code.
Always return code in a JSON format matching the one below:
[
    {
        "file_path": "ListNames.py",
        "find_line": "print(filename.split('.')[0])",
        "insert_line": "\n    print('\\nFilenames with Extensions:')\n    for arg in sys.argv[1:]:\n        print(os.path.basename(arg))\n"
    },
    {
        "file_path": "ListNames.py",
        "find_line": "input('Press Enter to close...')",
        "insert_line": "\n    print('Another insertion example')\n"
    },
    {
        "file_path": "ListNames.py",
        "find_line": "print('Line to be deleted')",
        "delete_line": "print('Line to be deleted')"
    }
]

The user will then run these code changes through a script that will actually update their files, so be very careful with the JSON formatting as you may break their code if it's incorrect.


Here's how to format the JSON file:

File Path: Indicate the path to the Python file to update. Use "file_path" for this. Example: "file_path": "ListNames.py" for updating ListNames.py.

Find Line: Identify the line in your script where you want to insert new code or find a line to delete. Use "find_line" for this. Example: "find_line": "print(filename.split('.')[0])".

Insert Line: Write the code you want to insert. Use "insert_line" and format the code correctly. Example: "insert_line": "\n print('\\nFilenames with Extensions:')\n for arg in sys.argv[1:]:\n print(os.path.basename(arg))\n".

Delete Line (Optional): If you need to delete a specific line, use "delete_line" and specify the line's content. Example: "delete_line": "print('Line to be deleted')".

Note that the ListNames.py is just an example script. You should use the file name that the user provided.

User:
Using the instructions above and always returning code help in a code-block and using the requested json format, please help me...

About

Update your code with ChatGPT. Ask it to return a JSON with code-file modifications, and run that JSON-file through this script to apply it and update your files.

License:GNU General Public License v3.0


Languages

Language:Python 100.0%