Skip to content

Commit 75d1289

Browse files
authored
Merge pull request #2180 from oracle-devrel/newpush
Add files via upload
2 parents 8a15cb6 + ef0ca50 commit 75d1289

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+7005
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
Copyright (c) 2025 Oracle and/or its affiliates.
2+
3+
The Universal Permissive License (UPL), Version 1.0
4+
5+
Subject to the condition set forth below, permission is hereby granted to any
6+
person obtaining a copy of this software, associated documentation and/or data
7+
(collectively the "Software"), free of charge and under any and all copyright
8+
rights in the Software, and any and all patent rights owned or freely
9+
licensable by each licensor hereunder covering either (i) the unmodified
10+
Software as contributed to or provided by such licensor, or (ii) the Larger
11+
Works (as defined below), to deal in both
12+
13+
(a) the Software, and
14+
(b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
15+
one is included with the Software (each a "Larger Work" to which the Software
16+
is contributed by such licensors),
17+
18+
without restriction, including without limitation the rights to copy, create
19+
derivative works of, display, perform, and distribute the Software and make,
20+
use, sell, offer for sale, import, export, have made, and have sold the
21+
Software and the Larger Work(s), and to sublicense the foregoing rights on
22+
either these or other terms.
23+
24+
This license is subject to the following condition:
25+
The above copyright notice and either this complete permission notice or at
26+
a minimum a reference to the UPL must be included in all copies or
27+
substantial portions of the Software.
28+
29+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
35+
SOFTWARE.
Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
1+
# SQL Graph Generator Dashboard
2+
3+
SQL Graph Generator Dashboard is an AI-powered assistant that enables natural language database queries and intelligent chart generation.
4+
It extracts data from your database using conversational queries, automatically generates appropriate visualizations, and provides multi-turn conversational context for data exploration.
5+
It runs as an interactive Next.js web app backed by a FastAPI server, LangChain orchestration, and Oracle Cloud Infrastructure GenAI models.
6+
7+
Reviewed: October 13, 2025
8+
9+
# When to use this asset?
10+
11+
Use this asset when you want to:
12+
13+
- Query databases using natural language instead of SQL
14+
- Automatically generate charts and visualizations from query results
15+
- Build conversational data exploration interfaces
16+
- Integrate OCI GenAI models with database operations
17+
- Demonstrate intelligent routing between data queries, visualizations, and insights
18+
19+
Ideal for:
20+
21+
- AI engineers building conversational data analytics tools
22+
- Data teams needing natural language database interfaces
23+
- OCI customers integrating GenAI into business intelligence workflows
24+
- Anyone showcasing LangChain + OCI GenAI + dynamic visualization generation
25+
26+
# How to use this asset?
27+
28+
This assistant can be launched via:
29+
30+
- Next.js Web UI
31+
32+
It supports:
33+
34+
- Natural language to SQL conversion
35+
- Automatic chart generation from query results
36+
- Multi-turn conversations with context preservation
37+
- Multiple chart types: bar, line, pie, scatter, heatmap
38+
- Real-time data visualization using matplotlib/seaborn
39+
- Intelligent routing between data queries, visualizations, and insights
40+
41+
## Setup Instructions
42+
43+
### OCI Generative AI Model Configuration
44+
45+
1. Go to: OCI Console → Generative AI
46+
2. Select your model (this demo uses OpenAI GPT OSS 120B):
47+
`ocid1.generativeaimodel.oc1.eu-frankfurt-1.amaaaaaask7dceyav...`
48+
3. Set up an OCI Agent Runtime endpoint for SQL queries
49+
4. Copy the following values:
50+
- MODEL_ID
51+
- AGENT_ENDPOINT_ID
52+
- COMPARTMENT_ID
53+
- SERVICE_ENDPOINT (e.g., `https://inference.generativeai.eu-frankfurt-1.oci.oraclecloud.com`)
54+
5. Configure them in `backend/utils/config.py`
55+
56+
Documentation:
57+
[OCI Generative AI Documentation](https://docs.oracle.com/en-us/iaas/Content/generative-ai/home.htm)
58+
59+
No API key is required — authentication is handled via OCI identity.
60+
61+
Ensure your OCI CLI credentials are configured.
62+
Edit or create the following config file at `~/.oci/config`:
63+
64+
```
65+
[DEFAULT]
66+
user=ocid1.user.oc1..exampleuniqueID
67+
fingerprint=c6:4f:66:e7:xx:xx:xx:xx
68+
tenancy=ocid1.tenancy.oc1..exampleuniqueID
69+
region=eu-frankfurt-1
70+
key_file=~/.oci/oci_api_key.pem
71+
```
72+
73+
### Install Dependencies
74+
75+
Backend:
76+
77+
```bash
78+
cd backend
79+
pip install -r requirements.txt
80+
```
81+
82+
Frontend:
83+
84+
```bash
85+
cd ..
86+
npm install
87+
```
88+
89+
### Configure Database
90+
91+
1. Set up your database connection in OCI Agent Runtime
92+
2. The demo uses a sample e-commerce database with tables:
93+
- orders
94+
- customers
95+
- products
96+
- order_items
97+
98+
### Start the Application
99+
100+
Backend (FastAPI):
101+
102+
```bash
103+
cd backend
104+
python -m uvicorn api.main:app --reload --host 0.0.0.0 --port 8000
105+
```
106+
107+
Frontend (Next.js):
108+
109+
```bash
110+
npm run dev
111+
```
112+
113+
Access the application at: http://localhost:3000
114+
115+
## Key Features
116+
117+
| Feature | Description |
118+
| ------------------------ | ---------------------------------------------------------------- |
119+
| Natural Language Queries | Ask questions like "show me the top 5 orders" |
120+
| Intelligent Routing | GenAI-powered routing between data queries, charts, and insights |
121+
| Auto Chart Generation | Automatically creates appropriate visualizations from data |
122+
| Multi-Turn Conversations | Maintains context across multiple queries |
123+
| Real-Time Visualization | Generates matplotlib/seaborn charts as base64 images |
124+
| Multiple Chart Types | Supports bar, line, pie, scatter, and heatmap charts |
125+
| OCI GenAI Integration | Uses OCI Agent Runtime and Chat API |
126+
| LangChain Runnables | Clean integration pattern wrapping OCI SDK calls |
127+
| Conversation Management | Tracks query history and data state |
128+
| Error Handling | Clear error messages and fallback behavior |
129+
130+
## Architecture
131+
132+
### Backend Components
133+
134+
1. **Router Agent** (OCI Chat API)
135+
136+
- Intelligent query routing using GenAI
137+
- Routes: DATA_QUERY, CHART_EDIT, INSIGHT_QA
138+
- Returns structured JSON decisions
139+
140+
2. **SQL Agent** (OCI Agent Runtime)
141+
142+
- Natural language to SQL conversion
143+
- Database query execution
144+
- Structured data extraction
145+
146+
3. **Chart Generator** (OCI Chat API + Python Execution)
147+
148+
- GenAI generates matplotlib/seaborn code
149+
- Safe code execution in sandboxed environment
150+
- Returns base64-encoded chart images
151+
152+
4. **Orchestrator**
153+
- Coordinates agents based on routing decisions
154+
- Manages conversation state
155+
- Handles multi-turn context
156+
157+
### Frontend Components
158+
159+
1. **Chat Interface**
160+
161+
- Real-time message display
162+
- Support for text, tables, and images
163+
- Speech recognition integration
164+
165+
2. **Service Layer**
166+
167+
- API communication with backend
168+
- Response transformation
169+
- Error handling
170+
171+
3. **Context Management**
172+
- User session handling
173+
- Message history
174+
- State management
175+
176+
## Example Queries
177+
178+
```
179+
"Show me the top 5 orders"
180+
→ Returns table with order data
181+
182+
"Make a bar chart of those orders by total amount"
183+
→ Generates bar chart visualization
184+
185+
"Show me orders grouped by region"
186+
→ Returns data aggregated by region
187+
188+
"Create a pie chart of the order distribution"
189+
→ Generates pie chart from current data
190+
191+
"What insights can you provide about these sales?"
192+
→ Provides AI-generated analysis
193+
```
194+
195+
## Configuration Files
196+
197+
Key configuration in `backend/utils/config.py`:
198+
199+
- MODEL_ID: Your OCI GenAI model OCID
200+
- AGENT_ENDPOINT_ID: Your OCI Agent Runtime endpoint
201+
- COMPARTMENT_ID: Your OCI compartment
202+
- SERVICE_ENDPOINT: GenAI service endpoint URL
203+
- DATABASE_SCHEMA: Database table definitions
204+
205+
## Notes
206+
207+
- Prompts can be customized in `backend/orchestration/oci_direct_runnables.py`
208+
- Chart generation code is dynamically created by GenAI
209+
- Designed specifically for Oracle Cloud Infrastructure + Generative AI
210+
- Sample database schema included for e-commerce use case
211+
- Frontend uses Material-UI for consistent design
212+
213+
# Useful Links
214+
215+
- [OCI Generative AI](https://docs.oracle.com/en-us/iaas/Content/generative-ai/home.htm)
216+
Official documentation for Oracle Generative AI
217+
218+
- [OCI Agent Runtime](https://docs.oracle.com/en-us/iaas/Content/generative-ai/agent-runtime.htm)
219+
Documentation for OCI Agent Runtime
220+
221+
- [LangChain Documentation](https://python.langchain.com/docs/get_started/introduction)
222+
LangChain framework documentation
223+
224+
- [Next.js Documentation](https://nextjs.org/docs)
225+
Next.js framework documentation
226+
227+
# License
228+
229+
Copyright (c) 2025 Oracle and/or its affiliates.
230+
231+
Licensed under the Universal Permissive License (UPL), Version 1.0.
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
# Database Setup
2+
3+
## Overview
4+
5+
This application uses OCI Agent Runtime to query your database. The sample schema is for an e-commerce database.
6+
7+
## Database Schema
8+
9+
### CUSTOMERS Table
10+
```sql
11+
CREATE TABLE CUSTOMERS (
12+
CUSTOMER_ID NUMBER PRIMARY KEY,
13+
CUSTOMER_NAME VARCHAR2(100),
14+
EMAIL VARCHAR2(100),
15+
SIGNUP_DATE DATE,
16+
SEGMENT VARCHAR2(50),
17+
COUNTRY VARCHAR2(50),
18+
LIFETIME_VALUE NUMBER(10,2),
19+
CREATION_DATE DATE,
20+
CREATED_BY VARCHAR2(50),
21+
LAST_UPDATED_DATE DATE,
22+
LAST_UPDATED_BY VARCHAR2(50)
23+
);
24+
```
25+
26+
### PRODUCTS Table
27+
```sql
28+
CREATE TABLE PRODUCTS (
29+
PRODUCT_ID NUMBER PRIMARY KEY,
30+
PRODUCT_NAME VARCHAR2(200),
31+
CATEGORY VARCHAR2(100),
32+
PRICE NUMBER(10,2),
33+
COST NUMBER(10,2),
34+
STOCK_QUANTITY NUMBER,
35+
LAUNCH_DATE DATE,
36+
CREATION_DATE DATE,
37+
CREATED_BY VARCHAR2(50),
38+
LAST_UPDATED_DATE DATE,
39+
LAST_UPDATED_BY VARCHAR2(50)
40+
);
41+
```
42+
43+
### ORDERS Table
44+
```sql
45+
CREATE TABLE ORDERS (
46+
ORDER_ID NUMBER PRIMARY KEY,
47+
CUSTOMER_ID NUMBER,
48+
ORDER_DATE DATE,
49+
TOTAL_AMOUNT NUMBER(10,2),
50+
STATUS VARCHAR2(50),
51+
REGION VARCHAR2(100),
52+
SALES_REP VARCHAR2(100),
53+
CREATION_DATE DATE,
54+
CREATED_BY VARCHAR2(50),
55+
LAST_UPDATED_DATE DATE,
56+
LAST_UPDATED_BY VARCHAR2(50),
57+
FOREIGN KEY (CUSTOMER_ID) REFERENCES CUSTOMERS(CUSTOMER_ID)
58+
);
59+
```
60+
61+
### ORDER_ITEMS Table
62+
```sql
63+
CREATE TABLE ORDER_ITEMS (
64+
ORDER_ITEM_ID NUMBER PRIMARY KEY,
65+
ORDER_ID NUMBER,
66+
PRODUCT_ID NUMBER,
67+
QUANTITY NUMBER,
68+
UNIT_PRICE NUMBER(10,2),
69+
DISCOUNT_PERCENT NUMBER(5,2),
70+
CREATION_DATE DATE,
71+
CREATED_BY VARCHAR2(50),
72+
LAST_UPDATED_DATE DATE,
73+
LAST_UPDATED_BY VARCHAR2(50),
74+
FOREIGN KEY (ORDER_ID) REFERENCES ORDERS(ORDER_ID),
75+
FOREIGN KEY (PRODUCT_ID) REFERENCES PRODUCTS(PRODUCT_ID)
76+
);
77+
```
78+
79+
## Sample Data
80+
81+
### Sample Customers
82+
```sql
83+
INSERT INTO CUSTOMERS VALUES (1, 'Acme Corp', '[email protected]', DATE '2023-01-15', 'Enterprise', 'USA', 150000, SYSDATE, 'SYSTEM', SYSDATE, 'SYSTEM');
84+
INSERT INTO CUSTOMERS VALUES (2, 'TechStart Inc', '[email protected]', DATE '2023-03-20', 'SMB', 'UK', 45000, SYSDATE, 'SYSTEM', SYSDATE, 'SYSTEM');
85+
INSERT INTO CUSTOMERS VALUES (3, 'Global Solutions', '[email protected]', DATE '2023-02-10', 'Enterprise', 'Germany', 200000, SYSDATE, 'SYSTEM', SYSDATE, 'SYSTEM');
86+
```
87+
88+
### Sample Products
89+
```sql
90+
INSERT INTO PRODUCTS VALUES (1, 'Enterprise Security Suite', 'Software', 3499.99, 1200, 100, DATE '2023-01-01', SYSDATE, 'SYSTEM', SYSDATE, 'SYSTEM');
91+
INSERT INTO PRODUCTS VALUES (2, 'AI Analytics Platform', 'Software', 2999.99, 1000, 150, DATE '2023-02-01', SYSDATE, 'SYSTEM', SYSDATE, 'SYSTEM');
92+
INSERT INTO PRODUCTS VALUES (3, 'Cloud Storage Pro', 'Cloud', 999.99, 300, 500, DATE '2023-03-01', SYSDATE, 'SYSTEM', SYSDATE, 'SYSTEM');
93+
INSERT INTO PRODUCTS VALUES (4, 'Premium Consulting', 'Services', 5000, 2000, 50, DATE '2023-01-15', SYSDATE, 'SYSTEM', SYSDATE, 'SYSTEM');
94+
INSERT INTO PRODUCTS VALUES (5, 'Training Program', 'Services', 2500, 800, 100, DATE '2023-02-20', SYSDATE, 'SYSTEM', SYSDATE, 'SYSTEM');
95+
```
96+
97+
### Sample Orders
98+
```sql
99+
INSERT INTO ORDERS VALUES (1, 1, DATE '2024-01-15', 8999.98, 'Completed', 'North America', 'John Smith', SYSDATE, 'SYSTEM', SYSDATE, 'SYSTEM');
100+
INSERT INTO ORDERS VALUES (2, 2, DATE '2024-01-20', 2999.99, 'Completed', 'Europe', 'Sarah Johnson', SYSDATE, 'SYSTEM', SYSDATE, 'SYSTEM');
101+
INSERT INTO ORDERS VALUES (3, 3, DATE '2024-02-01', 12499.97, 'Completed', 'Europe', 'Mike Davis', SYSDATE, 'SYSTEM', SYSDATE, 'SYSTEM');
102+
INSERT INTO ORDERS VALUES (4, 1, DATE '2024-02-15', 7500, 'Processing', 'North America', 'John Smith', SYSDATE, 'SYSTEM', SYSDATE, 'SYSTEM');
103+
INSERT INTO ORDERS VALUES (5, 2, DATE '2024-03-01', 999.99, 'Completed', 'Europe', 'Sarah Johnson', SYSDATE, 'SYSTEM', SYSDATE, 'SYSTEM');
104+
```
105+
106+
### Sample Order Items
107+
```sql
108+
INSERT INTO ORDER_ITEMS VALUES (1, 1, 1, 2, 3499.99, 0, SYSDATE, 'SYSTEM', SYSDATE, 'SYSTEM');
109+
INSERT INTO ORDER_ITEMS VALUES (2, 1, 3, 2, 999.99, 10, SYSDATE, 'SYSTEM', SYSDATE, 'SYSTEM');
110+
INSERT INTO ORDER_ITEMS VALUES (3, 2, 2, 1, 2999.99, 0, SYSDATE, 'SYSTEM', SYSDATE, 'SYSTEM');
111+
INSERT INTO ORDER_ITEMS VALUES (4, 3, 1, 1, 3499.99, 0, SYSDATE, 'SYSTEM', SYSDATE, 'SYSTEM');
112+
INSERT INTO ORDER_ITEMS VALUES (5, 3, 2, 2, 2999.99, 10, SYSDATE, 'SYSTEM', SYSDATE, 'SYSTEM');
113+
INSERT INTO ORDER_ITEMS VALUES (6, 3, 5, 1, 2500, 0, SYSDATE, 'SYSTEM', SYSDATE, 'SYSTEM');
114+
INSERT INTO ORDER_ITEMS VALUES (7, 4, 4, 1, 5000, 0, SYSDATE, 'SYSTEM', SYSDATE, 'SYSTEM');
115+
INSERT INTO ORDER_ITEMS VALUES (8, 4, 5, 1, 2500, 0, SYSDATE, 'SYSTEM', SYSDATE, 'SYSTEM');
116+
INSERT INTO ORDER_ITEMS VALUES (9, 5, 3, 1, 999.99, 0, SYSDATE, 'SYSTEM', SYSDATE, 'SYSTEM');
117+
```
118+
119+
## OCI Agent Runtime Configuration
120+
121+
1. Create database connection in OCI Agent Runtime
122+
2. Configure database tool/function with:
123+
- Connection string
124+
- User credentials
125+
- Query permissions
126+
3. Test connection with simple query
127+
4. Update AGENT_ENDPOINT_ID in config.py
128+
129+
130+

0 commit comments

Comments
 (0)