A small SvelteKit app that uses Google Gemini (via @google/genai) to suggest well-formatted filenames from a short description. It exposes a secure server endpoint that calls the GenAI model and returns a JSON array of suggested filenames.
This repository is a compact demo and starter for integrating a text-generation model into a web UI where the model output is constrained and validated.
/api/generate) that calls the GenAI client and returns 5 filename suggestions.zod (trim, non-empty, min/max length).See package.json for exact versions.
GEMINI_API_KEY.npm install
.env.local file at the project root (next to package.json) and add your key:GEMINI_API_KEY=YOUR_REAL_KEY_HERE
Important: Do NOT commit
.env.localto source control. Ensure your.gitignorecontains it.
npm run dev
Open http://localhost:5173 (or the port printed by dev server) and try the textarea.
{ "description": "...your description..." }Success response:
{ "success": true, "names": ["file-name-1.pdf", "file-name-2.docx", ...] }
Failure responses include a success: false and an error message. Validation errors return HTTP 400 with a message assembled from Zod issues.
curl -X POST 'http://localhost:5173/api/generate' \
-H 'Content-Type: application/json' \
-d '{"description":"List of employee names in my company"}'
Validation is implemented with src/lib/schema.js using zod:
description is trimmedThe server uses FilenameSchema.safeParse(body) to validate the incoming JSON before calling the model.
src/routes/+page.svelte contains the main UI. It posts to the server route at api/generate and renders results.GEMINI_API_KEY is set and the dev server was restarted after creating/updating .env.local.GEMINI_API_KEY in production instead of .env.local.@sveltejs/adapter-* packages in devDependencies; choose and configure an adapter for your target platform (Vercel, Netlify, Cloudflare Pages, etc.).+server.ts) if you want stronger types for request/response objects.src/lib/schema.js to assert validation behaviour across edge cases.PRs are welcome. Keep changes small and focused. If adding features that change the API shape, update this README and add tests.
Choose a license for your project (e.g., MIT). This repo currently does not include a license file.