Skip to content

Commit

Permalink
refactor: moved redis host and port to AppSettings
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrienHdz committed Oct 17, 2023
1 parent 3bd0959 commit 66d2edd
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
4 changes: 4 additions & 0 deletions backend/avatar_assistant_api/api/app_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions backend/avatar_assistant_api/api/cache/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions backend/avatar_assistant_api/api/cache/redis_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 66d2edd

Please sign in to comment.