From 62e55389f94181c2cd1ed14a244134eebd9c6b29 Mon Sep 17 00:00:00 2001 From: "IGNY8 VPS (Salman)" Date: Wed, 17 Dec 2025 11:11:11 +0000 Subject: [PATCH] Add support for GPT-5.1 and GPT-5.2: update token limits and pricing --- backend/igny8_core/ai/ai_core.py | 6 ++++- backend/igny8_core/ai/constants.py | 4 +++- backend/igny8_core/ai/settings.py | 6 +++-- .../igny8_core/api/tests/test_ai_framework.py | 2 +- .../modules/system/integration_views.py | 13 ++++++++--- backend/igny8_core/utils/ai_processor.py | 22 +++++++++++++------ frontend/src/pages/Settings/Integration.tsx | 2 ++ 7 files changed, 40 insertions(+), 15 deletions(-) diff --git a/backend/igny8_core/ai/ai_core.py b/backend/igny8_core/ai/ai_core.py index 8e1168d0..4046c7f2 100644 --- a/backend/igny8_core/ai/ai_core.py +++ b/backend/igny8_core/ai/ai_core.py @@ -239,8 +239,12 @@ class AICore: 'temperature': temperature, } + # GPT-5.1 and GPT-5.2 use max_completion_tokens instead of max_tokens if max_tokens: - body_data['max_tokens'] = max_tokens + if active_model in ['gpt-5.1', 'gpt-5.2']: + body_data['max_completion_tokens'] = max_tokens + else: + body_data['max_tokens'] = max_tokens if response_format: body_data['response_format'] = response_format diff --git a/backend/igny8_core/ai/constants.py b/backend/igny8_core/ai/constants.py index 88235998..2458c41b 100644 --- a/backend/igny8_core/ai/constants.py +++ b/backend/igny8_core/ai/constants.py @@ -6,6 +6,8 @@ MODEL_RATES = { 'gpt-4.1': {'input': 2.00, 'output': 8.00}, 'gpt-4o-mini': {'input': 0.15, 'output': 0.60}, 'gpt-4o': {'input': 2.50, 'output': 10.00}, + 'gpt-5.1': {'input': 1.25, 'output': 10.00}, + 'gpt-5.2': {'input': 1.75, 'output': 14.00}, } # Image model pricing (per image) - EXACT from reference plugin @@ -33,7 +35,7 @@ VALID_SIZES_BY_MODEL = { DEFAULT_AI_MODEL = 'gpt-4.1' # JSON mode supported models -JSON_MODE_MODELS = ['gpt-4o', 'gpt-4o-mini', 'gpt-4-turbo-preview'] +JSON_MODE_MODELS = ['gpt-4o', 'gpt-4o-mini', 'gpt-4-turbo-preview', 'gpt-5.1', 'gpt-5.2'] # Debug mode - controls console logging # Set to False in production to disable verbose logging diff --git a/backend/igny8_core/ai/settings.py b/backend/igny8_core/ai/settings.py index f84484b9..1139279a 100644 --- a/backend/igny8_core/ai/settings.py +++ b/backend/igny8_core/ai/settings.py @@ -99,8 +99,10 @@ def get_model_config(function_name: str, account) -> Dict[str, Any]: # MODEL_RATES not available - skip validation pass - # Get max_tokens and temperature from config (standardized to 8192) - max_tokens = config.get('max_tokens', 8192) # Standardized across entire codebase + # Get max_tokens and temperature from config (standardized to 8192, 16384 for GPT-5.x) + # GPT-5.1 and GPT-5.2 use 16384 max_tokens by default + default_max_tokens = 16384 if model in ['gpt-5.1', 'gpt-5.2'] else 8192 + max_tokens = config.get('max_tokens', default_max_tokens) temperature = config.get('temperature', 0.7) # Reasonable default # Build response format based on model (JSON mode for supported models) diff --git a/backend/igny8_core/api/tests/test_ai_framework.py b/backend/igny8_core/api/tests/test_ai_framework.py index 956f22be..fbe53fb1 100644 --- a/backend/igny8_core/api/tests/test_ai_framework.py +++ b/backend/igny8_core/api/tests/test_ai_framework.py @@ -140,7 +140,7 @@ class GetModelConfigTestCase(TestCase): def test_get_model_config_json_mode_models(self): """Test get_model_config() sets response_format for JSON mode models""" - json_models = ['gpt-4o', 'gpt-4o-mini', 'gpt-4-turbo-preview'] + json_models = ['gpt-4o', 'gpt-4o-mini', 'gpt-4-turbo-preview', 'gpt-5.1', 'gpt-5.2'] for model in json_models: IntegrationSettings.objects.filter(account=self.account).delete() diff --git a/backend/igny8_core/modules/system/integration_views.py b/backend/igny8_core/modules/system/integration_views.py index 5164a1f3..0cf0f73d 100644 --- a/backend/igny8_core/modules/system/integration_views.py +++ b/backend/igny8_core/modules/system/integration_views.py @@ -191,8 +191,10 @@ class IntegrationSettingsViewSet(viewsets.ViewSet): # Get model from config or use default (reference plugin: get_option('igny8_model', 'gpt-4.1')) model = (config or {}).get('model', 'gpt-4.1') if config else 'gpt-4.1' - # Get max_tokens from config or use default - max_tokens = (config or {}).get('max_tokens', 8192) if config else 8192 + # Get max_tokens from config or use default based on model + # GPT-5.1 and GPT-5.2 use 16384 max_tokens by default + default_max_tokens = 16384 if model in ['gpt-5.1', 'gpt-5.2'] else 8192 + max_tokens = (config or {}).get('max_tokens', default_max_tokens) if config else default_max_tokens # Check if test with response is requested (reference plugin: $with_response parameter) with_response = (config or {}).get('with_response', False) if config else False @@ -207,10 +209,15 @@ class IntegrationSettingsViewSet(viewsets.ViewSet): 'content': 'Reply with exactly: OK! Ping Received' } ], - 'max_tokens': max_tokens, 'temperature': 0.7, } + # GPT-5.1 and GPT-5.2 use max_completion_tokens instead of max_tokens + if model in ['gpt-5.1', 'gpt-5.2']: + request_body['max_completion_tokens'] = max_tokens + else: + request_body['max_tokens'] = max_tokens + try: response = requests.post( 'https://api.openai.com/v1/chat/completions', diff --git a/backend/igny8_core/utils/ai_processor.py b/backend/igny8_core/utils/ai_processor.py index 09a6eb57..f2697d53 100644 --- a/backend/igny8_core/utils/ai_processor.py +++ b/backend/igny8_core/utils/ai_processor.py @@ -174,8 +174,12 @@ class AIProcessor: } # Add max_tokens if specified (reference plugin uses 4000 default) + # GPT-5.1 and GPT-5.2 use max_completion_tokens instead of max_tokens if max_tokens: - body_data['max_tokens'] = max_tokens + if model in ['gpt-5.1', 'gpt-5.2']: + body_data['max_completion_tokens'] = max_tokens + else: + body_data['max_tokens'] = max_tokens # Add response_format if specified (for JSON mode) if response_format: @@ -1131,15 +1135,17 @@ Make sure each prompt is detailed enough for image generation, describing the vi # Call OpenAI with JSON response format - Steps 8-10 happen in _call_openai # Use the active model from integration settings (self.default_model) # Check if model supports JSON mode - json_models = ['gpt-4o', 'gpt-4o-mini', 'gpt-4-turbo-preview'] active_model = self.default_model # This is the active model from IntegrationSettings - response_format = {'type': 'json_object'} if active_model in json_models else None + response_format = {'type': 'json_object'} if active_model in JSON_MODE_MODELS else None + + # GPT-5.1 and GPT-5.2 use 16384 max_tokens + max_tokens = 16384 if active_model in ['gpt-5.1', 'gpt-5.2'] else 8192 try: result = self._call_openai( prompt, model=active_model, # Explicitly pass to ensure consistency - max_tokens=8192, + max_tokens=max_tokens, temperature=0.7, response_format=response_format, response_steps=response_steps @@ -1339,14 +1345,16 @@ Make sure each prompt is detailed enough for image generation, describing the vi # Use the active model from integration settings (self.default_model) # Check if model supports JSON mode - json_models = ['gpt-4o', 'gpt-4o-mini', 'gpt-4-turbo-preview'] active_model = self.default_model # This is the active model from IntegrationSettings - response_format = {'type': 'json_object'} if active_model in json_models else None + response_format = {'type': 'json_object'} if active_model in JSON_MODE_MODELS else None + + # GPT-5.1 and GPT-5.2 use 16384 max_tokens + max_tokens = 16384 if active_model in ['gpt-5.1', 'gpt-5.2'] else 8192 result = self._call_openai( prompt, model=active_model, # Explicitly pass to ensure consistency - max_tokens=8192, + max_tokens=max_tokens, temperature=0.7, response_format=response_format ) diff --git a/frontend/src/pages/Settings/Integration.tsx b/frontend/src/pages/Settings/Integration.tsx index 80f1e0e9..ba2db006 100644 --- a/frontend/src/pages/Settings/Integration.tsx +++ b/frontend/src/pages/Settings/Integration.tsx @@ -506,6 +506,8 @@ export default function Integration() { { value: 'gpt-4.1', label: 'GPT-4.1 - $2.00 / $8.00 per 1M tokens' }, { value: 'gpt-4o-mini', label: 'GPT-4o mini - $0.15 / $0.60 per 1M tokens' }, { value: 'gpt-4o', label: 'GPT-4o - $2.50 / $10.00 per 1M tokens' }, + { value: 'gpt-5.1', label: 'GPT-5.1 - $1.25 / $10.00 per 1M tokens (16K)' }, + { value: 'gpt-5.2', label: 'GPT-5.2 - $1.75 / $14.00 per 1M tokens (16K)' }, ], }, ];