Update app.py
Browse files
app.py
CHANGED
@@ -102,6 +102,13 @@ llm = ChatOpenAI(temperature=0, model_name="gpt-4o-mini", max_tokens=512)
|
|
102 |
# base_compressor=compressor, base_retriever=retriever
|
103 |
# )
|
104 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
# Contextualization prompt and retriever
|
106 |
contextualize_q_system_prompt = """Given a chat history and the latest user question \
|
107 |
which might reference context in the chat history, formulate a standalone question \
|
@@ -115,7 +122,7 @@ contextualize_q_prompt = ChatPromptTemplate.from_messages(
|
|
115 |
("human", "{input}")
|
116 |
]
|
117 |
)
|
118 |
-
history_aware_retriever = create_history_aware_retriever(llm,
|
119 |
|
120 |
# QA system prompt and chain
|
121 |
qa_system_prompt = """ You are a highly skilled information retrieval assistant. Use the following context to answer questions effectively.
|
@@ -135,10 +142,8 @@ When responding to queries, follow these guidelines:
|
|
135 |
- Use emphasis on headings, important texts, and phrases.
|
136 |
|
137 |
3. Proper Citations:
|
138 |
-
- ALWAYS
|
139 |
-
-
|
140 |
-
- AT THE END OF THE RESPONSE, LIST OUT THE CITATIONS WITH THEIR SOURCES.
|
141 |
-
- If there are multiple citations with the same source URL then only cite that single source URL instead of all those multiple sources.
|
142 |
|
143 |
FOLLOW ALL THE GIVEN INSTRUCTIONS, FAILURE TO DO SO WILL RESULT IN THE TERMINATION OF THE CHAT.
|
144 |
{context}
|
|
|
102 |
# base_compressor=compressor, base_retriever=retriever
|
103 |
# )
|
104 |
|
105 |
+
from langchain.retrievers.document_compressors import FlashrankRerank
|
106 |
+
|
107 |
+
compressor = FlashrankRerank()
|
108 |
+
compression_retriever = ContextualCompressionRetriever(
|
109 |
+
base_compressor=compressor, base_retriever=retriever
|
110 |
+
)
|
111 |
+
|
112 |
# Contextualization prompt and retriever
|
113 |
contextualize_q_system_prompt = """Given a chat history and the latest user question \
|
114 |
which might reference context in the chat history, formulate a standalone question \
|
|
|
122 |
("human", "{input}")
|
123 |
]
|
124 |
)
|
125 |
+
history_aware_retriever = create_history_aware_retriever(llm, compression_retriever, contextualize_q_prompt)
|
126 |
|
127 |
# QA system prompt and chain
|
128 |
qa_system_prompt = """ You are a highly skilled information retrieval assistant. Use the following context to answer questions effectively.
|
|
|
142 |
- Use emphasis on headings, important texts, and phrases.
|
143 |
|
144 |
3. Proper Citations:
|
145 |
+
- ALWAYS SPECIFY SOURCES AT THE END OF THE RESPONSE WITH THEIR URL SO THAT USERS CAN GET MORE INFORMATION.
|
146 |
+
- At the end of response list out this sources.
|
|
|
|
|
147 |
|
148 |
FOLLOW ALL THE GIVEN INSTRUCTIONS, FAILURE TO DO SO WILL RESULT IN THE TERMINATION OF THE CHAT.
|
149 |
{context}
|