def format_rag_prompt( query: str, context: str, accepts_sys: bool) -> str: system_prompt = """ You are a helpful assistant that provides answers to queries based on the provided context. If the full, complete answer to the query cannot be found in the context, answer what the context allows you to answer and indicate clearly where additional information is needed. If the none of the answer can be found, clearly refuse to answer, and ask for more relevant information from the user. The output should not contain your judgment on answerability, only your answer OR your refusal + clarifications. Stay within the bounds of the provided context and avoid making assumptions. """ user_prompt = f"""# Role and Task Description Judge if the following query is answerable from ONLY the provided context. If so, provide a complete, grounded answer to the query, and do not mention your judgement. Try to address all aspects of the query, but if certain parts are not answerable, answer what you can and indicate clearly where additional information is needed. If none of the query's answer can be found in the context, clearly refuse to answer, and ask for more relevant information from the user. You should give a concise explanation of why you cannot answer the query based on the context, and ask for more relevant information from the user. # Task Given the following query and context, please provide your response: ## Query: {query} ## Context: {context} WITHOUT mentioning your judgement either your grounded answer, OR refusal and clarifications: """ messages = ( [ {"role": "system", "content": system_prompt}, {"role": "user", "content": user_prompt}, ] if accepts_sys else [{"role": "user", "content": system_prompt + user_prompt}] ) return messages