49 lines
1.4 KiB
JavaScript
49 lines
1.4 KiB
JavaScript
const axios = require('axios');
|
|
const dotenv = require('dotenv');
|
|
|
|
dotenv.config();
|
|
|
|
const apiKey = process.env.GOOGLE_GEMINI_API_KEY;
|
|
|
|
/**
|
|
* Genera una lista de ideas creativas para un tema dado.
|
|
* @param {String} topic - Tema para el cual generar ideas.
|
|
* @returns {Promise<String>} - Lista de ideas creativas.
|
|
*/
|
|
const brainstormIdeas = async (topic) => {
|
|
const url = `https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash-latest:generateContent?key=${apiKey}`;
|
|
|
|
// Define el prompt para pedir ideas creativas sobre el tema
|
|
const prompt = `
|
|
Por favor, genera una lista de ideas creativas sobre el siguiente tema.
|
|
Las ideas deben ser únicas y variadas, apropiadas para el contexto y el tema proporcionado.
|
|
|
|
Tema:
|
|
|
|
${topic}
|
|
`;
|
|
|
|
try {
|
|
const response = await axios.post(
|
|
url,
|
|
{
|
|
contents: [{ parts: [{ text: prompt }] }]
|
|
},
|
|
{
|
|
headers: { 'Content-Type': 'application/json' }
|
|
}
|
|
);
|
|
|
|
// Extrae las ideas generadas de la respuesta
|
|
const ideas = response.data.candidates[0].content.parts[0].text;
|
|
return ideas;
|
|
} catch (error) {
|
|
console.error('Error al generar ideas:', JSON.stringify(error.response?.data, null, 2));
|
|
return 'Hubo un problema al generar ideas creativas.';
|
|
}
|
|
};
|
|
|
|
module.exports = {
|
|
brainstormIdeas
|
|
};
|