Spaces:
Runtime error
Runtime error
import os | |
from langchain import PromptTemplate | |
from langchain.llms import OpenAI | |
from langchain.chains import ConversationalRetrievalChain | |
from langchain.chains import LLMChain | |
#from llama_index import SimpleDirectoryReader, LangchainEmbedding, GPTListIndex,GPTSimpleVectorIndex, PromptHelper | |
#from llama_index import LLMPredictor, ServiceContext | |
prompt_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. | |
Chat History:{chat_history} Chat Message: {chat_message} | |
Answer in Markdown:""" | |
def get_chain(chat_message, chat_history): | |
llm = OpenAI(temperature=0.9) | |
llm_chain = LLMChain(llm=llm, prompt=PromptTemplate.from_template(prompt_template)), | |
input_variables=["chat_message", "chat_history"] | |
output = llm_chain.run() | |
return output |