2024/5/18 LT daiiz

ソフトウェアエンジニア
Gyazo
Scrapbox
Helpfeel
LLM組み込みエンジニア?
個人開発
雑談
なつかしい
LLM ビッグリリース 2つも来ましたね!!!
OpenAI Spring Update
GPT-4o 
早くてそれなりに賢い
oは"omni"
Gemini 
API利用の無料枠もある
Google I/O 2024
コンテキストが200万トークンに
速くてそれなりに賢い、安い
2024/5/30 から課金プラン開始
いまのうちにたくさん遊ぼう!
最近の推しです
無料で使える!
js
/*
* Install the Generative AI SDK
*
* $ npm install @google/generative-ai
*
* See the getting started guide for more information
* https://ai.google.dev/gemini-api/docs/get-started/node
*/
const {
GoogleGenerativeAI,
HarmCategory,
HarmBlockThreshold,
} = require("@google/generative-ai");
const { GoogleAIFileManager } = require("@google/generative-ai/files");
const apiKey = process.env.GEMINI_API_KEY;
const genAI = new GoogleGenerativeAI(apiKey);
const fileManager = new GoogleAIFileManager(apiKey);
/**
* Uploads the given file to Gemini.
*
* See https://ai.google.dev/gemini-api/docs/prompting_with_media
*/
async function uploadToGemini(path, mimeType) {
const uploadResult = await fileManager.uploadFile(path, {
mimeType,
displayName: path,
});
const file = uploadResult.file;
console.log(`Uploaded file ${file.displayName} as: ${file.name}`);
return file;
}
const model = genAI.getGenerativeModel({
model: "gemini-1.5-flash-latest",
});
const generationConfig = {
temperature: 1,
topP: 0.95,
topK: 64,
maxOutputTokens: 8192,
responseMimeType: "text/plain",
};
const safetySettings = [
{
category: HarmCategory.HARM_CATEGORY_HARASSMENT,
threshold: HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE,
},
{
category: HarmCategory.HARM_CATEGORY_HATE_SPEECH,
threshold: HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE,
},
{
category: HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT,
threshold: HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE,
},
{
category: HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT,
threshold: HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE,
},
];
async function run() {
// TODO Make these files available on the local file system
// You may need to update the file paths
const imageArchitecture2 = await uploadToGemini("image_architecture2.jpeg", "image/jpeg");
const chatSession = model.startChat({
generationConfig,
safetySettings,
history: [
{
role: "user",
parts: [
{text: "bye"},
{text: "Hello"},
],
},
{
role: "model",
parts: [
{text: "Hello!"},
{text: "How can I help you today? 😊 \n"},
],
},
{
role: "user",
parts: [
{text: "これはなんですか?"},
{
fileData: {
mimeType: imageArchitecture2.mimeType,
fileUri: imageArchitecture2.uri,
},
},
],
},
{
role: "model",
parts: [
{text: "This is the Great Pyramid of Giza in Egypt. \n"},
],
},
],
});
const result = await chatSession.sendMessage("INSERT_INPUT_HERE");
console.log(result.response.text());
}
run();