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-27 19:19:22 -06:00
|
|
|
import pickle
|
|
|
|
import traceback
|
|
|
|
|
|
|
|
import redis
|
|
|
|
|
|
|
|
from llm_server.database.database import do_db_log
|
2024-05-07 09:48:51 -06:00
|
|
|
from llm_server.logging import create_logger
|
2023-10-27 19:19:22 -06:00
|
|
|
|
|
|
|
|
|
|
|
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')
|
2024-05-07 09:48:51 -06:00
|
|
|
logger = create_logger('main_bg')
|
2023-10-27 19:19:22 -06:00
|
|
|
|
|
|
|
for message in p.listen():
|
|
|
|
try:
|
|
|
|
if message['type'] == 'message':
|
|
|
|
data = pickle.loads(message['data'])
|
|
|
|
function_name = data['function']
|
|
|
|
args = data['args']
|
|
|
|
kwargs = data['kwargs']
|
|
|
|
|
|
|
|
if function_name == 'log_prompt':
|
|
|
|
do_db_log(*args, **kwargs)
|
|
|
|
except:
|
2024-05-07 09:48:51 -06:00
|
|
|
logger.error(traceback.format_exc())
|