From ad3ddd50242aff100464aa1da39b0b206cb3d726 Mon Sep 17 00:00:00 2001 From: Dicklesworthstone Date: Tue, 21 May 2024 15:24:01 -0400 Subject: [PATCH] Fix --- misc_utility_functions.py | 6 ++++-- swiss_army_llama.py | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/misc_utility_functions.py b/misc_utility_functions.py index 1497156..6086d5e 100644 --- a/misc_utility_functions.py +++ b/misc_utility_functions.py @@ -78,7 +78,7 @@ def restart_redis_server(): print("Redis server restarted successfully.") except subprocess.CalledProcessError as e: logger.error(f"Failed to restart Redis server: {e}") - raise + raise async def build_faiss_indexes(): global faiss_indexes, token_faiss_indexes, associated_texts_by_model @@ -129,7 +129,6 @@ async def build_faiss_indexes(): logger.info("Faiss indexes built.") return faiss_indexes, token_faiss_indexes, associated_texts_by_model - def normalize_logprobs(avg_logprob, min_logprob, max_logprob): range_logprob = max_logprob - min_logprob return (avg_logprob - min_logprob) / range_logprob if range_logprob != 0 else 0.5 @@ -289,3 +288,6 @@ def set_config(key, value): print("Redis configuration optimized successfully.") print("Restarting Redis server to apply changes...") restart_redis_server() + +def configure_redis_in_background(): + threading.Thread(target=configure_redis_optimally).start() \ No newline at end of file diff --git a/swiss_army_llama.py b/swiss_army_llama.py index fc2d167..21907cc 100644 --- a/swiss_army_llama.py +++ b/swiss_army_llama.py @@ -3,7 +3,7 @@ from logger_config import setup_logger from database_functions import AsyncSessionLocal, DatabaseWriter, get_db_writer from ramdisk_functions import clear_ramdisk -from misc_utility_functions import build_faiss_indexes, safe_path, configure_redis_optimally +from misc_utility_functions import build_faiss_indexes, safe_path, configure_redis_in_background from embeddings_data_models import DocumentEmbedding, TokenLevelEmbeddingBundle from embeddings_data_models import EmbeddingRequest, SemanticSearchRequest, AdvancedSemanticSearchRequest, SimilarityRequest, TextCompletionRequest, AddGrammarRequest from embeddings_data_models import EmbeddingResponse, SemanticSearchResponse, AdvancedSemanticSearchResponse, SimilarityResponse, AllStringsResponse, AllDocumentsResponse, TextCompletionResponse, AddGrammarResponse @@ -49,7 +49,6 @@ asyncio.set_event_loop_policy(uvloop.EventLoopPolicy()) logger = setup_logger() magika = Magika() -configure_redis_optimally() gpu_check_results = is_gpu_available() logger.info(f"\nGPU check results:\n {gpu_check_results}\n") @@ -104,6 +103,9 @@ async def general_exception_handler(request: Request, exc: Exception) -> JSONRes logger.exception(exc) return JSONResponse(status_code=500, content={"message": "An unexpected error occurred"}) +@app.on_event("startup") +async def startup_event(): + configure_redis_in_background() @app.get("/", include_in_schema=False) async def custom_swagger_ui_html():