// ============================================================ // 🧠 LEGALAI MULTILINGUAL ENGINE // ============================================================ // Configuration for the Gemini API call const model = 'gemini-2.5-flash'; // ============================================================ // 🚨 PLACE YOUR GEMINI API KEY BELOW (REQUIRED TO RUN LEGALAI) // ============================================================ // Example: const apiKey = "AIzaSyXXXXXX"; // 👉 NOTE: Without this key, the app will NOT return any AI responses. // 🔐 Keep your key secret — never share it publicly or commit it to GitHub. const apiKey = "PLACE_YOUR_GEMINI_API_KEY_HERE"; // ============================================================ // Auto-check: warn if key is missing if (!apiKey || apiKey === "AIzaSyCpyfWnhXhrTkN1BvcoEC4a82Lk-Vws4lc") { alert("🚨 LegalAI Configuration Error:\nPlease insert your Gemini API key in the code before continuing."); throw new Error("Missing Gemini API Key"); } const apiUrl = `https://generativelanguage.googleapis.com/v1beta/models/${model}:generateContent?key=${apiKey}`; // Supported languages const supportedLanguages = [ "English", "Afrikaans", "Zulu", "Xhosa", "Sotho", "Tswana", "Venda", "Ndebele", "Tsonga", "Swati", "Pedi" ]; // Function to handle LegalAI query async function getLegalAIResponse(prompt, language = "English") { if (!supportedLanguages.includes(language)) { throw new Error(`Unsupported language: ${language}.`); } const requestBody = { contents: [{ parts: [{ text: `${prompt}\n\nLanguage: ${language}` }] }] }; try { const response = await fetch(apiUrl, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(requestBody) }); if (!response.ok) { throw new Error(`HTTP error! Status: ${response.status}`); } const data = await response.json(); const result = data.candidates?.[0]?.content?.parts?.[0]?.text || "No response from LegalAI."; console.log(`🧠 [${language}] LegalAI Response:`, result); return result; } catch (error) { console.error("🚨 LegalAI Request Failed:", error); return `Error: ${error.message}`; } } // Example Usage (async () => { const query = "Summarize South African contract law requirements for enforceability."; const output = await getLegalAIResponse(query, "English"); console.log("✅ LegalAI Output:", output); })();