Skip to content

This project demonstrates how to create an "Executive Summary" generated by Luzmo IQ, accompanied by an embedded dashboard

Notifications You must be signed in to change notification settings

luzmo-official/data-talks_ai-workshop

Repository files navigation

AI Workshop: Luzmo IQ Streaming Implementation

This project demonstrates how to create an "Executive Summary" generated by Luzmo IQ, accompanied by an embedded dashboard. The project is mainly created for use during a workshop at Luzmo's Data Talks event in Paris.

  • AI-Powered Business Analytics: Automatically generates an AI summary from your sales data using Luzmo IQ, with live status updates
  • Interactive Dashboard: Embeds a Luzmo dashboard for deeper data exploration

📁 Project Structure

data-talks_ai-workshop/
├── iq_summary_with_embedded_dashboard.html    # Main demo application
├── neon_db_workshop_sales_schema_and_data.sql # Database setup with sample sales data
└── workshop_sql-dataset-definition.sql        # SQL query for denormalized Luzmo dataset

🚀 Quick Start Guide

1. Set Up Neon Database (Serverless PostgreSQL)

You can skip this if you'd like to connect your own data source to Luzmo!

  1. Create Neon Account

  2. Set Up Database Schema & Data

    • In your Neon console, go to the SQL Editor
    • Copy and paste the entire content of neon_db_workshop_sales_schema_and_data.sql
    • Execute the script to create tables, insert sample data, and set up a read-only user
  3. Get Connection Details

    • In Neon console, go to DashboardConnection Details
    • Note down your connection string (make sure to swith to the "Role" luzmo_readonly_user)

2. Set Up Luzmo Account

  1. Start Free Trial

    Sign up for a free trial account (or log in to your existing Luzmo account)

  2. Connect Your Data Source

    • In Luzmo, click "Connect" to add a new data source
    • Select the PostgreSQL connector
    • Use the connection details from Neon:
      • Host: Your Neon host (e.g., ep-cool-name-123456-pooler.us-east-1.aws.neon.tech)
      • Port: 5432
      • Database: neondb (or your database name)
      • Username: luzmo_readonly_user
      • Password: SuperSecretPassword123
    • Create the connection
  3. Create Dataset

    • In Luzmo, create a new SQL Dataset
    • Use the query from workshop_sql-dataset-definition.sql:
    SELECT
      po.*,
      -- Case statement to map sales codes into meaningful descriptions
      CASE 
          WHEN po.sales_code = 'S001' THEN 'No discount'
          WHEN po.sales_code = 'S020' THEN 'Vendor discount'
          WHEN po.sales_code = 'S500' THEN 'End-of-day discount'
          ELSE 'Other / Unknown'
      END AS sales_code_description,
      c.customer_first_name,
      c.customer_last_name,
      c.customer_email,
      c.customer_date_of_birth,
      p.product_name,
      p.product_category,
      p.product_release_date,
      s.store_name,
      s.store_country
    FROM product_orders po
    JOIN customers c ON po.customer_id = c.customer_id
    JOIN products p ON po.product_id = p.product_id
    JOIN stores s ON po.store_id = s.store_id
  4. Create a Dashboard

    • Create a new dashboard in Luzmo and add some charts using your dataset (e.g., revenue by store, top products)
    • Note down your Dashboard ID (found in the dashboard URL, or dashboard settings at the bottom)

3. Generate Embed Token

  1. Generate token via Embed button

    • In your Luzmo dashboard, click the "Embed" button
    • Copy the Embed Key and Embed Token
    • Important: These are temporary tokens for demo purposes and are only valid for 30 minutes!
  2. Recommended: Generate via API
    In production setups, Embed Authorization tokens are requested server-side in your application; for the sake of this demo application, we can use tools like Postman or Insomia (or just plain curl requests) to manually generate an Embed key-token pair. This might be necessary if you'd like to e.g. specify extra context for Luzmo IQ (somewhat like a "Master prompt").

    1. Create a Luzmo API key-token pair in your account settings: https://app.luzmo.com/settings/api-tokens
    2. Use your API key-token pair to generate a temporary Embed key-token pair via an HTTP request to the /authorization API endpoint (see this guide). Make sure to give access to both your dashboard and dataset (e.g. via a Collection).
    curl https://api.luzmo.com/0.1.0/authorization  -H "Content-Type: application/json" -d @- << EOF
     {
       "action": "create",
       "version": "0.1.0",
       "key": "<your Luzmo API key>",
       "token": "<your Luzmo API token>",
       "properties": {
         "type": "embed",
         "username": "luzmo-iq-embed@example.com",
         "name": "Embed Luzmo IQ Test User",
         "suborganization": "Company A",
         "email": "luzmo-iq-embed@example.com",
         "access": {
           "collections": [
             {
               "id": "<collection_id>",
               "inheritRights": "use"
             }
           ]
         }
       }
     }
     EOF

4. Configure the HTML File

Open iq_summary_with_embedded_dashboard.html and update the following values in the CONFIG object (around line 84):

const CONFIG = {
  // Replace with your actual embed credentials
  authKey: "YOUR_EMBED_KEY_HERE",
  authToken: "YOUR_EMBED_TOKEN_HERE",
  dashboardId: "YOUR_DASHBOARD_ID_HERE"
};

You can also customize the "Executive Summary" prompt by modifying BUSINESS_SUMMARY_PROMPT in the HTML file (right below the CONFIG object):

const BUSINESS_SUMMARY_PROMPT = `Your custom prompt here...`;

5. Run the Application

Simply open iq_summary_with_embedded_dashboard.html in your web browser. The application will automatically start generating AI insights while allowing you to already slice-and-dice in the embedded dashboard!

🔧 Technical Details

Luzmo IQ Streaming API

The project uses Luzmo's Message streaming API (/ai/v1/message) to get real-time AI responses:

  • Streaming States: AnalyzingQueryingSummarizingCompleted
  • Response Modes: text_only (used in this demo), chart_only, or mixed

🛠️ Troubleshooting

Common Issues

  1. "Failed to load dashboard"

    • Check that your embed key-token pair is correctly set
    • Ensure your dashboard ID is valid
    • If you're not on the EU multitenant VPC, make sure to adapt the API Host URL and App Server URL in the CONFIG object
  2. "No data found"

    • Confirm your Neon database has data
    • Check that your Luzmo dataset is properly configured
    • Verify the SQL query in your dataset
  3. "Connection failed"

    • Verify your connection string is correct
    • Check that the read-only database user has the proper permissions to query the schema, tables, etc.

Getting Help

About

This project demonstrates how to create an "Executive Summary" generated by Luzmo IQ, accompanied by an embedded dashboard

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages