Skip to content

Commit 4b551c8

Browse files
chore: update demo readmes (#189)
1 parent 5885bfe commit 4b551c8

File tree

2 files changed

+98
-76
lines changed

2 files changed

+98
-76
lines changed

demo/browser/README.md

Lines changed: 51 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,55 @@
1-
# React + TypeScript + Vite
2-
3-
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
4-
5-
Currently, two official plugins are available:
6-
7-
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
8-
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
9-
10-
## Expanding the ESLint configuration
11-
12-
If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
13-
14-
```js
15-
export default tseslint.config({
16-
extends: [
17-
// Remove ...tseslint.configs.recommended and replace with this
18-
...tseslint.configs.recommendedTypeChecked,
19-
// Alternatively, use this for stricter rules
20-
...tseslint.configs.strictTypeChecked,
21-
// Optionally, add this for stylistic rules
22-
...tseslint.configs.stylisticTypeChecked,
23-
],
24-
languageOptions: {
25-
// other options...
26-
parserOptions: {
27-
project: ["./tsconfig.node.json", "./tsconfig.app.json"],
28-
tsconfigRootDir: import.meta.dirname,
29-
},
30-
},
31-
});
1+
# Browser Workflow Demo
2+
3+
Run LlamaIndex workflows directly in the browser with React and Vite.
4+
This demo renders workflow output and showcases the streaming APIs without any server component.
5+
6+
## Highlights
7+
- Fully client-side workflow execution with the `WorkflowContext` stream API
8+
- Event chaining example using `startEvent` and `stopEvent` to emit UI updates
9+
10+
## Prerequisites
11+
- Node.js 20+
12+
- npm, pnpm, or yarn (examples below use npm)
13+
14+
## Getting Started
15+
```bash
16+
npm install
17+
npm run dev
18+
```
19+
The dev server starts on http://localhost:5173 by default.
20+
21+
To create a production build, run:
22+
```bash
23+
npm run build
24+
npm run preview
3225
```
3326

34-
You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:
35-
36-
```js
37-
// eslint.config.js
38-
import reactX from "eslint-plugin-react-x";
39-
import reactDom from "eslint-plugin-react-dom";
40-
41-
export default tseslint.config({
42-
plugins: {
43-
// Add the react-x and react-dom plugins
44-
"react-x": reactX,
45-
"react-dom": reactDom,
46-
},
47-
rules: {
48-
// other rules...
49-
// Enable its recommended typescript rules
50-
...reactX.configs["recommended-typescript"].rules,
51-
...reactDom.configs.recommended.rules,
52-
},
27+
## How It Works
28+
The demo defines two events and a simple workflow in `src/App.tsx`:
29+
```ts
30+
const startEvent = workflowEvent();
31+
const stopEvent = workflowEvent<string>();
32+
33+
workflow.handle([startEvent], (context) => {
34+
setTimeout(() => {
35+
context.sendEvent(stopEvent.with("Hello, World!"));
36+
}, 1000);
5337
});
38+
39+
const context = workflow.createContext();
40+
context.sendEvent(startEvent.with());
41+
const events = await context.stream.until(stopEvent).toArray();
5442
```
43+
- `startEvent` triggers when the component loads.
44+
- The handler fires an async side effect, then emits `stopEvent`.
45+
- `context.stream.until(stopEvent)` collects the events and the component renders the payload.
46+
47+
## Customize the Workflow
48+
- Edit `src/App.tsx` to add additional events, stateful middleware, or validation.
49+
- Import React hooks to stream multiple updates or feed results into components.
50+
51+
## Project Structure
52+
- `src/` – React components and workflow definition
53+
- `public/` – Static assets served by Vite
54+
- `vite.config.ts` – Vite configuration with the React SWC plugin
55+

demo/next/README.md

Lines changed: 47 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,57 @@
1-
This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app).
2-
3-
## Getting Started
4-
5-
First, run the development server:
6-
1+
# Next.js AI News Report Demo
2+
3+
Generate downloadable news briefs with a server-side LlamaIndex workflow. This Next.js app orchestrates OpenAI web search, report writing, and PDF conversion
4+
and surfaces the results in a polished Tailwind UI.
5+
6+
## Highlights
7+
- Multi-stage workflow (`userInputEvent → webSearchEvent → createReportEvent → finalResponseEvent`)
8+
- OpenAI Responses API with Zod parsing for query validation and report generation
9+
- Server-side PDF rendering via Puppeteer with instant preview and download links
10+
- Client UI built with Next.js App Router, Radix UI primitives, and Tailwind utilities
11+
12+
## Requirements
13+
- Node.js 20+
14+
- `OPENAI_API_KEY` available to the server (set in `.env.local`)
15+
- Chrome-compatible environment for Puppeteer PDF rendering (works locally by default)
16+
17+
## Setup
18+
1. Install dependencies:
19+
```bash
20+
npm install
21+
```
22+
2. Create `.env.local` in this directory:
23+
```bash
24+
echo "OPENAI_API_KEY=your-key" > .env.local
25+
```
26+
27+
## Run the Demo
728
```bash
829
npm run dev
9-
# or
10-
yarn dev
11-
# or
12-
pnpm dev
13-
# or
14-
bun dev
1530
```
31+
Visit http://localhost:3000 to access the News Report Generator.
1632

17-
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
18-
19-
You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
20-
21-
This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel.
22-
23-
## Learn More
33+
For production builds:
34+
```bash
35+
npm run build
36+
npm start
37+
```
2438

25-
To learn more about Next.js, take a look at the following resources:
39+
## Workflow Overview
40+
Core orchestration lives in `src/utils/ai-workflow.ts`:
41+
- `userInputEvent` validates the search request with `evaluateQueryAndEnhance`
42+
- `webSearchEvent` calls OpenAI's web search tool to gather context
43+
- `createReportEvent` composes a markdown report with title/content fields
44+
- `finalResponseEvent` returns either a refusal message or the generated PDF path
2645

27-
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
28-
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
46+
The route `src/app/api/report/route.ts` runs the workflow and returns the output path. A follow-up `POST /api/download` route streams the PDF back to the client.
2947

30-
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome!
48+
## UI Flow
49+
`src/app/page.tsx` collects the query, tracks workflow status, and renders results. The `FileDisplay` component provides PDF preview and download controls once a report is available.
3150

32-
## Deploy on Vercel
51+
Generated PDFs are stored in `public/outputs/pdfs`. Files served from `/outputs/pdfs/...` are accessible directly in the browser and through the download endpoint.
3352

34-
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
53+
## Customizing
54+
- Extend the workflow with additional events (e.g., fact checking) or middleware
55+
- Adjust PDF styling in `src/utils/pdf-conversion.ts`
56+
- Update UI components under `src/components` for different branding or layouts
3557

36-
Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details.

0 commit comments

Comments
 (0)