pvanand commited on
Commit
71e7504
·
verified ·
1 Parent(s): dec5cf0

Delete utils.py

Browse files
Files changed (1) hide show
  1. utils.py +0 -32
utils.py DELETED
@@ -1,32 +0,0 @@
1
- import tiktoken
2
- import time
3
- import asyncio
4
- import logging
5
-
6
- logger = logging.getLogger(__name__)
7
-
8
- # Token encoding
9
- encoding = tiktoken.encoding_for_model("gpt-3.5-turbo")
10
-
11
- def limit_tokens(input_string, token_limit=6000):
12
- return encoding.decode(encoding.encode(input_string)[:token_limit])
13
-
14
- def calculate_tokens(msgs):
15
- return sum(len(encoding.encode(str(m))) for m in msgs)
16
-
17
- # In-memory storage for conversations
18
- conversations = {}
19
- last_activity = {}
20
-
21
- async def clear_inactive_conversations():
22
- while True:
23
- current_time = time.time()
24
- inactive_convos = [conv_id for conv_id, last_time in last_activity.items()
25
- if current_time - last_time > 3600*24] # 24 hour
26
- for conv_id in inactive_convos:
27
- if conv_id in conversations:
28
- del conversations[conv_id]
29
- if conv_id in last_activity:
30
- del last_activity[conv_id]
31
- logger.info(f"Cleared {len(inactive_convos)} inactive conversations")
32
- await asyncio.sleep(600) # Check every hour