BASA is an internal chatbot for the Philippine Department of Economy, Planning and Development (DEPDev), built with Laravel and powered by local LLMs via Ollama. It provides professional, context-aware answers to agency-related questions, and features a modern, user-friendly chat interface.
- Modern, responsive chat UI (ChatGPT-style)
- File upload and document parsing for PDF, DOCX, XLSX, and other formats
- Retrieval-Augmented Generation (RAG) powered by
nomic-embed-text
for semantic chunk search - Enhanced file gallery with static previews and grid/list view toggle
- Animated loading indicator and retry on failure
- Auto-streaming support for real-time token responses
- Background queue processing for large documents
- Real-time notifications when file processing completes (via Redis broadcasting)
- System prompt and context injection for accurate, professional answers
.pdf
(viasmalot/pdfparser
).docx
,.doc
,.odt
,.rtf
(viaphpoffice/phpword
).xlsx
,.xls
,.csv
(viaphpoffice/phpspreadsheet
).txt
and similar plaintext files
For a complete automated setup:
# 1. Clone and install dependencies
git clone https://[email protected]/luisapi/basa-chatbot.git
cd basa-chatbot
composer install
npm install
# 2. Environment configuration
cp .env.example .env
# Edit .env to configure your settings
# 3. Run comprehensive setup
php artisan setup:basa
The setup:basa
command will automatically:
- Check database connection
- Run migrations
- Set up queue tables
- Generate application key
- Process default government documents
- Clear application caches
- Create required directories
Options:
--skip-documents
- Skip processing default documents--force
- Force reprocessing of existing documents
If the automated setup fails or you prefer manual control:
git clone https://[email protected]/luisapi/basa-chatbot.git
cd basa-chatbot
composer install
npm install
cp .env.example .env
php artisan key:generate
Then edit .env
to configure:
- Laravel app (
APP_URL
,APP_DEBUG
, etc.) - Database connection (default: SQLite)
- Queue driver (
QUEUE_CONNECTION=database
) - LLM model (
LLM_MODEL=tinyllama
orphi
, etc.) - Ollama endpoint (
http://localhost:11434
) - Broadcasting driver (
BROADCAST_DRIVER=redis
)
php artisan migrate
php artisan queue:table
php artisan migrate
php artisan queue:work
php artisan documents:process-default
This processes bundled government documents for the RAG system.
Option A: Use the start script (Windows)
.\start-all.ps1
Option B: Start manually
# Terminal 1: Laravel development server
php artisan serve --port=8080
# Terminal 2: Queue worker
php artisan queue:work
# Terminal 3: Vite development server
npm run dev
php artisan serve --port=8080
starts the Laravel web server.php artisan queue:work
processes background jobs for file processing.npm run dev
starts the Vite development server for frontend assets.
Start Ollama and make sure both your chat model and embedding model are installed and running:
ollama run tinyllama
ollama pull nomic-embed-text
tinyllama
or similar is used for generating responses.nomic-embed-text
is used for vector embedding in RAG.
BASA includes a comprehensive Ollama connection management system:
# Basic status check
php artisan ollama:status
# Detailed connection information
php artisan ollama:status --detailed
The system supports multiple Ollama endpoints and auto-discovery:
Environment Variables:
OLLAMA_ENDPOINT=http://localhost:11434
OLLAMA_CORPORATE_ENDPOINT=https://ollama.depdev.gov.ph
OLLAMA_AUTO_DISCOVER=true
OLLAMA_TIMEOUT=30
OLLAMA_RETRY_ATTEMPTS=3
Features:
- Auto-discovery: Automatically finds Ollama instances on the network
- Fallback endpoints: Multiple endpoint support with automatic failover
- User preferences: Save and remember preferred endpoints
- Connection testing: Built-in endpoint validation
- Graceful degradation: Handles connection failures gracefully
Then access: http://localhost:8080/chatbot
BASA comes bundled with essential government documents that provide the core knowledge base for the chatbot. These documents are automatically available in every instance without requiring manual uploads.
Default documents are stored in public/documents/
and are version-controlled with the application.
Documents can be organized in subdirectories for better organization:
public/documents/
├── pdp/ # Philippine Development Plans
├── oc/ # Office Circulars
├── policies/ # Government Policies
└── README.md
- Philippine Development Plan (PDP) 2023-2028 - The country's medium-term development plan
- Other government policy documents and reference materials
To process the bundled documents for the RAG system:
# Process all default documents
php artisan documents:process-default
# Force reprocessing of existing documents
php artisan documents:process-default --force
- Place PDF files in
public/documents/
- Run
php artisan documents:process-default
- Documents are immediately available in the chatbot
In the File Gallery, system documents are marked with:
- Blue border and header in Grid view
- "System" badge
- Shield icon instead of file icon
- Highlighted row in List view
The enhanced File Gallery provides a Google Drive-style interface for managing uploaded documents:
- Static Previews: Each file shows a preview of its content (first 200 characters)
- View Toggle: Switch between Grid view (cards) and List view (table)
- File Information: File type, size, upload date, and chunk count
- System Documents: Visual distinction between user uploads and bundled documents
- Responsive Design: Works on desktop and mobile devices
- Hover Effects: Interactive file cards with smooth animations
Navigate to the File Gallery via:
- Sidebar menu: "File Gallery" link
- Direct URL:
http://localhost:8080/chatbot/files
- Grid View (default): Card-based layout showing file previews
- List View: Table format with all file details in columns
- View Chunks: Click "View Chunks" to see detailed file content
- File Details: Hover over cards to see additional information
- System Documents: Blue-highlighted cards indicate bundled government documents
BASA uses database broadcasting with polling for file processing notifications. When files are uploaded and processed in the background, users receive near real-time notifications about the processing status through AJAX polling.
The broadcasting is configured to use database as the driver:
- Driver: Database (SQLite)
- Method: AJAX polling (every 2 seconds)
- Events:
FileProcessed
andFileFailed
events
- File Upload → Laravel processes file in background queue
- Processing Complete →
FileProcessed
event dispatched and stored inbroadcasts
table - Frontend Polling → JavaScript polls
/chatbot/processing-status
every 2 seconds - Status Update → UI updates with processing status
If file processing notifications aren't working:
- Check database: Ensure the
broadcasts
table exists and is accessible - Check browser console: Look for AJAX polling errors
- Verify event dispatch: Check Laravel logs for event broadcasting errors
- Check queue worker: Ensure
php artisan queue:work
is running
These packages were added for file parsing and RAG support:
Package | Description |
---|---|
smalot/pdfparser |
Extracts text content from PDF files |
phpoffice/phpword |
Reads .doc , .docx , .odt , and .rtf documents |
phpoffice/phpspreadsheet |
Parses .xlsx , .xls , .csv spreadsheet files |
predis/predis |
Redis client for broadcasting |
laravel/horizon (optional) |
(Optional) Queue dashboard for Redis (if used) |
These allow BASA to process uploaded office documents and extract meaningful context for chunking and embedding.
BASA (Bot for Automated Semantic Assistance) is designed for internal use by DEPDev employees, providing fast, reliable, and contextually relevant answers about the agency's functions, services, and structure. It leverages local language models via Ollama and Laravel's elegant ecosystem.
This project is built with Laravel. For more information, visit the Laravel documentation.