AI MODELS & final updates - feat: Implement AI Model Configuration with dynamic pricing and REST API
- Added AIModelConfig model to manage AI model configurations in the database. - Created serializers and views for AI model configurations, enabling read-only access via REST API. - Implemented filtering capabilities for model type, provider, and default status in the API. - Seeded initial data for text and image models, including pricing and capabilities. - Updated Django Admin interface for managing AI models with enhanced features and bulk actions. - Added validation methods for model and image size checks. - Comprehensive migration created to establish the AIModelConfig model and seed initial data. - Documented implementation and validation results in summary and report files.
This commit is contained in:
@@ -751,3 +751,75 @@ class AdminBillingViewSet(viewsets.ViewSet):
|
||||
return Response({'error': 'Method not found'}, status=404)
|
||||
|
||||
|
||||
@extend_schema_view(
|
||||
list=extend_schema(tags=['AI Models'], summary='List available AI models'),
|
||||
retrieve=extend_schema(tags=['AI Models'], summary='Get AI model details'),
|
||||
)
|
||||
class AIModelConfigViewSet(viewsets.ReadOnlyModelViewSet):
|
||||
"""
|
||||
ViewSet for AI Model Configuration (Read-Only)
|
||||
Provides model information for frontend dropdowns and displays
|
||||
"""
|
||||
permission_classes = [IsAuthenticatedAndActive]
|
||||
authentication_classes = [JWTAuthentication, CSRFExemptSessionAuthentication]
|
||||
throttle_scope = 'billing'
|
||||
throttle_classes = [DebugScopedRateThrottle]
|
||||
pagination_class = None # No pagination for model lists
|
||||
lookup_field = 'model_name'
|
||||
|
||||
def get_queryset(self):
|
||||
"""Get AIModelConfig queryset with filters"""
|
||||
from igny8_core.business.billing.models import AIModelConfig
|
||||
|
||||
queryset = AIModelConfig.objects.filter(is_active=True)
|
||||
|
||||
# Filter by model type
|
||||
model_type = self.request.query_params.get('type', None)
|
||||
if model_type:
|
||||
queryset = queryset.filter(model_type=model_type)
|
||||
|
||||
# Filter by provider
|
||||
provider = self.request.query_params.get('provider', None)
|
||||
if provider:
|
||||
queryset = queryset.filter(provider=provider)
|
||||
|
||||
# Filter by default
|
||||
is_default = self.request.query_params.get('default', None)
|
||||
if is_default is not None:
|
||||
is_default_bool = is_default.lower() in ['true', '1', 'yes']
|
||||
queryset = queryset.filter(is_default=is_default_bool)
|
||||
|
||||
return queryset.order_by('model_type', 'sort_order', 'model_name')
|
||||
|
||||
def get_serializer_class(self):
|
||||
"""Return serializer class"""
|
||||
from .serializers import AIModelConfigSerializer
|
||||
return AIModelConfigSerializer
|
||||
|
||||
def list(self, request, *args, **kwargs):
|
||||
"""List all available models with filters"""
|
||||
queryset = self.get_queryset()
|
||||
serializer = self.get_serializer(queryset, many=True)
|
||||
|
||||
return success_response(
|
||||
data=serializer.data,
|
||||
message='AI models retrieved successfully'
|
||||
)
|
||||
|
||||
def retrieve(self, request, *args, **kwargs):
|
||||
"""Get details for a specific model"""
|
||||
try:
|
||||
instance = self.get_queryset().get(model_name=kwargs.get('model_name'))
|
||||
serializer = self.get_serializer(instance)
|
||||
|
||||
return success_response(
|
||||
data=serializer.data,
|
||||
message='AI model details retrieved successfully'
|
||||
)
|
||||
except Exception as e:
|
||||
return error_response(
|
||||
message='Model not found',
|
||||
errors={'model_name': [str(e)]},
|
||||
status_code=status.HTTP_404_NOT_FOUND
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user