William Grasel PRO
Desenvolvedor Web, Google Developer Expert, Microsoft Most Valuable Professional, palestrante, consultor e coordenador do AngularSP.
import { GoogleGenerativeAI } from "@google/generative-ai";
const API_KEY = "MI LINDA CLAVE API SECRETA";
const genAI = new GoogleGenerativeAI(API_KEY);
const model = genAI.getGenerativeModel({ model: "gemini-pro"});
const prompt = "complete the follow sentence: ping";
const result = await model.generateContent(prompt);
const response = await result.response;
const text = response.text();
curl \
-H 'Content-Type: application/json' \
-d '{"contents":[{"parts":[{"text":"Write a story about a magic backpack"}]}]}' \
-X POST 'https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent?key=YOUR_API_KEY'
const genAI = new GoogleGenerativeAI(process.env.API_KEY);
const model = genAI.getGenerativeModel({ model: "gemini-pro"});
const chat = model.startChat({
history: [
{
role: "user",
parts: [{ text: "Olá, eu tenho 2 cachorros na minha casa!" }]
}
]
});
const result = await chat.sendMessage(
"¿Qué tengo en mi casa?"
);
const response = await result.response;
const text = response.text();
const genAI = new GoogleGenerativeAI(process.env.API_KEY);
const model = genAI.getGenerativeModel({ model: "gemini-pro"});
const prompt = "complete the follow sentence: ping";
//const result = await model.generateContent(prompt);
const result = await model.generateContentStream(prompt);
const response = await result.response;
const text = response.text();
for await (const chunk of result.stream) {
const chunkText = chunk.text();
console.log(chunkText);
}
const genAI = new GoogleGenerativeAI(process.env.API_KEY);
const model = genAI.getGenerativeModel({ model: "gemini-pro-vision" });
const result = await model.generateContent([
"Qual a diferença desas imagens?",
fileToGenerativePart("image1.png", "image/png"),
fileToGenerativePart("image2.jpeg", "image/jpeg"),
]);
function fileToGenerativePart(path, mimeType) {
return {
inlineData: {
data: Buffer.from(fs.readFileSync(path)).toString("base64"),
mimeType
},
};
}
const response = await result.response;
const text = response.text();
http://www.linkedin.com/in/alvarocamillont
By William Grasel
¿Eres un desarrollador web frontend y no quieres quedar fuera de esta ola de IA generativa? ¡En esta charla te mostraremos todo lo que necesitas saber, de forma práctica y con ejemplos, para conectar la IA Generativa con tu Webapp!
Desenvolvedor Web, Google Developer Expert, Microsoft Most Valuable Professional, palestrante, consultor e coordenador do AngularSP.