Gopikanth123 commited on
Commit
c32fec2
·
verified ·
1 Parent(s): f5c5e39

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +12 -5
main.py CHANGED
@@ -61,34 +61,41 @@ def handle_query(query):
61
  (
62
  "user",
63
  """
64
- You are the Taj Hotel chatbot and your name is Taj Hotel Helper. Your goal is to provide accurate, professional, and helpful answers to user queries based on the given Taj hotel's data. Always ensure your responses are clear and concise. Give response within 10-15 words only. You need to give an answer in the same language used by the user.
 
65
  {context_str}
66
- Question:
67
  {query_str}
68
  """
69
  )
70
  ]
 
71
  text_qa_template = ChatPromptTemplate.from_messages(chat_text_qa_msgs)
72
 
73
  storage_context = StorageContext.from_defaults(persist_dir=PERSIST_DIR)
74
  index = load_index_from_storage(storage_context)
75
  context_str = ""
 
 
76
  for past_query, response in reversed(current_chat_history):
77
  if past_query.strip():
78
  context_str += f"User asked: '{past_query}'\nBot answered: '{response}'\n"
79
 
80
  query_engine = index.as_query_engine(text_qa_template=text_qa_template, context_str=context_str)
81
- print(query)
82
  answer = query_engine.query(query)
83
 
 
84
  if hasattr(answer, 'response'):
85
  response = answer.response
86
  elif isinstance(answer, dict) and 'response' in answer:
87
  response = answer['response']
88
  else:
89
- response = "Sorry, I couldn't find an answer."
 
 
90
  current_chat_history.append((query, response))
91
- return response
92
 
93
  app = Flask(__name__)
94
 
 
61
  (
62
  "user",
63
  """
64
+ You are the Taj Hotel chatbot, known as Taj Hotel Helper. Your goal is to provide accurate and professional answers to user queries based on the information available about the Taj Hotel. Always respond clearly and concisely, ideally within 10-15 words. If you don't know the answer, say so politely.
65
+ Context:
66
  {context_str}
67
+ User's Question:
68
  {query_str}
69
  """
70
  )
71
  ]
72
+
73
  text_qa_template = ChatPromptTemplate.from_messages(chat_text_qa_msgs)
74
 
75
  storage_context = StorageContext.from_defaults(persist_dir=PERSIST_DIR)
76
  index = load_index_from_storage(storage_context)
77
  context_str = ""
78
+
79
+ # Build context from current chat history
80
  for past_query, response in reversed(current_chat_history):
81
  if past_query.strip():
82
  context_str += f"User asked: '{past_query}'\nBot answered: '{response}'\n"
83
 
84
  query_engine = index.as_query_engine(text_qa_template=text_qa_template, context_str=context_str)
85
+ print(f"Querying: {query}")
86
  answer = query_engine.query(query)
87
 
88
+ # Extracting the response
89
  if hasattr(answer, 'response'):
90
  response = answer.response
91
  elif isinstance(answer, dict) and 'response' in answer:
92
  response = answer['response']
93
  else:
94
+ response = "I'm sorry, I couldn't find an answer to that."
95
+
96
+ # Append to chat history
97
  current_chat_history.append((query, response))
98
+ return response
99
 
100
  app = Flask(__name__)
101