A chatgpt enabled python debugger
Project description
chatpdb
chatpdb
is an extension to ipdb that lets you ask questions while debugging your code.
Installation
pip install chatpdb
Ensure that you have OPENAI_API_KEY
set in your environment.
Usage
In your code:
import chatpdb; chatpdb.set_trace()
Simply type y
to receive a summary of the current code and stack trace.
> /Users/you/sample.py (9) test_function()
8
----> 9 import chatpdb; chatpdb.set_trace()
10
ipdb> y
You are currently in a python debugger, etc.
Type y "prompt"
to ask a question.
> /Users/you/sample.py (9) test_function()
8
----> 9 import chatpdb; chatpdb.set_trace()
10
ipdb> y "what does chatpdb do in this case?"
You are currently in a python debugger, etc.
How does it work?
chatpdb
uses the OpenAI API to generate responses to your questions. It uses the gpt-4-turbo
model by default.
chatpdb
will automatically include relevant context from the current frame and stack trace, as well as
exception information if one has been raised.
Advanced
Usage
ipdb and pdb support many different entrypoints which chatpdb
also supports.
import chatpdb; chatpdb.run('print("hello")')
import chatpdb; chatpdb.runcall(lambda x: x + 1, 1)
# chatpdb will launch on exception
# @chatpdb.iex is also supported
@chatpdb.cex
def sample_cex_function():
raise
def sample_with_function():
with chatpdb.launch_chatpdb_on_exception(): # or chatpdb.launch_ipdb_on_exception()
raise
# See pdb documentation for pm (post-mortem) usage
import chatpdb; chatpdb.pm()
Configuration
You can use more specific environment variables to configure an OpenAI key and preferred model for chatpdb. The following environment variables are supported:
CHAT_PDB_OPENAI_API_KEY
: Your OpenAI API keyCHAT_PDB_OPENAI_MODEL
: The model to use for chatpdb. Default is 'gpt-4-turbo'
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.