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 = "MINHA LINDA API KEY 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(
"O que eu tenho na minha 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();
By William Grasel
Você é desenvolvedor frontend Web e não quer ficar de fora dessa onda de IA Generativa? Nessa palestra vamos mostrar tudo o que você precisa saber, de maneira prática e com exemplos, para conectar uma IA Generativa com a sua Webapp!
Desenvolvedor Web, Google Developer Expert, Microsoft Most Valuable Professional, palestrante, consultor e coordenador do AngularSP.