Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Applications and reference implementations demonstrating how to build AI-powered
| FitTracker | Gamified fitness platform built with Oracle 26ai JSON Duality Views (FastAPI + Redis), created live during a webinar. | [![View App](https://img.shields.io/badge/View%20App-blue?style=flat-square)](./apps/FitTracker) |
| agentic_rag | Intelligent RAG system with multi-agent Chain of Thought (CoT), PDF/Web/Repo processing, and Oracle AI Database 26ai integration | [![View App](https://img.shields.io/badge/View%20App-blue?style=flat-square)](./apps/agentic_rag) |
| finance-ai-agent-demo | Financial services AI agent with Oracle AI Database as a unified memory core for vector, graph, spatial, and relational queries | [![View App](https://img.shields.io/badge/View%20App-blue?style=flat-square)](./apps/finance-ai-agent-demo) |
| generative-ui-data-chat | Next.js and [OpenUI](https://github.com/thesysdev/openui) data chatbot that pairs Oracle AI Database 26ai SQL, vector, and hybrid search with typed generative UI components such as charts, KPI cards, tables, and source cards. | [![View App](https://img.shields.io/badge/View%20App-blue?style=flat-square)](./apps/generative-ui-data-chat) |
| oci-generative-ai-jet-ui | Full-stack AI application with Oracle JET UI, OCI Generative AI integration, Kubernetes deployment, and Terraform infrastructure | [![View App](https://img.shields.io/badge/View%20App-blue?style=flat-square)](./apps/oci-generative-ai-jet-ui) |
| tanstack-shoe-store | AI chat app using TanStack Start and Oracle 26ai Select AI to query a shoe store database with natural language | [![View App](https://img.shields.io/badge/View%20App-blue?style=flat-square)](./apps/tanstack-shoe-store) |
| oracle-data-migration-harness | AI agent harness that migrates a RAG corpus from MongoDB into Oracle AI Database 26ai while preserving vector search and unlocking SQL/JSON Duality queries | [![View App](https://img.shields.io/badge/View%20App-blue?style=flat-square)](./apps/oracle-data-migration-harness) |
Expand Down
1 change: 1 addition & 0 deletions apps/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Applications and reference implementations demonstrating how to build AI-powered
| agent-reasoning | Interactive TUI + CLI demo of 11 cognitive architectures (Chain of Thought, Tree of Thoughts, ReAct, Self-Reflection, and more) for agent reasoning. | [![View App](https://img.shields.io/badge/View%20App-blue?style=flat-square)](./agent-reasoning) |
| agentic_rag | Intelligent RAG system with multi-agent Chain of Thought (CoT), PDF/Web/Repo processing, and Oracle AI Database 26ai integration. | [![View App](https://img.shields.io/badge/View%20App-blue?style=flat-square)](./agentic_rag) |
| finance-ai-agent-demo | Agentic Financial Service Assistant — Oracle AI Database as a unified memory core for vector, graph, spatial, and relational queries in one agent loop. | [![View App](https://img.shields.io/badge/View%20App-blue?style=flat-square)](./finance-ai-agent-demo) |
| generative-ui-data-chat | Next.js and [OpenUI](https://github.com/thesysdev/openui) data chatbot that pairs Oracle AI Database 26ai SQL, vector, and hybrid search with typed generative UI components such as charts, KPI cards, tables, and source cards. | [![View App](https://img.shields.io/badge/View%20App-blue?style=flat-square)](./generative-ui-data-chat) |
| limitless-workflow | Claude Code-first understanding machine powered by Oracle AI Database. | [![View App](https://img.shields.io/badge/View%20App-blue?style=flat-square)](./limitless-workflow) |
| oci-generative-ai-jet-ui | Full-stack AI application with Oracle JET UI, OCI Generative AI integration, Kubernetes deployment, and Terraform infrastructure. | [![View App](https://img.shields.io/badge/View%20App-blue?style=flat-square)](./oci-generative-ai-jet-ui) |
| oracle-data-migration-harness | AI agent harness that migrates a RAG corpus from MongoDB into Oracle AI Database 26ai while preserving vector search and unlocking SQL/JSON Duality queries. | [![View App](https://img.shields.io/badge/View%20App-blue?style=flat-square)](./oracle-data-migration-harness) |
Expand Down
12 changes: 12 additions & 0 deletions apps/generative-ui-data-chat/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# OCI GenAI or any OpenAI-compatible chat completions endpoint.
LLM_BASE_URL=http://localhost:9999/v1
LLM_API_KEY=oci-genai
LLM_MODEL=xai.grok-4

# Local Docker Oracle Database Free/26ai defaults.
ORACLE_USER=DATA_CHAT
ORACLE_PASSWORD=DataChatPwd_2026
ORACLE_CONNECTION_STRING=127.0.0.1:1522/FREEPDB1

# Optional admin password used by scripts/setup_db.sh.
ORACLE_ADMIN_PWD=OraclePwd_2026
9 changes: 9 additions & 0 deletions apps/generative-ui-data-chat/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
node_modules
.next
out
dist
coverage
.env
.env*.local
*.local
.DS_Store
17 changes: 17 additions & 0 deletions apps/generative-ui-data-chat/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Copyright (c) 2026 Oracle and/or its affiliates.

The Universal Permissive License (UPL), Version 1.0

Subject to the condition set forth below, permission is hereby granted to any person obtaining a copy of this software, associated documentation and/or data (collectively the "Software"), free of charge and under any and all copyright rights in the Software, and any and all patent rights owned or freely licensable by each licensor hereunder covering either (i) the unmodified Software as contributed to or provided by such licensor, or (ii) the Larger Works (as defined below), to deal in both

(a) the Software, and

(b) any piece of software and/or hardware listed in the lrgrwrks.txt file if one is included with the Software (each a "Larger Work" to which the Software is contributed by such licensors),

without restriction, including without limitation the rights to copy, create derivative works of, display, perform, and distribute the Software and make, use, sell, offer for sale, import, export, have made, and have sold the Software and the Larger Work(s), and to sublicense the foregoing rights on either these or other terms.

This license is subject to the following condition:

The above copyright notice and either this complete permission notice or at a minimum a reference to the UPL must be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
155 changes: 155 additions & 0 deletions apps/generative-ui-data-chat/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@



# Generative UI Data Chat

Copyright (c) 2026 Oracle and/or its affiliates.

A Next.js and [OpenUI](https://github.com/thesysdev/openui) reference app showing how Oracle AI Database 26ai can back a data chatbot experience that returns typed UI components instead of plain text. The model chooses a query strategy and rendering shape, the server validates that plan, Oracle executes SQL/vector/hybrid retrieval, and React renders the result with [`@openuidev/react-ui`](https://www.npmjs.com/package/@openuidev/react-ui) as charts, tables, KPI cards, source cards, or mixed insight views.

## Demo

https://github.com/user-attachments/assets/34cb03eb-5648-4fa0-9cba-8de8faebaa81


[Watch the demo video](./oracle.mp4)

## Architecture

```text
Browser (Next.js App Router)
|-- Chat transcript and composer
|-- OpenUI / @openuidev/react-ui generative UI renderer
|-- Oracle query trace
|
Next.js Node runtime API route (/api/chat)
|-- OpenAI-compatible LLM call (OCI GenAI proxy or hosted endpoint)
|-- Zod validation for the plan and response envelope
|-- SQL / vector / hybrid query executors
|
Oracle AI Database 26ai
|-- Revenue, account, and active-user tables
|-- Contract chunks with VECTOR embeddings
|-- Oracle Text index for hybrid evidence search
```

## What This Demonstrates

- Structured questions map to SQL-backed UI, including line charts, area charts, bar charts, horizontal rankings, donut charts, tables, and KPI cards.
- Contract/evidence questions map to vector-backed source cards with citations.
- Mixed questions use hybrid retrieval, combining revenue trend SQL with Oracle Text and vector evidence.
- [OpenUI](https://github.com/thesysdev/openui) ([`@openuidev/react-ui`](https://www.npmjs.com/package/@openuidev/react-ui)) supplies the app shell primitives, chart, table, cards, tags, callouts, follow-up buttons, and trace accordion styling.
- The API response is a typed `DataChatResponse` JSON envelope, not markdown.

## Prerequisites

- Node.js 20+
- Docker Desktop
- Access to an OpenAI-compatible chat-completions endpoint. For OCI Generative AI, you can use a local OpenAI-compatible proxy and set `LLM_BASE_URL` to that proxy.

## Quick Start

All commands assume you are in `apps/generative-ui-data-chat`.

```bash
npm install
cp .env.example .env.local
bash scripts/setup_db.sh
npm run db:seed
npm run dev
```

Open http://localhost:3000.

## Environment Variables

| Variable | Required | Description |
| --- | --- | --- |
| `LLM_BASE_URL` | Yes | OpenAI-compatible base URL, for example `http://localhost:9999/v1` for an OCI GenAI proxy. |
| `LLM_API_KEY` | Yes | API key or proxy token. |
| `LLM_MODEL` | Yes | Model id, for example `xai.grok-4`, `meta.llama-3.3-70b-instruct`, or another OCI-hosted model id exposed by your proxy. |
| `ORACLE_USER` | Yes | App user. Local default: `DATA_CHAT`. |
| `ORACLE_PASSWORD` | Yes | App password. Local default: `DataChatPwd_2026`. |
| `ORACLE_CONNECTION_STRING` | Yes | Local default: `127.0.0.1:1522/FREEPDB1`. |
| `ORACLE_ADMIN_PWD` | Local setup only | Admin password used by the Docker setup script. |

## Demo Prompts

- `Revenue trend over the last 12 months`
- `Top 5 accounts by region in Q1`
- `Active users this month`
- `Which contracts mention auto-renewal?`
- `What's driving the dip in March?`
- `Can you analyse the data into a dashboard?`

## API Contract

```http
POST /api/chat
Content-Type: application/json

{ "message": "Revenue trend over the last 12 months" }
```

Response:

```json
{
"answer": {
"title": "Revenue trend",
"summary": "Revenue ended at ...",
"components": [
{
"type": "lineChart",
"title": "Revenue over the last 12 months",
"xKey": "month",
"yKey": "revenue",
"data": []
}
]
},
"queryTrace": [
{
"strategy": "sql",
"label": "Revenue trend",
"statement": "SELECT ...",
"elapsedMs": 42,
"rowCount": 13
}
]
}
```

Supported component types are `lineChart`, `areaChart`, `barChart`, `horizontalBarChart`, `pieChart`, `comparisonTable`, `kpiCard`, `sourceCards`, and `mixedInsight`.

## Database Notes

The seed script creates:

- `revenue_metrics`
- `accounts`
- `active_user_metrics`
- `contracts`
- `contract_chunks`
- Oracle Text index on `contract_chunks.chunk_text`
- Optional vector index on `contract_chunks.embedding`

The demo uses deterministic 8-dimensional vectors so it can run without a separate embedding service. In a production implementation, replace those seed vectors with embeddings generated by OCI Generative AI, ONNX in-database embeddings, or another approved embedding model.

## Development

```bash
npm run test
npm run build
```

## V1 Limitations

- No authentication, RBAC, tenant isolation, or query policy enforcement.
- The model chooses from five supported demo intents.
- The server owns executable SQL and vector queries for reliability; the model returns a validated plan rather than arbitrary SQL.
- Full OCI deployment automation is intentionally out of scope for the first PR.

## License

Licensed under the Universal Permissive License (UPL), Version 1.0. See [LICENSE](LICENSE).
101 changes: 101 additions & 0 deletions apps/generative-ui-data-chat/app/api/chat/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import { NextResponse } from "next/server";
import { ZodError } from "zod";

import { runDataChat } from "@/lib/data-chat";
import { DataChatApiRequestSchema } from "@/lib/schemas";

export const runtime = "nodejs";
export const dynamic = "force-dynamic";

const encoder = new TextEncoder();

function wantsStream(request: Request) {
return request.headers.get("accept")?.includes("text/event-stream") ?? false;
}

function encodeEvent(event: string, data: unknown) {
return encoder.encode(`event: ${event}\ndata: ${JSON.stringify(data)}\n\n`);
}

export async function POST(request: Request) {
try {
const body = DataChatApiRequestSchema.parse(await request.json());

if (wantsStream(request)) {
let isClosed = false;
const markClosed = () => {
isClosed = true;
};

const stream = new ReadableStream<Uint8Array>({
start(controller) {
const safeEnqueue = (event: string, data: unknown) => {
if (isClosed) {
return;
}

try {
controller.enqueue(encodeEvent(event, data));
} catch {
markClosed();
}
};
const closeOnce = () => {
if (isClosed) {
return;
}

markClosed();
try {
controller.close();
} catch {
// The client may have already closed the stream.
}
};

request.signal.addEventListener("abort", markClosed, { once: true });

void runDataChat(body.message, {
onProgress: (progress) => {
safeEnqueue("status", progress);
}
})
.then((response) => {
safeEnqueue("complete", response);
})
.catch((error) => {
const message = error instanceof Error ? error.message : "Unknown data chat error";
safeEnqueue("error", { error: message });
})
.finally(closeOnce);
},
cancel() {
markClosed();
}
});

return new Response(stream, {
headers: {
"Cache-Control": "no-cache, no-transform",
Connection: "keep-alive",
"Content-Type": "text/event-stream; charset=utf-8",
"X-Accel-Buffering": "no"
}
});
}

const response = await runDataChat(body.message);

return NextResponse.json(response);
} catch (error) {
const status = error instanceof ZodError ? 400 : 500;
const message = error instanceof Error ? error.message : "Unknown data chat error";

return NextResponse.json(
{
error: message
},
{ status }
);
}
}
Loading