-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcall_clerkie.py
61 lines (53 loc) · 1.87 KB
/
call_clerkie.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import requests
from rich import print
from rich.console import Console
import os
# Set the base URL of the Flask app
base_url = "https://clerkieserverchromeextensionv1.krrishdholakia.repl.co/"
error_log_path = os.path.expanduser("~") + "/.clerkie-cli/clerkie-src/c.log"
user_email_path = os.path.expanduser("~") + "/.clerkie-cli/clerkie-src/clerkie.txt"
def get_user_id():
if not os.path.exists(user_email_path): # if user has not gone through email setup
return "default_user"
user_id_file = open(user_email_path, 'r')
email = ""
for line in user_id_file:
line = line.strip()
if line != "":
email = line
return email
def debug_terminal():
f = open(error_log_path,'r')
i = 0
error_msg =""
for line in f:
if i > 50:
break
error_msg += line.replace('\x00', '') # handle empty bytes, don't send in req
i+=1
f.close()
# clear file
f = open(error_log_path,'w')
f.seek(0)
f.close()
lib_err_msg = """shell_session_save"""
if len(error_msg.strip())==0 or "type your request:" in error_msg or lib_err_msg in error_msg: # don't send empty stacktraces
return
# Send a GET request to the app with the user_query argument
console = Console()
returned = False
with console.status("[bold green] Clerkie noticed an error. Thinking :robot:") as status:
while not returned:
response = requests.get(base_url + "/term", params={"user_query": error_msg, "user_id": get_user_id()})
returned = True
# Check the status code of the response
if response.status_code == 200:
# Print the response body
clerkie_resp = response.json()["response"]
print("[bold green]\nClerkie:robot:: " + clerkie_resp.strip())
return response.json()["response"]
else:
# Print an error message
return
# print("Failed to query the app. Status code: " + str(response.status_code))
clerkie_resp = debug_terminal()