AlignmentSpeedrun / query_data.py
ShoggySpray's picture
Upload 7 files
4dd4c75
Raw
History Blame Contribute Delete
1.27 kB
from langchain.prompts.prompt import PromptTemplate
from langchain.llms import OpenAI
from langchain.chains import ChatVectorDBChain
_template = """Given the following conversation and a follow up question, rephrase the follow up question to be a standalone question.
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 AI alignment.
You will receive a question and relevant context. Your goal is to provide a easy-to-understand answer in a conversational manner.
If avoid unnecessary jargon to ensure that your answer is accessible to a wide audience.
If you don't know the answer say "Hmm, I'm not sure." Don't try to make up an answer, keep it grounded to the context you are given.
Question: {question}
=========
{context}
=========
Answer in Markdown:"""
QA_PROMPT = PromptTemplate(template=template, input_variables=["question", "context"])
def get_chain(vectorstore):
llm = OpenAI(temperature=0)
qa_chain = ChatVectorDBChain.from_llm(
llm,
vectorstore,
qa_prompt=QA_PROMPT,
condense_question_prompt=CONDENSE_QUESTION_PROMPT,
)
return qa_chain