-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathqa.py
35 lines (27 loc) · 858 Bytes
/
qa.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
import argparse
import pickle
import faiss
from promptlayer.langchain.llms import OpenAI
from langchain.chains import VectorDBQAWithSourcesChain
parser = argparse.ArgumentParser(description="Ask a question to the cloudflare docs.")
parser.add_argument(
"question", type=str, help="The question to ask the cloudflare docs"
)
args = parser.parse_args()
index = faiss.read_index("docs.index")
with open("cloudflare_docs.pkl", "rb") as f:
store = pickle.load(f)
store.index = index
chain = VectorDBQAWithSourcesChain.from_llm(
llm=OpenAI(
temperature=0,
max_tokens=1500,
model_name="text-davinci-003",
max_retries=3,
pl_tags=["cloudflare-qa-agent"],
),
vectorstore=store,
)
result = chain({"question": args.question})
print(f"Answer: {result['answer']}")
print(f"Sources: {result['sources']}")