Spaces:
Sleeping
Sleeping
| """Contains the prompt templates for chat and summarization tasks.""" | |
| from langchain.prompts import ChatPromptTemplate, MessagesPlaceholder | |
| from logger import get_logger | |
| log = get_logger(name="chains_prompts") | |
| # Chat Template: | |
| template_chat = ChatPromptTemplate.from_messages( | |
| messages=[ | |
| ("system", ( | |
| "You are a highly knowledgeable and helpful AI assistant.\n" | |
| "You will be provided with:\n" | |
| "- The user's ongoing conversation history\n" | |
| "- A set of external context documents\n\n" | |
| "Your responsibilities:\n" | |
| "1. Answer the user's latest query clearly and accurately.\n" | |
| "2. Integrate relevant information from the context documents provided below.\n" | |
| "3. Use markdown formatting for readability (e.g., headings, bullet points, code blocks, tables, ...).\n" | |
| "4. If the required answer is not found in the context, explicitly mention this and fall back to your general knowledge, making it clear that the source is outside the provided documents.\n\n" | |
| "### Context Documents\n" | |
| "<CONTEXT>{context}</CONTEXT>" | |
| )), | |
| MessagesPlaceholder(variable_name="chat_history"), | |
| # ("human", "{input} \n\n **Strictly stick to the instructions!**") | |
| ("human", "{input}") | |
| ] | |
| ) | |
| # Summarizer Template: | |
| template_summarize = ChatPromptTemplate.from_messages( | |
| messages=[ | |
| ("system", "".join([ | |
| "You are an expert at summarizing conversations into standalone prompts.\n" | |
| "You are given a complete chat history, ending with the user's latest message.\n\n" | |
| "Your task is to:\n" | |
| "- Understand the entire conversation context.\n" | |
| "- Identify references in the latest user message that relate to earlier messages.\n" | |
| "- Create a single clear, concise, and standalone question or prompt.\n" | |
| "- This final prompt should be fully understandable without needing the prior conversation.\n" | |
| "- It will be used to retrieve the most relevant documents.\n\n" | |
| "Only return the rewritten standalone prompt. Do not add explanations or formatting." | |
| ])), | |
| MessagesPlaceholder(variable_name="chat_history"), | |
| ("human", "{input}. \n\n **Make one standalone prompt as asked!**") | |
| ] | |
| ) | |
| log.info("Initialized chat and summarize prompt templates.") | |