6
This commit is contained in:
@@ -34,16 +34,14 @@ class BaseAIFunction(ABC):
|
|||||||
def validate(self, payload: dict, account=None) -> Dict[str, Any]:
|
def validate(self, payload: dict, account=None) -> Dict[str, Any]:
|
||||||
"""
|
"""
|
||||||
Validate input payload.
|
Validate input payload.
|
||||||
Default: checks for 'ids' array, max_items limit.
|
Default: checks for 'ids' array.
|
||||||
Override for custom validation.
|
Override for custom validation.
|
||||||
"""
|
"""
|
||||||
ids = payload.get('ids', [])
|
ids = payload.get('ids', [])
|
||||||
if not ids:
|
if not ids:
|
||||||
return {'valid': False, 'error': 'No IDs provided'}
|
return {'valid': False, 'error': 'No IDs provided'}
|
||||||
|
|
||||||
max_items = self.get_max_items()
|
# Removed max_items limit check - no limits enforced
|
||||||
if max_items and len(ids) > max_items:
|
|
||||||
return {'valid': False, 'error': f'Maximum {max_items} items allowed'}
|
|
||||||
|
|
||||||
return {'valid': True}
|
return {'valid': True}
|
||||||
|
|
||||||
|
|||||||
@@ -34,14 +34,15 @@ class AutoClusterFunction(BaseAIFunction):
|
|||||||
}
|
}
|
||||||
|
|
||||||
def get_max_items(self) -> int:
|
def get_max_items(self) -> int:
|
||||||
return 20
|
# No limit - return None
|
||||||
|
return None
|
||||||
|
|
||||||
def validate(self, payload: dict, account=None) -> Dict:
|
def validate(self, payload: dict, account=None) -> Dict:
|
||||||
"""Custom validation for clustering with plan limit checks"""
|
"""Custom validation for clustering"""
|
||||||
from igny8_core.ai.validators import validate_ids, validate_keywords_exist, validate_cluster_limits
|
from igny8_core.ai.validators import validate_ids, validate_keywords_exist
|
||||||
|
|
||||||
# Base validation
|
# Base validation (no max_items limit)
|
||||||
result = validate_ids(payload, max_items=self.get_max_items())
|
result = validate_ids(payload, max_items=None)
|
||||||
if not result['valid']:
|
if not result['valid']:
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@@ -51,10 +52,7 @@ class AutoClusterFunction(BaseAIFunction):
|
|||||||
if not keywords_result['valid']:
|
if not keywords_result['valid']:
|
||||||
return keywords_result
|
return keywords_result
|
||||||
|
|
||||||
# Check plan limits
|
# Removed plan limits check
|
||||||
limit_result = validate_cluster_limits(account, operation_type='cluster')
|
|
||||||
if not limit_result['valid']:
|
|
||||||
return limit_result
|
|
||||||
|
|
||||||
return {'valid': True}
|
return {'valid': True}
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,8 @@ class GenerateContentFunction(BaseAIFunction):
|
|||||||
}
|
}
|
||||||
|
|
||||||
def get_max_items(self) -> int:
|
def get_max_items(self) -> int:
|
||||||
return 50 # Max tasks per batch
|
# No limit - return None
|
||||||
|
return None
|
||||||
|
|
||||||
def validate(self, payload: dict, account=None) -> Dict:
|
def validate(self, payload: dict, account=None) -> Dict:
|
||||||
"""Validate task IDs"""
|
"""Validate task IDs"""
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ from django.db import transaction
|
|||||||
from igny8_core.ai.base import BaseAIFunction
|
from igny8_core.ai.base import BaseAIFunction
|
||||||
from igny8_core.modules.planner.models import Clusters, ContentIdeas
|
from igny8_core.modules.planner.models import Clusters, ContentIdeas
|
||||||
from igny8_core.ai.ai_core import AICore
|
from igny8_core.ai.ai_core import AICore
|
||||||
from igny8_core.ai.validators import validate_cluster_exists, validate_cluster_limits
|
from igny8_core.ai.validators import validate_cluster_exists
|
||||||
from igny8_core.ai.tracker import ConsoleStepTracker
|
from igny8_core.ai.tracker import ConsoleStepTracker
|
||||||
from igny8_core.ai.prompts import PromptRegistry
|
from igny8_core.ai.prompts import PromptRegistry
|
||||||
from igny8_core.ai.settings import get_model_config
|
from igny8_core.ai.settings import get_model_config
|
||||||
@@ -38,10 +38,11 @@ class GenerateIdeasFunction(BaseAIFunction):
|
|||||||
}
|
}
|
||||||
|
|
||||||
def get_max_items(self) -> int:
|
def get_max_items(self) -> int:
|
||||||
return 10 # Max clusters per idea generation
|
# No limit - return None
|
||||||
|
return None
|
||||||
|
|
||||||
def validate(self, payload: dict, account=None) -> Dict:
|
def validate(self, payload: dict, account=None) -> Dict:
|
||||||
"""Validate cluster IDs and plan limits"""
|
"""Validate cluster IDs"""
|
||||||
result = super().validate(payload, account)
|
result = super().validate(payload, account)
|
||||||
if not result['valid']:
|
if not result['valid']:
|
||||||
return result
|
return result
|
||||||
@@ -54,10 +55,7 @@ class GenerateIdeasFunction(BaseAIFunction):
|
|||||||
if not cluster_result['valid']:
|
if not cluster_result['valid']:
|
||||||
return cluster_result
|
return cluster_result
|
||||||
|
|
||||||
# Check plan limits
|
# Removed plan limits check
|
||||||
limit_result = validate_cluster_limits(account, operation_type='idea')
|
|
||||||
if not limit_result['valid']:
|
|
||||||
return limit_result
|
|
||||||
|
|
||||||
return {'valid': True}
|
return {'valid': True}
|
||||||
|
|
||||||
|
|||||||
@@ -36,7 +36,8 @@ class GenerateImagesFunction(BaseAIFunction):
|
|||||||
}
|
}
|
||||||
|
|
||||||
def get_max_items(self) -> int:
|
def get_max_items(self) -> int:
|
||||||
return 20 # Max tasks per batch
|
# No limit - return None
|
||||||
|
return None
|
||||||
|
|
||||||
def validate(self, payload: dict, account=None) -> Dict:
|
def validate(self, payload: dict, account=None) -> Dict:
|
||||||
"""Validate task IDs"""
|
"""Validate task IDs"""
|
||||||
|
|||||||
@@ -10,11 +10,11 @@ logger = logging.getLogger(__name__)
|
|||||||
|
|
||||||
def validate_ids(payload: dict, max_items: Optional[int] = None) -> Dict[str, Any]:
|
def validate_ids(payload: dict, max_items: Optional[int] = None) -> Dict[str, Any]:
|
||||||
"""
|
"""
|
||||||
Base validation: checks for 'ids' array and max_items limit.
|
Base validation: checks for 'ids' array.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
payload: Request payload containing 'ids' array
|
payload: Request payload containing 'ids' array
|
||||||
max_items: Maximum number of items allowed (None = no limit)
|
max_items: Maximum number of items allowed (deprecated - no longer enforced)
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Dict with 'valid' (bool) and optional 'error' (str)
|
Dict with 'valid' (bool) and optional 'error' (str)
|
||||||
@@ -23,8 +23,7 @@ def validate_ids(payload: dict, max_items: Optional[int] = None) -> Dict[str, An
|
|||||||
if not ids:
|
if not ids:
|
||||||
return {'valid': False, 'error': 'No IDs provided'}
|
return {'valid': False, 'error': 'No IDs provided'}
|
||||||
|
|
||||||
if max_items and len(ids) > max_items:
|
# Removed max_items limit check - no limits enforced
|
||||||
return {'valid': False, 'error': f'Maximum {max_items} items allowed'}
|
|
||||||
|
|
||||||
return {'valid': True}
|
return {'valid': True}
|
||||||
|
|
||||||
@@ -55,46 +54,16 @@ def validate_keywords_exist(ids: list, account=None) -> Dict[str, Any]:
|
|||||||
def validate_cluster_limits(account, operation_type: str = 'cluster') -> Dict[str, Any]:
|
def validate_cluster_limits(account, operation_type: str = 'cluster') -> Dict[str, Any]:
|
||||||
"""
|
"""
|
||||||
Validate plan limits for cluster operations.
|
Validate plan limits for cluster operations.
|
||||||
|
DISABLED: All limits have been removed.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
account: Account object
|
account: Account object
|
||||||
operation_type: Type of operation ('cluster', 'idea', etc.)
|
operation_type: Type of operation ('cluster', 'idea', etc.)
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Dict with 'valid' (bool) and optional 'error' (str)
|
Dict with 'valid' (bool) - always returns valid
|
||||||
"""
|
"""
|
||||||
if not account:
|
# All limits removed - always return valid
|
||||||
return {'valid': False, 'error': 'Account is required'}
|
|
||||||
|
|
||||||
plan = getattr(account, 'plan', None)
|
|
||||||
if not plan:
|
|
||||||
return {'valid': False, 'error': 'Account does not have an active plan'}
|
|
||||||
|
|
||||||
if operation_type == 'cluster':
|
|
||||||
from igny8_core.modules.planner.models import Clusters
|
|
||||||
|
|
||||||
# Check daily cluster limit
|
|
||||||
now = timezone.now()
|
|
||||||
start_of_day = now.replace(hour=0, minute=0, second=0, microsecond=0)
|
|
||||||
clusters_today = Clusters.objects.filter(
|
|
||||||
account=account,
|
|
||||||
created_at__gte=start_of_day
|
|
||||||
).count()
|
|
||||||
|
|
||||||
if plan.daily_cluster_limit and clusters_today >= plan.daily_cluster_limit:
|
|
||||||
return {
|
|
||||||
'valid': False,
|
|
||||||
'error': f'Daily cluster limit reached ({plan.daily_cluster_limit} clusters per day). Please try again tomorrow.'
|
|
||||||
}
|
|
||||||
|
|
||||||
# Check max clusters limit
|
|
||||||
total_clusters = Clusters.objects.filter(account=account).count()
|
|
||||||
if plan.max_clusters and total_clusters >= plan.max_clusters:
|
|
||||||
return {
|
|
||||||
'valid': False,
|
|
||||||
'error': f'Maximum cluster limit reached ({plan.max_clusters} clusters). Please upgrade your plan or delete existing clusters.'
|
|
||||||
}
|
|
||||||
|
|
||||||
return {'valid': True}
|
return {'valid': True}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user