2023-09-27 23:36:44 -06:00
|
|
|
import os
|
|
|
|
import sys
|
2023-09-29 00:09:44 -06:00
|
|
|
import time
|
2023-09-27 23:36:44 -06:00
|
|
|
from pathlib import Path
|
|
|
|
|
2023-09-30 19:41:50 -06:00
|
|
|
from llm_server.cluster.cluster_config import cluster_config
|
|
|
|
from llm_server.cluster.redis_cycle import redis_cycler_db
|
|
|
|
from llm_server.cluster.stores import redis_running_models
|
|
|
|
from llm_server.config.load import load_config, parse_backends
|
2023-09-29 00:09:44 -06:00
|
|
|
from llm_server.custom_redis import redis
|
2023-09-27 23:36:44 -06:00
|
|
|
from llm_server.database.create import create_db
|
2023-09-30 19:41:50 -06:00
|
|
|
from llm_server.routes.queue import priority_queue
|
2023-09-30 19:42:41 -06:00
|
|
|
from llm_server.routes.v2.generate_stats import generate_stats
|
2023-09-29 00:09:44 -06:00
|
|
|
from llm_server.workers.threader import start_background
|
2023-09-27 23:36:44 -06:00
|
|
|
|
|
|
|
script_path = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
config_path_environ = os.getenv("CONFIG_PATH")
|
|
|
|
if config_path_environ:
|
|
|
|
config_path = config_path_environ
|
|
|
|
else:
|
|
|
|
config_path = Path(script_path, 'config', 'config.yml')
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
flushed_keys = redis.flush()
|
|
|
|
print('Flushed', len(flushed_keys), 'keys from Redis.')
|
|
|
|
|
2023-09-30 19:41:50 -06:00
|
|
|
redis_cycler_db.flushall()
|
|
|
|
redis_running_models.flush()
|
|
|
|
|
2023-09-29 00:09:44 -06:00
|
|
|
success, config, msg = load_config(config_path)
|
2023-09-27 23:36:44 -06:00
|
|
|
if not success:
|
|
|
|
print('Failed to load config:', msg)
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
create_db()
|
2023-09-30 19:41:50 -06:00
|
|
|
|
|
|
|
priority_queue.flush()
|
|
|
|
cluster_config.clear()
|
|
|
|
cluster_config.load(parse_backends(config))
|
|
|
|
|
|
|
|
print('Loading backend stats...')
|
|
|
|
generate_stats()
|
|
|
|
|
2023-09-27 23:36:44 -06:00
|
|
|
start_background()
|
|
|
|
|
|
|
|
redis.set('daemon_started', 1)
|
|
|
|
print('== Daemon Setup Complete ==\n')
|
|
|
|
|
2023-09-30 19:41:50 -06:00
|
|
|
try:
|
|
|
|
while True:
|
|
|
|
time.sleep(3600)
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
redis.set('daemon_started', 0)
|