stylechatGPT / query_data.py
sshaileshk's picture
updated files
6b14dad
Raw History Blame Contribute Delete
2.61 kB
from langchain.prompts.prompt import PromptTemplate
from langchain.chat_models import ChatOpenAI
from langchain.chains import ConversationalRetrievalChain
#from langchain.chains import ChatVectorDBChain
import langchain
langchain.verbose = False
_template = """Given the following conversation and a follow up question, rephrase the follow up question to be a standalone question.
You can assume the question about the most recent response being sent.
Chat History:
{chat_history}
Follow Up Input: {question}
Standalone question:"""
CONDENSE_QUESTION_PROMPT = PromptTemplate.from_template(_template)
template_1 = """You are an AI assistant for answering questions about the most recent chat conversation.
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 files being sent, politely inform them that you are tuned to only answer questions about the files being outside of contents in this chat.
Question: {question}
=========
{context}
=========
Answer in Markdown:"""
template_2 = """You are an AI assistant for answering questions about the most recent chat conversation.
Question: {question}
=========
{context}
=========
Answer in Markdown:"""
qa_template = """
You are a helpful AI assistant named ICC. The user gives you a file its content is represented by the following pieces of context, use them to answer the question at the end.
If you don't know the answer, just say you don't know. Do NOT try to make up an answer.
If the question is not related to the context, politely respond that you are tuned to only answer questions that are related to the context.
Use as much detail as possible when responding.
Question: {question}
=========
{context}
=========
Answer in Markdown:"""
QA_PROMPT = PromptTemplate(template=qa_template, input_variables=["question", "context"])
def get_chain(vectorstore):
#llm = ChatOpenAI(temperature=0)
llm = ChatOpenAI(model_name="gpt-3.5-turbo", temperature=0)
retriever = vectorstore.as_retriever()
qa_chain = ConversationalRetrievalChain.from_llm(llm=llm,
retriever=retriever, verbose=False, return_source_documents=True, max_tokens_limit=4097, combine_docs_chain_kwargs={'prompt':QA_PROMPT})
#qa_chain = ChatVectorDBChain.from_llm(
# llm,
# vectorstore,
# qa_prompt=QA_PROMPT,
# condense_question_prompt=CONDENSE_QUESTION_PROMPT,
#)
return qa_chain