import { Card, CardContent } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { Tabs, TabsList, TabsTrigger, TabsContent } from "@/components/ui/tabs"; import { Input } from "@/components/ui/input"; import { Textarea } from "@/components/ui/textarea"; import { Badge } from "@/components/ui/badge"; import { Avatar, AvatarFallback } from "@/components/ui/avatar"; import { MessageSquareIcon, UploadIcon, BrainIcon, FolderIcon, BookOpenIcon, ClockIcon, SendIcon } from "lucide-react"; import { useState } from "react"; const GoogleAPI = 'AIzaSyAMqFn0dNAoS75Zo4GUdcD99reEIM2IvzU' export default function TeachingAssistantDashboard() { const [message, setMessage] = useState(""); const [chatHistory, setChatHistory] = useState([]); const handleSend = async () => { if (message.trim() === "") return; const newEntry = { sender: "user", content: message }; setChatHistory([...chatHistory, newEntry]); setMessage(""); try { const response = await fetch( `https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent?key=${GoogleAPI}`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ contents: [{ parts: [{ text: message }] }] }) } ); const data = await response.json(); console.log("Gemini raw response:", data); // More robust extraction of AI message let aiMessage = ""; if (data.candidates && data.candidates.length > 0) { const candidate = data.candidates[0]; // Try nested parts if (candidate.content?.parts) { aiMessage = candidate.content.parts.map(p => p.text).join("\n"); } // Fallback to simple text else if (candidate.content?.text) { aiMessage = candidate.content.text; } // Fallback to candidate text else if (candidate.text) { aiMessage = candidate.text; } } // Last resort: stringify whole response if (!aiMessage) { aiMessage = JSON.stringify(data); } setChatHistory(prev => [...prev, { sender: "ai", content: aiMessage }] ); } catch (error) { console.error("Error connecting to Gemini API:", error); setChatHistory(prev => [...prev, { sender: "ai", content: "[Error connecting to Gemini API]" }]); } }; return (
Supported: PDF, PPT, TXT
Next review cycle: Tomorrow (2 docs) based on Ebbinghaus curve