-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
42 lines (29 loc) · 1.36 KB
/
index.js
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
import { GoogleGenerativeAI } from "@google/generative-ai";
import * as fs from "fs";
import * as dotenv from "dotenv";
dotenv.config();
const template = `Task: Image Analysis and Textual Description
Step 1: Image Recognition and Verification
Examine the provided image to identify and verify the presence of objects, locations, or individuals.
Step 2: Data Extraction
For identified elements in the photo, extract detailed information about the specific objects, places, or individuals present.
Step 3: Reporting in a Strict Three-Step Format
First Step: Describe the nature of the object, place, or person(s) captured in the photo.
Second Step: Provide names, including individuals, brands, or locations featured in the image.
Third Step: Include any additional pertinent details or relevant information associated with the identified elements.
`;
const genAI = new GoogleGenerativeAI(process.env.GOOGLE_API_KEY);
function fileToGenerativePart(path, mimeType) {
return {
inlineData: {
data: Buffer.from(fs.readFileSync(path)).toString("base64"),
mimeType,
},
};
}
const model = genAI.getGenerativeModel({ model: "gemini-pro-vision" });
const image = [fileToGenerativePart("./messi.png", "image/jpeg")];
const result = await model.generateContent([template, ...image]);
const response = await result.response;
const text = response.text();
console.log(text);