From 5a92142d5302b99a087077667d04bb177f6df06c Mon Sep 17 00:00:00 2001 From: Kastan Day Date: Thu, 19 Dec 2024 10:26:56 -0800 Subject: [PATCH] Migrate from Vercel Redis to Redis standalone client --- ai_ta_backend/service/project_service.py | 6 ++++-- requirements.txt | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/ai_ta_backend/service/project_service.py b/ai_ta_backend/service/project_service.py index d336d2d2..0d028826 100644 --- a/ai_ta_backend/service/project_service.py +++ b/ai_ta_backend/service/project_service.py @@ -1,6 +1,7 @@ import json import os +import redis import requests from injector import inject @@ -23,6 +24,8 @@ def __init__(self, sql_db: SQLDatabase, posthog_service: PosthogService, sentry_ self.posthog = posthog_service self.sentry = sentry_service + self.redis_client = redis.Redis.from_url(os.environ['REDIS_URL'], db=0) + def generate_json_schema(self, project_name: str, project_description: str | None) -> None: # Generate metadata schema using project_name and project_description json_schema = generate_schema_from_project_description(project_name, project_description) @@ -93,8 +96,7 @@ def create_project(self, project_name: str, project_description: str | None, pro llm_val[row['providerName']] = row['providerBodyNoModels'] # Insert the pre-assigned API keys into Redis - set_llm_url = str(os.environ['KV_REST_API_URL']) + f"/set/{redis_key}" - set_response = requests.post(set_llm_url, headers=headers, data=json.dumps(llm_val)) + self.redis_client.set(redis_key, json.dumps(llm_val)) # Check the response status if set_response.status_code == 200: diff --git a/requirements.txt b/requirements.txt index f328c5b8..8495d482 100644 --- a/requirements.txt +++ b/requirements.txt @@ -38,6 +38,7 @@ boto3==1.28.79 qdrant-client==1.7.3 supabase==2.5.3 minio==7.2.12 +"redis[hiredis]" # Logging posthog==3.1.0