Compare commits
51 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
e1a47b0af4
|
|||
|
23f9a25184
|
|||
|
da96ae89a2
|
|||
|
f201486b8f
|
|||
|
01e8845328
|
|||
| 0f8aa521a9 | |||
|
bd0daf45bd
|
|||
| ddbf340af7 | |||
|
b84468441c
|
|||
|
f92534f814
|
|||
|
a6b604f04f
|
|||
| cbff64906b | |||
| 27955fc264 | |||
| ee59400d76 | |||
| 88d229cb2d | |||
| 79a29ad982 | |||
| e98b39a9da | |||
| f41d33625f | |||
| ae9108769c | |||
| 6d0813c8db | |||
| 1c7c9425bc | |||
| 341a3a127b | |||
| 66a6ac22d0 | |||
| 466d0b7abe | |||
| 07d691ad4e | |||
| 89af132577 | |||
| 762e246ccd | |||
| ddf28d9a46 | |||
| 586fd41133 | |||
| 982fbba413 | |||
| b805b8e34e | |||
| 956fb5604a | |||
| 6dc57b28b1 | |||
| fdee1beb05 | |||
| 58cd02b3a5 | |||
| bf03fa12f6 | |||
| c41d788328 | |||
| d5086e21ae | |||
| 355f13b33d | |||
| 68f3efc128 | |||
| 8db0eeba9a | |||
| 439dbe51b6 | |||
| 8ad01a5c50 | |||
| d9c299a58f | |||
| f7cb1af2c4 | |||
|
8438a9a2b7
|
|||
| 357071b967 | |||
|
75f31b5b93
|
|||
| 15593af2a9 | |||
|
33b5c9ccc8
|
|||
|
8f13ac6d4b
|
@@ -0,0 +1 @@
|
||||
Backend/package-lock.json
|
||||
@@ -1,6 +1,7 @@
|
||||
const Crop = require("../Models/crop.model.js");
|
||||
const Farm = require("../Models/farm.model.js");
|
||||
const { uploadOnCloudinary } = require("../Utils/cloudinary.js");
|
||||
const { run } = require("../Utils/model.js");
|
||||
|
||||
// Create a new crop
|
||||
const createCrop = async (req, res) => {
|
||||
@@ -145,6 +146,61 @@ const updateHealthStatus = async (req, res) => {
|
||||
}
|
||||
};
|
||||
|
||||
const cropHarvest = async (req, res) => {
|
||||
try {
|
||||
const crop = await Crop.findById(req.params.cropId).populate("farm");
|
||||
console.log(crop);
|
||||
|
||||
const message = `My crop is ${crop.name}, given that I have planted it on ${crop.plantedDate}, suggest me a date as to when it will be harvested. Give output in the form: ${crop.name} will take .. months to harvest around (give month name and year).`; // for harvest expectation
|
||||
|
||||
const result = await run(message);
|
||||
res.status(200).json({ message: result });
|
||||
} catch (error) {
|
||||
res.status(500).json({ message: error.message });
|
||||
}
|
||||
};
|
||||
|
||||
const suggestNextCrop = async (req, res) => {
|
||||
try {
|
||||
const crop = await Crop.findById(req.params.cropId).populate("farm");
|
||||
console.log(crop);
|
||||
|
||||
const message = `Currently I have ${crop.name} in my field. Considering the best optimal time for its harvestation give my location, ${crop.farm.location} and water content of my field is ${crop.farm.waterContent}. Suggest next crop I should grow and give more suggestions around it. Don't tell me when to harvest ${crop.name}, only tell me next best crop to plant in my field and give suggestions around it.`; // for next sowing suggestion
|
||||
|
||||
const result = await run(message);
|
||||
res.status(200).json({ message: result });
|
||||
} catch (error) {
|
||||
res.status(500).json({ message: error.message });
|
||||
}
|
||||
};
|
||||
|
||||
const suggestPesticides = async (req, res) => {
|
||||
try {
|
||||
const crop = await Crop.findById(req.params.cropId).populate("farm");
|
||||
console.log(crop);
|
||||
|
||||
const message = `Considering I have grown ${crop.name} in my field located in ${crop.farm.location} and has water content of ${crop.farm.waterContent}. Suggest pesticides I should use on the crop and when to use it considering my sow date is ${crop.sowDate}. Give precautionary measures and suggestions around it.`; // for pesticides
|
||||
|
||||
const result = await run(message);
|
||||
res.status(200).json({ message: result });
|
||||
} catch (error) {
|
||||
res.status(500).json({ message: error.message });
|
||||
}
|
||||
};
|
||||
|
||||
const suggestFertilizers = async (req, res) => {
|
||||
try {
|
||||
const crop = await Crop.findById(req.params.cropId).populate("farm");
|
||||
console.log(crop);
|
||||
|
||||
const message = `Considering I have grown ${crop.name} in my field located in ${crop.farm.location} and has water content of ${crop.farm.waterContent}. Suggest fertilizers I should use on the crop and when to use it, i.e. after how many months after sowing considering sowing date is ${crop.sowDate} considering my sow date is ${crop.sowDate}. Give me precautionary measures.`; // for fertilizers
|
||||
|
||||
const result = await run(message);
|
||||
res.status(200).json({ message: result });
|
||||
} catch (error) {
|
||||
res.status(500).json({ message: error.message });
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
createCrop,
|
||||
@@ -154,4 +210,8 @@ module.exports = {
|
||||
deleteCrop,
|
||||
updateGrowthStage,
|
||||
updateHealthStatus,
|
||||
cropHarvest,
|
||||
suggestNextCrop,
|
||||
suggestPesticides,
|
||||
suggestFertilizers,
|
||||
};
|
||||
|
||||
@@ -2,7 +2,7 @@ const multer = require("multer");
|
||||
|
||||
const storage = multer.diskStorage({
|
||||
destination: function (req, file, cb) {
|
||||
cb(null, "./public/images");
|
||||
cb(null, "./uploads");
|
||||
},
|
||||
|
||||
filename: function (req, file, cb) {
|
||||
|
||||
@@ -7,6 +7,10 @@ const {
|
||||
deleteCrop,
|
||||
updateHealthStatus,
|
||||
updateGrowthStage,
|
||||
cropHarvest,
|
||||
suggestNextCrop,
|
||||
suggestPesticides,
|
||||
suggestFertilizers,
|
||||
} = require("../Controllers/crop.controller.js");
|
||||
const { checkAuthenticated } = require("../Middlewares/authentication.js");
|
||||
const upload = require("../Middlewares/multer.js");
|
||||
@@ -22,4 +26,9 @@ router.delete("/:cropId", checkAuthenticated, deleteCrop); // Delete a crop
|
||||
router.put("/health/:cropId", checkAuthenticated, updateHealthStatus);
|
||||
router.put("/growth/:cropId", checkAuthenticated, updateGrowthStage);
|
||||
|
||||
router.get("/harvest/:cropId", checkAuthenticated, cropHarvest);
|
||||
router.get("/nextCrop/:cropId", checkAuthenticated, suggestNextCrop);
|
||||
router.get("/pesticides/:cropId", checkAuthenticated, suggestPesticides);
|
||||
router.get("/fertilizers/:cropId", checkAuthenticated, suggestFertilizers);
|
||||
|
||||
module.exports = router;
|
||||
|
||||
@@ -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 };
|
||||
|
||||
Generated
-4823
File diff suppressed because it is too large
Load Diff
+11
-14
@@ -10,23 +10,20 @@
|
||||
"license": "ISC",
|
||||
"description": "",
|
||||
"dependencies": {
|
||||
"@google/generative-ai": "^0.22.0",
|
||||
"@huggingface/transformers": "^3.3.3",
|
||||
"@xenova/transformers": "^2.17.2",
|
||||
"bcrypt": "^5.1.1",
|
||||
"cloudinary": "^2.5.1",
|
||||
"cookie-parser": "^1.4.6",
|
||||
"@google/generative-ai": "^0.24.1",
|
||||
"bcrypt": "^6.0.0",
|
||||
"cloudinary": "^2.7.0",
|
||||
"cookie-parser": "^1.4.7",
|
||||
"cors": "^2.8.5",
|
||||
"dotenv": "^16.4.5",
|
||||
"express": "^4.19.2",
|
||||
"jimp": "^1.6.0",
|
||||
"dotenv": "^16.5.0",
|
||||
"express": "^5.1.0",
|
||||
"jsonwebtoken": "^9.0.2",
|
||||
"mongoose": "^8.6.1",
|
||||
"multer": "^1.4.5-lts.1",
|
||||
"nodemailer": "^6.9.15",
|
||||
"socket.io": "^4.7.5"
|
||||
"mongoose": "^8.16.0",
|
||||
"multer": "^2.0.1",
|
||||
"nodemailer": "^7.0.3",
|
||||
"socket.io": "^4.8.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"nodemon": "^3.1.4"
|
||||
"nodemon": "^3.1.10"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# Status200
|
||||
# CropCompass
|
||||
|
||||
Karan's branch for backend developement.
|
||||
This branch houses backend code developed and maintained by Karan Salvi for this project.
|
||||
|
||||
---
|
||||
|
||||
|
||||
⚠️⚠️ DO NOT PUSH TO THIS BRANCH, IT HAS BEEN LOCKED. IT WAS DIFFICULT TO KEEP A TRACK OF ALL THE CHANGES BEING MADE TO DIFFERENT BRANCHES. TO SIMPLIFY THINGS, CREATE A NEW FEATURE BRANCH DERIVED FROM `main` BRANCH AND CREATE A PULL REQUEST. ⚠️⚠️
|
||||
|
||||
Reference in New Issue
Block a user