A Cloudflare-native AI chat application for explaining and improving the performance of Python, C++, and CUDA code. Not a benchmarking or code-execution service: suggestions are hypotheses until measured.
Try CodePilot here: https://ai-code-optimization-assistant.codepilot-ai.workers.dev
- User-submitted code or questions through a responsive chat interface
- Llama 3.3 70B on Cloudflare Workers AI
- Cloudflare Worker coordinates model calls, conversation lookup, input validation, and persistence
- D1 SQL database stores conversation history across refreshes, scoped to a browser session cookie
- Follow-up context (up to 12 previous messages) and reset conversation action
- Plain-text model display prevents generated HTML from executing
| Requirement | Implementation |
|---|---|
| LLM | Workers AI / Llama 3.3 |
| Coordination | Worker fetch handler |
| User input | Responsive web chat, served as static Worker assets |
| Memory/state | D1 persisted messages and session cookie |
Requires Node.js 20+, npm, and a Cloudflare account.
npm installnpx wrangler loginnpx wrangler d1 create code-coach-db- Copy the new
database_idinto the D1 entry inwrangler.jsonc(replaceREPLACE_WITH_YOUR_D1_DATABASE_ID). Never deploy with the placeholder. npm run db:localnpm run dev- Visit the local URL shown by Wrangler.
npm run db:remote(creates the tables in the production D1 database)npm run deploy- Open the deployed
*.workers.devURL printed by Wrangler.
Important: Workers AI usage may incur charges beyond free allowances. Review your account's Cloudflare usage and pricing. Production deployments should add rate limiting and user authentication; this demo deliberately uses only an anonymous, per-browser session cookie. The cookie is not a replacement for sign-in and should not store sensitive code. The app does not execute submitted code.
npm run checkchecks JavaScript syntax.npm testruns lightweight API tests.- After binding the services, test chat, refresh history, and reset in the browser.
Browser chat (HTML/CSS/JS)
| fetch('/api/chat')
Cloudflare Worker
|-- D1 -> read last 12 messages, store exchange
`-- Workers AI -> Llama 3.3 70B
See PROMPT_HISTORY.md. The user must add any later AI-assisted edits and prompts they use before submitting. The record documents the request that led to this initial generation, rather than fabricating prompts.