π File Manager
π /
/
home
/
u857492117
/
domains
/
mangaldaicollege.org
/
public_html
Dosya DΓΌzenle: faqAPI.php
<?php /** * includes/faq_api.php β FREE AI proxy using Google Gemini API * βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ * FREE TIER LIMITS (no credit card needed): * β’ gemini-1.5-flash : 15 req/min Β· 1,000,000 tokens/day Β· 100% FREE * * HOW TO GET YOUR FREE KEY: * 1. Go to https://aistudio.google.com/app/apikey * 2. Sign in with any Google account * 3. Click "Create API Key" β done, it's free * 4. Paste it below as GEMINI_API_KEY */ /* ββ CONFIG ββ */ define('GEMINI_API_KEY', 'AQ.Ab8RN6KNdKKleWu8qTQEipvVYxvHbFjLxdQWFjtu7Ytaazhu5Q'); // β paste your free key define('GEMINI_MODEL', 'gemini-1.5-flash'); // free tier model define('MAX_TOKENS', 1024); define('MAX_HISTORY', 20); // max message pairs kept define('MAX_CHARS', 500); // mirror textarea maxlength /* ββ System prompt + knowledge base ββ */ define('SYSTEM_PROMPT', 'You are the official AI FAQ Assistant for Mangaldai College (Autonomous), Mangaldai, Darrang, Assam, India. Answer ONLY using the knowledge base below. Never make up information. === KNOWLEDGE BASE === ABOUT: - Mangaldai College (Autonomous), Mangaldai, Darrang, Assam β Est. 1951 - Affiliated: Gauhati University | NAAC Accredited | DBT Star College - Principal: Dr. Kamala Kanta Borah (M.Sc., Ph.D.) - Motto: Tamaso Ma Jyotirgamaya - Email: mangaldaicollege@gmail.com | Phone: +91 86380 67481 - Office: MonβSat, 9 AM β 4 PM PROGRAMMES: - HS: Arts, Science, Commerce - UG (NEP 2020 FYUGP): BA, BSc, BCA, B.Voc - PG: MA Assamese - Integrated: ITEP (itep.mangaldaicollege.org) - Add-on / Certificate courses: addonCourse.php BSc DEPARTMENTS (7): Physics, Chemistry, Mathematics, Botany, Zoology, Statistics, Computer Science β all offer Major & Minor ADMISSION: - Portal: https://assamshesp.samarth.edu.in/index.php/site/login - Academic year: 2026β27 - Fee structure: pdf/fees Sturcture 23-24.pdf - Fee Refund Policy: Fee_Refund_Policy.php - Exact dates: check Notices section or admission portal (changes yearly) IQAC & ACCREDITATION: - IQAC: iqac.php | NAAC SSR: ssr.php | NIRF: nirf.php | Feedback: feedback.php FACILITIES: - Library: central library, e-resources, N-LIST/INFLIBNET, OPAC (mangaldaicollege-opac.in) - Smart Classrooms, Science Labs (DBT Star equipped) - Girls Hostel (gh.php), Botanical Garden, Sports, Canteen - UGC Network Centre, e-Content Centre, BIO-TECH Hub - SWAYAM-NPTEL Local Chapter, GUCDOE, KKHSOU Study Centre STUDENT SERVICES: - Scholarships: scholarship.php | Old Papers: question.php - Study Material: studyMatAll.php | Handbook: studenthandbook.php - Mentoring: mentor.php | Career Cell: career.php - Alumni: alumni.php | Union Body: unionBody.php NCC & NSS: Active units β camps, blood donation, environment programs COMMITTEES: Anti-Ragging, ICC, Equal Opportunity, Sexual Harassment Prevention, Grievance Redressal, R&D Cell, SEDGs, Library Management, Vigilance, Website Committee NEWSLETTER: Issue I β upload/Newsletter Issue1New.pdf | Issue II β upload/Newsletter Issue2New.pdf COURSES & SYLLABUS: courses_available.php | POs & COs: pdf/MC_POs_COs.pdf ADMINISTRATION: Governing Body β gb.php | Organogram β organogram.php | RTI β RTI Declaration Mangaldai College.pdf AICTE data: aictedata.php | Events: event.php === END KNOWLEDGE BASE === RULES: 1. Answer ONLY from the knowledge base above. 2. Be friendly, concise, and professional. 3. Use bullet points (β’) for lists. 4. Mention source pages when helpful (e.g., "see scholarship.php"). 5. If not in the knowledge base, say exactly: "I could not find this information on the website. Please contact the college office at +91 86380 67481 or email mangaldaicollege@gmail.com." 6. Never guess fees, dates, or contact details not listed above. 7. Do not answer questions unrelated to Mangaldai College. 8. If user greets you, respond warmly and offer help.'); /* ββ Headers ββ */ header('Content-Type: application/json; charset=utf-8'); header('X-Content-Type-Options: nosniff'); if ($_SERVER['REQUEST_METHOD'] !== 'POST') { http_response_code(405); echo json_encode(['error' => 'Method not allowed']); exit; } /* ββ Parse request ββ */ $raw = file_get_contents('php://input'); $body = json_decode($raw, true); if (!$body || !isset($body['messages']) || !is_array($body['messages'])) { http_response_code(400); echo json_encode(['error' => 'Invalid request']); exit; } /* ββ Build Gemini conversation history ββ */ // Gemini uses "contents" array with role "user" / "model" $contents = []; $msgs = array_slice($body['messages'], -MAX_HISTORY); foreach ($msgs as $msg) { if (!isset($msg['role'], $msg['content'])) continue; $role = ($msg['role'] === 'assistant') ? 'model' : 'user'; $content = mb_substr(trim((string)$msg['content']), 0, MAX_CHARS * 4); if ($content === '') continue; $contents[] = [ 'role' => $role, 'parts' => [['text' => $content]], ]; } if (empty($contents)) { http_response_code(400); echo json_encode(['error' => 'No valid messages']); exit; } /* ββ Gemini API payload ββ */ $payload = json_encode([ 'system_instruction' => [ 'parts' => [['text' => SYSTEM_PROMPT]] ], 'contents' => $contents, 'generationConfig' => [ 'maxOutputTokens' => MAX_TOKENS, 'temperature' => 0.3, // lower = more factual ], ]); /* ββ Call Gemini API ββ */ $url = 'https://generativelanguage.googleapis.com/v1beta/models/' . GEMINI_MODEL . ':generateContent?key=' . GEMINI_API_KEY; $ch = curl_init($url); curl_setopt_array($ch, [ CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true, CURLOPT_POSTFIELDS => $payload, CURLOPT_TIMEOUT => 30, CURLOPT_HTTPHEADER => ['Content-Type: application/json'], ]); $result = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); $curlErr = curl_error($ch); curl_close($ch); if ($curlErr) { http_response_code(502); echo json_encode(['error' => 'Could not reach AI service. Try again.']); exit; } /* ββ Parse Gemini response & convert to simple format ββ */ $gemini = json_decode($result, true); // Extract reply text $replyText = ''; if (isset($gemini['candidates'][0]['content']['parts'][0]['text'])) { $replyText = $gemini['candidates'][0]['content']['parts'][0]['text']; } elseif (isset($gemini['error']['message'])) { http_response_code(500); echo json_encode(['error' => $gemini['error']['message']]); exit; } /* ββ Return in a simple format the JS can read ββ */ echo json_encode([ 'reply' => $replyText, 'model' => GEMINI_MODEL, ]);
πΎ Kaydet
Δ°ptal