DevRev is a platform used by many organizations. These organizations love to see insights about their business,
customers, and operations. The number of widgets and dashboards required is significant, and they frequently
approach our team to create widgets and dashboards for them.
The Opportunity
As of now, customers are using COMPUTER less. Why can't we take this to the next level? We can give them access
to the notebook with the same OpenAI tool we're using to create this automation.
The vision: Users can choose their dataset, speak with Computer in natural language, and
create widgets/dashboards automatically. No SQL knowledge required. No waiting for developers.
The Impact
Might potentially increase DevRev Usage: More widgets and dashboards = more engagement with the platform
Might potentially increase ComputerApp Usage: Customers will actively use the notebook feature to create insights
Reduces Time Spent on Routine Tasks: Teams can focus on creative, high-value work instead of repetitive widget creation
Self-Service Analytics: Organizations can create their own insights without waiting for developer support
Faster Time to Insights: From days/weeks to minutes - instant widget creation
Scalability: Handle hundreds of widget requests without proportional increase in developer workload
Current State vs. Future State
Current State
Organizations request widgets from our team
Developers spend hours creating each widget
Long wait times for customers
Limited number of widgets due to resource constraints
Customers use Computer less
Future State
Organizations create widgets themselves
AI automates widget creation in minutes
Instant widget generation
Unlimited widgets - scale as needed
Increased Computer app usage and engagement
How It Works
Overview
Widget Creation Automation is an AI-powered tool that transforms CSV data into production-ready SQL queries and DevRev widget JSON configurations.
It uses OpenAI's GPT-4o-mini model to analyze data structures, generate SQL queries, and create widget configurations automatically.
Core Components
1. CSV Parser
Component:CSVUpload.jsx
Parses CSV files using PapaParse library
Currently supports up to 3 CSV files (scalable to many files in the future)
Extracts headers, data rows, and metadata
Handles JSON/array fields automatically
2. Query Generator
Component:QuerySuggestions.jsx
Uses OpenAI API to generate SQL queries
Automatically detects relationships between tables
Generates JOIN queries when multiple tables are detected
Fixes NULL handling in SQL queries automatically
3. Widget Generator
Component:QueryDetail.jsx
Creates DevRev widget JSON configurations
Processes SQL queries to extract dimensions and measures
Multi-CSV Support: Upload multiple CSV files (currently up to 3, scalable to many in the future), automatic table name generation, relationship detection between tables, and automatic JOIN query generation
Smart NULL Handling: Automatically fixes SQL queries for NULL values, handles boolean, date, ID, and JSON fields correctly, preserves existing COALESCE statements, and prevents type conversion errors
DevRev Widget Compatibility: Generates widget JSON that works immediately, follows DevRev schema requirements exactly, handles field types correctly, and supports all visualization types
AI-Powered Query Generation: Generates SQL queries from natural language, understands data structure automatically, creates JOIN queries when relationships detected, and handles complex aggregations
Automatic Query Fixing: Fixes NULL handling automatically, adds required COALESCE statements, handles array/JSON fields correctly, and ensures queries work in DevRev
Progress Tracking: Real-time progress updates, loading states for all operations, error handling and user feedback, and success/error messages
Custom Query Generation: Generates SQL queries from natural language descriptions provided by users
Column Descriptions: Generates user-friendly, business-focused descriptions of CSV columns
All prompts are designed to ensure DevRev OASIS compatibility, proper NULL handling, and correct SQL syntax.
The system automatically validates and fixes generated queries to ensure they work correctly in DevRev widgets.
Model: GPT-4o-mini | Temperature: 0.7 | Max Tokens: 1000-3000 (depending on use case)
Technical Architecture
Frontend Stack
React 18: UI framework
Vite: Build tool and dev server
Recharts: Chart visualization library
PapaParse: CSV parsing library
API Integration
OpenAI GPT-4o-mini: AI model for query generation
API Endpoint:https://api.openai.com/v1/chat/completions
Model:gpt-4o-mini (cost-effective, fast)
Note: This is an MVP (Minimum Viable Product) version. Future iterations will include additional features, optimizations, and enhanced capabilities.
Key Algorithms
1. NULL Handling Fixer
Function:fixNullHandling()
Automatically fixes SQL queries to handle NULL values
Detects boolean columns and adds COALESCE
Handles array/JSON fields correctly
Preserves existing COALESCE statements
2. Correlation Detector
File:correlationDetector.js
Detects relationships between tables
Finds matching column names (e.g., id, user_id)
Calculates confidence scores
Generates JOIN queries automatically
3. SQL Query Processor
Function:processSqlQuery()
Extracts dimensions from SELECT clause
Extracts measures (aggregate functions)
Removes GROUP BY and HAVING (handled by widget builder)
Adds IS NOT NULL filters for dimensions
4. Widget JSON Generator
Function:createWorkingWidget()
Creates DevRev-compliant widget JSON
Handles field type detection
Generates dimensions and measures
Creates visualization configurations
Conclusion
Widget Creation Automation automates the entire widget creation workflow, from CSV upload to production-ready widget JSON.
It uses AI to understand data structures, generate SQL queries, and create widget configurations automatically.
The system handles complex scenarios like multi-table JOINs, NULL value handling, and DevRev schema requirements,
making it easy for non-technical users to create sophisticated data visualizations.