mirror of
https://github.com/tiennm99/atnvc-qa.git
synced 2026-08-07 02:23:55 +00:00
23 lines
762 B
Python
23 lines
762 B
Python
"""Ask a question to the notion database."""
|
|
import faiss
|
|
from langchain.chat_models import ChatOpenAI
|
|
from langchain.chains import RetrievalQAWithSourcesChain
|
|
import pickle
|
|
import argparse
|
|
|
|
parser = argparse.ArgumentParser(description='Ask a question to the ATNVC.')
|
|
parser.add_argument('question', type=str, help='The question to ask the ATNVC')
|
|
args = parser.parse_args()
|
|
|
|
# Load the LangChain.
|
|
index = faiss.read_index("docs.index")
|
|
|
|
with open("faiss_store.pkl", "rb") as f:
|
|
store = pickle.load(f)
|
|
|
|
store.index = index
|
|
chain = RetrievalQAWithSourcesChain.from_chain_type(llm=ChatOpenAI(temperature=0), retriever=store.as_retriever())
|
|
result = chain({"question": args.question})
|
|
print(f"Answer: {result['answer']}")
|
|
print(f"Sources: {result['sources']}")
|