-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
105 lines (76 loc) · 3.89 KB
/
main.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
from flask import Flask, request
from agent_executor.agent_executer import *
from langchain.callbacks import get_openai_callback
import time
app = Flask(__name__)
@app.route('/predict' , methods = ['POST'])
def predict():
input_data = request.json['input']
output = predict_function(input_data)
# if output["output"] == [] and thought==[]:
# output["thought"] = "Encountered internal error!"
return {'output': output}
import json
cot = 0
def predict_function(query):
agent_executor.eval()
print('response_schema : ' , agent_executor.return_schema)
with get_openai_callback() as cb:
x = agent_executor(inputs={"input": query})
predict_json = agent_executor.return_schema
# json.dump(predict_json, open('predict.json', 'w'))
thought_action_observations = agent_executor.thought_execution_chain
a = {'thought': thought_action_observations ,'output': predict_json , }
json.dump(a, open('abc.json', 'w'), indent = 4)
print('\n\n\n\n\n' ,cb.total_cost)
return a
# if __name__ == '__main__':
# app.run()
# Dataset Queries:
# predict_function('Prioritize all tickets from the support channel "Email"') #
# predict_function('Summarize issues similar to don:core:dvrv-us-1:devo/0:issue/1') #
# predict_function('What is the meaning of life?') #
# predict_function('List all high severity tickets coming in from slack from customer Cust123 and generate a summary of them.') #
# predict_function('Prioritize my P0 issues and add them to the current sprint') #
# predict_function('How crocodiles give birth?') #
# predict_function('Summarize high severity tickets from the customer UltimateCustomer') #
# predict_function('Prioritize my P0 issues and what is the meaning of life') #
# predict_function('Get all work items similar to TKT-123, summarize them, create issues from that summary, and prioritize them ') #
# predict_function('Get all my blocker and high severity tickets, prioritize them, and summarize them and create actionable task from summary') #
def keep_digits(string):
return re.sub(r'[^\d]+', '', string)
def parser(arguments_dict,function_signatures):
for key,values in arguments_dict.copy().items():
if key not in function_signatures.keys():
continue
if values==[]:
del arguments_dict[key]
continue
if values==False and key=='ticket_needs_response':
del arguments_dict[key]
continue
if type(values)==list:
for i,value in enumerate(values):
if type(value)==str:
if "PREV" in value:
arguments_dict[key][i]=f"$$PREV[{keep_digits(value)}]"
if function_signatures[key]==str:
arguments_dict[key]=value
else:
arguments_dict[key][i].replace(arguments_dict[key][i],value)
else:
if type(values)==str:
if "PREV" in values:
arguments_dict[key]=f"$$PREV[{keep_digits(values)}]"
if function_signatures[key]==List[str]:
if type(values)!=list:
arguments_dict[key]=[values]
return arguments_dict
# predict_function('What are my all issues in the triage stage under part FEAT-123? Summarize them.')
# predict_function('Given a customer meeting transcript T, create action items and add them to my current sprint')
# predict_function('MANGO MOO about my MEOW')
# predict_function('If $$PREV[0] is greater than $$PREV[1] then return 1 else return 3')
# predict_function('Get all work items similar to TKT-123, summarize them, create issues from that summary, and prioritize them.')
# predict_function('List all high severity tickets coming in from slack from customer abc123 and generate a summary of them.')
# predict_function('How is life going?')
# predict_function('Prioritise my p0 issues')