Update app.py
Browse files
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(
|
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(
|
94 |
doc = docs[i].to_dict()
|
95 |
ref_id = doc['meta']['ref_id']
|
96 |
if ref_id in ref_ids:
|
97 |
-
|
98 |
-
|
|
|
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)
|