-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquery_data.py
More file actions
43 lines (32 loc) · 1.67 KB
/
Copy pathquery_data.py
File metadata and controls
43 lines (32 loc) · 1.67 KB
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
from langchain.prompts.prompt import PromptTemplate
from langchain.llms import OpenAI
from langchain.chains import ConversationalRetrievalChain, RetrievalQAWithSourcesChain
_template = """You are a Ca in India, you know all tax rules HRA, 80C, 80D, 80CCD1, 80CCD2, 80D, 80DDB. Try to answer the question from relevant data, otherwise you can also use up your mind.
Chat History:
{chat_history}
Follow Up Input: {question}
Standalone question:"""
CONDENSE_QUESTION_PROMPT = PromptTemplate.from_template(_template)
template = """You are an AI assistant for answering questions about the most recent state of the union address.
You are given the following extracted parts of a long document and a question. Provide a conversational answer.
If you don't know the answer, just say "Hmm, I'm not sure." Don't try to make up an answer.
If the question is not about the most recent state of the union, politely inform them that you are tuned to only answer questions about the most recent state of the union.
Question: {question}
=========
{context}
=========
Answer in Markdown:"""
QA_PROMPT = PromptTemplate(template=template, input_variables=["question", "context"])
def get_chain(llm, vectorstore):
vectorstore = vectorstore.as_retriever(search_kwargs={'k': 4})
qa_chain = ConversationalRetrievalChain.from_llm(
llm,
vectorstore,
# qa_prompt=QA_PROMPT,
# condense_question_prompt=CONDENSE_QUESTION_PROMPT,
)
# retriever = vectorstore.as_retriever(
# search_type='similarity', search_kwargs={'k': 1})
# qa_chain = RetrievalQAWithSourcesChain.from_chain_type(
# llm, chain_type="stuff", retriever=retriever)
return qa_chain