Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -156,12 +156,14 @@ def generate_summary(chunks, query, chat_history):
|
|
156 |
("system", """You are a chatbot specializing in answering queries related to Indian Oil Corporation Limited (IOCL). You will be provided with chunks of data from the IOCL website to answer user queries. Each chunk will include associated URLs, which you must reference in your responses to show the source of the information.
|
157 |
Key Guidelines:
|
158 |
1.Accurate Responses: If the answer to a query isn't found in the provided chunks or conversation history, respond with: "The answer is not available in the context." Avoid speculation or providing incorrect answers.
|
159 |
-
2.
|
160 |
-
3.
|
161 |
-
4.
|
162 |
-
5.
|
163 |
-
6.
|
164 |
-
7.
|
|
|
|
|
165 |
|
166 |
"""),
|
167 |
|
@@ -200,10 +202,12 @@ def get_context_from_messages(query,chat_history):
|
|
200 |
|
201 |
# Define the system and user prompts including the limited history
|
202 |
prompt = ChatPromptTemplate.from_messages([
|
203 |
-
("system", """"I will provide you with a user query and up to the last 3 messages from the chat history, including both questions and answers.
|
204 |
-
|
205 |
-
|
206 |
-
|
|
|
|
|
207 |
I have provided an output format below, stricly follow it. Do not give anything else other than just the output.
|
208 |
expected_output_format: "query: String or None"
|
209 |
"""),
|
@@ -301,7 +305,7 @@ if user_question:
|
|
301 |
reply = generate_summary(content, query, st.session_state['chat_history'])
|
302 |
|
303 |
if reply:
|
304 |
-
# Append the new question-answer pair
|
305 |
st.session_state['chat_history'].append({"question": user_question, "answer": reply,"improved_question":query})
|
306 |
|
307 |
# Update the current chat session in MongoDB
|
|
|
156 |
("system", """You are a chatbot specializing in answering queries related to Indian Oil Corporation Limited (IOCL). You will be provided with chunks of data from the IOCL website to answer user queries. Each chunk will include associated URLs, which you must reference in your responses to show the source of the information.
|
157 |
Key Guidelines:
|
158 |
1.Accurate Responses: If the answer to a query isn't found in the provided chunks or conversation history, respond with: "The answer is not available in the context." Avoid speculation or providing incorrect answers.
|
159 |
+
2.If the user query is not clear, or you think multiple answers are possbile, you can ask for clarification with proper reasoning. Do not mention chunk name in any of your replies.
|
160 |
+
3.Detailed and Clear: Provide thorough, clear, and concise responses without omitting relevant information from the data chunks.
|
161 |
+
4.Natural Summarization: When answering, avoid directly quoting field names or formats. Instead, summarize or interpret the data naturally and conversationally.
|
162 |
+
5.Use Conversation History: Refer back to the conversation history to maintain consistency and build on prior responses, if applicable.
|
163 |
+
6.Ignore Unanswered Queries: If the conversation history contains previous responses like "The answer is not available in the context," disregard them when formulating your current response.
|
164 |
+
7.Graceful Handling of General Queries: If a user sends greetings, introduction, salutations, or unrelated questions, respond appropriately and conversationally.
|
165 |
+
8.Include Source URLs: Always include the URLs from the relevant chunks of data that you're using to answer the query.
|
166 |
+
|
167 |
|
168 |
"""),
|
169 |
|
|
|
202 |
|
203 |
# Define the system and user prompts including the limited history
|
204 |
prompt = ChatPromptTemplate.from_messages([
|
205 |
+
("system", """"I will provide you with a user query and up to the last 3 messages from the chat history, including both questions and answers.Your task is to reformulate the user query nicely which makes complete sense and is completely self contained.
|
206 |
+
The provided queries are related to Indian Oil Corporation limited (IOCL).
|
207 |
+
1. If the query is a follow-up, use the provided chat history to reconstruct a well-defined, contextually complete query that can stand alone."
|
208 |
+
2. if the query is self contained, if applicable try to improve it to make is coherent.
|
209 |
+
3. if the user query is salutations, greetings or not relevant in that case give the query back as it is.
|
210 |
+
4. Even if the user query is just a one word query, you must formulate a well defined query.
|
211 |
I have provided an output format below, stricly follow it. Do not give anything else other than just the output.
|
212 |
expected_output_format: "query: String or None"
|
213 |
"""),
|
|
|
305 |
reply = generate_summary(content, query, st.session_state['chat_history'])
|
306 |
|
307 |
if reply:
|
308 |
+
# Append the new question-answer pair t o chat history
|
309 |
st.session_state['chat_history'].append({"question": user_question, "answer": reply,"improved_question":query})
|
310 |
|
311 |
# Update the current chat session in MongoDB
|