Skip to content

Commit

Permalink
Respect arguments in chat command
Browse files Browse the repository at this point in the history
  • Loading branch information
nicovank committed Feb 20, 2024
1 parent afce64b commit cea2c76
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
7 changes: 5 additions & 2 deletions src/chatdbg/assistant/assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,17 @@ class Assistant:
json.txt.
"""

def __init__(self, name, instructions, model="gpt-3.5-turbo-1106", debug=True):
# TODO: At some point, if we unify the argument parsing, we should just have this take args.
def __init__(
self, name, instructions, model="gpt-3.5-turbo-1106", timeout=30, debug=True
):
if debug:
self.json = open(f"json.txt", "w")
else:
self.json = None

try:
self.client = OpenAI(timeout=30)
self.client = OpenAI(timeout=timeout)
except OpenAIError:
print("You need an OpenAI key to use this tool.")
print("You can get a key here: https://platform.openai.com/api-keys")
Expand Down
25 changes: 19 additions & 6 deletions src/chatdbg/chatdbg_lldb.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import argparse
import os
import sys
import textwrap
Expand Down Expand Up @@ -525,9 +526,19 @@ def _instructions(debugger: lldb.SBDebugger):
""".strip()


def _make_assistant(debugger: lldb.SBDebugger):
def _make_assistant(debugger: lldb.SBDebugger, args: argparse.Namespace):
if args.show_prompt:
print(_instructions(debugger))
sys.exit(0)

global _assistant
_assistant = Assistant("ChatDBG", _instructions(debugger), debug=True)
_assistant = Assistant(
"ChatDBG",
_instructions(debugger),
model=args.llm,
timeout=args.timeout,
debug=True,
)

def lldb(command):
"""
Expand Down Expand Up @@ -562,12 +573,14 @@ def lldb(command):

@lldb.command("chat")
def chat(debugger: lldb.SBDebugger, command: str, result: str, internal_dict: dict):
args, remaining = chatdbg_utils.parse_known_args(command.split())
# TODO: Bug: as of right now, arguments are only respected on the very first chat invocation.
if _assistant == None:
_make_assistant(debugger)
_make_assistant(debugger, args)

def client_print(line=""):
line = llm_utils.word_wrap_except_code_blocks(line, 115)
line = textwrap.indent(line, " ", lambda _: True)
line = llm_utils.word_wrap_except_code_blocks(line, 120)
line = textwrap.indent(line, " " * 4)
print(line, file=sys.stdout, flush=True)

_assistant.run(command, client_print)
_assistant.run(" ".join(remaining), client_print)

0 comments on commit cea2c76

Please sign in to comment.