Git Product home page Git Product logo

chatpdb's Introduction

image image image image Checked with pyright Ruff

chatpdb

chatpdb is a drop-in replacement for ipdb or pdb that lets you ask questions while debugging.

chatpdb meets you where you are - AI tooling that's only invoked when you need it.

Installation

pip install chatpdb

Ensure that you have OPENAI_API_KEY set in your environment.

export OPENAI_API_KEY=...```

## Usage
In your code:
```python3
import chatpdb; chatpdb.set_trace()

Simply type y to receive a summary of the current code and stack trace.

> /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`. [...]

Type y "prompt" to ask a question.

> /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. [...]

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

Just like ipdb and pdb, chatpdb supports many different entrypoints.

Running code:

import chatpdb; chatpdb.run('print("hello")')
import chatpdb; chatpdb.runcall(lambda x: x + 1, 1)

As a decorator:

@chatpdb.cex
def sample_cex_function():
    raise # any exception within the decorated function will trigger chatpdb

As a context manager:

with chatpdb.launch_chatpdb_on_exception():
    raise # any exception within the with block will trigger chatpdb

On files:

python3 -m chatpdb file.py

post-mortem support:

chatpdb.pm()

See the documentation of ipdb or pdb for the full api.

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 key
  • CHAT_PDB_OPENAI_MODEL: The model to use for chatpdb. Default is 'gpt-4-turbo'

chatpdb's People

Contributors

caelean avatar emdoyle avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.