1
1
import os
2
2
import logging
3
- import dotenv
3
+ from dotenv import load_dotenv
4
4
from contextlib import asynccontextmanager
5
5
from fastapi import FastAPI , Request
6
6
from fastapi .staticfiles import StaticFiles
7
7
from fastapi .templating import Jinja2Templates
8
- from routers import messages , assistants_files , tool_outputs
8
+ from fastapi .responses import RedirectResponse
9
+ from routers import files , messages , tools
9
10
10
11
11
12
logger = logging .getLogger ("uvicorn.error" )
12
13
13
- dotenv .load_dotenv ()
14
+ # Get the assistant ID from .env file
15
+ load_dotenv ()
14
16
15
17
@asynccontextmanager
16
18
async def lifespan (app : FastAPI ):
@@ -22,8 +24,8 @@ async def lifespan(app: FastAPI):
22
24
23
25
# Mount routers
24
26
app .include_router (messages .router )
25
- app .include_router (assistants_files .router )
26
- app .include_router (tool_outputs .router )
27
+ app .include_router (files .router )
28
+ app .include_router (tools .router )
27
29
28
30
29
31
# Mount static files (e.g., CSS, JS)
@@ -36,6 +38,12 @@ async def lifespan(app: FastAPI):
36
38
async def read_home (request : Request ):
37
39
logger .info ("Home page requested" )
38
40
41
+ # Check if assistant ID is missing
42
+ if not os .getenv ("ASSISTANT_ID" ):
43
+ return RedirectResponse (url = "/warnings" , message = "Assistant ID is missing" )
44
+ elif not os .getenv ("OPENAI_API_KEY" ):
45
+ return RedirectResponse (url = "/warnings" , message = "OpenAI API key is missing" )
46
+
39
47
categories = {
40
48
"Basic chat" : "basic-chat" ,
41
49
"File search" : "file-search" ,
@@ -107,6 +115,14 @@ async def read_all(request: Request, messages: list = [], thread_id: str = None)
107
115
}
108
116
)
109
117
118
+ # Add new warnings route
119
+ @app .get ("/warnings" )
120
+ async def read_warnings (request : Request ):
121
+ return templates .TemplateResponse (
122
+ "warnings.html" ,
123
+ {"request" : request }
124
+ )
125
+
110
126
if __name__ == "__main__" :
111
127
import uvicorn
112
128
0 commit comments