-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
69 lines (61 loc) · 2.55 KB
/
Copy pathscript.js
File metadata and controls
69 lines (61 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
const {
GoogleGenerativeAI,
HarmCategory,
HarmBlockThreshold,
} = require("@google/generative-ai");
const { GoogleAIFileManager } = require("@google/generative-ai/server");
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",
});
const generationConfig = {
temperature: 0.9,
topP: 0.95,
topK: 40,
maxOutputTokens: 8192,
responseMimeType: "text/plain",
};
async function run() {
// TODO Make these files available on the local file system
// You may need to update the file paths
const files = [
await uploadToGemini("1YiEBYWTHPiLQw5KN3M7LiK0krIY24Lgp", "application/octet-stream"),
];
const parts = [
{text: "What object is this? Describe how it might be used. List three related items."},
{text: "Object: "},
{text: "Description: This is a pipe organ. It is a large musical instrument that is used in churches, concert halls, and other large buildings. It is made up of a series of pipes that are arranged in different sizes and shapes. The pipes are played by pressing keys on a keyboard. When a key is pressed, air is forced through the pipe, which produces a sound. The sound of a pipe organ is very powerful and can be used to create a wide variety of music."},
{text: "Object: "},
{text: "Description: This is a sundial. It is a device that uses the sun's position in the sky to tell the time. The sundial has a flat surface with a hole in the center. A metal rod is placed through the hole and is pointed at the North Star. The shadow of the rod falls on the flat surface and indicates the time."},//This is my final project in github.
{text: "Object: "},
{
fileData: {
mimeType: files[0].mimeType,
fileUri: files[0].uri,
},
},
{text: "Description: "},
];
const result = await model.generateContent({
contents: [{ role: "user", parts }],
generationConfig,
});
console.log(result.response.text());
}
run();