Widget Creation Automation - Project Details

Complete technical documentation covering how it works, step-by-step workflow, and OpenAI prompts.

Table of Contents

Where Can We use our automation in devrev?

The Problem

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

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

2. Query Generator

Component: QuerySuggestions.jsx

3. Widget Generator

Component: QueryDetail.jsx

4. Visualization Engine

Component: ChartVisualization.jsx

Key Features

Data Flow

CSV Files → Parse → Analyze Structure → Generate SQL Queries → Process Queries → Generate Widget JSON → Visualize Data

Step-by-Step Workflow

1

Upload CSV Files

Component: CSVUpload.jsx

  1. User uploads CSV files (currently up to 3, scalable to many in the future)
  2. System parses each file using PapaParse
  3. For each file:
    • Extracts headers (column names)
    • Parses data rows
    • Generates default table name from filename
    • Shows preview (first 5 rows)
  4. User can customize table names for each file
  5. System validates all files have table names
Key Features:
  • Supports multiple CSV files (currently up to 3, scalable to many in the future)
  • Automatic table name generation
  • Data preview before processing
  • Error handling for malformed CSV files
2

Generate Query Suggestions

Component: CSVUpload.jsx → QuerySuggestions.jsx

  1. User clicks "Generate Query Suggestions"
  2. System shows loading progress (10% → 100%)
  3. System builds prompt with:
    • All column names from all tables
    • Table names and structure
    • Special instructions for JOIN queries (if multiple tables)
  4. OpenAI API call generates SQL queries
  5. System automatically fixes NULL handling:
    • Boolean columns: Adds COALESCE(column, FALSE) = FALSE
    • Array/JSON fields: Uses IS NOT NULL instead of COALESCE
    • Date fields: Uses IS NOT NULL
    • ID fields: Uses IS NOT NULL
  6. Queries are organized by table (if multiple tables)
  7. System detects correlations between tables and generates JOIN queries
Output: Array of query objects with:
  • title: Human-readable query title
  • description: What the query does
  • suggested_query: Complete SQL query
3

Select Query

Component: QuerySuggestions.jsx

  1. User views list of generated queries
  2. Queries are organized by:
    • JOIN queries (if multiple tables detected)
    • Individual table queries (grouped by table)
  3. Each query card shows:
    • Query title and description
    • SQL query preview
    • "View Details & Visualize" button
  4. User clicks on a query to see details
4

View Query Details & Generate Widget

Component: QueryDetail.jsx

  1. System extracts dataset name from SQL query (FROM clause)
  2. System processes SQL query:
    • Extracts dimensions (non-aggregate columns)
    • Extracts measures (aggregate functions: COUNT, SUM, AVG, etc.)
    • Removes GROUP BY and HAVING clauses (handled by widget builder)
    • Adds IS NOT NULL filters for dimension columns
  3. System generates widget JSON:
    • Creates data_sources with dimensions and measures
    • Creates sub_widgets with visualization configurations
    • Ensures field types are lowercase (DevRev requirement)
    • Handles JSON/array fields with JSON_EXTRACT_STRING
    • Converts COUNT(*) to SUM(count) pattern
  4. System generates chart suggestions:
    • Table chart
    • Column chart
    • Line chart
  5. Each chart suggestion includes complete widget JSON
Key Processing:
  • SQL query is processed ONCE to ensure consistency
  • Dimensions and measures are extracted from SQL
  • Widget JSON follows DevRev schema exactly
  • Field types are automatically detected and set correctly
5

Visualize Data

Component: ChartVisualization.jsx

  1. User selects a chart type (table, column, or line)
  2. System transforms CSV data to match SQL query structure
  3. System renders chart using Recharts
  4. User can:
    • View the visualization
    • Copy widget JSON
    • Go back to select different chart type
Note: In production, this would execute actual SQL queries against the data warehouse. Currently, it uses CSV data for visualization.

AI Integration

OpenAI Integration Overview

The system uses OpenAI's GPT-4o-mini model to power three main AI capabilities:

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

API Integration

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()

2. Correlation Detector

File: correlationDetector.js

3. SQL Query Processor

Function: processSqlQuery()

4. Widget JSON Generator

Function: createWorkingWidget()

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.

Widget Creation Automation - Product Details Documentation

Generated for internal use and sharing