2024-08-12 00:32:42 -07:00
from langchain_core . prompts . prompt import PromptTemplate
from datetime import datetime , timezone
2024-08-13 19:56:54 -07:00
2024-08-12 00:32:42 -07:00
DATE_TODAY = " Today ' s date is " + datetime . now ( timezone . utc ) . astimezone ( ) . isoformat ( ) + ' \n '
2024-09-19 22:50:16 -07:00
# Create a prompt template for sub-query decomposition
SUBQUERY_DECOMPOSITION_TEMPLATE = DATE_TODAY + """ You are an AI assistant tasked with breaking down complex queries into simpler sub-queries for a vector store.
Given the original query , decompose it into 2 - 4 simpler sub - queries for vector search that helps in expanding context .
2024-08-13 19:56:54 -07:00
2024-09-19 22:50:16 -07:00
Original query : { original_query }
2024-08-13 19:56:54 -07:00
2024-09-19 22:50:16 -07:00
IMPORTANT INSTRUCTION : Make sure to only return sub - queries and no explanation .
2024-08-13 19:56:54 -07:00
2024-09-19 22:50:16 -07:00
EXAMPLE :
2024-08-13 19:56:54 -07:00
2024-09-19 22:50:16 -07:00
User Query : What are the impacts of climate change on the environment ?
2024-08-13 19:56:54 -07:00
2024-09-19 22:50:16 -07:00
AI Answer :
What are the impacts of climate change on biodiversity ?
How does climate change affect the oceans ?
What are the effects of climate change on agriculture ?
What are the impacts of climate change on human health ?
2024-08-12 00:32:42 -07:00
"""
2024-09-19 22:50:16 -07:00
# SUBQUERY_DECOMPOSITION_TEMPLATE_TWO = DATE_TODAY + """You are an AI language model assistant. Your task is to generate five
# different versions of the given user question to retrieve relevant documents from a vector
# database. By generating multiple perspectives on the user question, your goal is to help
# the user overcome some of the limitations of the distance-based similarity search.
# Provide these alternative questions separated by newlines.
# Original question: {original_query}"""
2024-08-12 00:32:42 -07:00
2024-09-19 22:50:16 -07:00
SUBQUERY_DECOMPOSITION_PROMT = PromptTemplate (
input_variables = [ " original_query " ] ,
template = SUBQUERY_DECOMPOSITION_TEMPLATE
)
2024-08-12 00:32:42 -07:00
2024-09-20 16:30:48 -07:00
CONTEXT_ANSWER_TEMPLATE = DATE_TODAY + """ You are a phd in english litrature. You are given the task to give detailed research report and explanation to the user query based on the given context.
2024-08-16 20:35:50 -07:00
2024-09-19 22:50:16 -07:00
IMPORTANT INSTRUCTION : Only return answer if you can find it in given context otherwise just say you don ' t know.
2024-08-16 20:35:50 -07:00
2024-09-19 22:50:16 -07:00
Context : { context }
2024-08-16 20:35:50 -07:00
User Query : { query }
2024-09-19 22:50:16 -07:00
Detailed Report : """
2024-08-16 20:35:50 -07:00
2024-09-20 16:30:48 -07:00
ANSWER_WITH_CITATIONS = DATE_TODAY + """ You ' re a helpful AI assistant. Given a user question and some Webpage article snippets, \
answer the user question and provide citations . If none of the articles answer the question , just say you don ' t know.
2024-10-08 01:33:16 -07:00
Remember , you must return both an answer and citations . Citation information is given in Document Metadata .
2024-09-20 16:30:48 -07:00
Here are the Webpage article snippets :
{ context }
User Query : { query }
Your Answer : """
2024-08-16 20:35:50 -07:00
2024-09-19 22:50:16 -07:00
CONTEXT_ANSWER_PROMPT = PromptTemplate (
input_variables = [ " context " , " query " ] ,
2024-09-20 16:30:48 -07:00
template = ANSWER_WITH_CITATIONS
2024-09-19 22:50:16 -07:00
)
2024-08-21 23:06:30 -07:00
2024-08-16 20:35:50 -07:00
2024-08-12 00:32:42 -07:00