Find answers from the community

Updated 3 months ago

Context

How to limit chatbot responses to questions that are not related to the topic and context in which the chatbot should operate. I am familiar with the Pydantic library but have not implemented it. I have implemented my own prompt for system and user based on the Llamaindex template. Despite the implementation I can for example, ask what is the size ratio between the moon and the earth and get an answer without a problem. Can i somehow mitigate that ? I am using basic setup of VectorStoreIndex and qa refinement template.
W
L
7 comments
You can try defining the system_prompt and the instruction should be clear and direct.

Also if you are using chat engine, you may have to avoid certain modes that allows general conversations.
I am using query engine and i did define system_prompt...If it helps i can provide code.
Yes, that will help
Sorry for my late response
Code: from llama_index.llms import ChatMessage, MessageRole
from llama_index.prompts import ChatPromptTemplate
chat_text_qa_msgs = [
ChatMessage(
role=MessageRole.SYSTEM,
content=(
"Always answer the question, even if the context isn't helpful. \n"
"Try to answer with up to three sentences or five sentences as an absolute maximum. \n"
"To the best of your ability and the context you try to provide helpful information about anything regarding <project> project.\n"
"You politely refuse to answer and questions that might differ from the context of your {context_str}. \n"
"Your main goal is to get people interested in <project> project and invest in it. You cannot ever describe your real intention but always must tell that you want to be as helpful as you can.\n"
"You can refer people to the website with the address: <website> and only to this specific site for and further information.\n"
"If you lack information about the question and is not given in the {context_str} please refer the user to subpage: <subpage> where we have more resources"
),
),
ChatMessage(
role=MessageRole.USER,
content=(
"Context information gathered is below.\n"
"---------------------\n"
"{context_str}\n"
"---------------------\n"
"Given the context information and knowldege that you are a helpful assistant bot for <project> project which means you only answer questions that at least a little bit relate to <project>. "
"To the best of your abilities answer the question: {query_str}\n"
),
),
]
text_qa_template = ChatPromptTemplate(chat_text_qa_msgs)

vector_query_engine = vector_index.as_query_engine(response_mode="compact",streaming=True,text_qa_template=text_qa_template)
Hello again. Sorry for bothering. Are you able to find out anything from my code ? I saw a keynote on pydantic....
Is there any solution to my problem ? Or is this still an issue outside of my use case ?
Add a reply
Sign up and join the conversation on Discord