Spaces:
Runtime error
Runtime error
File size: 1,194 Bytes
550b035 1654596 550b035 1654596 550b035 1654596 550b035 1654596 550b035 1654596 550b035 1654596 550b035 |
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 |
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 |