mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-04-26 01:06:23 +02:00
feat: added image gen support
This commit is contained in:
parent
459ffd2b78
commit
19e2857343
39 changed files with 3950 additions and 181 deletions
|
|
@ -81,6 +81,56 @@ def load_router_settings():
|
|||
return default_settings
|
||||
|
||||
|
||||
def load_global_image_gen_configs():
|
||||
"""
|
||||
Load global image generation configurations from YAML file.
|
||||
|
||||
Returns:
|
||||
list: List of global image generation config dictionaries, or empty list
|
||||
"""
|
||||
global_config_file = BASE_DIR / "app" / "config" / "global_llm_config.yaml"
|
||||
|
||||
if not global_config_file.exists():
|
||||
return []
|
||||
|
||||
try:
|
||||
with open(global_config_file, encoding="utf-8") as f:
|
||||
data = yaml.safe_load(f)
|
||||
return data.get("global_image_generation_configs", [])
|
||||
except Exception as e:
|
||||
print(f"Warning: Failed to load global image generation configs: {e}")
|
||||
return []
|
||||
|
||||
|
||||
def load_image_gen_router_settings():
|
||||
"""
|
||||
Load router settings for image generation Auto mode from YAML file.
|
||||
|
||||
Returns:
|
||||
dict: Router settings dictionary
|
||||
"""
|
||||
default_settings = {
|
||||
"routing_strategy": "usage-based-routing",
|
||||
"num_retries": 3,
|
||||
"allowed_fails": 3,
|
||||
"cooldown_time": 60,
|
||||
}
|
||||
|
||||
global_config_file = BASE_DIR / "app" / "config" / "global_llm_config.yaml"
|
||||
|
||||
if not global_config_file.exists():
|
||||
return default_settings
|
||||
|
||||
try:
|
||||
with open(global_config_file, encoding="utf-8") as f:
|
||||
data = yaml.safe_load(f)
|
||||
settings = data.get("image_generation_router_settings", {})
|
||||
return {**default_settings, **settings}
|
||||
except Exception as e:
|
||||
print(f"Warning: Failed to load image generation router settings: {e}")
|
||||
return default_settings
|
||||
|
||||
|
||||
def initialize_llm_router():
|
||||
"""
|
||||
Initialize the LLM Router service for Auto mode.
|
||||
|
|
@ -105,6 +155,33 @@ def initialize_llm_router():
|
|||
print(f"Warning: Failed to initialize LLM Router: {e}")
|
||||
|
||||
|
||||
def initialize_image_gen_router():
|
||||
"""
|
||||
Initialize the Image Generation Router service for Auto mode.
|
||||
This should be called during application startup.
|
||||
"""
|
||||
image_gen_configs = load_global_image_gen_configs()
|
||||
router_settings = load_image_gen_router_settings()
|
||||
|
||||
if not image_gen_configs:
|
||||
print(
|
||||
"Info: No global image generation configs found, "
|
||||
"Image Generation Auto mode will not be available"
|
||||
)
|
||||
return
|
||||
|
||||
try:
|
||||
from app.services.image_gen_router_service import ImageGenRouterService
|
||||
|
||||
ImageGenRouterService.initialize(image_gen_configs, router_settings)
|
||||
print(
|
||||
f"Info: Image Generation Router initialized with {len(image_gen_configs)} models "
|
||||
f"(strategy: {router_settings.get('routing_strategy', 'usage-based-routing')})"
|
||||
)
|
||||
except Exception as e:
|
||||
print(f"Warning: Failed to initialize Image Generation Router: {e}")
|
||||
|
||||
|
||||
class Config:
|
||||
# Check if ffmpeg is installed
|
||||
if not is_ffmpeg_installed():
|
||||
|
|
@ -216,6 +293,12 @@ class Config:
|
|||
# Router settings for Auto mode (LiteLLM Router load balancing)
|
||||
ROUTER_SETTINGS = load_router_settings()
|
||||
|
||||
# Global Image Generation Configurations (optional)
|
||||
GLOBAL_IMAGE_GEN_CONFIGS = load_global_image_gen_configs()
|
||||
|
||||
# Router settings for Image Generation Auto mode
|
||||
IMAGE_GEN_ROUTER_SETTINGS = load_image_gen_router_settings()
|
||||
|
||||
# Chonkie Configuration | Edit this to your needs
|
||||
EMBEDDING_MODEL = os.getenv("EMBEDDING_MODEL")
|
||||
# Azure OpenAI credentials from environment variables
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue