Skip to content

Commit

Permalink
refactor and add colored output
Browse files Browse the repository at this point in the history
  • Loading branch information
uzairname committed Nov 19, 2023
1 parent 989632c commit 7b21e70
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 15 deletions.
22 changes: 20 additions & 2 deletions src/swibin/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,35 @@ def explain_error_with_gpt(error_message):
model="gpt-3.5-turbo-1106",
messages=[
{"role": "system", "content": "You are a python expert that gives specific code suggestions."},
{"role": "user", "content": f"{error_message}\n\nUnderstand the following exception, along with all of the associated functions. Explain what might have caused it and suggest possible fixes. Mention line numbers and function names if applicable. Be concise. Answer in 200 words or less."}
{"role": "user", "content": f"{error_message}\n\nUnderstand the following exception, along with all of the associated functions. Explain what might have caused it and suggest possible fixes. Mention line numbers and include code blocks. When using line numbers, use the format \"/path/to/file:line\" "}
],
stream=True
)

for chunk in response:
print(chunk.choices[0].delta.content, end="")
print(color_terminal_code_blocks( chunk.choices[0].delta.content), end="")

except Exception as e:
return f"Error in contacting OpenAI API: {str(e)}"

is_code_block = False

def color_terminal_code_blocks(text):
# replace all instances of ``` with a color

for char in text:
if char == '`':
global is_code_block
is_code_block = not is_code_block
if is_code_block:
text = text.replace('`', f'\033[{31}m`', 1)
else:
text = text.replace('`', '\033[0m`', 1)

return text



def run_script(script_path, custom_prompt=""):
try:
output = subprocess.check_output([sys.executable, script_path], stderr=subprocess.STDOUT)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
13 changes: 0 additions & 13 deletions src/test/helpers/vectormath.py → test/helpers/vectormath.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,6 @@ def proj(v,u):
return pv


def transpose(A):
'''Calculate the transpose of matrix A represented as list of lists'''
n = len(A)
m = len(A[0])
AT = list()
for j in range(0,m):
temp = list()
for i in range(0,n):
temp.append(A[i][j])
AT.append(temp)
return AT


def subtract(a, b):
return [(a_ - b_) for (a_, b_) in list(zip(a, b))]

File renamed without changes.

0 comments on commit 7b21e70

Please sign in to comment.