mtyrrell commited on
Commit
2cfbdba
1 Parent(s): 8e99f61

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -79,23 +79,24 @@ def get_docs(input_query, country = None):
79
  ls_dict.append(doc)
80
  return(ls_dict)
81
 
82
- def get_refs(docs, res):
83
  '''
84
  Parse response for engineered reference ids (refer to prompt template)
85
  Extract documents using reference ids
86
  '''
87
- # This pattern should be returned by gpt3.5 & llama2
88
  # pattern = r'ref\. (\d+)\]\.'
89
  pattern = r'ref\. (\d+)'
90
  ref_ids = [int(match) for match in re.findall(pattern, res)]
91
  # extract
92
  result_str = "" # Initialize an empty string to store the result
93
- for i in range(len(res['documents'])):
94
  doc = docs[i].to_dict()
95
  ref_id = doc['meta']['ref_id']
96
  if ref_id in ref_ids:
97
- result_str += "**Ref. " + str(ref_id) + " [" + doc['meta']['country'] + " " + doc['meta']['document_name'] + "]:** " + "*'" + doc['content'] + "'*<br> <br>" # Add <br> for a line break
98
- return result_str
 
99
 
100
  def run_query(input_text, country):
101
  docs = get_docs(input_text, country)
 
79
  ls_dict.append(doc)
80
  return(ls_dict)
81
 
82
+ def get_refs(res):
83
  '''
84
  Parse response for engineered reference ids (refer to prompt template)
85
  Extract documents using reference ids
86
  '''
87
+ # This pattern should be returned by gpt3.5
88
  # pattern = r'ref\. (\d+)\]\.'
89
  pattern = r'ref\. (\d+)'
90
  ref_ids = [int(match) for match in re.findall(pattern, res)]
91
  # extract
92
  result_str = "" # Initialize an empty string to store the result
93
+ for i in range(len(docs)):
94
  doc = docs[i].to_dict()
95
  ref_id = doc['meta']['ref_id']
96
  if ref_id in ref_ids:
97
+ result_str += "**Ref. " + str(ref_id) + " [" + doc['meta']['country'] + " " + doc['meta']['document_name'] + "]:** " + "*'" + doc['content'] + "'*<br> <br>" # Add <br> for a line break
98
+
99
+ return result_str
100
 
101
  def run_query(input_text, country):
102
  docs = get_docs(input_text, country)