GitHub user FrancescoCastaldi added a comment to the discussion: ai chat bot

Integrating an AI chatbot into Apache Superset to assist users with querying 
and creating visualizations can be accomplished cleanly using one of two proven 
architectures:

### Architecture 1: Portal / Embedded Wrapper (Recommended for Production)
Rather than modifying the Superset frontend source code, host Superset inside 
an internal web portal using the `@superset-ui/embedded-sdk`.
1. The host portal embeds the Superset dashboard via iframe using guest tokens.
2. A floating chat drawer or sidebar sits on the host portal next to the 
embedded dashboard.
3. The AI agent backend connects to Superset via the **Superset MCP Server** 
(`@modelcontextprotocol/server-superset` or native `/mcp/`), using tools like:
   - `execute_sql`: validates and runs queries
   - `list_datasets`: inspects table schemas
   - `generate_explore_link`: generates pre-configured chart exploration URLs
4. When the AI generates a recommendation, it updates the embedded dashboard or 
navigates the user directly to the generated explore link.

### Architecture 2: Frontend Script Injection via FLASK_APP_MUTATOR (In-App 
Floating Widget)
If you want the chat window to appear directly inside the standalone Superset 
UI without an external wrapper, you can inject a floating widget script via 
`superset_config.py`:

```python
# In superset_config.py
def inject_chatbot_widget(app):
    @app.after_request
    def add_widget(response):
        if response.content_type and "text/html" in response.content_type:
            widget_code = '''
            <script>
              (function() {
                var script = document.createElement("script");
                script.src = "https://your-cdn.com/ai-chat-widget.js";;
                script.async = true;
                document.body.appendChild(script);
              })();
            </script>
            '''
            response.set_data(response.get_data().replace(b"</body>", 
widget_code.encode("utf-8") + b"</body>"))
        return response

FLASK_APP_MUTATOR = inject_chatbot_widget
```

Your `ai-chat-widget.js` script mounts a floating chat icon in the bottom-right 
corner of the browser. When opened, it communicates with your LLM backend 
orchestrating actions through Superset MCP or REST API endpoints 
(`/api/v1/chart/data`, `/api/v1/dataset/`).


GitHub link: 
https://github.com/apache/superset/discussions/41151#discussioncomment-19164795

----
This is an automatically sent email for [email protected].
To unsubscribe, please send an email to: 
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to