Skip to content

Commit

Permalink
Remove remnants of asyncio
Browse files Browse the repository at this point in the history
  • Loading branch information
nicovank committed Oct 3, 2023
1 parent 680964f commit 458a51c
Show file tree
Hide file tree
Showing 6 changed files with 310 additions and 222 deletions.
4 changes: 1 addition & 3 deletions src/chatdbg/chatdbg.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#! /usr/bin/env python3

import asyncio
import os
import pathlib
import re
import sys
import traceback

Expand All @@ -18,7 +16,7 @@

class ChatDBG(chatdbg_pdb.Pdb):
def do_why(self, arg):
asyncio.run(chatdbg_why.why(self, arg))
chatdbg_why.why(self, arg)


import importlib.metadata
Expand Down
10 changes: 3 additions & 7 deletions src/chatdbg/chatdbg_gdb.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
# Add 'source <path to chatdbg>/chatdbg_gdb.py' to ~/.gdbinit

import asyncio
import os
import pathlib
import sys
import textwrap

import gdb
import openai

the_path = pathlib.Path(__file__).parent.resolve()

Expand Down Expand Up @@ -65,6 +62,7 @@ def stop_handler(event):

gdb.events.stop.connect(stop_handler)


# Implement the command `why`
class Why(gdb.Command):
"""Provides root cause analysis for a failure."""
Expand All @@ -86,10 +84,8 @@ def invoke(self, arg, from_tty, really_run=True):
the_prompt = buildPrompt()
if the_prompt:
# Call `explain` function with pieces of the_prompt as arguments.
asyncio.run(
chatdbg_utils.explain(
the_prompt[0], the_prompt[1], the_prompt[2], really_run
)
chatdbg_utils.explain(
the_prompt[0], the_prompt[1], the_prompt[2], really_run
)


Expand Down
6 changes: 1 addition & 5 deletions src/chatdbg/chatdbg_lldb.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#!env python3
import asyncio
import os
import pathlib
import re
import sys

import lldb
Expand Down Expand Up @@ -258,9 +256,7 @@ def why(
print("Execution stopped at a breakpoint, not an error.")
return
the_prompt = buildPrompt(debugger)
asyncio.run(
chatdbg_utils.explain(the_prompt[0], the_prompt[1], the_prompt[2], really_run)
)
chatdbg_utils.explain(the_prompt[0], the_prompt[1], the_prompt[2], really_run)


@lldb.command("why_prompt")
Expand Down
1 change: 0 additions & 1 deletion src/chatdbg/chatdbg_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ def namespace(self):


class Pdb(bdb.Bdb, cmd.Cmd):

_previous_sigint_handler = None

def __init__(
Expand Down
5 changes: 2 additions & 3 deletions src/chatdbg/chatdbg_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def word_wrap_except_code_blocks(text: str) -> str:
def read_lines_width() -> int:
return 10


def read_lines(file_path: str, start_line: int, end_line: int) -> str:
"""
Read lines from a file and return a string containing the lines between start_line and end_line.
Expand Down Expand Up @@ -101,9 +102,7 @@ def read_lines(file_path: str, start_line: int, end_line: int) -> str:
return "\n".join(lines[start_line:end_line])


async def explain(
source_code: str, traceback: str, exception: str, really_run=True
) -> None:
def explain(source_code: str, traceback: str, exception: str, really_run=True) -> None:
import httpx

user_prompt = "Explain what the root cause of this error is, given the following source code context for each stack frame and a traceback, and propose a fix. In your response, never refer to the frames given below (as in, 'frame 0'). Instead, always refer only to specific lines and filenames of source code.\n"
Expand Down
Loading

0 comments on commit 458a51c

Please sign in to comment.