Merged backend changes made by salvi to crop controller.js

This commit is contained in:
K
2025-02-23 09:14:01 +05:30
parent 1f0855c9f3
commit 1966a696ab
3 changed files with 168 additions and 0 deletions
+99
View File
@@ -272,6 +272,88 @@
// console.log(result.response.text());
// }
// const {
// GoogleGenerativeAI,
// HarmCategory,
// HarmBlockThreshold,
// } = require("@google/generative-ai");
// const apiKey = "AIzaSyDsXug23r4umgcJpj77KeqNyYW0hQnYDgg";
// const genAI = new GoogleGenerativeAI(apiKey);
// const model = genAI.getGenerativeModel({
// model: "gemini-2.0-flash",
// });
// const generationConfig = {
// temperature: 1,
// topP: 0.95,
// topK: 40,
// maxOutputTokens: 8192,
// responseMimeType: "text/plain",
// };
// async function run(message) {
// const chatSession = model.startChat({
// generationConfig,
// history: [
// {
// role: "user",
// parts: [
// {
// text: "AI Guidelines:\n- The AI must only provide answers related to farming, including crops, sowing, irrigation, harvesting, fertilizers, pesticides, soil health, and climate conditions. \n- The AI must not answer anything outside farming. \n- If asked an unrelated question, the AI must not respond. \n- If the query is unclear, the AI must default to farming-related guidance. \n- The AI must provide only one-line responses without extra details. \n- No harmful, hurtful, or controversial responses. \n- No advice on illegal, unsafe, or unethical farming practices.\n",
// },
// ],
// },
// {
// role: "model",
// parts: [
// {
// text: "Understood. I will only provide one-line responses directly related to farming.\n",
// },
// ],
// },
// {
// role: "user",
// parts: [
// {
// text: "you can also receive json or javascript object as an input ",
// },
// ],
// },
// {
// role: "model",
// parts: [
// {
// text: "Understood. I will process the JSON or JavaScript object only if it pertains to farming and respond with a single line.\n",
// },
// ],
// },
// {
// role: "user",
// parts: [
// {
// text: "Answer everything which falls under the farming and agriculture even if the prompt does not include any farm or agriculture word in it",
// },
// ],
// },
// {
// role: "model",
// parts: [
// {
// text: "Understood. I will assume all queries are related to farming and provide a one-line farming-related response.\n",
// },
// ],
// },
// ],
// });
// const result = await chatSession.sendMessage(message);
// console.log(result.response.text());
// return result.response.text();
// }
const {
GoogleGenerativeAI,
HarmCategory,
@@ -345,11 +427,28 @@ async function run(message) {
},
],
},
{
role: "user",
parts: [
{
text: "Give me a percise answer no matter what, dont give useless or incomplete answer \n",
},
],
},
{
role: "model",
parts: [
{
text: "Understood. I will strive to provide precise and complete one-line farming-related answers.\n",
},
],
},
],
});
const result = await chatSession.sendMessage(message);
console.log(result.response.text());
return result.response.text();
}
module.exports = { run };