Skip to content

Commit 179e2ff

Browse files
committed
Added support for gpt-5, gpt-5-mini and gpt-5-nano chat completions model.
1 parent a178f7d commit 179e2ff

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

class-gwiz-gf-openai.php

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -261,16 +261,22 @@ public function init() {
261261
public function get_openai_models() {
262262
$models = array(
263263
'chat/completions' => array(
264-
'gpt-4o' => array(
265-
'description' => __( 'OpenAI\'s fastest and most affordable flagship model. Context length: 128k. <a href="https://platform.openai.com/docs/models/gpt-4o" target="_blank">More Details</a>', 'gravityforms-openai' ),
264+
'gpt-5' => array(
265+
'description' => __( 'OpenAI\'s flagship model for coding, reasoning, and agentic tasks across domains. Context length: 128k. <a href="https://platform.openai.com/docs/models/gpt-5" target="_blank">More Details</a>', 'gravityforms-openai' ),
266266
),
267-
'gpt-4-turbo' => array(
267+
'gpt-5-mini' => array(
268+
'description' => __( 'OpenAI\'s faster, more cost-efficient version of GPT-5. It\'s great for well-defined tasks and precise prompts. Context length: 128k. <a href="https://platform.openai.com/docs/models/gpt-5-mini" target="_blank">More Details</a>', 'gravityforms-openai' ),
269+
),
270+
'gpt-5-nano' => array(
271+
'description' => __( 'OpenAI\'s fastest, cheapest version of GPT-5. It\'s great for summarization and classification tasks. It\'s great for well-defined tasks and precise prompts. Context length: 128k. <a href="https://platform.openai.com/docs/models/gpt-5-mini" target="_blank">More Details</a>', 'gravityforms-openai' ),
272+
),
273+
'gpt-4-turbo' => array(
268274
'description' => __( 'OpenAI\'s previous high-intelligence model. Context length: 128k. <a href="https://platform.openai.com/docs/models/gpt-4-turbo-and-gpt-4" target="_blank">More Details</a>', 'gravityforms-openai' ),
269275
),
270-
'gpt-4o-mini' => array(
276+
'gpt-4o-mini' => array(
271277
'description' => __( 'OpenAI\'s most cost-efficient small model. Context length: 128k. <a href="https://platform.openai.com/docs/models/gpt-4o-mini" target="_blank">More Details</a>', 'gravityforms-openai' ),
272278
),
273-
'gpt-3.5-turbo' => array(
279+
'gpt-3.5-turbo' => array(
274280
'description' => __( 'Inexpensive model for simple tasks. Context length: 16k. <a href="https://platform.openai.com/docs/models/gpt-3-5-turbo" target="_blank">More Details</a>', 'gravityforms-openai' ),
275281
),
276282
),
@@ -1174,7 +1180,13 @@ public function get_text_from_response( $response ) {
11741180
return trim( rgars( $response, 'choices/0/message/content' ) );
11751181
}
11761182

1177-
return trim( rgar( $response, 'text' ) );
1183+
$text = rgar( $response, 'text', '' );
1184+
if ( ! empty( $response ) ) {
1185+
// safetly check as trim() doesn't accept null values
1186+
$text = trim( $text );
1187+
}
1188+
1189+
return $text;
11781190
}
11791191

11801192
/**
@@ -1373,11 +1385,11 @@ public function make_request( $endpoint, $body, $feed ) {
13731385

13741386
switch ( $endpoint ) {
13751387
case 'chat/completions':
1376-
$body['max_tokens'] = (float) rgar( $feed['meta'], $endpoint . '_' . 'max_tokens', $this->default_settings['chat/completions']['max_tokens'] );
1377-
$body['temperature'] = (float) rgar( $feed['meta'], $endpoint . '_' . 'temperature', $this->default_settings['chat/completions']['temperature'] );
1378-
$body['top_p'] = (float) rgar( $feed['meta'], $endpoint . '_' . 'top_p', $this->default_settings['chat/completions']['top_p'] );
1379-
$body['frequency_penalty'] = (float) rgar( $feed['meta'], $endpoint . '_' . 'frequency_penalty', $this->default_settings['chat/completions']['frequency_penalty'] );
1380-
$body['presence_penalty'] = (float) rgar( $feed['meta'], $endpoint . '_' . 'presence_penalty', $this->default_settings['chat/completions']['presence_penalty'] );
1388+
$body['max_completion_tokens'] = (float) rgar( $feed['meta'], $endpoint . '_' . 'max_tokens', $this->default_settings['chat/completions']['max_tokens'] );
1389+
$body['temperature'] = (float) rgar( $feed['meta'], $endpoint . '_' . 'temperature', $this->default_settings['chat/completions']['temperature'] );
1390+
$body['top_p'] = (float) rgar( $feed['meta'], $endpoint . '_' . 'top_p', $this->default_settings['chat/completions']['top_p'] );
1391+
$body['frequency_penalty'] = (float) rgar( $feed['meta'], $endpoint . '_' . 'frequency_penalty', $this->default_settings['chat/completions']['frequency_penalty'] );
1392+
$body['presence_penalty'] = (float) rgar( $feed['meta'], $endpoint . '_' . 'presence_penalty', $this->default_settings['chat/completions']['presence_penalty'] );
13811393
break;
13821394
}
13831395

0 commit comments

Comments
 (0)