Spaces:
Running
Running
Commit History
-
Fix generation outage: retired Groq model and anthropic SDK signature
Donne120 +1: Claude Opus 5Two separate production failures, neither an expired key, both surfacing to students as "the AI service is unavailable": Groq 404 - The model `llama-3.3-70b-versatile` does not exist Claude Messages.create() got an unexpected keyword argument 'temperature' The Groq id was hardcoded in five places, so a retirement broke chat and the email briefing at once. From outside, a 404 on a retired model is indistinguishable from a bad key, which is what made this expensive to find. The Claude break came from `anthropic>=0.39.0` having no upper bound: the Space rebuilt, pip resolved a build with a different signature, and every call failed. The code never changed. Changes: - model_discovery.py: shared model-resolution helper. Walks a candidate list on model errors only, adopts what works, and remembers it so later requests do not re-probe dead models. Auth/quota/rate-limit errors stop after one attempt — walking the list there would multiply latency on a request that is already …107a904
-
Add per-organization Google Sheet sync
Donne120 +1: Claude Opus 5Sheet ingestion was single-tenant: one KNOWLEDGE_JSON_URL environment variable, one SheetSync, one collection. Retrieval and document upload are both per-organization now, so Sheets was the last path where a second university had nowhere to put its own content — their rows would have had to go in ALU's Sheet, landing in ALU's collection and answering ALU's students. Each university now keeps its own Sheet, stored as organizations.sheet_url beside the rest of its tenant configuration, and it syncs into that university's own collection through the same org_registry path retrieval and uploads use. - schema_organization_sheet_url.sql adds the nullable column. An organization without a Sheet is a normal state, not an error — its knowledge base can still be filled by upload. - SheetSync takes an optional json_url and organization_id. Omit both and it behaves exactly as before, so ALU's existing sync is untouched. - Version markers are now per organization. A shared marker would make …2b18225 -
Scope all knowledge-base access to the caller's organization
Donne120 +1: Claude Opus 5Three routes reached the global retrieval engine regardless of who called them, so per-organization isolation held for retrieval in /api/chat/claude and nowhere else: - POST /api/documents/upload wrote uploaded documents into the shared collection. A university admin's handbook therefore became answerable to students at every other university — a cross-tenant leak through the ingestion path, in a platform whose core promise is isolation. - DELETE /api/documents/{doc_id} removed chunks from the shared collection, so an admin could delete another university's content. - POST /api/chat/claude/stream resolved no organization at all. A student streaming a question was answered from the global collection whatever university they belong to. This one affected students directly, not just admins. In practice only our own team has had upload access, because ADMIN_EMAILS is still one global list — which is why this has not bitten yet. It would have the moment a university admin was…3526cf9
-
fix(admin): make admin authorization per-organization, not one flat global list
Donne120 +1: Claude Sonnet 5Real gap found while designing per-university curator management: the existing admin authorization had two problems that made it unsafe for a real second university, not just cosmetically single-tenant. 1. admin_routes.py's current_org/current_org_read still checked the Phase-1-hardcoded ALLOWED_DOMAINS tuple directly, never updated when auth.py's require_user was fixed to use the real Aurora lookup. A second university's admin would be rejected with "ALU email required" regardless of ADMIN_EMAILS membership — this route was never actually reachable by any admin outside the original two ALU domains. 2. ADMIN_EMAILS was one flat, global env var with no organization attached to any entry. current_org derived the admin's org purely from their OWN email domain — which happens to be safe against cross-tenant access (an admin can't reach an org other than their own domain's) but gives no structural way to manage two universities' admin lists independently, rev…a9f393f -
feat(auth): add public GET /api/organizations/check for pre-signup domain lookup
Donne120 +1: Claude Sonnet 5Frontend-facing piece of the multi-university rollout: the student app (frontend/) currently hardcodes @alustudent.com/@alueducation.com in three places to gate signup, which means a newly onboarded university's students are rejected client-side even after their organizations row exists — the Phase 1/2/3 backend work is unreachable from the actual signup form. GET /api/organizations/check?email=... is deliberately public (no Firebase token — none exists yet pre-signup) and rate-limited (30/min per IP) rather than auth-gated, since it's a cheap, non-sensitive, indexed lookup — the exact one auth.py's require_user already performs for every authenticated request, just exposed before an account exists so the signup form can give an immediate answer instead of creating a Firebase account only to tear it down when verifyAluEmail rejects it after the fact (today's actual, wasteful behavior on the Google OAuth path). Returns {"allowed": bool, "organization_name": string|null} — never errors…0082c36 -
feat(retrieval): scope document retrieval to the caller's organization
Donne120 +1: Claude Sonnet 5Phase 2 (part 1 of 2) of the multi-university platform plan. The one production route with per-user auth already wired (/api/chat/claude) now resolves the caller's organization_id (reusing Phase 1's auth work via admin_routes.current_org_any_user) and asks a new org_registry for that org's own retrieval engine, instead of always using the single global ALU engine. - retrieval_engine.py / retrieval_engine_extended.py: RetrievalEngine and ExtendedRetrievalEngine now take an optional collection_name / brain_dir, defaulting to ALU's existing "alu_documents" collection and "alu_brain" folder — so building either with no arguments is byte-identical to before this change. Also fixes a real, pre-existing bug this work surfaced: get_collection()'s "does not exist" case was caught as ValueError, which is version-fragile (newer chromadb raises a different exception type) and would have silently broken the "create it" fallback for any collection that doesn't exist yet, including e…3700462
-
feat: answer chat questions from the student's own inbox (email_qa)
Donne120 +1: Claude Fable 5Regex gate + one-call LLM router classifies mailbox questions and writes a Gmail search query; matching messages' bodies are fetched (quoted reply chains stripped) and the answer is composed with email content pinned as untrusted quoted data. Responses carry mail.google.com deep links as sources. Wired into both /api/chat/claude endpoints; falls through to the normal RAG path whenever routing, search, or the LLM is unavailable. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>2674e75
-
feat: email briefing — Gmail OAuth + spoken inbox summary (/api/email/*)
Donne120 +1: Claude Fable 5Students connect their ALU Gmail (gmail.readonly) from the frontend Settings page. Routes: status / connect / oauth callback / preferences / briefing / disconnect. Identity binds via HMAC-signed OAuth state; refresh tokens live in Aurora (email_accounts, auto-created; optional Fernet encryption via EMAIL_TOKEN_KEY) with in-memory fallback. The briefing is written by the existing Claude -> NVIDIA -> Groq chain and cached 10 min per student. Needs GOOGLE_OAUTH_CLIENT_ID/SECRET secrets — see EMAIL_BRIEFING_SETUP.md. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>8fa8bd9
-
Add NVIDIA NIM as the primary fallback (stronger free model than Groq)
Donne120 +1: Claude Opus 4.8When Claude is unavailable, try NVIDIA NIM (OpenAI-compatible, free tier, DeepSeek by default) BEFORE Groq, which stays as a final backstop. The richer model follows the grounded prompt better than Llama-3.3-70B, so fallback answers are closer to Claude quality. - nvidia_fallback.py: OpenAI-compatible client, same grounded system prompt and signature as groq_fallback; strips any leaked <think> reasoning block; model via NVIDIA_MODEL env (default deepseek-ai/deepseek-v4-flash). - app.py (/api/chat/claude) and main.py (/api/chat): try NVIDIA first, then Groq. Surfaced in /api/services/status. - requirements: openai>=1.0.0. Config: set NVIDIA_API_KEY (nvapi-...) as an HF Space secret. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>a017e41 -
Remove temporary index-audit diagnostic
Donne120 +1: Claude Opus 4.8The /api/_debug/index-audit endpoint served its purpose (confirmed the retrieval merge/sort bugs). Removing it — it was unauthenticated and exposed index internals. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>5e6e8e4 -
Add temporary index-audit diagnostic (to be removed)
Donne120 +1: Claude Opus 4.8Read-only /api/_debug/index-audit: reports vector-store chunk counts by origin/department/tab and, given ?q=, what retrieval returns for a query. Lets us see whether the Sheet's richness is fully indexed and retrievable before tuning further. Remove after the audit. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>f7996dd -
Fix poor Groq fallback answers: ground them like Claude
Donne120 +1: Claude Opus 4.8The fallback gave weak/nonsensical answers because it (1) saw only the first retrieved doc truncated to 500 chars, (2) had no anti-hallucination rules and hardcoded possibly-stale facts (tuition/programs), and (3) got no conversation history. - groq_fallback: grounded system prompt mirroring the Claude engine's "answer only from context, never invent fees/dates/faculty" discipline; drop hardcoded tuition/program facts; accept history; temperature 0.7->0.4; max_tokens 500->1024. - app.py /api/chat/claude fallback: pass the SAME formatted context Claude got (all docs, titles/urls) + history, not one truncated doc. - main.py /api/chat fallback: pass all retrieved docs (labeled) + history instead of context_docs[0][:500]. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>bbec9ec -
Serve data-layer routes at both bare and /api-prefixed paths
Donne120 +1: Claude Opus 4.8The v0 dashboard's base URL isn't pinned down (could call /admin/* or /api/admin/*), so mount each router at both: - admin routes -> /admin/* and /api/admin/* - student feed -> /opportunities and /api/db/opportunities (the /api/db base avoids colliding with the legacy Tavily /api/opportunities) Routers no longer hardcode a prefix; app.py applies it at include time so a single router can be mounted twice. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>3897490 -
Add opportunities routes (admin CRUD + student feed) on Aurora
Donne120 +1: Claude Opus 4.8Closes the demo loop: admin posts an opportunity, students see it live. - POST /admin/opportunities (publish), GET /admin/opportunities (full list incl. draft/closed), PATCH /admin/opportunities/{id} (status). - GET /opportunities (published only) + POST /opportunities/{id}/view, on a separate public_router so they sit at the top level, mirroring the existing /api/opportunities shape. Legacy Tavily /api/opportunities is untouched (different path) until the frontend is repointed (Step E). - Category/status validated against schema.sql CHECK lists -> clean 422. - Every read/write scoped by organization_id (tenant isolation). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>5ea14f8
-
Add Aurora PostgreSQL data layer (pool + admin routes)
Donne120 +1: Claude Opus 4.8Adds a relational data layer alongside the untouched RAG path: - db.py: lazy, fail-soft psycopg pool with two auth modes — static DATABASE_URL (password) or IAM-token auth (fresh RDS auth token minted per physical connection, so 15-min token expiry never breaks the pool). This cluster uses IAM mode. - admin_routes.py: /admin router with a Firebase-derived multi-tenant guard (current_org from the verified email domain) + GET /admin/overview reading the three analytics views. - app.py: mount the router, surface aurora status in /api/services/status. - requirements.txt: psycopg[binary,pool] + boto3. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>b580c2a -
Fix shadowed /api/analytics/dashboard that bypassed require_admin
Donne120 +1: Claude Opus 4.8FastAPI resolves a path to the FIRST handler registered for it. Because app.py does `from main import app`, main.py's routes register before app.py's. A leftover duplicate /api/analytics/dashboard in main.py (no auth) was therefore shadowing the require_admin-locked handler in app.py — the live route returned 200 to unauthenticated requests. - Remove the duplicate analytics handler from main.py; app.py's require_admin version is now the only registration. - Remove the likewise-shadowed (dead) /api/alu-events handler from app.py; main.py's keeps serving it (no auth needed — public event data). - Drop the now-unused ALUDataConnector import from app.py. - Add notes in both files documenting the first-registered-wins gotcha. Verified: no duplicate route paths remain. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>7192a04 -
Auth, rate limiting, upload hardening, and error hygiene on all routes
Donne120 +1: Claude Opus 4.8Closes the remaining audit findings beyond the admin lock: - require_user on student-facing routes: /api/chat/claude, /chat/claude/stream, /coach/essay, /api/opportunities (was unauthenticated paid-LLM/Tavily access). - require_admin on /api/documents/upload, DELETE /api/documents/{id}, GET /api/documents, /api/analytics/dashboard (were open: KB poisoning, IDOR delete, analytics leak). - slowapi rate limiting keyed by client IP: chat 20/min, upload 5/min, opportunities 10/min, essay 5/min. Clean 429 on limit. - ClaudeChatRequest.message capped at 4000 chars, history at 40 turns; essay capped at 12000 chars — bounds single-request LLM cost. - Upload hardening: 10 MB size cap enforced while streaming to disk; saved-file extension derived from validated content-type, never the client filename. - Stop returning str(e) to clients (analytics, upload, deep-query, events, health) — log server-side, return a generic message. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.c…b76768d -
Lock admin routes with Firebase auth; harden CORS, docs, debug
Donne120 +1: Claude Opus 4.8Server-side authorization is now the real gate for /api/admin/*: - auth.py verifies Firebase ID tokens; require_admin checks ADMIN_EMAILS, require_user enforces the ALU-email allowlist server-side. - /api/admin/sheet-status now requires an admin (was fully open). - /api/admin/refresh-sheet accepts an admin token OR the static X-Refresh-Token so the Apps Script onEdit trigger keeps working. - CORS defaults to the Vercel origin instead of "*". - /docs, /redoc, /openapi.json and /debug are off unless ENABLE_DOCS=1. Secrets (FIREBASE_SERVICE_ACCOUNT, ADMIN_EMAILS) are read only from the environment / HF Space secrets and never stored in the repo. Also refines the Claude system prompt with a Swaniker-style voice guide. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>ae1a47a
-
Wire Google Sheet knowledge base into Claude RAG
Donne120eaa56f0
-
Phase 3: streaming chat via SSE with prompt caching preserved
Donne12036f325e -
Phase 3: prompt caching, history cap, essay coach endpoint
Donne1206d4cffe
-
Phase 2: Claude RAG, document upload, Tavily opportunities
Donne120a14da29
-
Revert to working app.py before my changes
687d84e -
Use minimal backend to avoid model loading issues
fd78c25 -
Use lightweight backend to fix startup timeout
2763daf -
Temporarily disable KB loading to fix startup timeout
c36dbbf -
Fix import path for alu-chatbot repo structure
8156855 -
Add automatic comprehensive knowledge base loading on startup
a7b8adc
-
Update API URL to Hugging Face Spaces backend
Donne12015631f8 -
Initial commit for Hugging Face Spaces
Donne12049ef41e