nanochat/services/frontend
Manmohan 3ab89e7890
feat: deploy d24-sft-r6 with full reasoning mode + live tool use (Tavily)
Model R6 (97% pass rate on 33-probe eval, val_bpb 0.2635):
- modal/serve.py + modal/_tools.py: tool-aware streaming with
  TavilySearchBackend auto-detect, python_start/end state machine,
  output_start/end forcing; mount tavily secret
- modal/serve.py: MODEL_TAG=d24-sft-r6, model path points at new SFT r6
- services/chat-api/routes/messages.py: accept thinking_mode flag,
  inject samosaChaat system prompt (direct or <think> variant) into
  first user message before streaming to Modal
- services/frontend/components/chat/ChatInput.tsx: Brain toggle
  'Think' button next to send; when active, model uses think mode
- services/frontend/components/chat/ChatWindow.tsx: track
  thinkingMode state, pass through to API body as thinking_mode
- services/frontend/components/chat/MessageBubble.tsx: parse and
  render <think>...</think> as collapsible italic blocks;
  <|python_start|>...<|python_end|> as tool-call cards with icons
  per tool name; <|output_start|>...<|output_end|> as result cards
  with expandable JSON
- nanochat/tools.py: TavilySearchBackend class + auto-detect
- nanochat/ui.html: legacy UI reasoning toggle (kept for parity)

Tool execution verified live: query -> web_search via Tavily ->
Macron returned with grounded answer.
2026-04-22 13:43:43 -07:00
..
app fix(frontend): widen nav pill, default to dark theme (#41) 2026-04-16 20:08:55 -04:00
components feat: deploy d24-sft-r6 with full reasoning mode + live tool use (Tavily) 2026-04-22 13:43:43 -07:00
hooks fix(frontend): widen nav pill, default to dark theme (#41) 2026-04-16 20:08:55 -04:00
lib feat(frontend): wire frontend to real backend auth + chat-api services 2026-04-16 13:21:38 -07:00
public feat(frontend): Next.js 14 frontend service for samosaChaat (#2) 2026-04-16 11:26:57 -07:00
store feat(frontend): wire frontend to real backend auth + chat-api services 2026-04-16 13:21:38 -07:00
types feat(frontend): Next.js 14 frontend service for samosaChaat (#2) 2026-04-16 11:26:57 -07:00
.dockerignore feat(frontend): Next.js 14 frontend service for samosaChaat (#2) 2026-04-16 11:26:57 -07:00
.env.example feat(frontend): Next.js 14 frontend service for samosaChaat (#2) 2026-04-16 11:26:57 -07:00
.eslintrc.json feat: deploy d24 SFT + polished UI redesign with dark mode (#39) 2026-04-16 19:55:16 -04:00
.gitignore feat(frontend): Next.js 14 frontend service for samosaChaat (#2) 2026-04-16 11:26:57 -07:00
auth.ts feat(frontend): wire frontend to real backend auth + chat-api services 2026-04-16 13:21:38 -07:00
Dockerfile feat(frontend): Next.js 14 frontend service for samosaChaat (#2) 2026-04-16 11:26:57 -07:00
index.html scaffold monorepo platform layout 2026-04-16 11:06:29 -07:00
middleware.ts feat(frontend): wire frontend to real backend auth + chat-api services 2026-04-16 13:21:38 -07:00
next-env.d.ts feat(frontend): Next.js 14 frontend service for samosaChaat (#2) 2026-04-16 11:26:57 -07:00
next.config.mjs feat(frontend): Next.js 14 frontend service for samosaChaat (#2) 2026-04-16 11:26:57 -07:00
package-lock.json feat(frontend): wire frontend to real backend auth + chat-api services 2026-04-16 13:21:38 -07:00
package.json feat(frontend): wire frontend to real backend auth + chat-api services 2026-04-16 13:21:38 -07:00
postcss.config.mjs feat(frontend): Next.js 14 frontend service for samosaChaat (#2) 2026-04-16 11:26:57 -07:00
README.md feat(frontend): Next.js 14 frontend service for samosaChaat (#2) 2026-04-16 11:26:57 -07:00
tailwind.config.ts feat: deploy d24 SFT + polished UI redesign with dark mode (#39) 2026-04-16 19:55:16 -04:00
tsconfig.json feat(frontend): Next.js 14 frontend service for samosaChaat (#2) 2026-04-16 11:26:57 -07:00

samosaChaat — Frontend Service

Next.js 14 (App Router) application that replaces the legacy nanochat/ui.html. It blends Sarvam.ai's clean split-screen layout with samosaChaat's warm desi personality — samosa and chai illustrations, lemon-mirchi toran, gold + cream palette.

Pages

  • / Landing — Devanagari + Great Vibes calligraphy, animated samosa (float), chai kettle (wobble + steam), toran (pendulum), ambient doodles, CTA.
  • /login Sign-in — left: architectural/mandala motif with saffron-cream gradient; right: Google + GitHub OAuth, disabled email input.
  • /chat Chat — collapsible 260px sidebar (grouped history, model selector, user avatar, logout), main area with empty state + suggestion chips, markdown rendering with code-copy, auto-expanding textarea, slash commands (/temperature, /topk, /clear, /help), SSE streaming with steam typing indicator.

Tech

  • Next.js 14 (App Router, standalone output)
  • Tailwind CSS (theme tokens carried from ui.html)
  • Zustand (persisted conversations/settings)
  • NextAuth.js v5 (Google + GitHub)
  • Framer Motion (hero transitions)
  • Lucide React (icons)
  • react-markdown + rehype-highlight (assistant rendering)

Environment

Copy .env.example.env.local and fill in:

Var Purpose
NEXT_PUBLIC_APP_URL Public URL (defaults to http://localhost:3000)
AUTH_SERVICE_URL Auth microservice (BFF only; reserved for future)
CHAT_API_URL Upstream chat service. If unset the frontend serves mock echo responses — perfect for local dev.
NEXTAUTH_SECRET openssl rand -base64 32
GOOGLE_CLIENT_ID / GOOGLE_CLIENT_SECRET Google OAuth (optional in dev)
GITHUB_CLIENT_ID / GITHUB_CLIENT_SECRET GitHub OAuth (optional in dev)

Middleware protects /chat/* — unauthenticated users are redirected to /login?callbackUrl=/chat.

Run locally

cd services/frontend
npm install
cp .env.example .env.local    # then edit
npm run dev
# → http://localhost:3000

Without any OAuth keys the /login buttons will show the NextAuth error page; the rest of the UI works via the mocked API routes.

API routes (BFF pattern)

All client calls hit Next.js routes — the frontend never talks to the chat backend directly.

  • GET /api/health — service info + upstream config flags
  • GET /api/conversations — mocked conversation list
  • POST /api/chat/stream — proxies to CHAT_API_URL/chat/completions if set, otherwise streams a mock echo. Emits SSE: data: {"token": "...", "gpu": 0}\n\n and terminates with data: {"done": true}\n\n.

Docker

docker build -t samosachaat-frontend .
docker run --rm -p 3000:3000 \
  -e NEXTAUTH_SECRET=... \
  -e CHAT_API_URL=http://host.docker.internal:8000 \
  samosachaat-frontend

The image is based on node:20-alpine, uses Next.js output: standalone, and runs as a non-root user.

Porting notes

All SVG assets (samosa, chai kettle, toran, steam, doodles, logo) are componentized under components/svg/. CSS keyframes (pendulum, float, wobble, steamFloat, steamType) moved into tailwind.config.ts — reference via the animate-* utilities. The original single-file UI lives at nanochat/ui.html for reference.