Spaces:
Running
Running
Update app.py
Browse files
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
-
|
276 |
-
|
277 |
return answer
|
278 |
|
279 |
except Exception as e:
|
280 |
-
print("Error in handle_user_query:", e)
|
281 |
-
return f"
|
|
|
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:
|