-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
72 lines (55 loc) · 1.74 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
'''
This is the main file for the Auto Vector Database.
'''
import logging
import sys
import argparse
from helpers.AutoVectorDatabase import AutoVectorDatabase
from helpers.LoggingSetup import loggingSetup
from dotenv import load_dotenv
from controllers.conversation import Conversation
from models.dialog import Dialog
from views.ViewResponse import ViewResponse
def parseArguments():
''' Parse command line arguments '''
# Create parser
parser = argparse.ArgumentParser(
description='Auto Vector Database')
# Add arguments
parser.add_argument('-vs', '--view-sources', action='store_true',
help='View sources of response.')
# Parse arguments
args = parser.parse_args()
# Return arguments
return args
def main():
''' Main function '''
# Load .env file
load_dotenv()
# Arguments : Parse
args = parseArguments()
# Logging : Setup
loggingSetup(console_log_enabled=True,
logfile_enabled=False)
# Database : Create
database = AutoVectorDatabase(databasePath='database')
# Conversation : Create
conversation = Conversation()
# Prompt : Prompt database in a loop
prompt = ''
while (len(prompt) != 'q'):
# User input : get prompt
prompt = input('Prompt (write `q` to exit):')
# Prompt : Check
if (len(prompt) == 0) or (prompt == 'q'):
break
# Database : Query prompt
response = database.Query(prompt)
# Response : Print
ViewResponse.View(args, response)
# Conversation : Add dialog
conversation.Add(Dialog(question=prompt, answer=response))
# Conversation : Save
conversation.Save(args=args)
if __name__ == '__main__':
main()