import { useState, useEffect } from "react"; import { ChatKit, useChatKit } from "@openai/chatkit-react"; import { CHATKIT_API_DOMAIN_KEY, CHATKIT_API_URL } from "../lib/config"; import { ReasoningPanel } from "./ReasoningPanel"; interface ExamAnalyzerProps { teacherEmail: string; onBack: () => void; } export function ExamAnalyzer({ teacherEmail, onBack }: ExamAnalyzerProps) { const [showCopiedToast, setShowCopiedToast] = useState(false); const [selectedModel, setSelectedModel] = useState("gpt-4.1-mini"); const [availableModels, setAvailableModels] = useState>({}); // Load available models useEffect(() => { fetch("/api/models") .then(res => res.json()) .then(data => { setAvailableModels(data.models || {}); setSelectedModel(data.default || "gpt-4.1-mini"); }) .catch(err => console.error("Failed to load models:", err)); }, []); // Force Traditional Chinese locale for ChatKit useEffect(() => { // Set document language to zh-TW document.documentElement.lang = 'zh-TW'; // Try to override browser language detection if (navigator.language) { Object.defineProperty(navigator, 'language', { get: () => 'zh-TW', configurable: true, }); } // Set Accept-Language header hint (may not work for iframe) const meta = document.createElement('meta'); meta.httpEquiv = 'Content-Language'; meta.content = 'zh-TW'; document.head.appendChild(meta); }, []); // Store selected model in sessionStorage for backend access useEffect(() => { sessionStorage.setItem("selected_model", selectedModel); }, [selectedModel]); const chatkit = useChatKit({ api: { url: CHATKIT_API_URL, domainKey: CHATKIT_API_DOMAIN_KEY, }, composer: { attachments: { enabled: false }, }, }); const handleCopyPrompt = (prompt: string) => { navigator.clipboard.writeText(prompt); setShowCopiedToast(true); setTimeout(() => setShowCopiedToast(false), 2000); }; const examplePrompts = [ { title: "📊 分析 Google 試算表", prompt: `請分析這個 Google 試算表中的考試答案: https://docs.google.com/spreadsheets/d/YOUR_SHEET_ID/edit 標準答案是: - Q1: 4 - Q2: 加速度是速度的變化率 我的電子郵件是 ${teacherEmail}。請評分、解釋錯誤答案、建議同儕學習小組,並將報告發送到我的電子郵件。`, }, { title: "📝 分析 CSV 資料", prompt: `請分析這些考試資料: Timestamp,Email,Student Name,Q1 (2+2),Q2 (Explain acceleration) 2026-01-26 08:00:00,alice@student.edu,Alice,4,Acceleration is the rate of change of velocity 2026-01-26 08:01:00,bob@student.edu,Bob,3,I dont know 2026-01-26 08:02:00,carol@student.edu,Carol,4,velocity change over time 2026-01-26 08:03:00,david@student.edu,David,5,speed 標準答案是: - Q1: 4 - Q2: Acceleration is the rate of change of velocity over time 我的電子郵件是 ${teacherEmail}。請評分並建立完整報告。`, }, { title: "⚡ 快速摘要", prompt: `請給我班級表現的快速摘要。我的電子郵件是 ${teacherEmail}。`, }, ]; return (
{/* Copied toast */} {showCopiedToast && (
✓ 提示已複製!請在聊天中貼上。
)}
{/* Top bar */}
已連接為 {teacherEmail}
模型:
{/* Left Sidebar - AI Reasoning */}
{/* AI Reasoning Panel - Shows LLM thinking process */} {/* Example Prompts */}

快速開始提示

{examplePrompts.map((example, i) => ( ))}
{/* Tips */}

💡 專業提示

  • 包含標準答案以提高準確度
  • 將 Google 試算表設為公開,或使用 CSV
  • 要求以電子郵件發送報告
{/* Main Chat Area - Use same structure as SimpleChatPanel */}
{/* Chat Header */}

ClassLens 助手

請在下方貼上您的考試資料或 Google 試算表網址

{availableModels[selectedModel]?.name || selectedModel}
{/* ChatKit - Using the EXACT same structure as SimpleChatPanel that works */}
); }