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
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ This repository contains a complete Retrieval-Augmented Generation (RAG) workflo

The system accepts only `.txt` and `.pdf`, does not persist uploaded files, and supports streamed answers.

The frontend is managed with Yarn 4.17.1 through Corepack and is deployed with Wrangler. The main CI workflow validates the backend with pytest and the frontend with a Yarn 4 immutable install plus a production build.

## Repository Structure

- `app/` FastAPI backend for RAG queries
Expand All @@ -23,14 +25,15 @@ The system accepts only `.txt` and `.pdf`, does not persist uploaded files, and
## Prerequisites

- Python 3.10+
- Node.js 24+ and Yarn
- Node.js 24+
- Corepack-enabled Yarn 4.17.1
- A Hugging Face token

## 1) Clone and Install

```bash
git clone <your-repo-url>
cd nlp_projects
cd doc_rag
pip install -r requirements.txt
cd front
yarn install
Expand All @@ -55,6 +58,12 @@ yarn dev

Open the URL printed by Vite (typically http://localhost:5173).

To deploy the frontend through Cloudflare from the `front/` directory:

```bash
yarn deploy
```

## 4) Use the App

- Paste your Hugging Face token in the frontend (stored in browser localStorage)
Expand All @@ -76,6 +85,7 @@ Optional backend variables:
## Notes

- Uploaded files are processed in-memory and are not stored by the API.
- Frontend install and build should use Yarn 4.17.1 with Corepack enabled.
- Frontend build check:
```bash
cd front
Expand Down
6 changes: 6 additions & 0 deletions app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ From repository root:
uvicorn app.main:app --reload
```

The frontend lives in `front/` and uses Yarn 4.17.1 with Corepack. For the frontend install, build, and deploy commands, see [front/README.md](../front/README.md).

## API Contract

`POST /rag/query` multipart form fields:
Expand All @@ -42,6 +44,10 @@ If `hf_token` is omitted, backend tries `HUGGINGFACE_API_KEY`/`HF_TOKEN`/`HUGGIN
- Keep real secrets in deployment environment variables.
- Rotate the token immediately if it is ever exposed.

## CI Notes

The repository workflow runs backend tests with pytest and validates the frontend with a Yarn 4 immutable install followed by a production build.

## Useful Endpoints

- `GET /docs` (private; requires `DOCS_ACCESS_TOKEN`)
Expand Down
9 changes: 8 additions & 1 deletion front/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,11 @@ dist-ssr
*.njsproj
*.sln
*.sw?
*.gz
*.gz

# wrangler files
.wrangler
.dev.vars*
!.dev.vars.example
.env*
!.env.example
9 changes: 9 additions & 0 deletions front/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

This folder contains the mobile-friendly UI for the RAG system.

The frontend uses Yarn 4.17.1 via Corepack, and the deploy script runs Wrangler from this directory.

## What It Does

- Lets users provide Hugging Face token (stored in browser localStorage)
Expand All @@ -13,9 +15,12 @@ This folder contains the mobile-friendly UI for the RAG system.

```bash
cd front
yarn --version
yarn install
```

If Corepack is not already enabled, run `corepack enable` once in your environment before installing.

## Run (Development)

```bash
Expand All @@ -29,6 +34,8 @@ yarn build
yarn preview
```

`yarn deploy` runs the production build and then executes `wrangler deploy`.

## Backend URL

