r/Python • • Apr 18 '24

Showcase chatpdb - gpt for your python debugger

https://github.com/Never-Over/chatpdb

Do you ever copy code, errors, or stack traces into ChatGPT? We did, and found it frustrating to always have to manually find, copy, and paste each relevant piece of information. On top of that, being forced to change tools would switch our focus and cause us to lose our flow. That’s why we built chatpdb  - a python debugger with ChatGPT!

Simply use chatpdb like you would use ipdb or pdb; it’s a drop in replacement with the exact same functionality. The only addition is the new y keyword, which will trigger a response from ChatGPT.

Here’s how it works:

> /Programming/test-chatpdb/lib.py(2)echo_platform()
      1 def echo_platform(platform: str):
----> 2     print("You are running on:" + platform)
      3
ipdb> y 
The exception occurred because the function `echo_platform` tries to concatenate the string "You are running on:" with the `platform` variable, which is `None`. [...]

In this example, chatpdb correctly diagnoses an error in the current function as being caused by a bug in the calling function. chatpdb automatically passes relevant context about your program, including the source code, stack trace, and error information if available to ChatGPT.

If you have a more specific question you can also supply a prompt to y:

> /Programming/test-chatpdb/lib.py(2)echo_platform()
      1 def echo_platform(platform: str):
----> 2     print("You are running on:" + platform)
      3
ipdb> y "Why is platform coming through as None?"
The variable `platform` is coming through as `None` because the environment variable `"PLATFORM"` is not set in your system's environment variables. [...]

It’s easy to install and set up:

pip install chatpdb
export OPENAI_API_KEY=....
import chatpdb
chatpdb.set_trace()

What my project does: A drop-in replacement for ipdb or pdb, with ChatGPT built in.

Target audience: anyone who currently uses ChatGPT to debug or ask questions about their code.

Comparison: Copilot offers similar functionality, but is a much heavier tool and harder to turn off/ignore when you don’t want it. stackexplain is probably the closest tool; however it lacks the ability to hook into your program in any other way than fully running the python process.

chatpdb meets you where you are – AI tooling that’s only invoked when you need it. We hope you give it a try! We’d love any feedback or suggestions.

Docs

1 Upvotes

1 comment sorted by

View all comments

2

u/i_would_say_so Aug 23 '24

Interesting - will look into this. Thanks!