Update
This commit is contained in:
@@ -6,6 +6,51 @@
|
||||
|
||||
class OpenAI
|
||||
{
|
||||
public static function getMemeKeywords(string $name, string $description)
|
||||
{
|
||||
$apiKey = config('services.openai.api_key'); // Make sure to set this in config/services.php
|
||||
|
||||
$response = Http::withHeaders([
|
||||
'Content-Type' => 'application/json',
|
||||
'Authorization' => 'Bearer ' . $apiKey,
|
||||
])->post('https://api.openai.com/v1/responses', [
|
||||
'model' => 'gpt-4.1-nano',
|
||||
'input' => [
|
||||
[
|
||||
'role' => 'system',
|
||||
'content' => [
|
||||
[
|
||||
'type' => 'input_text',
|
||||
'text' => "You are a meme annotation assistant. Given a meme name and description, you must populate three keyword categories: action_keywords: List specific actions being performed in the meme (e.g., wearing, singing, dancing) emotion_keywords: List feelings and emotions conveyed by the meme (e.g., joy, excitement, sadness) misc_keywords: List core identifying elements - keep this concise and focused on essential references only (e.g., main subjects, key objects, proper nouns) Format your response with clear category labels. Be precise and avoid over-elaborating, especially in misc_keywords. Example: Input: \"7th Element OIIA Cat, OIIA cat wearing 7th element head ban and sings 7th element song chorous with OIIA sounds\" Output: action_keywords: wearing, singing, performing emotion_keywords: excitement, joy, playfulness misc_keywords: cat, 7th element, headband, OIIA. the description may also have spelling and grammar issues, please fix it\n\nreturn in json:\n{\ndescription: \"\",\naction_keywords:[],\nemotion_keywords:[],\nmisc_keywords:[],\n}",
|
||||
],
|
||||
],
|
||||
],
|
||||
[
|
||||
'role' => 'user',
|
||||
'content' => [
|
||||
[
|
||||
'type' => 'input_text',
|
||||
'text' => "Name: $name\nDescription: $description",
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
'text' => [
|
||||
'format' => [
|
||||
'type' => 'json_object',
|
||||
],
|
||||
],
|
||||
'reasoning' => new \stdClass,
|
||||
'tools' => [],
|
||||
'temperature' => 1,
|
||||
'max_output_tokens' => 2048,
|
||||
'top_p' => 1,
|
||||
'store' => true,
|
||||
]);
|
||||
|
||||
return $response->json();
|
||||
}
|
||||
|
||||
public static function getSingleMemeGenerator($user_prompt)
|
||||
{
|
||||
|
||||
@@ -17,7 +62,6 @@ public static function getSingleMemeGenerator($user_prompt)
|
||||
'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'),
|
||||
@@ -56,9 +100,27 @@ public static function getSingleMemeGenerator($user_prompt)
|
||||
'type' => 'string',
|
||||
'description' => $caption_descriptions[rand(0, count($caption_descriptions) - 1)],
|
||||
],
|
||||
'meme_keywords' => [
|
||||
'primary_keyword_type' => [
|
||||
'type' => 'string',
|
||||
'description' => "Primary keyword type, choose only between: (action|emotion|misc)",
|
||||
],
|
||||
'action_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.',
|
||||
'description' => 'List specific actions being performed in the meme (e.g., wearing, singing, dancing)',
|
||||
'items' => [
|
||||
'type' => 'string',
|
||||
],
|
||||
],
|
||||
'emotion_keywords' => [
|
||||
'type' => 'array',
|
||||
'description' => 'List feelings and emotions conveyed by the meme (e.g., joy, excitement, sadness)',
|
||||
'items' => [
|
||||
'type' => 'string',
|
||||
],
|
||||
],
|
||||
'misc_keywords' => [
|
||||
'type' => 'array',
|
||||
'description' => 'List core identifying elements - keep this concise and focused on essential references only (e.g., main subjects, key objects, proper nouns)',
|
||||
'items' => [
|
||||
'type' => 'string',
|
||||
],
|
||||
@@ -78,7 +140,10 @@ public static function getSingleMemeGenerator($user_prompt)
|
||||
],
|
||||
'required' => [
|
||||
'caption',
|
||||
'meme_keywords',
|
||||
'primary_keyword_type',
|
||||
'action_keywords',
|
||||
'emotion_keywords',
|
||||
'misc_keywords',
|
||||
'background',
|
||||
'keywords',
|
||||
],
|
||||
@@ -109,7 +174,7 @@ public static function getSingleMemeGenerator($user_prompt)
|
||||
|
||||
public static function getOpenAIOutput($data)
|
||||
{
|
||||
//dump($data);
|
||||
// dump($data);
|
||||
|
||||
$output = null;
|
||||
|
||||
@@ -117,7 +182,7 @@ public static function getOpenAIOutput($data)
|
||||
|
||||
if ($response_type === 'output_text') {
|
||||
$output = data_get($data, 'output.0.content.0.text', null);
|
||||
} else if ($response_type === 'refusal') {
|
||||
} elseif ($response_type === 'refusal') {
|
||||
$output = data_get($data, 'output.0.content.0.refusal', null);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user