ZoniaChatbot commited on
Commit
4fafe95
·
verified ·
1 Parent(s): f45d702

Update chatpdf.py

Browse files
Files changed (1) hide show
  1. chatpdf.py +17 -7
chatpdf.py CHANGED
@@ -383,14 +383,24 @@ class ChatPDF:
383
  """
384
  reference_results = []
385
  sim_contents = self.sim_model.most_similar(query, topn=self.similarity_top_k)
386
- # Get reference results from corpus
387
- hit_chunk_dict = dict()
388
- for query_id, id_score_dict in sim_contents.items():
389
- for corpus_id, s in id_score_dict.items():
 
 
 
390
  hit_chunk = self.sim_model.corpus[corpus_id]
391
  reference_results.append(hit_chunk)
392
- hit_chunk_dict[corpus_id] = hit_chunk
393
-
 
 
 
 
 
 
 
394
  if reference_results:
395
  if self.rerank_model is not None:
396
  # Rerank reference results
@@ -410,7 +420,7 @@ class ChatPDF:
410
  expanded_reference += self.sim_model.corpus.get(corpus_id + i + 1, '')
411
  new_reference_results.append(expanded_reference)
412
  reference_results = new_reference_results
413
- return reference_results
414
 
415
  def predict_stream(
416
  self,
 
383
  """
384
  reference_results = []
385
  sim_contents = self.sim_model.most_similar(query, topn=self.similarity_top_k)
386
+
387
+ # Verificar si sim_contents es una lista
388
+ if isinstance(sim_contents, list):
389
+ # Ajusta esto dependiendo de la estructura de los elementos de la lista
390
+ for item in sim_contents:
391
+ # Ejemplo: si es una lista de tuplas (corpus_id, score)
392
+ corpus_id, _ = item
393
  hit_chunk = self.sim_model.corpus[corpus_id]
394
  reference_results.append(hit_chunk)
395
+
396
+ elif isinstance(sim_contents, dict):
397
+ for query_id, id_score_dict in sim_contents.items():
398
+ for corpus_id, s in id_score_dict.items():
399
+ hit_chunk = self.sim_model.corpus[corpus_id]
400
+ reference_results.append(hit_chunk)
401
+ else:
402
+ logger.error(f"Unexpected type for sim_contents: {type(sim_contents)}")
403
+
404
  if reference_results:
405
  if self.rerank_model is not None:
406
  # Rerank reference results
 
420
  expanded_reference += self.sim_model.corpus.get(corpus_id + i + 1, '')
421
  new_reference_results.append(expanded_reference)
422
  reference_results = new_reference_results
423
+ return reference_results
424
 
425
  def predict_stream(
426
  self,