32 lines
785 B
Python
32 lines
785 B
Python
|
import pickle
|
||
|
import traceback
|
||
|
|
||
|
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():
|
||
|
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:
|
||
|
traceback.print_exc()
|