Spaces:
Running
on
Zero
Running
on
Zero
| 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. | |
| You MUST clearly refuse to answer the query and ask for additional information from the user if the answer cannot be found in the context. | |
| 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, clearly state that you do not have enough information. | |
| OTHERWISE, refuse clearly to answer and ask for the additional information you require 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 |