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.
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)