ZarinT commited on
Commit
cee37a9
Β·
verified Β·
1 Parent(s): 4e99304

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -5
app.py CHANGED
@@ -176,6 +176,7 @@ def get_kw_model():
176
  return kw_model
177
 
178
  def self_reasoning(query, context):
 
179
  llm = GeminiLLM()
180
  reasoning_prompt = f"""
181
  You are an AI assistant that analyzes the context provided to answer the user's query comprehensively and clearly.
@@ -200,7 +201,13 @@ def self_reasoning(query, context):
200
 
201
  **Answer:**
202
  """
203
- return llm._call(reasoning_prompt)
 
 
 
 
 
 
204
 
205
  def faiss_search_with_keywords(query):
206
  global vectorstore_global
@@ -266,19 +273,27 @@ def handle_user_query(query):
266
  if vectorstore_global is None:
267
  raise ValueError("Vectorstore is not initialized.")
268
 
 
 
269
  if "how" in query.lower():
 
270
  context = faiss_search_with_reasoning(query)
271
  else:
 
272
  context = faiss_search_with_keywords(query)
273
 
 
 
 
274
  answer = self_reasoning(query, context)
275
- if not answer or answer.strip() == "":
276
- raise ValueError("No answer was generated.")
277
  return answer
278
 
279
  except Exception as e:
280
- print("Error in handle_user_query:", e)
281
- return f"Sorry, an error occurred: {str(e)}"
 
282
 
283
  def save_feedback_to_huggingface():
284
  try:
 
176
  return kw_model
177
 
178
  def self_reasoning(query, context):
179
+ print("πŸ§ͺ self_reasoning received context of length:", len(context))
180
  llm = GeminiLLM()
181
  reasoning_prompt = f"""
182
  You are an AI assistant that analyzes the context provided to answer the user's query comprehensively and clearly.
 
201
 
202
  **Answer:**
203
  """
204
+ try:
205
+ result = llm._call(reasoning_prompt)
206
+ print("βœ… Gemini returned a result.")
207
+ return result
208
+ except Exception as e:
209
+ print("❌ Error in self_reasoning:", e)
210
+ return f"⚠️ Gemini failed: {e}"
211
 
212
  def faiss_search_with_keywords(query):
213
  global vectorstore_global
 
273
  if vectorstore_global is None:
274
  raise ValueError("Vectorstore is not initialized.")
275
 
276
+ print("πŸ” Starting handle_user_query with:", query)
277
+
278
  if "how" in query.lower():
279
+ print("🧠 Routing to: faiss_search_with_reasoning")
280
  context = faiss_search_with_reasoning(query)
281
  else:
282
+ print("🧠 Routing to: faiss_search_with_keywords")
283
  context = faiss_search_with_keywords(query)
284
 
285
+ print("πŸ“š Context length:", len(context))
286
+ print("✍️ Calling self_reasoning...")
287
+
288
  answer = self_reasoning(query, context)
289
+
290
+ print("βœ… Answer generated.")
291
  return answer
292
 
293
  except Exception as e:
294
+ print("❌ Error in handle_user_query:", e)
295
+ return f"⚠️ Error: {e}"
296
+
297
 
298
  def save_feedback_to_huggingface():
299
  try: