-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
34 lines (24 loc) · 1.09 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
import dotenv from "dotenv";
dotenv.config();
import { startUdpServer, createResponse, createTxtAnswer } from "denamed";
import { GoogleGenerativeAI } from "@google/generative-ai";
const port = process.env.PORT || 8000;
const genAI = new GoogleGenerativeAI(process.env.GEMINI_API_KEY || "AIzaSyAea5SZcZq_TKrNmthK0O0o1ej17PV1mY4");
const model = genAI.getGenerativeModel({ model: "gemini-1.5-flash" }); // Simplified model name for example
startUdpServer(
async (query) => {
try {
const question = query.questions[0];
const prompt = `
Answer the following question in one word or sentence
Question : ${question.name.split(".").join(" ")}`;
const result = await model.generateContent(prompt);
const output = createResponse(query, [createTxtAnswer(question, result.response.text())]);
console.log("Sending response:", output.answers[0].data.target);
return output;
} catch (error) {
console.error("Error processing query:", error);
}
},
{ port: 8001 }
);