-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
67 lines (58 loc) · 3.04 KB
/
main.py
File metadata and controls
67 lines (58 loc) · 3.04 KB
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
from colorama import Fore, Style
from call_gpt import predicate_gen, sentence_diversity, sentence_gen, chat, query_confirm, change_mind_confirm, irrelevant_reply
from reasoner import reasoner
from filter import get_predicates, filter
from call_gpt import predicate_gen
paths = ['data/info_list.pl', 'data/state.pl', 'data/knowledge.pl', 'src/functions.pl', 'src/update.pl', 'src/preference.pl', 'src/extra_preference.pl', 'src/results.pl', 'data/log.pl', 'src/query.pl']
attrs, values = get_predicates()
r = reasoner(paths)
session_continues = True
mode = 'recommend'
confirm = ''
reply = 'Hello what can I do for you?'
while(session_continues):
reply = sentence_diversity(reply).strip()
print('\n' + Fore.YELLOW + 'Finance Bot:' + Style.RESET_ALL)
if confirm:
print(confirm + ' ' + reply + Fore.CYAN + '\n\nYou: ' + Style.RESET_ALL)
confirm = ''
else:
print(reply + Fore.CYAN + '\n\nYou: ' + Style.RESET_ALL)
query = input()
if mode == 'ask':
query = '[begin context] ' + reply + ' [end context] ' + query
query_predicates = predicate_gen(query).strip()
print(Fore.GREEN + '\n[extracted semantics] ' + Style.RESET_ALL + query_predicates)
query_predicates = filter(query_predicates, attrs, values)
if query_predicates == 'quit.':
session_continues = False
print('\n' + Fore.YELLOW + 'FinanceBot:' + Style.RESET_ALL + '\n' + chat(query + 'Please quit.'))
continue
if query_predicates == 'irrelevant.':
#irr_reply = chat(query)
#irr_reply = irrelevant_reply(query)
irr_reply = 'Sorry, I am just a Finance Professional suggesting stocks for beginners. For other things, please ask other people for help.'
if mode == 'ask':
reply = irr_reply + reply
else:
reply = irr_reply + ' What can I help you with?'
elif query_predicates == 'thank.':
reply = 'You are welcome. It\'s my pleasure to help. What else can I help you?'
else:
reply_predicates = r.reason(query_predicates)
if not reply_predicates:
reply = 'Sorry could you please say that again?'
elif type(reply_predicates) == dict and 'Success' in reply_predicates:
reply = 'Sorry, but we can\'t find the result for your requirement. We can find result with ' + reply_predicates['Success'] + ', but no stock has ' + reply_predicates['Fail'] + '.'
mode = 'recommend'
else:
confirm = query_confirm(query_predicates)
mode = reply_predicates['Mode']
if mode == 'change':
mode = 'ask'
print(Fore.GREEN + '\n[preference confirming] ' + Style.RESET_ALL + reply_predicates['Output'])
reply = change_mind_confirm(reply_predicates['Output'])
if mode == 'ask':
reply = 'Do you have any preference for the ' + reply_predicates['Output'] + ' of the stock?'
if mode == 'recommend':
reply = sentence_gen(reply_predicates['Output'][1:-1]).strip() + ' Do you like it?'