Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/plasma-umass/ChatDBG into HEAD
Browse files Browse the repository at this point in the history
  • Loading branch information
emeryberger committed Apr 4, 2024
2 parents fd88edf + 0d186d2 commit 2342a8f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ For technical details and a complete evaluation, see our arXiv paper, [_ChatDBG:

> **Note**
>
> ChatDBG needs to be connected to an [OpenAI account](https://openai.com/api/). _Your account will need to have a positive balance for this to work_ ([check your balance](https://platform.openai.com/account/usage)). If you have never purchased credits, you will need to purchase at least $1 in credits (if your API account was created before August 13, 2023) or $0.50 (if you have a newer API account) in order to have access to GPT-4, which ChatDBG uses. [Get a key here.](https://platform.openai.com/account/api-keys)
> ChatDBG needs to be connected to an [OpenAI account](https://openai.com/api/). _Your account will need to have a positive balance for this to work_ ([check your balance](https://platform.openai.com/account/usage)). If you have never purchased credits, you will need to purchase at least \$1 in credits (if your API account was created before August 13, 2023) or \$0.50 (if you have a newer API account) in order to have access to GPT-4, which ChatDBG uses. [Get a key here.](https://platform.openai.com/account/api-keys)
>
> Once you have an API key, set it as an environment variable called `OPENAI_API_KEY`.
>
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ classifiers = [

[project.scripts]
chatdbg = "chatdbg.__main__:main"
print_chatdbg_log = "chatdbg.util.plog:main"

[project.urls]
"Homepage" = "https://github.com/plasma-umass/ChatDBG"
Expand Down
21 changes: 14 additions & 7 deletions src/chatdbg/chatdbg_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,23 @@ def load_ipython_extension(ipython):
from IPython.terminal.debugger import TerminalPdb

ChatDBGSuper = TerminalPdb
_user_file_prefixes = [os.getcwd(), "<ipython"]
# _user_file_prefixes = [ "<ipython" ]
else:
# inside jupyter
from IPython.core.debugger import InterruptiblePdb

ChatDBGSuper = InterruptiblePdb
_user_file_prefixes = [os.getcwd(), IPython.paths.tempfile.gettempdir()]
# _user_file_prefixes = [ IPython.paths.tempfile.gettempdir() ]
else:
# ichatpdb on command line
from IPython.terminal.debugger import TerminalPdb

ChatDBGSuper = TerminalPdb
_user_file_prefixes = [os.getcwd()]
# _user_file_prefixes = [ ]
except NameError as e:
print(f"Error {e}:IPython not found. Defaulting to pdb plugin.")
ChatDBGSuper = pdb.Pdb
# _user_file_prefixes = [ ]


class ChatDBG(ChatDBGSuper):
Expand All @@ -88,6 +89,12 @@ def __init__(self, *args, **kwargs):
# set this to True ONLY AFTER we have had access to stack frames
self._show_locals = False

self._library_paths = [os.path.dirname(os.__file__)] + [
path
for path in sys.path
if "site-packages" in path or "dist-packages" in path
]

self._log = ChatDBGLog(
log_filename=chatdbg_config.log,
config=chatdbg_config.to_json(),
Expand Down Expand Up @@ -127,11 +134,11 @@ def _is_user_file(self, file_name):
elif file_name == "<string>":
return False

for prefix in _user_file_prefixes:
if file_name.startswith(prefix):
return True
for path in self._library_paths:
if os.path.commonpath([file_name, path]) == path:
return False

return False
return True

def enriched_stack_trace(self, context=None):
old_stdout = self.stdout
Expand Down
6 changes: 5 additions & 1 deletion src/chatdbg/util/printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ def __init__(self, out, debugger_prompt, chat_prefix, width, stream=False):
self._out = out
self._debugger_prompt = debugger_prompt
self._chat_prefix = chat_prefix
self._width = min(width, os.get_terminal_size().columns - len(chat_prefix))
try:
self._width = min(width, os.get_terminal_size().columns - len(chat_prefix))
except:
# get_terminal_size() may file in notebooks
self._width = width
self._stream = stream

# Call backs
Expand Down

0 comments on commit 2342a8f

Please sign in to comment.