Skip to content

Repository files navigation

NightAI

Local AI assistant with chat, file editing, and image generation — Gemma for text, SDXL for images, React UI.

Quickstart

Requirements: Python 3.11 or 3.12, Node.js 18+

# 1. Install Python dependencies
pip install -r requirements.txt

# 2. Install Node dependencies
npm install

# 3. Configure
cp example.env .env
# Edit .env and set HF_TOKEN to your Hugging Face token

# 4. Start
npm start

Open http://localhost:3333

The first run downloads the model (~9 GB) — this can take a while. The UI shows a loading bar while the model initialises.

On Windows, npm start prefers py -3.12 when installed.

Usage

Chat — type any question and press Enter or click Run.

File editing — pick a project folder with the folder button, then mention a filename in your message (e.g. fix the layout in App.tsx). NightAI loads the file, applies the change, and writes it back. The UI shows a file card for each file written.

Create files — ask NightAI to write new code (create a login form in React) and it will generate and save the file automatically.

Images — phrases like create an image of a sunset or draw a castle run SDXL instead of chat. Images are saved to the images/ folder.

Stop — click the Stop button to abort generation mid-stream.

Config (.env)

Variable Default Description
HF_TOKEN Hugging Face token (required)
CHAT_MODEL google/gemma-4-E4B-it Chat model repo ID
IMAGE_MODEL stabilityai/sdxl-turbo Image model repo ID
NIGHTAI_PORT 8674 Backend port
NIGHTAI_MAX_TOKENS 20000 Max tokens for any generation
NIGHTAI_SDPA 0 Set to 1 to enable SDPA attention (CUDA only)
NIGHTAI_EDIT_GREEDY 0 Set to 1 for greedy decoding on file edits
NIGHTAI_IMAGES_DIR images/ Where generated images are saved

Backend (src/)

File Role
server.py HTTP API (/chat, /stop, /status, /pick-folder)
gemma.py Chat model — load, stream, history formatting
file_context.py Load files into prompts, extract and write code blocks
file_tools.py Safe file read/write scoped to the workspace folder
image_gen.py SDXL image generation (loaded on demand)
intent.py Detect image requests
folder_picker.py Native OS folder picker dialog
config.py All settings and environment variable parsing

Tests

npm test          # Python unit tests (tests/)
npm run test:e2e  # Playwright end-to-end (real server + model)

E2e tests start the Python server on port 18774 and Vite on 13333. They load the model, run chat, file edits against e2e/fixtures/workspace/, and image generation. Requires HF_TOKEN. First run can take 20+ minutes while the model downloads.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages