Use ChatGPT to debug your python code
pip install -U chatty-debug
NOTE: Requires OPENAI_API_KEY environment variable
fromchatty_debugimportchatty_debug@chatty_debug() # () is requireddeffoo():
a=0b=10return100/a/bif__name__=="__main__":
foo()# foo.pydeffoo():
a=0b=10return100/a/bif__name__=="__main__":
foo()python -m chatty_debug foo.py
You may also specify a unique prompt. For example, you can request a response in a different language, or provide more information about the error that might not be available in the traceback.
fromchatty_debugimportchatty_debug@chatty_debug(prompt="Me ajude a entender esse erro.")deffoo():
a=0b=10return1000/b/aif__name__=="__main__":
foo()Additionally, you can do the same with the script. Using the foo.py script from above, you can also do this command:
python -m chatty_debug foo.py --prompt "Me ajude a entender esse erro."
chatty-debug can also suggest improvements for your code.
Without further configuration, the decorator will submit a default prompt presenting your function. ChatGPT will then be asked to suggest improvements to it. It will then be asked to suggest some tests to improve it. These default prompts can be edited, removed, and added to.
fromchatty_debugimportsuggest_improvements@suggest_improvements() # () is requireddeffoo(value, set=set()):
list=list(set)
forval1inlist:
ifvalue==val1:
returnTruereturnFalseif__name__=='__main__':
foo()

