‘gpt-4’,
‘messages’ => [
[‘role’ => ‘system’, ‘content’ => ‘Você é um assistente que reescreve textos.’],
[‘role’ => ‘user’, ‘content’ => “Reescreva este texto de forma atrativa e envolvente: $text”]
]
];
$options = [
‘http’ => [
‘header’ => “Content-Type: application/json\r\n” .
“Authorization: Bearer $api_key\r\n”,
‘method’ => ‘POST’,
‘content’ => json_encode($data)
]
];
$context = stream_context_create($options);
$result = file_get_contents($endpoint, false, $context);
$response = json_decode($result, true);
return $response[‘choices’][0][‘message’][‘content’] ?? $text;
}
// Processar o feed RSS
$feed = simplexml_load_file($feed_url);
foreach ($feed->channel->item as $item) {
$original_content = (string)$item->description;
$new_content = rewrite_with_chatgpt($original_content);
// Aqui, use a função do WordPress para publicar o conteúdo
// Exemplo: wp_insert_post() para postar no blog
}
?>
Source link