From e4eb51b2b72ccc707321bc197536e925080fd8d3 Mon Sep 17 00:00:00 2001 From: Charles Teh Date: Thu, 23 Nov 2023 17:36:05 +0800 Subject: [PATCH] Update (ai): switch to gpt 3.5 --- app/Helpers/FirstParty/OpenAI/OpenAI.php | 11 +++++++++++ app/Jobs/Tasks/ParseRssPostMetadataTask.php | 4 ++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/Helpers/FirstParty/OpenAI/OpenAI.php b/app/Helpers/FirstParty/OpenAI/OpenAI.php index 0c9d182..d6abc3e 100644 --- a/app/Helpers/FirstParty/OpenAI/OpenAI.php +++ b/app/Helpers/FirstParty/OpenAI/OpenAI.php @@ -8,6 +8,17 @@ class OpenAI { + public static function getRssPostMetaGpt3($user_prompt, $model_max_tokens = 1536, $timeout = 60) + { + + $openai_config = 'openai-gpt-3-5-turbo-1106'; + + $system_prompt = "Based on given article, populate the following in valid JSON format:\n{\n\"title\":\"(Title based on article)\",\n\"keywords\":[\"(Important keywords in 1-2 words per keyword, letters only)\"],\n\"category\":\"(Updates|Opinions|Features|New Launches|How Tos|Reviews)\",\n\"summary\":\"(Summarise in 50-80 words to help readers understand this article, US grade 9 english)\",\n\"entities\":[\"(List of identified human or business legal entites in 1-2 words per entity, letters only)\"],\n\"society_impact\":\"(Explain in 30-50 words how it impact society on technological aspect, US grade 9 english)\",\n\"society_impact_level\":\"(low|medium|high)\"\n}"; + + return self::getChatCompletion($user_prompt, $system_prompt, $openai_config, $model_max_tokens, $timeout); + } + + public static function getRssPostMeta($user_prompt, $model_max_tokens = 1536, $timeout = 60) { diff --git a/app/Jobs/Tasks/ParseRssPostMetadataTask.php b/app/Jobs/Tasks/ParseRssPostMetadataTask.php index 3521760..0d1970a 100644 --- a/app/Jobs/Tasks/ParseRssPostMetadataTask.php +++ b/app/Jobs/Tasks/ParseRssPostMetadataTask.php @@ -25,12 +25,12 @@ public static function handle(int $rss_post_id) if (! is_null($rss_post->metadata)) { $post_meta_response = $rss_post->metadata; } else { - $post_meta_response = OpenAI::getRssPostMeta($rss_post->body, 1536, 30); + $post_meta_response = OpenAI::getRssPostMetaGpt3($rss_post->body, 1536, 30); if ((isset($post_meta_response->output)) && (! is_null($post_meta_response->output))) { $service_cost_usage = new ServiceCostUsage; $service_cost_usage->cost = $post_meta_response->cost; - $service_cost_usage->name = 'openai-getRssPostMeta'; + $service_cost_usage->name = 'openai-getRssPostMetaGpt3'; $service_cost_usage->reference_1 = 'rss_post'; $service_cost_usage->reference_2 = strval($rss_post->id); $service_cost_usage->output = $post_meta_response;