Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 49 additions & 9 deletions class-gwiz-gf-openai.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,16 +261,25 @@
public function get_openai_models() {
$models = array(
'chat/completions' => array(
'gpt-5' => array(
'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' ),
),
'gpt-5-mini' => array(
'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' ),
),
'gpt-5-nano' => array(
'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' ),
),
'gpt-4o' => array(

Check warning on line 273 in class-gwiz-gf-openai.php

View workflow job for this annotation

GitHub Actions / PHPCS

Array double arrow not aligned correctly; expected 8 space(s) between "'gpt-4o'" and double arrow, but found 13.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like gpt-4o is missing from the updating list.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed (amended my first commit)

'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' ),
),
'gpt-4-turbo' => array(
'gpt-4-turbo' => array(
'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' ),
),
'gpt-4o-mini' => array(
'gpt-4o-mini' => array(
'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' ),
),
'gpt-3.5-turbo' => array(
'gpt-3.5-turbo' => array(
'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' ),
),
),
Expand Down Expand Up @@ -1174,7 +1183,13 @@
return trim( rgars( $response, 'choices/0/message/content' ) );
}

return trim( rgar( $response, 'text' ) );
$text = rgar( $response, 'text', '' );
if ( ! empty( $response ) ) {
// safetly check as trim() doesn't accept null values
$text = trim( $text );
}

return $text;
}

/**
Expand Down Expand Up @@ -1373,17 +1388,42 @@

switch ( $endpoint ) {
case 'chat/completions':
$body['max_tokens'] = (float) rgar( $feed['meta'], $endpoint . '_' . 'max_tokens', $this->default_settings['chat/completions']['max_tokens'] );
$body['temperature'] = (float) rgar( $feed['meta'], $endpoint . '_' . 'temperature', $this->default_settings['chat/completions']['temperature'] );
$body['top_p'] = (float) rgar( $feed['meta'], $endpoint . '_' . 'top_p', $this->default_settings['chat/completions']['top_p'] );
$body['frequency_penalty'] = (float) rgar( $feed['meta'], $endpoint . '_' . 'frequency_penalty', $this->default_settings['chat/completions']['frequency_penalty'] );
$body['presence_penalty'] = (float) rgar( $feed['meta'], $endpoint . '_' . 'presence_penalty', $this->default_settings['chat/completions']['presence_penalty'] );
$body['max_completion_tokens'] = (float) rgar(
$feed['meta'],
$endpoint . '_max_tokens',
$this->default_settings['chat/completions']['max_tokens']
);

// temperature is deprecated in certain models, so only set if the user has set an explicit value.
$temperature = rgar( $feed['meta'], $endpoint . '_temperature' );
if ( $temperature !== null && $temperature !== '' ) {
$body['temperature'] = (float) $temperature;
}

// top_p is deprecated in certain models, so only set if the user has set an explicit value.
$top_p = rgar( $feed['meta'], $endpoint . '_top_p' );
if ( $top_p !== null && $top_p !== '' ) {
$body['top_p'] = (float) $top_p;
}

// frequency_penalty is deprecated in certain models, so only set if the user has set an explicit value.
$frequency_penalty = rgar( $feed['meta'], $endpoint . '_frequency_penalty' );
if ( $frequency_penalty !== null && $frequency_penalty !== '' ) {
$body['frequency_penalty'] = (float) $frequency_penalty;
}

// presence_penalty is deprecated in certain models, so only set if the user has set an explicit value.
$presence_penalty = rgar( $feed['meta'], $endpoint . '_presence_penalty' );
if ( $presence_penalty !== null && $presence_penalty !== '' ) {
$body['presence_penalty'] = (float) $presence_penalty;
}

break;
}

$body = apply_filters( 'gf_openai_request_body', $body, $endpoint, $feed );

$this->log_debug( __METHOD__ . '(): ' . sprintf( __( 'Making request to %s', 'gravityforms-openai' ), $url ) );

Check warning on line 1426 in class-gwiz-gf-openai.php

View workflow job for this annotation

GitHub Actions / PHPCS

A gettext call containing placeholders was found, but was not accompanied by a "translators:" comment on the line above to clarify the meaning of the placeholders.

// Cache successful responses.
$response = wp_remote_post($url, array_merge( array(
Expand Down Expand Up @@ -1544,7 +1584,7 @@
public function should_transform_feed( $feed ) {
$endpoint = rgars( $feed, 'meta/endpoint' );

if ( in_array( $endpoint, array( 'completions', 'edits' ) ) ) {

Check warning on line 1587 in class-gwiz-gf-openai.php

View workflow job for this annotation

GitHub Actions / PHPCS

Not using strict comparison for in_array; supply true for third argument.
return true;
}

Expand Down