Spaces:
Running
Running
File size: 1,668 Bytes
8a6248c | 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 | import dotenv from 'dotenv';
import { extractLanguage } from '../utils/aiOrchestrator.js';
import { generateAIContent } from '../utils/aiHelper.js';
export const getRecommendations = async (req, res) => {
dotenv.config();
const { climate, soilType, cropType, cropInfo, weatherDetails, cropConditions } = req.body;
const lang = extractLanguage(req);
try {
// Construct a detailed prompt for the API based on the farmer's inputs
const promptText = `
Please provide farming recommendations based on the following information:
1. **Climate**: ${climate}
2. **Soil Type**: ${soilType}
3. **Crop Type**: ${cropType}
4. **Information about the Crop**: ${cropInfo}
5. **Today's Weather**: ${weatherDetails}
6. **Crop Conditions**: ${cropConditions}
Based on this information, please suggest:
- Suitable farming practices for today.
- Care tips for the specified crop considering the current weather and soil conditions.
- Any precautions to take given today's weather and crop requirements.
Make the recommendations clear and easy to understand for farmers. Thank you!
${lang !== 'en' ? `\n\nRespond STRICTLY in ${req.langName || 'the user\'s preferred language'}.` : ''}
`;
const recommendation = await generateAIContent(promptText.trim());
res.status(200).json({ recommendation });
} catch (err) {
console.error("Error fetching recommendations: ", err);
res.status(500).json({ error: "Failed to fetch recommendations" });
}
};
|