Update
This commit is contained in:
@@ -9,9 +9,18 @@ class OpenAI
|
||||
public static function getSingleMemeGenerator($user_prompt)
|
||||
{
|
||||
|
||||
$caption_descriptions = [
|
||||
'A humorous, funny one-liner that starts with "When you", describes a specific visual or situational moment, avoids vagueness, and ends with no punctuation',
|
||||
'A POV meme that starts with "POV: ", clearly describes a specific scenario or feeling with high context, and ends with no punctuation',
|
||||
'A humorous, funny one-liner that starts with "I", grounded in a relatable, situational experience with visual context, and ends with no punctuation',
|
||||
'A humorous, funny one-liner that starts with "You", focused on a clear, specific reaction or moment, and ends with no punctuation',
|
||||
'A humorous, funny one-liner with no punctuation that describes a vivid, realistic scenario or reaction in a clearly defined context',
|
||||
];
|
||||
|
||||
|
||||
$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',
|
||||
@@ -45,15 +54,19 @@ public static function getSingleMemeGenerator($user_prompt)
|
||||
'properties' => [
|
||||
'caption' => [
|
||||
'type' => 'string',
|
||||
'description' => 'A humorous, one-liner or POV meme (under 15 words, no punctuation)',
|
||||
'description' => $caption_descriptions[rand(0, count($caption_descriptions) - 1)],
|
||||
],
|
||||
'meme_overlay' => [
|
||||
'type' => 'string',
|
||||
'description' => 'A short visual reaction that pairs with the caption (e.g., "guy blinking in disbelief")',
|
||||
'meme_keywords' => [
|
||||
'type' => 'array',
|
||||
'description' => 'Array of 3–5 tags that describe only internal emotional states (e.g., "anxiety", "burnout", "imposter syndrome", "joy", "excitement", "confusion", "awkwardness"). Avoid external concepts, situations, or behaviors like "familylife" or "comparison". Only include pure feelings.',
|
||||
'items' => [
|
||||
'type' => 'string',
|
||||
],
|
||||
],
|
||||
'background' => [
|
||||
'type' => 'string',
|
||||
'description' => 'The setting or location of the meme (e.g., "Zoom call grid", "office cubicle")',
|
||||
'description' => "Use this exact structure: 'Location: [setting only, e.g., empty office with cluttered desk and monitor]'. Do not mention people, animals, actions, or any living beings. No verbs. No brand names. Only interior spaces or physical locations. Examples: 'Location: quiet office cubicle with headset and papers'.",
|
||||
|
||||
],
|
||||
'keywords' => [
|
||||
'type' => 'array',
|
||||
@@ -65,7 +78,7 @@ public static function getSingleMemeGenerator($user_prompt)
|
||||
],
|
||||
'required' => [
|
||||
'caption',
|
||||
'meme_overlay',
|
||||
'meme_keywords',
|
||||
'background',
|
||||
'keywords',
|
||||
],
|
||||
@@ -90,12 +103,24 @@ 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)
|
||||
{
|
||||
return data_get($data, 'output.0.content.0.text', null);
|
||||
//dump($data);
|
||||
|
||||
$output = null;
|
||||
|
||||
$response_type = data_get($data, 'output.0.content.0.type', null);
|
||||
|
||||
if ($response_type === 'output_text') {
|
||||
$output = data_get($data, 'output.0.content.0.text', null);
|
||||
} else if ($response_type === 'refusal') {
|
||||
$output = data_get($data, 'output.0.content.0.refusal', null);
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user