Package: gpt-code-edit
GPT Code Editgpt-code-edit is a Command Line Interface that allows you to target specific functions, classes, or methods in a file and use chatgpt to perform several edits on them including refactoring, adding comments, adding docstrings, or adding error handling.Githubhttps://github.com/ben-23-96/chatgpt_code_improve_cliPyPIhttps://pypi.org/project/gpt-code-edit/PrerequisitesPython 3.9An active OpenAI account with API keysInstallationUse the package managerpipto install GPT code edit.pipinstallgpt-code-editUsageSet API KeyFirst, you need to set your OpenAI API key. You can find your key atOpenAI Platformif you have a valid OpenAI account.gptset-api-key<api_key>ArgumentsArgumentDescription<api_key>The OpenAI API key for the user.Code EditThis command allows you to target specific functions, classes, or methods in a file and perform several edits on the code including refactoring, adding comments, adding docstrings, or adding error handling.gptcode-edit<filename>[--target-functions<function1><function2>...][--target-classes<class1><class2>...][--target-methods<class1.method1><class2.method2>...][--refactor][--comments][--docstrings][--error-handling][--gpt-4][--temp<temperature>][--create-review-file][--edit-code-in-file]Note: One of--create-review-fileor--edit-code-in-filemust be set. Both can be set at the same time.Note: One of--refactor,--comments,--docstringsor--error-handlingmust be set. Multiple can be set at the same time.Note: One of--target-functions,--target-methodsor--target-classesmust be set. Multiple can be set at the same time.ExampleThe following command would add GPT generated comments into the function foo located in the main.py file.gptcode-editmain.py--target-functionsfoo--comments--edit-code-in-fileArgumentsArgumentDescription<filename>The filename of the file containing the code (eg. main.py).--target-functionsA space-separated list of function names to be targeted.--target-classesA space-separated list of class names to be targeted. Each class should be provided asClassName. This will target every method in each class provided. This cannot be used if--target-methodsis also used on a method within one of the given classes.--target-methodsA space-separated list of method names to be targeted. Each method should be given asClassName.method. This cannot be used if--target-classesis also used on the class the method is from.--refactorIf set, refactor the code.--commentsIf set, add comments to the code.--docstringsIf set, add docstrings to the code.--error-handlingIf set, add error handling to the code.--gpt-4If set, GPT-4 will be used instead of the default GPT-3.--tempAffects the randomness of the output. A higher value makes the output more creative and a lower value makes it more structured. Must be between 1 and 0. The default is 0.4.--create-review-fileIf set, creates a file{function_name}.pyin a foldergpt_edit_reviewcontaining the newly edited function code and the old function code. This allows you to review the code before replacing it in the actual file. Remember to gitignore or delete the folder created when done.--edit-code-in-fileIf set, rewrites the selected code within the file with the newly edited version returned from GPT. If used, it is advisable for code to be committed and saved in case of erroneous changes.Review to FileIf when using code-edit the --create-review-file flag has been used so the edited code has been placed in a file for review, this command allows you to apply the changes to the actual file.gptreview-to-file<filename>[--target-functions<function1><function2>...][--target-classes<class1><class2>...][--target-methods<class1.method1><class2.method2>...]ArgumentsArgumentDescription<filename>The filename of the file containing the original code (eg. main.py).--target-functionsA space-separated list of function names to be targeted from the correspondinggpt_edit_review/<filename>folder.--target-classesA space-separated list of class names to be targeted from the correspondinggpt_edit_review/<filename>folder. Each class should be provided asClassName. This cannot be used if--target-methodsis also used on a method within one of the given classes.--target-methodsA space-separated list of method names to be targeted from the correspondinggpt_edit_review/<filename>folder. Each method should be given asClassName.method. This cannot be used if--target-classesis also used on the class the method is from.