-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode_execution.js
61 lines (53 loc) · 1.71 KB
/
code_execution.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { GoogleGenerativeAI } from '@google/generative-ai';
import readline from 'readline';
import dotenv from 'dotenv';
dotenv.config();
const genAI = new GoogleGenerativeAI(process.env.API_KEY);
const model = genAI.getGenerativeModel({
model: 'gemini-1.5-pro',
tools: [
{
codeExecution: {}
}
]
});
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
async function askQuestion(query) {
return new Promise((resolve) => {
rl.question(query, (answer) => {
resolve(answer);
});
});
}
async function main() {
while (true) {
try {
const userQuestion1 = await askQuestion("Enter your condition (or type 'exit' to quit): ");
if (userQuestion1.toLowerCase() === 'exit') {
console.log('Exiting the program. Goodbye!');
rl.close();
break;
}
let userQuestion2;
if (userQuestion1 !== '') {
userQuestion2 = await askQuestion("Enter your question (or type 'exit' to quit): ");
if (userQuestion2.toLowerCase() === 'exit') {
console.log('Exiting the program. Goodbye!');
rl.close();
break;
}
}
if (userQuestion1 !== '' && userQuestion2 !== '') {
const result = await model.generateContent(userQuestion1 + userQuestion2);
const response = result.response;
console.log('Response:', response.candidates[0].content);
}
} catch (error) {
console.error('An error occurred:', error);
}
}
}
main();