forked from WomB0ComB0/gemini-node-1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgemini-chat.js
43 lines (36 loc) · 990 Bytes
/
gemini-chat.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
43
import dotenv from 'dotenv';
dotenv.config({ path: ".env.local" });
import readline from 'readline';
import { GoogleGenerativeAI } from '@google/generative-ai';
const genAI = new GoogleGenerativeAI(process.env.API_KEY);
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
async function run() {
const model = genAI.getGenerativeModel({ model: "gemini-pro" })
const chat = model.startChat({
history: [],
generationConfig: {
maxOutputTokens: 500
}
})
async function askAndRespond() {
rl.question('You: ', async (message) => {
if (message.toLowerCase() === 'exit') {
rl.close();
return;
} else {
const result = await chat.sendMessageStream(message)
const response = await result.response
console.log(`Gemini: ${response.text().toString().replace(
/<[^>]*>?/gm,
''
)}`)
askAndRespond()
}
})
}
askAndRespond()
}
run()