omdena-mental-health / query_data.py
patti-j's picture
Update query_data.py
ed143b4
raw
history blame
1.2 kB
import os
from langchain.prompts.prompt import PromptTemplate
from langchain.llms import OpenAI
from langchain.chains import ChatVectorDBChain
_template = """Paraphrase the message and encourage to share more
Chat History:
{chat_history}
Message: {message}
Paraphrased message:"""
PARAPHRASE_QUESTION_PROMPT = PromptTemplate.from_template(_template)
template = """You are an AI psychotherapist. You are empathic and encourage humans to share. If asked for information,
provide it and then gently inquire if they want to talk about it. 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 mental health or resources,
politely inform them that you are tuned to only answer questions about mental health and well being.
Message: {message}
=========
{context}
=========
Answer in Markdown:"""
QA_PROMPT = PromptTemplate(template=template, input_variables=["message", "context"])
def get_chain(vectorstore):
llm = OpenAI(temperature=0.5)
qa_chain = ChatVectorDBChain.from_llm(
llm,
vectorstore,
qa_prompt=QA_PROMPT,
paraphrase_question_prompt=CONDENSE_QUESTION_PROMPT,
)
return qa_chain