From 950202c1fb0e62ed0afe03a7b9fae77e9bdd17ce Mon Sep 17 00:00:00 2001 From: ct Date: Tue, 17 Jun 2025 16:37:19 +0800 Subject: [PATCH] Update --- app/Helpers/FirstParty/AI/OpenAI.php | 52 +++++++----------- database/seeders/data/json/.DS_Store | Bin 6148 -> 0 bytes database/seeders/data/json/category/.DS_Store | Bin 6148 -> 0 bytes 3 files changed, 21 insertions(+), 31 deletions(-) delete mode 100644 database/seeders/data/json/.DS_Store delete mode 100644 database/seeders/data/json/category/.DS_Store diff --git a/app/Helpers/FirstParty/AI/OpenAI.php b/app/Helpers/FirstParty/AI/OpenAI.php index 5791ff8..2ec6429 100644 --- a/app/Helpers/FirstParty/AI/OpenAI.php +++ b/app/Helpers/FirstParty/AI/OpenAI.php @@ -4,7 +4,6 @@ use Illuminate\Support\Facades\Http; - class OpenAI { public static function getSingleMemeGenerator($user_prompt) @@ -12,7 +11,7 @@ public static function getSingleMemeGenerator($user_prompt) $response = Http::withHeaders([ 'Content-Type' => 'application/json', - 'Authorization' => 'Bearer ' . env('OPENAI_API_KEY'), + 'Authorization' => 'Bearer '.env('OPENAI_API_KEY'), ]) ->post('https://api.openai.com/v1/responses', [ 'model' => 'gpt-4.1-nano', @@ -23,18 +22,18 @@ public static function getSingleMemeGenerator($user_prompt) [ 'type' => 'input_text', 'text' => '"You are an AI meme writer for a video meme generator.\n\nYour task is to generate a JSON array containing a unique, short-form workplace-related video meme ideas.\n\nEach meme object must include the following fields, with the format shown below. Each field contains an inline description of the type of content it must generate.\n\nReturn **only** a Markdown code block containing valid JSON with inline content guidance (as strings). Do not add any commentary or explanation outside the code block.\n\n- All memes must be funny, relatable, and clearly connected to the provided topic.\n- Use realistic but exaggerated expressions and settings to match meme-style content.\n- Style should suit video formats like TikTok, Instagram Reels, or YouTube Shorts."', - ] - ] + ], + ], ], [ 'role' => 'user', 'content' => [ [ 'type' => 'input_text', - 'text' => $user_prompt - ] - ] - ] + 'text' => $user_prompt, + ], + ], + ], ], 'text' => [ 'format' => [ @@ -46,40 +45,40 @@ public static function getSingleMemeGenerator($user_prompt) 'properties' => [ 'caption' => [ 'type' => 'string', - 'description' => 'A humorous, one-liner or POV meme (under 15 words, no punctuation)' + 'description' => 'A humorous, one-liner or POV meme (under 15 words, no punctuation)', ], 'meme_overlay' => [ 'type' => 'string', - 'description' => 'A short visual reaction that pairs with the caption (e.g., "guy blinking in disbelief")' + 'description' => 'A short visual reaction that pairs with the caption (e.g., "guy blinking in disbelief")', ], 'background' => [ 'type' => 'string', - 'description' => 'The setting or location of the meme (e.g., "Zoom call grid", "office cubicle")' + 'description' => 'The setting or location of the meme (e.g., "Zoom call grid", "office cubicle")', ], 'keywords' => [ 'type' => 'array', 'description' => 'Relevant lowercase tags for the meme (e.g., "burnout", "email fail", "meetings")', 'items' => [ - 'type' => 'string' - ] - ] + 'type' => 'string', + ], + ], ], 'required' => [ 'caption', 'meme_overlay', 'background', - 'keywords' + 'keywords', ], - 'additionalProperties' => false - ] - ] + 'additionalProperties' => false, + ], + ], ], - 'reasoning' => (object)[], + 'reasoning' => (object) [], 'tools' => [], 'temperature' => 1, 'max_output_tokens' => 2048, 'top_p' => 1, - 'store' => true + 'store' => true, ]); // Get the response data @@ -91,21 +90,12 @@ public static function getSingleMemeGenerator($user_prompt) return $data; } else { // Handle error - throw new \Exception('API request failed: ' . $response->body()); + throw new \Exception('API request failed: '.$response->body()); } } public static function getOpenAIOutput($data) { - if (isset($data['output'])) { - if (count($data['output']) > 0) { - - if (isset($data['output'][0]['content'])) { - if (isset($data['output'][0]['content'][0]['text'])) { - return $data['output'][0]['content'][0]['text']; - } - } - } - } + return data_get($data, 'output.0.content.0.text', null); } } diff --git a/database/seeders/data/json/.DS_Store b/database/seeders/data/json/.DS_Store deleted file mode 100644 index 70f36e5232445a15fb46d281821c00c891935cea..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHK%}T>S5T0$T-BN@e6!aGGTCj~GikDF93mDOZN=;C*c+XNTCOx-d`B25M!_5AdW_9qwyvR#nQ@ZS(as0Ui)_{^V1+5k6OX- zl4fU0#o^2j!tRtaNHylZop# z8+FG$aHn-=a_FMHx4S=`R^-O^&e3V-K7L5lvtd)by1Iz$3utW^lBT!bCXwSS=W`G&^83S}aIH-i4#oVAiI&h%hM~asSNzkUd1fgTm zvzQyi2#PSJh^AE7D~2%T=yz_N z&9p}S|K$7o|9lb8m;q+sUojv`ZNJ^ZE!p0>usQ0r4(bgm3FYMmKT6Qhtr&Bu6>p+y ZLBB%=qGvHTh#nOF5zsX7zzqB<1MkqOO2~NasYl}1V|>9l91XR*XGR+QY?e$D9{^e_j$)N zyYg3fb^w&sdv^mg0G1r4_^@ei_TI+KF4ALKe2+Ig;0`Cw{Ve)>hvhanV2c+#;XMBp z9rrn6z`i?d`^RDEdC2dYKm7kWKrABJW7NbNu{Was-)G;*DQT$}? zlP8z#P>P>UfAw&bHdM0+h`^MZO