Spaces:
Sleeping
Sleeping
from langchain_pinecone import PineconeVectorStore | |
from langchain_aws import BedrockEmbeddings | |
from langchain.chains.llm import LLMChain | |
from langchain.prompts import PromptTemplate | |
from langchain_aws import ChatBedrock | |
INDEX_NAME = "zeteo-health" | |
NAMESPACE = "knowedgebase" | |
EMBEDDING_DIMENSION = 1536 | |
EMBEDDING_MODEL_NAME = "amazon.titan-embed-text-v1" | |
PROMPT = """ | |
Your name is Zeteo Assistant. | |
You are answering questions about health. | |
Only use simple words and descriptions. | |
Respond with an empathetic tone. | |
Be informative but concise. | |
You will only respond in English. | |
Address your response in second person. | |
Use the first name if it is given to address the response. | |
Be friendly but formal, avoid phrases like "Hey there". | |
If the question is chit chat such as "Hello", "How are you?", "Good morning", "thank you" or "Howdy" respond with a simple greeting and do not include any other information, especially related to health. | |
Limit your response only to information contained in the <context>. When referring to the context, use the term "information". | |
If the question is not about healthcare and can't be found in the <context> respond with, "I am sorry, I don't have information to answer that question." | |
<context> | |
{context} | |
</context> | |
<profile> | |
{profile} | |
</profile> | |
<question> | |
{question} | |
</question> | |
""" | |
prompt = PromptTemplate.from_template(PROMPT) | |
def getkb(): | |
vectorstore = PineconeVectorStore(index_name=INDEX_NAME, | |
embedding=BedrockEmbeddings(model_id=EMBEDDING_MODEL_NAME), | |
namespace=NAMESPACE) | |
return vectorstore | |
def get_response(question, context, name): | |
llm = ChatBedrock(model_id='anthropic.claude-3-sonnet-20240229-v1:0') | |
chat_chain = LLMChain(llm=llm, prompt=prompt) | |
result = chat_chain.invoke( | |
{ | |
"context": context, | |
"question": question, | |
"profile": f"name: {name}" | |
} | |
)['text'] | |
return result | |