forked from ragapp/ragapp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
62 lines (50 loc) · 1.9 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from dotenv import load_dotenv
from src.constants import ENV_FILE_PATH
load_dotenv(
dotenv_path=ENV_FILE_PATH,
)
import os
import logging
import uvicorn
from fastapi import FastAPI
from fastapi.responses import RedirectResponse, FileResponse
from fastapi.staticfiles import StaticFiles
from create_llama.backend.app.settings import init_settings
from create_llama.backend.app.api.routers.chat import chat_router
from src.routers.management.config import config_router
from src.routers.management.files import files_router
from src.routers.management.tools import tools_router
from fastapi.middleware.cors import CORSMiddleware
app = FastAPI()
init_settings()
environment = os.getenv("ENVIRONMENT")
if environment == "dev":
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# Add chat router from create_llama/backend
app.include_router(chat_router, prefix="/api/chat")
app.include_router(config_router, prefix="/api/management/config")
app.include_router(files_router, prefix="/api/management/files")
app.include_router(tools_router, prefix="/api/management/tools")
@app.get("/")
async def redirect():
from src.models.env_config import get_config
config = get_config()
if config.configured:
# system is configured - / points to chat UI
return FileResponse("static/index.html")
else:
# system is not configured - redirect to onboarding page
return RedirectResponse(url="/admin/#new")
app.mount("/api/data", StaticFiles(directory="data"), name="static")
app.mount("", StaticFiles(directory="static", html=True), name="static")
if __name__ == "__main__":
app_host = os.getenv("APP_HOST", "0.0.0.0")
app_port = int(os.getenv("APP_PORT", "8000"))
reload = environment == "dev"
uvicorn.run(app="main:app", host=app_host, port=app_port, reload=reload)