This commit is contained in:
ct
2025-06-17 12:01:49 +08:00
parent 2dc85f70cc
commit e378245554
64 changed files with 4798 additions and 0 deletions

View File

@@ -0,0 +1,111 @@
<?php
namespace App\Helpers\FirstParty\AI;
use Illuminate\Support\Facades\Http;
class OpenAI
{
public static function getSingleMemeGenerator($user_prompt)
{
$response = Http::withHeaders([
'Content-Type' => 'application/json',
'Authorization' => 'Bearer ' . env('OPENAI_API_KEY'),
])
->post('https://api.openai.com/v1/responses', [
'model' => 'gpt-4.1-nano',
'input' => [
[
'role' => 'system',
'content' => [
[
'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' => [
'format' => [
'type' => 'json_schema',
'name' => 'meme_generator_single_1',
'strict' => true,
'schema' => [
'type' => 'object',
'properties' => [
'caption' => [
'type' => 'string',
'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")'
],
'background' => [
'type' => 'string',
'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'
]
]
],
'required' => [
'caption',
'meme_overlay',
'background',
'keywords'
],
'additionalProperties' => false
]
]
],
'reasoning' => (object)[],
'tools' => [],
'temperature' => 1,
'max_output_tokens' => 2048,
'top_p' => 1,
'store' => true
]);
// Get the response data
$data = $response->json();
// Check if the request was successful
if ($response->successful()) {
// Handle successful response
return $data;
} else {
// Handle error
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'];
}
}
}
}
}
}

View File

@@ -2,6 +2,8 @@
namespace App\Http\Controllers;
use App\Helpers\FirstParty\AI\OpenAI;
class TestController extends Controller
{
public function index()
@@ -13,4 +15,13 @@ public function populateDuration()
{
\App\Helpers\FirstParty\Maintenance\MemeMediaMaintenance::populateDurations();
}
public function writeMeme()
{
$meme_response = OpenAI::getSingleMemeGenerator('Write me 1 meme about workplace stress');
$meme_output = json_decode(OpenAI::getOpenAIOutput($meme_response));
dd($meme_output);
}
}