Electron BAML Streaming is a desktop application that demonstrates the power of BAML (Boundary AI Markup Language) for generating random user data with LLM streaming capabilities.
This cross-platform Electron app showcases how to integrate BAML with Electron to create a seamless user generation experience. The application uses LLMs to generate realistic but fictional user profiles with personal information and addresses.
Key features:
- Generate random user profiles with realistic data
- Stream generation results with real-time visual feedback using BAML streaming
- Demonstrate BAML integration with Electron
- Showcase LLM capabilities in desktop applications
- Implement proper streaming with BAML's @stream attributes
- Electron: Cross-platform desktop app framework
- Vite: Fast build tool and dev server
- TypeScript: Typed JavaScript for robust code
- React: Dynamic UI library
- BAML: AI function calling framework
Use Bun for package management to set up the project:
# Install dependencies
$ bun install
# Run in development mode
$ bun run dev
# Build for distribution
# Windows
$ bun run build:win
# macOS
$ bun run build:mac
# Linux
$ bun run build:linuxCreate a .env file based on the .env.example template with your API keys:
CEREBRAS_API_KEY=your_cerebras_api_key_here
OPENROUTER_API_KEY=your_openrouter_api_key_here
This application demonstrates the use of BAML's streaming capabilities:
- @stream.done: Applied to fields that should only be streamed when complete (like ID)
- @stream.not_null: Applied to fields that must have a value before streaming (like name and gender)
- @stream.with_state: Applied to complex objects (like address) to track streaming completion status
The streaming implementation follows these steps:
- Main process initiates a BAML stream using
b.stream.GenerateRandomUser() - Partial updates are sent to the renderer via IPC as they arrive
- React component updates the UI in real-time as data streams in
- Final complete data is returned when the stream completes
Explore the tech behind the project: