I wrapped Python traceback and Exception so whenever an Exception is raised, an automatic diagnosis is done by GPT-4. See results below:
This error message occurred because of 'test' at line 177 in file api.py, function main. The exception type is <class 'Exception'>. The function is:
async def main():
try:
raise Exception("test")
except Exception as e:
potential_fix = await error_wrap.run_chat_prompt(error_wrap.wrap_error(e))
print (potential_fix)
return {"error": str(e), "potential_fix": potential_fix}
How do I fix this?
The error message is occurring because you are deliberately raising an Exception
with the message "test". To fix this, you need to remove or comment out the line where the exception is being raised.
Here's the modified code without the exception being raised:
async def main():
try:
# remove or comment out the following line
# raise Exception("test")
# add your actual code here
except Exception as e:
potential_fix = await error_wrap.run_chat_prompt(error_wrap.wrap_error(e))
print (potential_fix)
return {"error": str(e), "potential_fix": potential_fix}
If you want to test your error handling without actually removing the line, you can simply comment it out, as shown above. Add your actual code inside the try block, and the error handling will work as intended.
This might also work in Javascript/Typescript but requires more steps (https://chat.openai.com/share/ca1ad6ad-68f6-4494-a35b-b1514deca12c)
Great idea man, thank you. I took it a step further and make it a decorator, so now all I do is @gpt_error and decorate all my functions and it prints the responses to the console.
Thanks for the idea my friend.
Here is my contribution thanks to your code. It handles async or non async functions and now supports azure and openai. I should prob wrap the openai call in some error handling, but....You all can do that ;)