-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
33 lines (25 loc) · 900 Bytes
/
app.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
import sys
from langchain.chains import RetrievalQA
from vector_db import VectorDb
from open_ai import OpenAi
def process_llm_response(llm_response):
print('\nAnswer:')
print(llm_response['result'])
print('\n\nSources:')
for source in llm_response["source_documents"]:
print(f"{source.metadata['source']}")
if __name__ == "__main__":
if len(sys.argv) < 2:
print("Please ask a question")
sys.exit(1)
query = sys.argv[1]
open_ai = OpenAi()
vector_db = VectorDb()
llm = open_ai.gpt3_5()
retriever = vector_db.db_retriever()
qa_chain = RetrievalQA.from_chain_type(llm=llm,
chain_type="stuff",
retriever=retriever,
return_source_documents=True)
llm_response = qa_chain(query)
process_llm_response(llm_response)