Carlos Rosas commited on
Commit
cbf42f2
·
verified ·
1 Parent(s): 8dbdf3b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -5
app.py CHANGED
@@ -46,8 +46,8 @@ table = db.open_table("edunat19")
46
  def hybrid_search(text):
47
  results = table.search(text, query_type="hybrid").limit(5).to_pandas()
48
 
49
- # Add a check for duplicate hashes
50
- seen_hashes = set()
51
 
52
  document = []
53
  document_html = []
@@ -58,17 +58,26 @@ def hybrid_search(text):
58
  if hash_id in seen_hashes:
59
  continue
60
 
61
- seen_hashes.add(hash_id)
62
  title = row['section']
63
  content = row['text']
64
 
65
- document.append(f"<|source_start|><|source_id_start|>{hash_id}<|source_id_end|>{title}\n{content}<|source_end|>")
 
66
  document_html.append(f'<div class="source" id="{hash_id}"><p><b>{hash_id}</b> : {title}<br>{content}</div>')
67
 
 
 
 
 
68
  document = "\n".join(document)
69
  document_html = '<div id="source_listing">' + "".join(document_html) + "</div>"
 
 
 
 
70
  return document, document_html
71
-
72
  class pleiasBot:
73
  def __init__(self, system_prompt="Tu es Appli, un asistant de recherche qui donne des responses sourcées"):
74
  self.system_prompt = system_prompt
 
46
  def hybrid_search(text):
47
  results = table.search(text, query_type="hybrid").limit(5).to_pandas()
48
 
49
+ # Use a list to maintain order
50
+ seen_hashes = []
51
 
52
  document = []
53
  document_html = []
 
58
  if hash_id in seen_hashes:
59
  continue
60
 
61
+ seen_hashes.append(hash_id) # append instead of add to maintain order
62
  title = row['section']
63
  content = row['text']
64
 
65
+ source_text = f"<|source_start|><|source_id_start|>{hash_id}<|source_id_end|>{title}\n{content}<|source_end|>"
66
+ document.append(source_text)
67
  document_html.append(f'<div class="source" id="{hash_id}"><p><b>{hash_id}</b> : {title}<br>{content}</div>')
68
 
69
+ # Print for debugging
70
+ print(f"Added source {hash_id}")
71
+ print(f"Length of source text: {len(source_text)}")
72
+
73
  document = "\n".join(document)
74
  document_html = '<div id="source_listing">' + "".join(document_html) + "</div>"
75
+
76
+ # Print total length for debugging
77
+ print(f"Total length of document: {len(document)}")
78
+
79
  return document, document_html
80
+
81
  class pleiasBot:
82
  def __init__(self, system_prompt="Tu es Appli, un asistant de recherche qui donne des responses sourcées"):
83
  self.system_prompt = system_prompt