Update app.py

This commit is contained in:
Alex 2023-03-03 18:05:00 +00:00
parent 17047b6201
commit 02aca04efe

View File

@ -1,7 +1,6 @@
import os import os
import json import json
import traceback import traceback
import pprint
import dotenv import dotenv
import requests import requests
@ -137,15 +136,10 @@ def api_answer():
qa_chain = load_qa_chain(llm=llm, chain_type="map_reduce", qa_chain = load_qa_chain(llm=llm, chain_type="map_reduce",
combine_prompt=c_prompt, question_prompt=q_prompt) combine_prompt=c_prompt, question_prompt=q_prompt)
chain = VectorDBQA(combine_documents_chain=qa_chain, vectorstore=docsearch, k=25, return_source_documents=True) chain = VectorDBQA(combine_documents_chain=qa_chain, vectorstore=docsearch, k=10)
# fetch the answer # fetch the answer
result = chain({"query": question}) result = chain({"query": question})
# pprint.pprint(result)
# docs = docsearch.similarity_search(question, k=8)
for i in result['source_documents']:
print(i.page_content)
# some formatting for the frontend # some formatting for the frontend
result['answer'] = result['result'] result['answer'] = result['result']
@ -154,7 +148,6 @@ def api_answer():
result['answer'] = result['answer'].split("SOURCES:")[0] result['answer'] = result['answer'].split("SOURCES:")[0]
except: except:
pass pass
del result['source_documents']
# mock result # mock result
# result = { # result = {