Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serve Raggenie UI using fastapi #149

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ This configuration ensures that the RAGGENIE system connects to the `chroma` vec

#### Raggenie Frontend

* **Move into the ui folder.**
* Move into the ui folder
```
cd ./ui
```
Expand All @@ -154,6 +154,21 @@ This configuration ensures that the RAGGENIE system connects to the `chroma` vec
```bash
npm run dev
```
* Running RAGGENIE Frontend using fast api

* Update .env file inside `./ui` folder
```env
VITE_BACKEND_URL=""
```
* To serve UI using python server first build the UI
```bash
npm run build
```
* Stop and start python server

```bash
python main.py --config ./config.yaml llm
```

for more details visit [frontend readme](./ui/README.md)

Expand Down
20 changes: 19 additions & 1 deletion app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from app.api.v1.auth import login as login
import app.services.connector_details as commonservices

from fastapi.responses import HTMLResponse


# from app.providers.middleware import AuthMiddleware
from fastapi.staticfiles import StaticFiles
Expand All @@ -28,6 +30,10 @@
import app.services.provider as provider_svc
from app.utils.database import SessionLocal, Base, engine

from fastapi.templating import Jinja2Templates
from fastapi import Request
from typing import Optional

session = SessionLocal()


Expand Down Expand Up @@ -104,8 +110,20 @@ def create_app(config):
logger.info("creating llm fast_api server")
app = FastAPI()

app.mount("/assets",StaticFiles(directory="assets"), name="assets")

app.mount("/assets",StaticFiles(directory="./assets"), name="assets")
app.mount("/ui/assets",StaticFiles(directory="./ui/dist/assets", html=True), name="ui", )

templates = Jinja2Templates(directory="./ui/dist")

@app.get("/ui", response_class=HTMLResponse)
@app.get("/ui/{full_path:path}", response_class=HTMLResponse)
def serve_home(request: Request, full_path: Optional[str]=""):
if request:
return templates.TemplateResponse("index.html", context= {"request": request})
else:
return templates.TemplateResponse("index.html")

app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,5 @@ pre-commit==3.8.0
codespell==2.3.0
flake8==7.1.1
pep8-naming==0.14.1
uvloop==0.20.0; sys_platform != 'win32'
uvloop==0.20.0; sys_platform != 'win32'
Jinja2==3.1.4
2 changes: 1 addition & 1 deletion ui/src/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import "./global.css"

ReactDOM.createRoot(document.getElementById('root')).render(
// <React.StrictMode>
<BrowserRouter>
<BrowserRouter basename="/ui">
<App />
<ToastContainer/>
</BrowserRouter>
Expand Down
2 changes: 1 addition & 1 deletion ui/src/utils/http/Request.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const Request = (method, url, data = {}, params = {}, config = {}, axiosConfig =
loaderContainer.style.display = "none";
}
if (error.response?.status == 401) {
window.location.href = '/login';
window.location.href = '/ui/login';
return null
}
return reject(error)
Expand Down
2 changes: 1 addition & 1 deletion ui/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react-swc'

export default defineConfig({
base: "/",
base: "/ui/",
plugins: [react()],
resolve: {
alias: {
Expand Down