pvanand commited on
Commit
c14035d
·
verified ·
1 Parent(s): 49af561

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +8 -3
main.py CHANGED
@@ -132,7 +132,12 @@ def update_db(user_id, conversation_id, message, response):
132
  # Utility Functions
133
  # ============================================================================
134
 
135
- def extract_data_from_tag(input_string, tag, invert=False, return_full_if_not_found=False):
 
 
 
 
 
136
  pattern = f'<{tag}.*?>(.*?)</{tag}>'
137
  matches = re.findall(pattern, input_string, re.DOTALL)
138
 
@@ -141,12 +146,12 @@ def extract_data_from_tag(input_string, tag, invert=False, return_full_if_not_fo
141
  out = re.sub(pattern, '', input_string, flags=re.DOTALL)
142
  return out.strip()
143
  else:
144
- return input_string if return_full_if_not_found else ""
145
  else:
146
  if matches:
147
  return '\n'.join(match.strip() for match in matches)
148
  else:
149
- return input_string if return_full_if_not_found else ""
150
 
151
 
152
  def calculate_tokens(msgs):
 
132
  # Utility Functions
133
  # ============================================================================
134
 
135
+ def extract_data_from_tag(input_string, tag, invert=False):
136
+ """
137
+ returns combined data from the identified tags, if not found return ""
138
+ if inverted returns data excluding tag, if tag not found, input_string is returned
139
+ """
140
+
141
  pattern = f'<{tag}.*?>(.*?)</{tag}>'
142
  matches = re.findall(pattern, input_string, re.DOTALL)
143
 
 
146
  out = re.sub(pattern, '', input_string, flags=re.DOTALL)
147
  return out.strip()
148
  else:
149
+ return input_string.strip()
150
  else:
151
  if matches:
152
  return '\n'.join(match.strip() for match in matches)
153
  else:
154
+ return ""
155
 
156
 
157
  def calculate_tokens(msgs):