28 lines
677 B
Python
28 lines
677 B
Python
|
import pickle
|
||
|
|
||
|
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():
|
||
|
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)
|