-
Notifications
You must be signed in to change notification settings - Fork 213
/
main.py
42 lines (34 loc) · 1.25 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
import box
import timeit
import yaml
import argparse
from dotenv import find_dotenv, load_dotenv
from src.utils import setup_dbqa
# Load environment variables from .env file
load_dotenv(find_dotenv())
# Import config vars
with open('config/config.yml', 'r', encoding='utf8') as ymlfile:
cfg = box.Box(yaml.safe_load(ymlfile))
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('--input',
type=str,
default='How much is the minimum guarantee payable by adidas?',
help='Enter the query to pass into the LLM')
args = parser.parse_args()
# Setup DBQA
start = timeit.default_timer()
dbqa = setup_dbqa()
response = dbqa({'query': args.input})
end = timeit.default_timer()
print(f'\nAnswer: {response["result"]}')
print('='*50)
# Process source documents
source_docs = response['source_documents']
for i, doc in enumerate(source_docs):
print(f'\nSource Document {i+1}\n')
print(f'Source Text: {doc.page_content}')
print(f'Document Name: {doc.metadata["source"]}')
print(f'Page Number: {doc.metadata["page"]}\n')
print('='* 60)
print(f"Time to retrieve response: {end - start}")