NTPU AI 是國立臺北大學提供的對話式 AI 服務。介面只有一個輸入框:你把問題打進去,系統會先用一個小模型判斷這則訊息的難度,再決定交給哪一個等級的模型回答;答案以串流方式顯示,並在訊息上標出這次實際使用的模型。 NTPU AI is a conversational AI service provided by National Taipei University. The interface is a single input box: you type a question, a small model first rates its difficulty, the system picks an answering model of the matching tier, and the reply is streamed back with the model it used shown on the message.
這份說明分成兩部分。一般版寫給使用這個服務的人;技術版說明一次請求怎麼被處理、資料存在哪裡。 These notes come in two parts. The general section is for people using the service; the technical section describes how a request is handled and where data is kept.
不需要指定模型或開什麼功能。把背景、想要的格式與限制寫進去,結果會比較接近需求。You don't pick a model or switch anything on. Including context, the format you want and any constraints gets you closer to a usable answer.
文件會在伺服器端取出文字後一起送給模型;圖片與 PDF 則直接讓模型看。Documents have their text extracted on the server and sent with your message; images and PDFs are passed to the model directly.
內容邊產生邊顯示,長答案不必等全部完成。訊息上會標示這次使用的模型。Text appears as it is generated, so long answers are readable immediately. The model used is shown on the message.
同一個對話會帶入前面的內容,可以逐步修正,不必每次重講背景。Earlier turns are carried within the same conversation, so you can refine step by step instead of restating everything.
登入採用寄到信箱的一次性連結,只接受學校信箱(gm、ms、mail.ntpu.edu.tw),連結 15 分鐘內有效。Sign-in uses a one-time link sent to your mailbox. Only university addresses (gm, ms, mail.ntpu.edu.tw) are accepted, and the link is valid for 15 minutes.
| 訪客Guest | 登入Signed in | |
|---|---|---|
| 聊天與上傳檔案Chat and uploads | 可以Yes | 可以Yes |
| 對話保存Conversation history | 只留在這個瀏覽器,關掉就沒了Kept in this browser only; closing it loses the conversation | 保存在伺服器,換裝置也看得到Stored on the server and available on other devices |
| 語音輸入Voice input | 不提供Not available | 可以Yes |
| 分享連結Share links | 不提供Not available | 可以Yes |
| 長期記憶與自訂指示Memory and custom instructions | 不提供Not available | 可以,並可在設定中檢視或清除Available, and can be reviewed or cleared in settings |
長期記憶是一份不超過 2000 字的摘要,記錄你的身份、常見需求與偏好的回答方式,讓之後的對話不用重講。它由系統定期整理,內容隨時可以在設定裡查看與清空。Memory is a summary of at most 2,000 characters covering who you are, what you usually ask for and how you like answers written, so later conversations don't start from zero. It is refreshed periodically and can be inspected or wiped in settings at any time.
整個服務是一個 Cloudflare Worker,前端靜態檔案由同一個 Worker 的 assets 綁定提供。The service is a single Cloudflare Worker; the static frontend is served from the same Worker's assets binding.
帶上登入權杖或 32 字元的隨機訪客 ID、Session ID、訊息文字,以及選用的引用段落與附件路徑。訪客會把自己的對話歷史一併送上來,因為伺服器沒有存。Carries a sign-in token or a 32-character random guest ID, the session ID, the message, plus an optional quoted passage and attachment key. Guests also send their own history, since the server keeps none.
驗證權杖或訪客 ID 格式;附件必須位於呼叫者自己的路徑前綴下,否則回 403。上傳與語音轉錄另有每分鐘 10 次的限流。Validates the token or guest ID format; an attachment must sit under the caller's own key prefix or the request is rejected with 403. Uploads and transcription are rate-limited to 10 per minute.
系統提示、今天日期、長期記憶、自訂指示與附件內容都在 Worker 端組合,接著取這個對話最近十輪作為脈絡。System prompt, today's date, long-term memory, custom instructions and attachment content are assembled inside the Worker, then the last ten turns are appended as context.
判官模型回傳一段 JSON,包含分數、級距、選定模型與一句理由;這些資訊會先以 judge 事件推給前端。The judge model returns JSON with a score, tier, chosen model and a one-line reason, pushed to the browser first as a judge event.
選定模型的輸出以 SSE 逐段送出(token),結束時送 done。之後才寫入用量紀錄,登入者的對話也在此時更新。The selected model's output is streamed as token events and closed with done. Usage rows are written afterwards, along with the conversation for signed-in users.
判官模型只負責輸出路由 JSON,不回答問題。它會讀最近十輪對話(每輪截斷)與可選模型清單,再給出 0–10 的分數。The judge only emits routing JSON and never answers the question. It reads the last ten turns (each truncated) plus the list of candidate models, and returns a score from 0 to 10.
| 分數Score | 級距Tier | 典型任務Typical tasks |
|---|---|---|
| 0 – 3 | small | 閒聊、問候、單一事實查詢、是非題Small talk, greetings, single-fact lookups, yes/no questions |
| 4 – 6 | medium | 概念解釋、摘要、基本程式碼、一般建議Explanations, summaries, basic code, general advice |
| 7 – 10 | large | 多步推理、複雜實作、數學證明、跨領域整合Multi-step reasoning, complex implementation, proofs, cross-domain synthesis |
每個級距各有一個 Claude 與一個 Gemini 候選。判官依附帶的模型說明擇一;若它回傳的名稱不在該級距內,就退回該級距的第一個候選。Each tier holds one Claude and one Gemini candidate. The judge picks by the model notes it is given; if it returns a name outside the tier, the tier's first candidate is used.
預設 medium 為 4 分、large 為 7 分,存在設定資料表中,可由管理端調整;管理員另可強制指定級距或單一模型。Defaults are 4 for medium and 7 for large, stored in a config table and adjustable from the admin panel. Admins can also force a tier or a specific model.
若判官逾時或回傳無法解析的內容,會以 5 分作為安全預設繼續處理,不中斷這次請求。If the judge times out or returns unparseable output, the request continues with a default score of 5 rather than failing.
分數、級距、選定模型、判官耗時與判官本身的 token 用量都會寫入用量紀錄,可在管理端依級距檢視分布。Score, tier, chosen model, judge latency and the judge's own token usage are written to the usage log and can be reviewed per tier.
送進模型的只有最近十輪;判官讀到的同樣是這十輪,且每輪內容另外截斷以控制成本。Only the last ten turns are sent to the answering model. The judge sees the same ten, each further truncated to keep its cost down.
登入者的對話存在資料庫,含標題、題數與更新時間;訪客的對話不落地,由瀏覽器在每次請求中一併送出。Signed-in conversations live in the database with a title, question count and timestamps. Guest conversations are never stored; the browser sends them with each request.
對話首次更新時會標記待整理,滿三小時後的下一次發問,由另一個較小的模型把既有摘要與最近對話合併成不超過 2000 字的新摘要,衝突時以新的為準。使用者可隨時查看或清除。A conversation is flagged for consolidation on its first update. Three hours later, on the next message, a separate smaller model merges the existing summary with recent turns into a new one of at most 2,000 characters, newer facts winning. Users can view or clear it at any time.
登入者可設定一段長期指示,附加在系統提示之後,一起送進每次請求。Signed-in users can set a standing instruction, appended after the system prompt on every request.
純文字與 JSON、XML 類型直接取用內容並截斷;Word、PowerPoint、Excel 在 Worker 內解壓縮抽出文字;圖片、PDF、音訊與影片以 base64 內嵌給模型。無法解析的格式會回覆提示改用支援的類型。Plain text, JSON and XML are read and truncated; Word, PowerPoint and Excel files are unzipped and text-extracted inside the Worker; images, PDFs, audio and video are inlined as base64. Unsupported types return a message asking for a supported format.
檔案存到物件儲存時依擁有者分路徑,登入者與訪客各有自己的前綴;讀取與預覽都會檢查前綴是否相符。Uploads are keyed by owner, with separate prefixes for signed-in users and guests; both reads and previews check that the prefix matches the caller.
Cloudflare Zero Trust Access 負責登入與身分驗證。Worker 會驗證 Access JWT 的簽章、簽發者與 Application Audience,再限制為 gm、ms、mail.ntpu.edu.tw,另加設定中的管理員信箱。Cloudflare Zero Trust Access handles sign-in and identity verification. The Worker validates the Access JWT signature, issuer and Application Audience, then restricts access to gm, ms and mail.ntpu.edu.tw plus the configured admin address.
Access 驗證成功後,Worker 以 HttpOnly、Secure、SameSite Cookie 建立七天的本站 Session;瀏覽器 JavaScript 無法讀取 Session 權杖。After Access verification, the Worker creates a seven-day application session in an HttpOnly, Secure, SameSite cookie that browser JavaScript cannot read.
所有回應統一加上 X-Content-Type-Options、X-Frame-Options: DENY、Referrer-Policy 與 Permissions-Policy。Every response carries X-Content-Type-Options, X-Frame-Options: DENY, Referrer-Policy and Permissions-Policy.
模型服務與信箱服務的金鑰都是 Worker 端的環境變數,不會出現在前端程式或回應中。Model and mail credentials are Worker-side environment variables and never appear in frontend code or responses.
每次回答寫一筆:使用者或訪客識別、Session ID、身分類型、模型、級距、分數與 token 數,不包含問題或回答的文字。One row per answer: user or guest identifier, session ID, access type, model, tier, score and token counts. No question or answer text is included.
讚/倒讚以「Session ID + 回答序號」為鍵,同一則回答只會保留最新一次;倒讚另存勾選的原因代碼、最多 1000 字的補充說明,以及該次回答的實際耗時(判官加生成,方便追查速度問題)。這是唯一會保存使用者輸入文字的統計資料。Votes are keyed by session ID plus the answer's position, so re-voting replaces the previous one. A thumbs-down also stores the selected reason codes, an optional comment of up to 1,000 characters, and the answer's measured latency (judge plus generation) so slowness reports can be traced — the only free text kept for reporting.
同一個 Session 累積三題後才會出現一次評分邀請,未達標的送出會被拒絕;每個 Session 只計一筆。A rating prompt appears once a session reaches three questions; submissions below that are rejected, and each session counts once.
帳號、對話、設定、用量、問卷、回答回饋、分享與限流紀錄都放在 Cloudflare D1;附件放在 R2。Accounts, conversations, profiles, usage, survey results, answer feedback, shares and rate-limit counters are in Cloudflare D1; attachments are in R2.
| 執行環境Runtime | Cloudflare Workers,前端靜態檔案由 assets 綁定提供Cloudflare Workers, with the static frontend served from the assets binding |
|---|---|
| 前端Frontend | 單一 HTML 檔、原生 JavaScript、SSE 串流渲染、中英雙語A single HTML file, vanilla JavaScript, SSE rendering, Chinese and English |
| 模型呼叫Model access | 透過 OpenRouter 呼叫 Claude 與 Gemini 系列;判官與記憶整理各自使用較小的模型Claude and Gemini models through OpenRouter; the judge and the memory step each use a smaller model |
| 語音轉文字Transcription | Whisper,僅登入者可用,音檔上限 25 MBWhisper, signed-in users only, 25 MB per clip |
| 資料庫Database | Cloudflare D1(SQLite)Cloudflare D1 (SQLite) |
| 物件儲存Object storage | Cloudflare R2 |
| 寄信Email | Cloudflare Email,用於寄送登入連結Cloudflare Email, used for sign-in links |