The app uses `VITE_API_URL` if provided, otherwise defaults to:
Expand All @@ -41,6 +48,8 @@ To override:
VITE_API_URL="https://your-backend-domain/rag/query" VITE_MAX_FILE_SIZE_MB=1 VITE_RATE_LIMIT_MAX_REQUESTS=10 yarn dev
```

The CI workflow uses `yarn install --immutable` and `yarn build` in `front/`.

## Notes

- Token is saved in browser localStorage key `hf_token`.
Expand Down
71 changes: 36 additions & 35 deletions front/package.json
Original file line number Diff line number Diff line change
@@ -1,37 +1,38 @@
{
"name": "front",
"private": true,
"version": "0.0.1",
"packageManager": "yarn@4.17.1",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc -b && vite build",
"deploy": "wrangler deploy",
"lint": "eslint .",
"preview": "vite preview"
},
"dependencies": {
"@rolldown/plugin-babel": "^0.2.3",
"react": "^19.2.4",
"react-dom": "^19.2.4"
},
"devDependencies": {
"@babel/core": "^7.29.0",
"@eslint/js": "^9.39.4",
"@types/babel__core": "^7.20.5",
"@types/node": "^24.12.0",
"@types/react": "^19.2.14",
"@types/react-dom": "^19.2.3",
"@vitejs/plugin-react": "^6.0.0",
"babel-plugin-react-compiler": "^1.0.0",
"eslint": "^9.39.4",
"eslint-plugin-react-hooks": "^7.0.1",
"eslint-plugin-react-refresh": "^0.5.2",
"globals": "^17.4.0",
"typescript": "~5.9.3",
"typescript-eslint": "^8.56.1",
"vite": "^8.0.0",
"wrangler": "^4.17.1"
}
"name": "front",
"private": true,
"version": "0.0.1",
"packageManager": "yarn@4.17.1",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc -b && vite build",
"deploy": "yarn run build && wrangler deploy",
"lint": "eslint .",
"preview": "yarn run build && wrangler dev"
},
"dependencies": {
"@rolldown/plugin-babel": "^0.2.3",
"react": "^19.2.4",
"react-dom": "^19.2.4"
},
"devDependencies": {
"@babel/core": "^7.29.0",
"@cloudflare/vite-plugin": "^1.47.0",
"@eslint/js": "^9.39.4",
"@types/babel__core": "^7.20.5",
"@types/node": "^24.12.0",
"@types/react": "^19.2.14",
"@types/react-dom": "^19.2.3",
"@vitejs/plugin-react": "^6.0.0",
"babel-plugin-react-compiler": "^1.0.0",
"eslint": "^9.39.4",
"eslint-plugin-react-hooks": "^7.0.1",
"eslint-plugin-react-refresh": "^0.5.2",
"globals": "^17.4.0",
"typescript": "~5.9.3",
"typescript-eslint": "^8.56.1",
"vite": "^8.0.0",
"wrangler": "^4.114.0"
}
}
9 changes: 4 additions & 5 deletions front/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ import { defineConfig } from 'vite'
import react, { reactCompilerPreset } from '@vitejs/plugin-react'
import babel from '@rolldown/plugin-babel'

import { cloudflare } from "@cloudflare/vite-plugin";

// https://vite.dev/config/
export default defineConfig({
plugins: [
react(),
babel({ presets: [reactCompilerPreset()] })
],
})
plugins: [react(), babel({ presets: [reactCompilerPreset()] }), cloudflare()],
})
14 changes: 14 additions & 0 deletions front/wrangler.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"$schema": "node_modules/wrangler/config-schema.json",
"name": "doc-rag",
"compatibility_date": "2026-07-24",
"observability": {
"enabled": true
},
"assets": {
"not_found_handling": "single-page-application"
},
"compatibility_flags": [
"nodejs_compat"
]
}
24 changes: 22 additions & 2 deletions front/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,25 @@ __metadata:
languageName: node
linkType: hard

"@cloudflare/vite-plugin@npm:^1.47.0":
version: 1.47.0
resolution: "@cloudflare/vite-plugin@npm:1.47.0"
dependencies:
"@cloudflare/unenv-preset": "npm:2.16.1"
miniflare: "npm:4.20260722.0"
unenv: "npm:2.0.0-rc.24"
workerd: "npm:1.20260722.1"
wrangler: "npm:4.114.0"
ws: "npm:8.21.0"
peerDependencies:
vite: ^6.1.0 || ^7.0.0 || ^8.0.0
wrangler: ^4.114.0
bin:
cf-vite: bin/cf-vite
checksum: 10c0/1748d51fbee3b37769b437e6f6f87aaed1a69b0df404fd948ff1ae4fb16a8985403e8d88999348d89e7a67ca6e3d91da7b8b8e906ce4810e04e2c880ed450737
languageName: node
linkType: hard

"@cloudflare/workerd-darwin-64@npm:1.20260722.1":
version: 1.20260722.1
resolution: "@cloudflare/workerd-darwin-64@npm:1.20260722.1"
Expand Down Expand Up @@ -1933,6 +1952,7 @@ __metadata:
resolution: "front@workspace:."
dependencies:
"@babel/core": "npm:^7.29.0"
"@cloudflare/vite-plugin": "npm:^1.47.0"
"@eslint/js": "npm:^9.39.4"
"@rolldown/plugin-babel": "npm:^0.2.3"
"@types/babel__core": "npm:^7.20.5"
Expand All @@ -1950,7 +1970,7 @@ __metadata:
typescript: "npm:~5.9.3"
typescript-eslint: "npm:^8.56.1"
vite: "npm:^8.0.0"
wrangler: "npm:^4.17.1"
wrangler: "npm:^4.114.0"
languageName: unknown
linkType: soft

Expand Down Expand Up @@ -3064,7 +3084,7 @@ __metadata:
languageName: node
linkType: hard

"wrangler@npm:^4.17.1":
"wrangler@npm:4.114.0, wrangler@npm:^4.114.0":
version: 4.114.0
resolution: "wrangler@npm:4.114.0"
dependencies:
Expand Down
Loading