Skip to content

Commit

Permalink
Black
Browse files Browse the repository at this point in the history
  • Loading branch information
nicovank committed Jul 8, 2024
1 parent 5893d59 commit 4e875e4
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 27 deletions.
32 changes: 22 additions & 10 deletions src/chatdbg/chatdbg_gdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def stop_handler(event):

gdb.events.stop.connect(stop_handler)


class Code(gdb.Command):

def __init__(self):
Expand All @@ -47,8 +48,10 @@ def invoke(self, command, from_tty):
print(code(command))
return


Code()


class Definition(gdb.Command):

def __init__(self):
Expand All @@ -58,8 +61,10 @@ def invoke(self, command, from_tty):
print(clangd_lsp_integration.native_definition(command))
return


Definition()


class Config(gdb.Command):

def __init__(self):
Expand All @@ -71,8 +76,10 @@ def invoke(self, command, from_tty):
print(message)
return


Config()


# Implement the command `why`
class Why(gdb.Command):
"""Provides root cause analysis for a failure."""
Expand All @@ -88,6 +95,7 @@ def invoke(self, command, from_tty):
print(str(e))
return


Why()

gdb.execute("alias chat = why")
Expand Down Expand Up @@ -117,10 +125,14 @@ def check_debugger_state(self):
frame = gdb.selected_frame()
block = frame.block()
except gdb.error:
self.fail("Must be attached to a program that fails to use `why` or `chat`.")
self.fail(
"Must be attached to a program that fails to use `why` or `chat`."
)
except RuntimeError:
self.fail("Your program must be compiled with debug information (`-g`) to use `why` or `chat`.")

self.fail(
"Your program must be compiled with debug information (`-g`) to use `why` or `chat`."
)

def _get_frame_summaries(
self, max_entries: int = 20
) -> Optional[List[Union[_FrameSummaryEntry, _SkippedFramesEntry]]]:
Expand Down Expand Up @@ -220,25 +232,25 @@ def _initial_prompt_command_line(self):

if executable_path.startswith(os.getcwd()):
executable_path = os.path.join(".", os.path.relpath(executable_path))

prefix = "Argument list to give program being debugged when it is started is "
args = gdb.execute("show args", to_string=True).strip()
if args.startswith(prefix):
args = args[len(prefix):].strip('."')
args = args[len(prefix) :].strip('."')

return executable_path + " " + args

def _initial_prompt_input(self):
prefix = "Argument list to give program being debugged when it is started is "
args = gdb.execute("show args", to_string=True).strip()
if args.startswith(prefix):
args = args[len(prefix):].strip('."')
args = args[len(prefix) :].strip('."')

input_pipe = args.find('<')
input_pipe = args.find("<")
if input_pipe != -1:
input_file = args[input_pipe + 1:].strip()
input_file = args[input_pipe + 1 :].strip()
try:
content = open(input_file, 'r').read()
content = open(input_file, "r").read()
return content
except Exception:
self.fail(f"The detected input file {input_file} could not be read.")
Expand All @@ -249,7 +261,7 @@ def _prompt_stack(self):
in followup prompts.
"""
return None

def llm_debug(self, command: str) -> str:
"""
{
Expand Down
3 changes: 1 addition & 2 deletions src/chatdbg/chatdbg_lldb.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ def _prompt_stack(self):
in followup prompts.
"""
return None

def llm_debug(self, command: str) -> str:
"""
{
Expand All @@ -328,4 +328,3 @@ def llm_debug(self, command: str) -> str:
}
"""
return command, self._run_one_command(command)

4 changes: 2 additions & 2 deletions src/chatdbg/chatdbg_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,10 @@ def _is_user_frame(self, frame):
def _is_user_file(self, file_name):
if file_name.endswith(".pyx"):
return False
elif file_name == "<string>" or file_name.startswith('<frozen'):
elif file_name == "<string>" or file_name.startswith("<frozen"):
# synthetic entry point or frozen modules
return False
elif file_name.startswith('<ipython'):
elif file_name.startswith("<ipython"):
# stdin from ipython session
return True

Expand Down
4 changes: 2 additions & 2 deletions src/chatdbg/native_util/dbg_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def _prompt_stack(self):
def _prompt_history(self):
return str(self._history)

def build_prompt(self, arg, conversing):
def build_prompt(self, arg, conversing):
if not conversing:
return build_initial_prompt(
self._initial_prompt_enchriched_stack_trace(),
Expand Down Expand Up @@ -200,7 +200,7 @@ def _make_assistant(self) -> Assistant:
# to support colors or streaming. So, just use the original stdout
# here for all subclasses.
printer = chatdbg_config.make_printer(sys.__stdout__, self._prompt, " ", 80)

assistant = Assistant(
instruction_prompt,
model=chatdbg_config.model,
Expand Down
4 changes: 2 additions & 2 deletions src/chatdbg/native_util/stacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def lineno(self):
return self._lineno

def __str__(self):
a = ', '.join([str(a) for a in self._arguments])
a = ", ".join([str(a) for a in self._arguments])
return f"{self._index}: {self._name}({a}) at {self._file_path}:{self._lineno}"

def __repr__(self):
Expand All @@ -68,7 +68,7 @@ def build_enriched_stacktrace(summaries):
if not summaries:
print("could not generate any frame summary.")
return
else:
else:
frame_summary = "\n".join([str(s) for s in summaries])
parts.append(frame_summary)

Expand Down
4 changes: 3 additions & 1 deletion src/chatdbg/pdb_util/locals.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ def _repr_if_defined(obj: Any) -> bool:
return result


def _format_limited(value: Union[int, np.ndarray], limit: int = 10, depth: int = 3) -> str:
def _format_limited(
value: Union[int, np.ndarray], limit: int = 10, depth: int = 3
) -> str:
def format_tuple(t, depth):
return tuple([helper(x, depth) for x in t])

Expand Down
6 changes: 3 additions & 3 deletions src/chatdbg/util/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ def error(self, message):


class ChatDBGConfig(Configurable):
model = Unicode(
_chatdbg_get_env("model", "gpt-4o"), help="The LLM model"
).tag(config=True)
model = Unicode(_chatdbg_get_env("model", "gpt-4o"), help="The LLM model").tag(
config=True
)

debug = Bool(_chatdbg_get_env("debug", False), help="Log LLM calls").tag(
config=True
Expand Down
12 changes: 7 additions & 5 deletions src/chatdbg/util/prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
from typing import Any, Callable, List, Union, Optional


def _wrap_it(
before: str, text: str, after: str = "", maxlen: int = 2048
) -> str:
def _wrap_it(before: str, text: str, after: str = "", maxlen: int = 2048) -> str:
if text:
text = truncate_proportionally(text, maxlen, 0.5)
before = before + ":\n" if before else ""
Expand Down Expand Up @@ -57,9 +55,13 @@ def build_followup_prompt(history: str, extra: str, user_text: str) -> str:

def initial_instructions(functions: List[Callable[[Any], Any]]) -> str:
if chatdbg_config.instructions == "":
file_path = os.path.join(os.path.dirname(__file__), f"instructions/{chatdbg_config.model}.txt")
file_path = os.path.join(
os.path.dirname(__file__), f"instructions/{chatdbg_config.model}.txt"
)
if not os.path.exists(file_path):
file_path = os.path.join(os.path.dirname(__file__), f"instructions/default.txt")
file_path = os.path.join(
os.path.dirname(__file__), f"instructions/default.txt"
)
else:
file_path = chatdbg_config.instructions

Expand Down

0 comments on commit 4e875e4

Please sign in to comment.