Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -131,6 +131,20 @@ def update_db(user_id, conversation_id, message, response):
|
|
| 131 |
# Utility Functions
|
| 132 |
# ============================================================================
|
| 133 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
def calculate_tokens(msgs):
|
| 135 |
return sum(len(encoding.encode(str(m))) for m in msgs)
|
| 136 |
|
|
@@ -197,8 +211,7 @@ async def clear_inactive_conversations():
|
|
| 197 |
del conversations[conv_id]
|
| 198 |
if conv_id in last_activity:
|
| 199 |
del last_activity[conv_id]
|
| 200 |
-
|
| 201 |
-
await asyncio.sleep(60) # Check every minute
|
| 202 |
|
| 203 |
# ============================================================================
|
| 204 |
# FastAPI Events and Endpoints
|
|
|
|
| 131 |
# Utility Functions
|
| 132 |
# ============================================================================
|
| 133 |
|
| 134 |
+
def extract_data_from_tag(input_string, tag):
|
| 135 |
+
# Create the regex pattern
|
| 136 |
+
pattern = f'<{tag}.*?>(.*?)</{tag}>'
|
| 137 |
+
|
| 138 |
+
# Find all matches
|
| 139 |
+
matches = re.findall(pattern, input_string, re.DOTALL)
|
| 140 |
+
|
| 141 |
+
# If matches are found, return them joined by newlines
|
| 142 |
+
if matches:
|
| 143 |
+
out = '\n'.join(match.strip() for match in matches)
|
| 144 |
+
return out
|
| 145 |
+
else:
|
| 146 |
+
return input_string
|
| 147 |
+
|
| 148 |
def calculate_tokens(msgs):
|
| 149 |
return sum(len(encoding.encode(str(m))) for m in msgs)
|
| 150 |
|
|
|
|
| 211 |
del conversations[conv_id]
|
| 212 |
if conv_id in last_activity:
|
| 213 |
del last_activity[conv_id]
|
| 214 |
+
await asyncio.sleep(600) # Check every hour
|
|
|
|
| 215 |
|
| 216 |
# ============================================================================
|
| 217 |
# FastAPI Events and Endpoints
|