Spaces:
Running
Running
| import { generateAIContent } from '../utils/aiHelper.js'; | |
| import { extractLanguage, getLanguageName } from '../utils/aiOrchestrator.js'; | |
| import dotenv from 'dotenv'; | |
| export const getBlogRecommendations = async (req, res) => { | |
| dotenv.config(); | |
| const { region: _region } = req.query; | |
| const lang = extractLanguage(req); | |
| const langName = getLanguageName(lang); | |
| const langInstruction = lang !== 'en' ? `\nRespond STRICTLY in ${langName} language.` : ''; | |
| try { | |
| const promptText = ` | |
| please provide the following for the experts with new recommendations every time : | |
| Suggest 2 topics in 5-6 words that an expert can write about to help farmers address current issues effectively . | |
| Keep each point clear, expert-friendly, and should focus on the most current weather problems, crop health problems, or economic conditions of the farmers or any recent concerns.${langInstruction} | |
| `; | |
| const recommendations = await generateAIContent(promptText.trim()); | |
| res.status(200).json({ recommendations }); | |
| } catch (err) { | |
| console.error("Error fetching expert recommendations: ", err); | |
| res.status(500).json({ error: "Failed to fetch recommendations" }); | |
| } | |
| }; | |