Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Dicklesworthstone committed May 21, 2024
1 parent 42f4a5d commit ad3ddd5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions misc_utility_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
6 changes: 4 additions & 2 deletions swiss_army_llama.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")

Expand Down Expand Up @@ -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():
Expand Down

0 comments on commit ad3ddd5

Please sign in to comment.