Skip to content
Merged
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,19 @@ pip install -r requirements.txt

# Start the backend server
python main.py

# Or run on a different port
PORT=8001 python main.py
```

```bash
# In another terminal, start the frontend
cd examples/fastapi-example/frontend
npm install
npm run dev

# If the backend is on a different port, set BACKEND_PORT
BACKEND_PORT=8001 npm run dev
```

Then open http://localhost:5173 to see the demo.
Expand Down
18 changes: 18 additions & 0 deletions examples/fastapi-example/frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions examples/fastapi-example/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/node": "^20.0.0",
"@types/react": "^18.2.0",
"@types/react-dom": "^18.2.0",
"@vitejs/plugin-react": "^4.0.0",
Expand Down
42 changes: 25 additions & 17 deletions examples/fastapi-example/frontend/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
import { defineConfig } from "vite";
import { defineConfig, loadEnv } from "vite";
import react from "@vitejs/plugin-react";
import path from "path";
import { fileURLToPath } from "url";

export default defineConfig({
plugins: [react()],
resolve: {
alias: {
"@llmpane/react": path.resolve(__dirname, "../../../packages/llmpane-react/src"),
const __dirname = path.dirname(fileURLToPath(import.meta.url));

export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), "");
const backendPort = env.BACKEND_PORT || "8000";

return {
plugins: [react()],
resolve: {
alias: {
"@llmpane/react": path.resolve(__dirname, "../../../packages/llmpane-react/src"),
},
},
},
server: {
proxy: {
"/api": {
target: "http://localhost:8000",
changeOrigin: true,
server: {
proxy: {
"/api": {
target: `http://localhost:${backendPort}`,
changeOrigin: true,
},
},
},
},
build: {
outDir: "../static",
emptyOutDir: true,
},
build: {
outDir: "../static",
emptyOutDir: true,
},
};
});
4 changes: 3 additions & 1 deletion examples/fastapi-example/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import asyncio
import json
import os
import random
import uuid
from collections.abc import AsyncGenerator
Expand Down Expand Up @@ -257,4 +258,5 @@ async def serve_index():
if __name__ == "__main__":
import uvicorn

uvicorn.run(app, host="0.0.0.0", port=8000)
port = int(os.environ.get("PORT", 8000))
uvicorn.run(app, host="0.0.0.0", port=port)