This repository has been archived on 2024-10-27. You can view files and clone it, but cannot push or open issues or pull requests.
2023-10-04 19:24:47 -06:00
|
|
|
import pickle
|
2023-10-11 18:04:15 -06:00
|
|
|
import traceback
|
2023-10-04 19:24:47 -06:00
|
|
|
|
|
|
|
import redis
|
|
|
|
|
|
|
|
from llm_server.database.database import do_db_log
|
|
|
|
|
|
|
|
|
|
|
|
def db_logger():
|
|
|
|
"""
|
|
|
|
We don't want the logging operation to be blocking, so we will use a background worker
|
|
|
|
to do the logging.
|
|
|
|
:return:
|
|
|
|
"""
|
|
|
|
|
|
|
|
r = redis.Redis(host='localhost', port=6379, db=3)
|
|
|
|
p = r.pubsub()
|
|
|
|
p.subscribe('database-logger')
|
|
|
|
|
|
|
|
for message in p.listen():
|
2023-10-11 18:04:15 -06:00
|
|
|
try:
|
|
|
|
if message['type'] == 'message':
|
|
|
|
data = pickle.loads(message['data'])
|
|
|
|
function_name = data['function']
|
|
|
|
args = data['args']
|
|
|
|
kwargs = data['kwargs']
|
2023-10-04 19:24:47 -06:00
|
|
|
|
2023-10-11 18:04:15 -06:00
|
|
|
if function_name == 'log_prompt':
|
|
|
|
do_db_log(*args, **kwargs)
|
|
|
|
except:
|
|
|
|
traceback.print_exc()
|