From fe72197b64583acf61e71822b85c8370b22cc2d2 Mon Sep 17 00:00:00 2001 From: Darin Kotter Date: Thu, 27 Jul 2023 13:11:36 -0600 Subject: [PATCH] Modify our excerpt prompt a bit more, trying to ensure the summary generated pairs well with the title. Exclude the title from the content we summarize. Increase temperature value --- includes/Classifai/Providers/OpenAI/ChatGPT.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/includes/Classifai/Providers/OpenAI/ChatGPT.php b/includes/Classifai/Providers/OpenAI/ChatGPT.php index cac19c827..ba279d4f6 100644 --- a/includes/Classifai/Providers/OpenAI/ChatGPT.php +++ b/includes/Classifai/Providers/OpenAI/ChatGPT.php @@ -557,7 +557,7 @@ public function generate_excerpt( int $post_id = 0, array $args = [] ) { * * @return {string} Prompt. */ - $prompt = apply_filters( 'classifai_chatgpt_excerpt_prompt', 'Provide a teaser for the following text using a maximum of ' . $excerpt_length . ' words', $post_id, $excerpt_length ); + $prompt = apply_filters( 'classifai_chatgpt_excerpt_prompt', sprintf( 'Summarize the following message using a maximum of %d words. Ensure this summary pairs well with the following text: %s.', $excerpt_length, get_the_title( $post_id ) ), $post_id, $excerpt_length ); /** * Filter the request body before sending to ChatGPT. @@ -575,12 +575,16 @@ public function generate_excerpt( int $post_id = 0, array $args = [] ) { [ 'model' => $this->chatgpt_model, 'messages' => [ + [ + 'role' => 'system', + 'content' => $prompt, + ], [ 'role' => 'user', - 'content' => $prompt . ': ' . $this->get_content( $post_id, $excerpt_length, true, $args['content'] ) . '', + 'content' => $this->get_content( $post_id, $excerpt_length, false, $args['content'] ) . '', ], ], - 'temperature' => 0, + 'temperature' => 0.9, ], $post_id ); @@ -731,10 +735,10 @@ public function get_content( int $post_id = 0, int $return_length = 0, bool $use /** * We then subtract those tokens from the max number of tokens ChatGPT allows * in a single request, as well as subtracting out the number of tokens in our - * prompt (13). ChatGPT counts both the tokens in the request and in + * prompt (~50). ChatGPT counts both the tokens in the request and in * the response towards the max. */ - $max_content_tokens = $this->max_tokens - $return_tokens - 13; + $max_content_tokens = $this->max_tokens - $return_tokens - 50; if ( empty( $post_content ) ) { $post = get_post( $post_id );