wokring models and image genration model and admin apges
This commit is contained in:
@@ -59,9 +59,21 @@ def get_model_config(function_name: str, account) -> Dict[str, Any]:
|
||||
# Start with global defaults
|
||||
model = global_settings.openai_model
|
||||
temperature = global_settings.openai_temperature
|
||||
max_tokens = global_settings.openai_max_tokens
|
||||
api_key = global_settings.openai_api_key # ALWAYS from global
|
||||
|
||||
# Get max_tokens from AIModelConfig for the selected model
|
||||
max_tokens = global_settings.openai_max_tokens # Fallback
|
||||
try:
|
||||
from igny8_core.business.billing.models import AIModelConfig
|
||||
model_config = AIModelConfig.objects.filter(
|
||||
model_name=model,
|
||||
is_active=True
|
||||
).first()
|
||||
if model_config and model_config.max_output_tokens:
|
||||
max_tokens = model_config.max_output_tokens
|
||||
except Exception as e:
|
||||
logger.warning(f"Could not load max_tokens from AIModelConfig for {model}: {e}")
|
||||
|
||||
# Check if account has overrides (only for Starter/Growth/Scale plans)
|
||||
# Free plan users cannot create IntegrationSettings records
|
||||
try:
|
||||
@@ -76,12 +88,23 @@ def get_model_config(function_name: str, account) -> Dict[str, Any]:
|
||||
# Override model if specified (NULL = use global)
|
||||
if config.get('model'):
|
||||
model = config['model']
|
||||
# Also update max_tokens for the overridden model
|
||||
try:
|
||||
from igny8_core.business.billing.models import AIModelConfig
|
||||
override_config = AIModelConfig.objects.filter(
|
||||
model_name=model,
|
||||
is_active=True
|
||||
).first()
|
||||
if override_config and override_config.max_output_tokens:
|
||||
max_tokens = override_config.max_output_tokens
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# Override temperature if specified
|
||||
if config.get('temperature') is not None:
|
||||
temperature = config['temperature']
|
||||
|
||||
# Override max_tokens if specified
|
||||
# Override max_tokens if explicitly specified (rare case)
|
||||
if config.get('max_tokens'):
|
||||
max_tokens = config['max_tokens']
|
||||
|
||||
|
||||
Reference in New Issue
Block a user