bjhk / ki_gen /prompts.py
heymenn's picture
Upload 15 files
6aaddef verified
from langchain_core.prompts.prompt import PromptTemplate
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.messages import SystemMessage, HumanMessage
from ki_gen.utils import ConfigSchema
CYPHER_GENERATION_TEMPLATE = """Task:Generate Cypher statement to query a graph database.
Instructions:
Use only the provided relationship types and properties in the schema.
Do not use any other relationship types or properties that are not provided.
Schema:
{schema}
Concepts:
{concepts}
Concept names can ONLY be selected from the above list
Note: Do not include any explanations or apologies in your responses.
Do not respond to any questions that might ask anything else than for you to construct a Cypher statement.
Do not include any text except the generated Cypher statement.
The question is:
{question}"""
CYPHER_GENERATION_PROMPT = PromptTemplate(
input_variables=["schema", "question", "concepts"], template=CYPHER_GENERATION_TEMPLATE
)
CYPHER_QA_TEMPLATE = """You are an assistant that helps to form nice and human understandable answers.
The information part contains the provided information that you must use to construct an answer.
The provided information is authoritative, you must never doubt it or try to use your internal knowledge to correct it.
Make the answer sound as a response to the question. Do not mention that you based the result on the given information.
Here is an example:
Question: Which managers own Neo4j stocks?
Context:[manager:CTL LLC, manager:JANE STREET GROUP LLC]
Helpful Answer: CTL LLC, JANE STREET GROUP LLC owns Neo4j stocks.
Follow this example when generating answers.
If the provided information is empty, say that you don't know the answer.
Information:
{context}
Question: {question}
Helpful Answer:"""
CYPHER_QA_PROMPT = PromptTemplate(
input_variables=["context", "question"], template=CYPHER_QA_TEMPLATE
)
PLAN_GEN_PROMPT = """System : You are a standardization expert working for 3GPP. You are given a specific technical requirement regarding the deployment of 5G services. Your goal is to specify NEW and INNOVATIVE Key Issues that could occur while trying to fulfill this requirement
System : Let's first understand the problem and devise a plan to solve the problem.
Output the plan starting with the header 'Plan:' and then followed by a numbered list of steps.
Make the plan the minimum number of steps required to accurately provide the user with NEW and INNOVATIVE Key Issues related to the technical requirement.
At the end of your plan, say '<END_OF_PLAN>'"""
PLAN_MODIFICATION_PROMPT = """You are a standardization expert working for 3GPP. You are given a specific technical requirement regarding the deployment of 5G services. Your goal is to specify NEW and INNOVATIVE Key Issues that could occur while trying to fulfill this requirement.
To achieve this goal we are going to follow this generic plan :
###PLAN TEMPLATE###
Plan:
1. **Understanding the Problem**: Gather information from existing specifications and standards to thoroughly understand the technical requirement. This should help you understand the key aspects of the problem.
2. **Gather information about latest innovations** : Gather information about the latest innovations related to the problem by looking at the most relevant research papers.
3. **Researching current challenges** : Research the current challenges in this area by looking at the existing similar key issues that have been identified by 3GPP.
4. **Identifying NEW and INNOVATIVE Key Issues**: Based on the understanding of the problem and the current challenges, identify new and innovative key issues that could occur while trying to fulfill this requirement. These key issues should be relevant, significant, and not yet addressed by existing solutions.
5. **Develop Detailed Descriptions for Each Key Issue**: For each identified key issue, provide a detailed description, including the specific challenges and areas requiring further study.
<END_OF_PLAN>
###END OF PLAN TEMPLATE###
Let's and devise a plan to solve the problem by adapting the PLAN TEMPLATE.
Output the plan starting with the header 'Plan:' and then followed by a numbered list of steps.
Make the plan the minimum number of steps required to accurately provide the user with NEW and INNOVATIVE Key Issues related to the technical requirement.
At the end of your plan, say '<END_OF_PLAN>' """
CONCEPT_SELECTION_TEMPLATE = """Task: Select the most relevant topic to the user question
Instructions:
Select the most relevant Concept to the user's question.
Concepts can ONLY be selected from the list below.
Concepts:
{concepts}
Note: Do not include any explanations or apologies in your responses.
Do not include any text except the selected concept.
The question is:
{question}"""
CONCEPT_SELECTION_PROMPT = PromptTemplate(
input_variables=["concepts", "question"], template=CONCEPT_SELECTION_TEMPLATE
)
RELEVANT_CONCEPTS_TEMPLATE = """
## CONCEPTS ##
{concepts}
## END OF CONCEPTS ##
Select the 20 most relevant concepts to the user query.
Output your answer as a numbered list preceeded with the header 'Concepts:'.
User query :
{user_query}
"""
RELEVANT_CONCEPTS_PROMPT = ChatPromptTemplate.from_messages([
("human", RELEVANT_CONCEPTS_TEMPLATE)
])
SUMMARIZER_TEMPLATE = """You are a 3GPP standardization expert.
Summarize the provided document in simple technical English for other experts in the field.
Document:
{document}"""
SUMMARIZER_PROMPT = ChatPromptTemplate.from_messages([
("system", SUMMARIZER_TEMPLATE)
])
BINARY_GRADER_TEMPLATE = """You are a grader assessing relevance of a retrieved document to a user question. \n
It does not need to be a stringent test. The goal is to filter out erroneous retrievals. \n
If the document contains keyword(s) or semantic meaning related to the user question, grade it as relevant. \n
Give a binary score 'yes' or 'no' score to indicate whether the document is relevant to the question."""
BINARY_GRADER_PROMPT = ChatPromptTemplate.from_messages(
[
("system", BINARY_GRADER_TEMPLATE),
("human", "Retrieved document: \n\n {document} \n\n User question: {question}"),
]
)
SCORE_GRADER_TEMPLATE = """Grasp and understand both the query and the document before score generation.
Then, based on your understanding and analysis quantify the relevance between the document and the query.
Give the rationale before answering.
Ouput your answer as a score ranging between 0 (irrelevant document) and 1 (completely relevant document)"""
SCORE_GRADER_PROMPT = ChatPromptTemplate.from_messages(
[
("system", SCORE_GRADER_TEMPLATE),
("human", "Passage: \n\n {document} \n\n User query: {query}")
]
)
def get_initial_prompt(config: ConfigSchema, user_query : str):
if config["configurable"].get("plan_method") == "generation":
prompt = PLAN_GEN_PROMPT
elif config["configurable"].get("plan_method") == "modification":
prompt = PLAN_MODIFICATION_PROMPT
else:
raise ValueError("Incorrect plan_method, should be 'generation' or 'modification'")
user_input = user_query or input("User :")
return {"messages" : [SystemMessage(content=prompt), HumanMessage(content=user_input)]}