- Introduction of dynamic Processors - Introduction of caching system - Introduction of a better template manager - Adaptation of ModelVariables to support dynamic Processors / Retrievers / Specialists - Start adaptation of chat client
62 lines
1.8 KiB
Python
62 lines
1.8 KiB
Python
# common/utils/cache/regions.py
|
|
|
|
from dogpile.cache import make_region
|
|
from flask import current_app
|
|
from urllib.parse import urlparse
|
|
import os
|
|
|
|
|
|
def get_redis_config(app):
|
|
"""
|
|
Create Redis configuration dict based on app config
|
|
Handles both authenticated and non-authenticated setups
|
|
"""
|
|
# Parse the REDIS_BASE_URI to get all components
|
|
redis_uri = urlparse(app.config['REDIS_BASE_URI'])
|
|
|
|
config = {
|
|
'host': redis_uri.hostname,
|
|
'port': int(redis_uri.port or 6379),
|
|
'db': 4, # Keep this for later use
|
|
'redis_expiration_time': 3600,
|
|
'distributed_lock': True
|
|
}
|
|
|
|
# Add authentication if provided
|
|
if redis_uri.username and redis_uri.password:
|
|
config.update({
|
|
'username': redis_uri.username,
|
|
'password': redis_uri.password
|
|
})
|
|
|
|
return config
|
|
|
|
|
|
def create_cache_regions(app):
|
|
"""Initialize all cache regions with app config"""
|
|
redis_config = get_redis_config(app)
|
|
|
|
# Region for model-related caching (ModelVariables etc)
|
|
model_region = make_region(name='model').configure(
|
|
'dogpile.cache.redis',
|
|
arguments=redis_config,
|
|
replace_existing_backend=True
|
|
)
|
|
|
|
# Region for eveai_chat_workers components (Specialists, Retrievers, ...)
|
|
eveai_chat_workers_region = make_region(name='chat_workers').configure(
|
|
'dogpile.cache.redis',
|
|
arguments=redis_config, # arguments={**redis_config, 'db': 4}, # Different DB
|
|
replace_existing_backend=True
|
|
)
|
|
|
|
# Region for eveai_workers components (Processors, ...)
|
|
eveai_workers_region = make_region(name='workers').configure(
|
|
'dogpile.cache.redis',
|
|
arguments=redis_config, # Same config for now
|
|
replace_existing_backend=True
|
|
)
|
|
|
|
return model_region, eveai_chat_workers_region, eveai_workers_region
|
|
|