Skip to content

Commit

Permalink
blackened
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenfreund committed Mar 22, 2024
1 parent dc4d1f4 commit 9ca4d3f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 23 deletions.
3 changes: 2 additions & 1 deletion src/chatdbg/__main__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from .chatdbg_pdb import *
import ipdb


def main():
ipdb.__main__._get_debugger_cls = lambda : ChatDBG
ipdb.__main__._get_debugger_cls = lambda: ChatDBG
ipdb.__main__.main()
37 changes: 20 additions & 17 deletions src/chatdbg/assistant/assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,16 @@ def __init__(
try:
self.client = OpenAI(timeout=timeout)
except OpenAIError:
print(textwrap.dedent("""\
print(
textwrap.dedent(
"""\
You need an OpenAI key to use this tool.
You can get a key here: https://platform.openai.com/api-keys
Set the environment variable OPENAI_API_KEY to your key value.
"""))
"""
)
)
sys.exit(-1)


self.assistants = self.client.beta.assistants
self.threads = self.client.beta.threads
Expand Down Expand Up @@ -146,11 +149,11 @@ def run(self, prompt, client_print=print):
try:
if self.assistant == None:
return {
'tokens' : run.usage.total_tokens,
'prompt_tokens' : run.usage.prompt_tokens,
'completion_tokens' : run.usage.completion_tokens,
'model' : self.assistant.model,
'cost' : cost,
"tokens": run.usage.total_tokens,
"prompt_tokens": run.usage.prompt_tokens,
"completion_tokens": run.usage.completion_tokens,
"model": self.assistant.model,
"cost": cost,
}

assert len(prompt) <= 32768
Expand Down Expand Up @@ -224,15 +227,15 @@ def run(self, prompt, client_print=print):
client_print(f"[Cost: ~${cost:.2f} USD]")

return {
'tokens' : run.usage.total_tokens,
'prompt_tokens' : run.usage.prompt_tokens,
'completion_tokens' : run.usage.completion_tokens,
'model' : self.assistant.model,
'cost' : cost,
'time' : elapsed_time,
'thread.id' : self.thread.id,
'run.id': run.id,
'assistant.id' : self.assistant.id
"tokens": run.usage.total_tokens,
"prompt_tokens": run.usage.prompt_tokens,
"completion_tokens": run.usage.completion_tokens,
"model": self.assistant.model,
"cost": cost,
"time": elapsed_time,
"thread.id": self.thread.id,
"run.id": run.id,
"assistant.id": self.assistant.id,
}
except OpenAIError as e:
client_print(f"*** OpenAI Error: {e}")
Expand Down
8 changes: 4 additions & 4 deletions src/chatdbg/chatdbg_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def __init__(self, *args, **kwargs):
self._assistant = None
self._history = []
self._error_specific_prompt = ""

global chatdbg_config
if chatdbg_config == None:
chatdbg_config = Chat()
Expand Down Expand Up @@ -152,7 +152,9 @@ def interaction(self, frame, tb_or_exc):
exception = None

if exception != None:
details = "".join(traceback.format_exception_only(type(exception), exception)).rstrip()
details = "".join(
traceback.format_exception_only(type(exception), exception)
).rstrip()
self._error_specific_prompt = (
f"The program encountered the following error:\n```\n{details}\n```\n"
)
Expand Down Expand Up @@ -587,8 +589,6 @@ def do_mark(self, arg):
else:
self._log.add_mark(arg)



def do_config(self, arg):
args = arg.split()
if len(args) == 0:
Expand Down
3 changes: 2 additions & 1 deletion src/chatdbg/ipdb_util/capture.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from io import StringIO, TextIOWrapper


class CaptureInput:
def __init__(self, input_stream):
input_stream = TextIOWrapper(input_stream.buffer, encoding='utf-8', newline='')
input_stream = TextIOWrapper(input_stream.buffer, encoding="utf-8", newline="")

self.original_input = input_stream
self.capture_buffer = StringIO()
Expand Down

0 comments on commit 9ca4d3f

Please sign in to comment.