Shreyas094 commited on
Commit
a6df94d
·
verified ·
1 Parent(s): 9933931

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -5
app.py CHANGED
@@ -267,9 +267,19 @@ def rank_search_results(titles, summaries, model):
267
 
268
  ranking_prompt += "Ranks:"
269
 
270
- ranks_str = generate_chunked_response(model, ranking_prompt)
271
- ranks = [float(rank.strip()) for rank in ranks_str.split(',')]
272
- return ranks
 
 
 
 
 
 
 
 
 
 
273
 
274
  def ask_question(question, temperature, top_p, repetition_penalty, web_search):
275
  global conversation_history
@@ -311,8 +321,12 @@ def ask_question(question, temperature, top_p, repetition_penalty, web_search):
311
  # Rank the results
312
  titles = [r["title"] for r in processed_results]
313
  summaries = [r["summary"] for r in processed_results]
314
- ranks = rank_search_results(titles, summaries, model)
315
-
 
 
 
 
316
  # Update Vector DB
317
  current_date = datetime.now().strftime("%Y-%m-%d")
318
  update_vector_db_with_search_results(processed_results, ranks, current_date)
 
267
 
268
  ranking_prompt += "Ranks:"
269
 
270
+ try:
271
+ ranks_str = generate_chunked_response(model, ranking_prompt)
272
+ ranks = [float(rank.strip()) for rank in ranks_str.split(',') if rank.strip()]
273
+
274
+ # Check if we have the correct number of ranks
275
+ if len(ranks) != len(titles):
276
+ raise ValueError("Number of ranks does not match number of titles")
277
+
278
+ return ranks
279
+ except Exception as e:
280
+ print(f"Error in ranking: {str(e)}. Using fallback ranking method.")
281
+ # Fallback: assign ranks based on original order
282
+ return list(range(1, len(titles) + 1))
283
 
284
  def ask_question(question, temperature, top_p, repetition_penalty, web_search):
285
  global conversation_history
 
321
  # Rank the results
322
  titles = [r["title"] for r in processed_results]
323
  summaries = [r["summary"] for r in processed_results]
324
+ try:
325
+ ranks = rank_search_results(titles, summaries, model)
326
+ except Exception as e:
327
+ print(f"Error in ranking results: {str(e)}. Using default ranking.")
328
+ ranks = list(range(1, len(processed_results) + 1))
329
+
330
  # Update Vector DB
331
  current_date = datetime.now().strftime("%Y-%m-%d")
332
  update_vector_db_with_search_results(processed_results, ranks, current_date)