Per tragjedi, viktima, dhune, raste sensitive ose
kur pyetja nuk eshte e pershtatshme, lere bosh.
Mos shto emoji, URL, hashtag apo markdown.
Kthe vetem JSON me dy fusha: summary dhe question.';
$payload = array(
'model' => 'gpt-6-luna',
'store' => false,
'max_output_tokens' => 1200,
'instructions' => $instructions,
'input' => wp_json_encode(array(
'title' => $title,
'categories' => $categories,
'article' => $article
), JSON_UNESCAPED_UNICODE),
'text' => array(
'format' => array(
'type' => 'json_schema',
'name' => 'zhurnal_caption',
'strict' => true,
'schema' => array(
'type' => 'object',
'properties' => array(
'summary' => array('type' => 'string'),
'question' => array('type' => 'string')
),
'required' => array('summary', 'question'),
'additionalProperties' => false
)
)
)
);
$response = wp_remote_post(
'https://api.openai.com/v1/responses',
array(
'timeout' => 60,
'redirection' => 0,
'sslverify' => true,
'headers' => array(
'Authorization' => 'Bearer ' . $key,
'Content-Type' => 'application/json'
),
'body' => wp_json_encode($payload)
)
);
if (is_wp_error($response)) {
return $fail("WordPress HTTP error: " . str_replace($key, "[REDACTED]", $response->get_error_message()));
}
if ((int) wp_remote_retrieve_response_code($response) !== 200) {
return $fail("OpenAI HTTP " . wp_remote_retrieve_response_code($response));
}
$data = json_decode(wp_remote_retrieve_body($response), true);
update_post_meta($post->ID, $prefix . 'tokens',
(int) ($data['usage']['total_tokens'] ?? 0));
if (($data['status'] ?? '') !== 'completed') {
return $fail("API status: " . ($data["status"] ?? "unknown") . " / " . ($data["incomplete_details"]["reason"] ?? "unknown"));
}
$output = '';
foreach (($data['output'] ?? array()) as $item) {
foreach (($item['content'] ?? array()) as $content) {
if (($content['type'] ?? '') === 'output_text') {
$output .= $content['text'] ?? '';
}
}
}
$result = json_decode($output, true);
if (!is_array($result) ||
!is_string($result['summary'] ?? null) ||
!is_string($result['question'] ?? null)) {
return $fail("Invalid AI JSON output");
}
$summary = sanitize_text_field($result['summary']);
$question = sanitize_text_field($result['question']);
if (!$summary || preg_match('~https?://|www\.~i', $summary . ' ' . $question)) {
return $fail("Empty summary or prohibited URL");
}
$summary_words = preg_split('/\s+/u', trim($summary));
if (count($summary_words) > 30) {
return $fail("Summary exceeds 30 words");
}
if ($question) {
$question_words = preg_split('/\s+/u', trim($question));
if (count($question_words) > 20 || substr($question, -1) !== '?') {
$question = '';
}
}
$emoji = zhfa_ai_category_emoji($post->ID);
$message = $emoji . ' ' . $title;
$message .= ($platform === "facebook" ? "\nđ " : "\n\nđ ") . $summary;
if ($question) {
$message .= ($platform === "facebook" ? "\nâ " : "\n\nâ ") . $question;
}
$message .= "\n\n" . $cta;
update_post_meta($post->ID, $prefix . 'status', 'success');
update_post_meta(
$post->ID,
$prefix . 'tokens',
(int) ($data['usage']['total_tokens'] ?? 0)
);
return $message;
}
require_once '/home/zhurnalmk/.zhurnal-automation/instagram-automation-v1.6.0.php';
Ăitaku pĂ«rplaset verbalisht me Haxhiun: Do ta ndalim shkatĂ«rrimin e shtetit - Zhurnal.mk â Lajme nga Maqedonia, Kosova, Bota, Analiza