Skip to content
Merged
Show file tree
Hide file tree
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
20 changes: 20 additions & 0 deletions includes/Classifai/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -956,3 +956,23 @@ function safe_wp_remote_post( string $url, array $args = [] ) {
return safe_wp_remote_request( 'POST', $url, $args );
}

/**
* Get the temperature for the request.
*
* We increase the base temperature proportionally
* to the number of results, ensuring it never exceeds 2.
*
* The goal here is to get more diverse results when
* we are requesting more results.
*
* @param float $temperature The temperature.
* @param int $results The number of results.
* @return float The temperature.
*/
function get_temperature( float $temperature, int $results = 1 ): float {
if ( 1 === $results ) {
return $temperature;
}

return (float) min( 2.0, $temperature + ( $results / 10 ) );
}
5 changes: 3 additions & 2 deletions includes/Classifai/Providers/Azure/OpenAI.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use function Classifai\get_default_prompt;
use function Classifai\sanitize_number_of_responses_field;
use function Classifai\safe_wp_remote_post;
use function Classifai\get_temperature;

class OpenAI extends Provider {

Expand Down Expand Up @@ -553,7 +554,7 @@ public function generate_titles( int $post_id = 0, array $args = [] ) {
'classifai_azure_openai_title_request_body',
[
'messages' => $this->get_request_messages( $post_id, $prompt, $message_content ),
'temperature' => 0.9,
'temperature' => get_temperature( 0.9, absint( $args['num'] ) ),
'n' => absint( $args['num'] ),
],
$post_id
Expand Down Expand Up @@ -660,7 +661,7 @@ public function resize_content( int $post_id, array $args = array() ) {
'content' => '"""' . esc_html( $args['content'] ) . '"""',
],
],
'temperature' => 0.9,
'temperature' => get_temperature( 0.9, absint( $args['num'] ) ),
'n' => absint( $args['num'] ),
],
$post_id
Expand Down
5 changes: 3 additions & 2 deletions includes/Classifai/Providers/OpenAI/ChatGPT.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use function Classifai\sanitize_number_of_responses_field;
use function Classifai\get_modified_image_source_url;
use function Classifai\get_largest_size_and_dimensions_image_url;
use function Classifai\get_temperature;

class ChatGPT extends Provider {

Expand Down Expand Up @@ -762,7 +763,7 @@ public function generate_titles( int $post_id = 0, array $args = [] ) {
[
'model' => $this->chatgpt_model,
'messages' => $this->get_request_messages( $post_id, $prompt, $message_content ),
'temperature' => 0.9,
'temperature' => get_temperature( 0.9, absint( $args['num'] ) ),
'n' => absint( $args['num'] ),
],
$post_id
Expand Down Expand Up @@ -867,7 +868,7 @@ public function resize_content( int $post_id, array $args = array() ) {
'content' => '"""' . esc_html( $args['content'] ) . '"""',
],
],
'temperature' => 0.9,
'temperature' => get_temperature( 0.9, absint( $args['num'] ) ),
'n' => absint( $args['num'] ),
],
$post_id
Expand Down
5 changes: 3 additions & 2 deletions includes/Classifai/Providers/XAI/Grok.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use function Classifai\sanitize_number_of_responses_field;
use function Classifai\get_modified_image_source_url;
use function Classifai\get_largest_size_and_dimensions_image_url;
use function Classifai\get_temperature;

class Grok extends Provider {
/**
Expand Down Expand Up @@ -628,7 +629,7 @@ public function generate_titles( int $post_id = 0, array $args = [] ) {
[
'model' => $this->get_model(),
'messages' => $this->get_request_messages( $post_id, $prompt, $message_content ),
'temperature' => 0.9,
'temperature' => get_temperature( 0.9, absint( $args['num'] ) ),
'stream' => false,
'n' => absint( $args['num'] ),
],
Expand Down Expand Up @@ -733,7 +734,7 @@ public function resize_content( int $post_id, array $args = array() ) {
'content' => '"""' . esc_html( $args['content'] ) . '"""',
],
],
'temperature' => 0.9,
'temperature' => get_temperature( 0.9, absint( $args['num'] ) ),
'stream' => false,
'n' => absint( $args['num'] ),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ export const AzureOpenAISettings = ( {
<InputControl
id={ `${ providerName }_number_of_suggestions` }
type="number"
min={ 1 }
max={ 10 }
value={ providerSettings.number_of_suggestions || 1 }
onChange={ ( value ) =>
onChange( { number_of_suggestions: value } )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ export const OpenAIChatGPTSettings = ( { isConfigured = false } ) => {
<InputControl
id={ `${ providerName }_number_of_suggestions` }
type="number"
min={ 1 }
max={ 10 }
value={ providerSettings.number_of_suggestions || 1 }
onChange={ ( value ) =>
onChange( { number_of_suggestions: value } )
Expand Down
2 changes: 2 additions & 0 deletions src/js/settings/components/provider-settings/xai-grok.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ export const XAIGrokSettings = ( { isConfigured = false } ) => {
<InputControl
id={ `${ providerName }_number_of_suggestions` }
type="number"
min={ 1 }
max={ 10 }
value={ providerSettings.number_of_suggestions || 1 }
onChange={ ( value ) =>
onChange( { number_of_suggestions: value } )
Expand Down