forked from FeatureBaseDB/slothbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscratch.py
60 lines (47 loc) · 1.89 KB
/
scratch.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
# reference code
answer_dict = ai("sql", document)
document = {**document, **answer_dict}
# not working
data_uuid = weaviate_update(document)
# got a SQL query back
if document.get("is_sql", False) and document.get("is_sql").lower() == "true":
try:
query = document.get("sql")
result = requests.post(url, data=query.encode('utf-8'), headers={'Content-Type': 'text/plain'}).json()
except Exception as bullshit:
# bad sql
exc_type, exc_obj, exc_tb = sys.exc_info()
await message.channel.send("(╯°□°)╯︵ ┻━┻")
await message.channel.send("%s: %s" % (exc_tb.tb_lineno, bullshit))
# got an answer from featurebase
if result.get('error', ""):
document.setdefault("error", result.get('error', ""))
answer_dict = ai("sql_feedback", document)
document = {**document, **answer_dict}
try:
query = document.get("sql")
result = requests.post(url, data=query.encode('utf-8'), headers={'Content-Type': 'text/plain'}).json()
except Exception as bullshit:
# bad sql
exc_type, exc_obj, exc_tb = sys.exc_info()
await message.channel.send("(╯°□°)╯︵ ┻━┻")
await message.channel.send("%s: %s" % (exc_tb.tb_lineno, bullshit))
elif result.get('data', []):
print(result.get('data'))
answer_dict = ai("response", document)
for bits in _result["data"]:
try:
# await message.channel.send(bits)
pass
except Exception as bullshit:
exc_type, exc_obj, exc_tb = sys.exc_info()
await message.channel.send("%s: %s" % (exc_tb.tb_lineno, bullshit))
await message.channel.send(ai("response", document={"query": message.content,"result": _result['data'], "user": message.author.name, "sql": query}))
else:
await message.channel.send(result)
else:
if document.get("explain") != "":
await message.channel.send(document.get("explain"))
else:
answer = "Unfortunately, when I thought about this I have nothing to say."
await message.channel.send(answer)