-
Notifications
You must be signed in to change notification settings - Fork 0
/
ai.mjs
44 lines (33 loc) · 1.1 KB
/
ai.mjs
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 fetch from "node-fetch";
global.fetch = fetch;
import { GoogleGenerativeAI } from "@google/generative-ai";
import dotenv from 'dotenv'
dotenv.config();
const genAI = new GoogleGenerativeAI(process.env.AI_KEY);
async function run(query, context) {
const model = genAI.getGenerativeModel({ model: "gemini-pro" });
if(query.toLowerCase().includes("differentiate") || query.toLowerCase().includes("differentiate")) query +="(10 points table)"
const prompt = context ? query + " [Context = " + "computer science" + "]" : query + " [Context = " + "computer science" + "]";
const result = await model.generateContent(prompt);
const response = await result.response;
const text = response.text();
process.stdout.write(text);
process.exit(0);
}
/*
let argv = process.argv;
let query = process.argv[2];
let context = process.argv[3];
console.log(argv);
try {
run(query,context);
} catch (e) {
process.stderr.write(e.message);
}
*/
process.stdin.on("data",(data) => {
if(data.toString().startsWith("-")) {
run(data.toString().replace("-"));
}
// process.stdout.write(data + "[ai.mj]")
})