-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathindex.js
More file actions
28 lines (20 loc) · 759 Bytes
/
index.js
File metadata and controls
28 lines (20 loc) · 759 Bytes
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
const { GoogleGenerativeAI } = require("@google/generative-ai");
const dotenv = require("dotenv")
dotenv.config()
const readline = require("readline")
// Access your API key as an environment variable (see "Set up your API key" above)
const genAI = new GoogleGenerativeAI(process.env.API_KEY);
const userInterface = readline.createInterface({
input: process.stdin,
output: process.stdout
})
userInterface.prompt()
userInterface.on("line", async input => {
// For text-only input, use the gemini-pro model
const model = genAI.getGenerativeModel({ model: "gemini-pro"});
const result = await model.generateContentStream([input]);
for await(const chunk of result.stream){
const chunkText = chunk.text();
console.log(chunkText)
}
})