akshansh36 commited on
Commit
d643aa1
·
verified ·
1 Parent(s): e8a6d88

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -11
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.Detailed and Clear: Provide thorough, clear, and concise responses without omitting relevant information from the data chunks.
160
- 3.Natural Summarization: When answering, avoid directly quoting field names or formats. Instead, summarize or interpret the data naturally and conversationally.
161
- 4.Use Conversation History: Refer back to the conversation history to maintain consistency and build on prior responses, if applicable.
162
- 5.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.
163
- 6.Graceful Handling of General Queries: If a user sends greetings, introduction, salutations, or unrelated questions, respond appropriately and conversationally.
164
- 7.Include Source URLs: Always include the URLs from the relevant chunks of data that you're using to answer the query.
 
 
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. Your task is to determine whether the provided user query is self-contained (i.e., it can be answered directly without relying on prior messages) or a follow-up query that depends on the previous context.
204
- 1. If the query is self-contained, return None
205
- 2. If the query is a follow-up, use the provided chat history to reconstruct a well-defined, contextually complete query that can stand alone."
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 to chat history
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