// Function to generate hashtags using Gemini API with prompt
function geneatename($prompt, $input, $apiKey)
{
$url = "https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent?key={$apiKey}";
$postData = json_encode([
"contents" => [
[
"parts" => [
["text" => $prompt . ' ' . $input] // Combine prompt and input
]
]
],
"generationConfig" => [
"temperature" => 0.9,
"topK" => 1,
"topP" => 1,
"maxOutputTokens" => 1500, // Adjust as necessary
"stopSequences" => []
],
"safetySettings" => [
[
"category" => "HARM_CATEGORY_HARASSMENT",
"threshold" => "BLOCK_ONLY_HIGH"
],
[
"category" => "HARM_CATEGORY_HATE_SPEECH",
"threshold" => "BLOCK_ONLY_HIGH"
],
[
"category" => "HARM_CATEGORY_SEXUALLY_EXPLICIT",
"threshold" => "BLOCK_ONLY_HIGH"
],
[
"category" => "HARM_CATEGORY_DANGEROUS_CONTENT",
"threshold" => "BLOCK_ONLY_HIGH"
]
]
]);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Content-Length: ' . strlen($postData)
]);
$response = curl_exec($ch);
curl_close($ch);
$responseData = json_decode($response, true);
if (isset($responseData['candidates'][0]['content']['parts'][0]['text'])) {
return $responseData['candidates'][0]['content']['parts'][0]['text'];
} else {
return "No generated hashtags found.";
}
}
add_action('wp_ajax_generate_name_json', 'generate_name_json');
add_action('wp_ajax_nopriv_generate_name_json', 'generate_name_json');
function generate_name_json()
{
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$videoInput = isset($_POST['videoInput']) ? $_POST['videoInput'] : '';
$numHashtags = isset($_POST['numHashtags']) ? intval($_POST['numHashtags']) : 30; // Default to 30 if not provided
$prompt = 'I Want You To Work As A Youtube Seo Expert Who Knowes Everything About Youtube Seo. My Main Gole Is To Rank Or Virel My Youtube Video About The Topic I Am Going To Give You. So You Have To Generate The Best Treanding Hastags For The Topic Generate A Minimum ' . $numHashtags . ' Hastags, Generate higly related highquality hastags that related to the topic or title. This Is Most Important To Not Add Any Other Unwanted Text Or Characters As It Breaks The Flow And Only Generates Hashtags. and generate the Hastags In JSON Formet Like The Example
{
"hashtags": [
{
"hashtag": "#WebDevelopment"
},
{
"hashtag": "#WebDevelopmentPodcast"
},
{
"hashtag": "#WebDevelopmentCareer"
}
]
}
gnerate the output same as i said dont add or remove anything like (```json) .
Now Generate ' . $numHashtags . ' hashtags For:'; // Your prompt
$geminiApiKey = 'YOUR_API_KEY';
$description = geneatename($prompt, $videoInput, $geminiApiKey);
// Return the generated description as JSON
echo json_encode(['description' => $description]);
exit;
}
}
function hashtags_generator()
{
ob_start(); ?>
---Advertisement---
LATEST Post
पंजाबरावांचा नवीन हवामान अंदाज ! ‘या’ भागात पावसाची शक्यता, तुमच्याकडे कसे राहणार हवामान? वाचा…
November 10, 2024
1:21 PM
NEW आजचे सोयाबिन बाजार भाव 26 सप्टेंबर 2024 Soyabin Bajar bhav
September 26, 2024
10:04 AM
राज्यात पुढील २ दिवस मुसळधार पावसाचा इशारा; ‘या’ भागांत धो-धो बरसणार, कसं असेल हवामान?
September 11, 2024
11:48 PM
Panjabrao Dakh Havaman Andaj | राज्यात आजपासून पावसाचा जोर वाढणार; या जिल्ह्यांमध्ये जोरदार बरसणार
September 1, 2024
3:21 PM