Spaces:
Sleeping
Sleeping
File size: 3,604 Bytes
c3057bf |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
from langchain_core.prompts import ChatPromptTemplate
# Rewriting process using ChatPromptTemplate
IMPROVE_PROMPT = ChatPromptTemplate.from_messages(
[
("system", """
You are a question rewriter that optimizes an input question for better retrieval from vectorstore data containing information security regulatory texts, especially tha digital operations security acrt (DORA).
The regulatory texts in the vectorstore mainly address the following topics: {topics}.
Your goal is to understand the underlying semantic intent of the input question and reformulate it to improve clarity and relevance for retrieving content on {topics}.
If the question is not related to any of the topics or information security regulatory texts, simply answer: "Thats an interesting question, but I dont think I can answer it based on my Dora knowledge."
"""),
(
"human",
"Here is the initial question: \n\n{question} \nPlease formulate an improved version of the question, focusing on clarity and retrieval optimization."
),
]
)
RELEVANCE_PROMPT = ChatPromptTemplate.from_messages(
[
("system", """You are a grader assessing relevance of a retrieved document to a user question. \n
If the document contains keyword(s) or semantic meaning related to the user question, grade it as relevant. \n
It does not need to be a stringent test. The goal is to filter out erroneous retrievals. \n
Give a binary score 'yes' or 'no' score to indicate whether the document is relevant to the question."""
),
("human", "Retrieved document: \n\n {document} \n\n User question: {question}"),
]
)
ANSWER_PROMPT = ChatPromptTemplate.from_messages(
[
(
"system",
"You are a highly experienced IT auditor, specializing in information security and regulatory compliance. Your task is to assist a colleague who has approached you with a question."
" You have access to relevant context, provided here: {context}."
" Please respond with a clear, concise, and precise answer, strictly based on the provided context. Ensure your response is accurate and always cite sources from the context."
" Do not introduce any new information or alter the context in any way."
),
("user", "{question}"),
]
)
HALLUCINATION_PROMPT = ChatPromptTemplate.from_messages(
[
("system", """You are a grader assessing whether an LLM generation is grounded in / supported by a set of retrieved facts. \n
Give a binary score 'yes' or 'no'. 'Yes' means that the answer is grounded in / supported by the set of facts."""),
("human", "Set of facts: \n\n {documents} \n\n LLM generation: {generation}"),
]
)
RESOLVER_PROMPT = ChatPromptTemplate.from_messages(
[
("system", """You are a grader assessing whether an answer addresses / resolves a question \n
Give a binary score 'yes' or 'no'. Yes' means that the answer resolves the question."""),
("human", "User question: \n\n {question} \n\n LLM generation: {generation}"),
]
)
REWRITER_PROMPT = ChatPromptTemplate.from_messages(
[
("system", """You a question re-writer that converts an input question to a better version that is optimized \n
for vectorstore retrieval. Look at the input and try to reason about the underlying semantic intent / meaning."""),
(
"human",
"Here is the initial question: \n\n {question} \n Formulate an improved question.",
),
]
)
|