@@ -33,6 +33,8 @@ async def lifespan(app: FastAPI):
33
33
# Initialize Jinja2 templates
34
34
templates = Jinja2Templates (directory = "templates" )
35
35
36
+ # TODO: Implement some kind of thread id storage or management logic to allow
37
+ # user to load an old thread, delete an old thread, etc. instead of start new
36
38
@app .get ("/" )
37
39
async def read_home (request : Request ):
38
40
logger .info ("Home page requested" )
@@ -42,115 +44,20 @@ async def read_home(request: Request):
42
44
if not os .getenv ("OPENAI_API_KEY" ) or not os .getenv ("ASSISTANT_ID" ):
43
45
return RedirectResponse (url = "/setup" )
44
46
45
- categories = {
46
- "Basic chat" : "basic-chat" ,
47
- "File search" : "file-search" ,
48
- "Function calling" : "function-calling" ,
49
- "All" : "all" ,
50
- }
51
- return templates .TemplateResponse (
52
- "index.html" ,
53
- {
54
- "request" : request ,
55
- "categories" : categories
56
- }
57
- )
58
-
59
- # TODO: Implement some kind of thread id storage or management logic to allow
60
- # user to load an old thread, delete an old thread, etc. instead of start new
61
- @app .get ("/basic-chat" )
62
- async def read_basic_chat (request : Request , messages : list = [], thread_id : str = None ):
63
- # Get assistant ID from environment variables
64
- load_dotenv ()
65
- assistant_id = os .getenv ("ASSISTANT_ID" )
66
-
67
47
# Create a new assistant chat thread if no thread ID is provided
68
48
if not thread_id or thread_id == "None" or thread_id == "null" :
69
49
thread_id : str = await create_thread ()
70
50
71
51
return templates .TemplateResponse (
72
- "examples/basic-chat .html" ,
52
+ "index .html" ,
73
53
{
74
54
"request" : request ,
75
- "assistant_id" : assistant_id ,
55
+ "assistant_id" : os . getenv ( "ASSISTANT_ID" ) ,
76
56
"messages" : messages ,
77
57
"thread_id" : thread_id
78
58
}
79
59
)
80
60
81
- @app .get ("/file-search" )
82
- async def read_file_search (request : Request , messages : list = [], thread_id : str = None ):
83
- # Get assistant ID from environment variables
84
- load_dotenv ()
85
- assistant_id = os .getenv ("ASSISTANT_ID" )
86
-
87
- # Create a new assistant chat thread if no thread ID is provided
88
- if not thread_id or thread_id == "None" or thread_id == "null" :
89
- thread_id : str = await create_thread ()
90
-
91
- return templates .TemplateResponse (
92
- "examples/file-search.html" ,
93
- {
94
- "request" : request ,
95
- "messages" : messages ,
96
- "thread_id" : thread_id ,
97
- "assistant_id" : assistant_id , # Add assistant_id to template context
98
- }
99
- )
100
-
101
- @app .get ("/function-calling" )
102
- async def read_function_calling (request : Request , messages : list = [], thread_id : str = None ):
103
- # Get assistant ID from environment variables
104
- load_dotenv ()
105
- assistant_id = os .getenv ("ASSISTANT_ID" )
106
-
107
- # Create a new assistant chat thread if no thread ID is provided
108
- if not thread_id or thread_id == "None" or thread_id == "null" :
109
- thread_id : str = await create_thread ()
110
-
111
- # Define the condition class map
112
- conditionClassMap = {
113
- "Cloudy" : "weatherBGCloudy" ,
114
- "Sunny" : "weatherBGSunny" ,
115
- "Rainy" : "weatherBGRainy" ,
116
- "Snowy" : "weatherBGSnowy" ,
117
- "Windy" : "weatherBGWindy" ,
118
- }
119
-
120
- return templates .TemplateResponse (
121
- "examples/function-calling.html" ,
122
- {
123
- "conditionClassMap" : conditionClassMap ,
124
- "location" : "---" ,
125
- "temperature" : "---" ,
126
- "conditions" : "Sunny" ,
127
- "isEmpty" : True ,
128
- "thread_id" : thread_id ,
129
- "messages" : messages ,
130
- "assistant_id" : assistant_id , # Add assistant_id to template context
131
- }
132
- )
133
-
134
-
135
- @app .get ("/all" )
136
- async def read_all (request : Request , messages : list = [], thread_id : str = None ):
137
- # Get assistant ID from environment variables
138
- load_dotenv ()
139
- assistant_id = os .getenv ("ASSISTANT_ID" )
140
-
141
- # Create a new assistant chat thread if no thread ID is provided
142
- if not thread_id or thread_id == "None" or thread_id == "null" :
143
- thread_id : str = await create_thread ()
144
-
145
- return templates .TemplateResponse (
146
- "examples/all.html" ,
147
- {
148
- "request" : request ,
149
- "assistant_id" : assistant_id , # Add assistant_id to template context
150
- "thread_id" : thread_id ,
151
- "messages" : messages
152
- }
153
- )
154
61
155
62
# Add new setup route
156
63
@app .get ("/setup" )
0 commit comments