Update app.py
Browse files
app.py
CHANGED
@@ -68,7 +68,7 @@ def initialize_pinecone(index_name: str):
|
|
68 |
|
69 |
# Initialize Pinecone index and BM25 encoder
|
70 |
pinecone_index = initialize_pinecone("updated-mbzuai-policies")
|
71 |
-
bm25 = BM25Encoder().load("./mbzuai-policies.json")
|
72 |
|
73 |
##################################################
|
74 |
##################################################
|
@@ -102,12 +102,12 @@ llm = ChatOpenAI(temperature=0, model_name="gpt-4o-mini", max_tokens=512)
|
|
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 |
-
|
110 |
-
)
|
111 |
|
112 |
# Contextualization prompt and retriever
|
113 |
contextualize_q_system_prompt = """Given a chat history and the latest user question \
|
@@ -122,7 +122,7 @@ contextualize_q_prompt = ChatPromptTemplate.from_messages(
|
|
122 |
("human", "{input}")
|
123 |
]
|
124 |
)
|
125 |
-
history_aware_retriever = create_history_aware_retriever(llm,
|
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,10 +142,12 @@ When responding to queries, follow these guidelines:
|
|
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
|
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}
|
150 |
"""
|
151 |
qa_prompt = ChatPromptTemplate.from_messages(
|
|
|
68 |
|
69 |
# Initialize Pinecone index and BM25 encoder
|
70 |
pinecone_index = initialize_pinecone("updated-mbzuai-policies")
|
71 |
+
bm25 = BM25Encoder().load("./updated-mbzuai-policies.json")
|
72 |
|
73 |
##################################################
|
74 |
##################################################
|
|
|
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 \
|
|
|
122 |
("human", "{input}")
|
123 |
]
|
124 |
)
|
125 |
+
history_aware_retriever = create_history_aware_retriever(llm, 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 IN A SECTION WITH HEADING 'Sources', SO USERS CAN GET MORE INFORMATION.
|
|
|
146 |
|
147 |
FOLLOW ALL THE GIVEN INSTRUCTIONS, FAILURE TO DO SO WILL RESULT IN THE TERMINATION OF THE CHAT.
|
148 |
+
|
149 |
+
== CONTEXT ==
|
150 |
+
|
151 |
{context}
|
152 |
"""
|
153 |
qa_prompt = ChatPromptTemplate.from_messages(
|