Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fkhan0520/cgpt_exceptions
https://github.com/fkhan0520/cgpt_exceptions
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/fkhan0520/cgpt_exceptions
- Owner: fkhan0520
- License: gpl-3.0
- Created: 2022-12-06T00:32:36.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2022-12-06T01:26:32.000Z (almost 2 years ago)
- Last Synced: 2024-06-15T15:33:09.176Z (5 months ago)
- Language: Python
- Size: 16.6 KB
- Stars: 36
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-ChatGPT-repositories - cgpt_exceptions - made a python package to automatically get help from chatgpt when an exception is thrown. check it out! (Others)
README
# cgpt_exceptions
Use ChatGPT to give helpful advice when your python program fails
# Usage
1. Install through git:
```
pip install git+https://github.com/fkhan0520/cgpt_exceptions
```
2. Create a `cgpt_exceptions_config.json` file with your OpenAI auth info and put it in the same directory as wherever `python` is invoked. It can use either your username/password or auth token. Full details in the [revChatGPT docs](https://github.com/acheong08/ChatGPT)3. Just import the package and invoke your program as normal!
```python
import cgpt_exceptions
import osdef foo():
os.listdir("a-random-directory")foo()
``````
Traceback (most recent call last)
File "/Users/farhan/test.py", line 7, in
foo()
File "/Users/farhan/test.py", line 5, in foo
os.listdir("a-random-directory")
FileNotFoundError: [Errno 2] No such file or directory: 'a-random-directory'Let's see what ChatGPT has to say...
Here are a few ways you can correct the exception:
1. Make sure that the directory "a-random-directory" exists and you have permission to access it.
2. Handle the `FileNotFoundError` exception that is raised when the directory doesn't exist by using a `try`-`except` block:
import os
def foo():
try:
os.listdir("a-random-directory")
except FileNotFoundError:
print("Directory not found.")foo()
```
# How it works
Sends ChatGPT the following prompt when an exception is thrown anywhere during execution:
```
Please correct the following python exception:from the following code:
```
Huge thanks to [acheong8](https://github.com/acheong08) for making this super straightforward with their [revChatGPT package](https://github.com/acheong08/ChatGPT)