diff --git a/backend/avatar_assistant_api/api/app_settings.py b/backend/avatar_assistant_api/api/app_settings.py index fc1a132..42b7040 100644 --- a/backend/avatar_assistant_api/api/app_settings.py +++ b/backend/avatar_assistant_api/api/app_settings.py @@ -6,6 +6,10 @@ class AppSettings(BaseSettings): REPLICATE_API_TOKEN: str ELEVENLABS_API_KEY: str + ###Redis + redis_port: int = 6379 + host: str = "redis" + ###OpenAi (response script) openai_model: str = "gpt-3.5-turbo" max_token: int = 50 diff --git a/backend/avatar_assistant_api/api/cache/cache.py b/backend/avatar_assistant_api/api/cache/cache.py index 2e62a94..407be2b 100644 --- a/backend/avatar_assistant_api/api/cache/cache.py +++ b/backend/avatar_assistant_api/api/cache/cache.py @@ -15,12 +15,14 @@ def decorator(fn): ROUTE_CACHING = None -def initialize_caching(config): +def initialize_caching(AppSettings): + host = AppSettings.host + port = AppSettings.redis_port cache_instance = CacheConfigurator() params = { "socket_timeout": 0.5, } - connection_string = "redis://redis:6379" + connection_string = f"{host}://{host}:{port}" cache_instance.setup(connection_string, **params) return cache_instance diff --git a/backend/avatar_assistant_api/api/cache/redis_helper.py b/backend/avatar_assistant_api/api/cache/redis_helper.py index 5bcbdbe..1d81a91 100644 --- a/backend/avatar_assistant_api/api/cache/redis_helper.py +++ b/backend/avatar_assistant_api/api/cache/redis_helper.py @@ -2,7 +2,7 @@ class RedisHelper: - def __init__(self, host="redis", port=6379): + def __init__(self, host: str, port: int): self.client = Redis(host=host, port=port) def get(self, key): @@ -18,4 +18,4 @@ def get_all_keys(self): def print_latest_content(self, session_id): value = self.get(session_id) if value: - print(f"PRINTING FROM REDIS {session_id, value}") + print(session_id, value) diff --git a/backend/avatar_assistant_api/api/generator/script_generation.py b/backend/avatar_assistant_api/api/generator/script_generation.py index 0a7b39b..01f022b 100644 --- a/backend/avatar_assistant_api/api/generator/script_generation.py +++ b/backend/avatar_assistant_api/api/generator/script_generation.py @@ -8,10 +8,12 @@ def __init__(self, AppSettings): self.model = AppSettings.openai_model self.max_token = AppSettings.max_token self.temperature = AppSettings.temperature + self.redis_port = AppSettings.redis_port + self.host = AppSettings.host openai.api_key = AppSettings.OPENAI_API_KEY def get_response_script(self, session_id: str, input_message: str) -> str: - redis_helper = RedisHelper() + redis_helper = RedisHelper(host=self.host, port=self.redis_port) # Check if a response for this session_id already exists in Redis prev_response = redis_helper.get(session_id)