Skip to content

Commit c225a7c

Browse files
Fixed some bad file path and template hierarchy references and included request object in the page template responses
1 parent 12d15a9 commit c225a7c

File tree

12 files changed

+53
-99
lines changed

12 files changed

+53
-99
lines changed

__pycache__/main.cpython-312.pyc

3.3 KB
Binary file not shown.

main.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import logging
22
import dotenv
33
from contextlib import asynccontextmanager
4-
from fastapi import FastAPI
4+
from fastapi import FastAPI, Request
55
from fastapi.staticfiles import StaticFiles
66
from fastapi.templating import Jinja2Templates
7+
import os
78

89

910
logger = logging.getLogger("uvicorn.error")
@@ -20,32 +21,37 @@ async def lifespan(app: FastAPI):
2021
app = FastAPI(lifespan=lifespan)
2122

2223
# Mount static files (e.g., CSS, JS)
23-
app.mount("/static", StaticFiles(directory="static"), name="static")
24+
app.mount("/static", StaticFiles(directory=os.path.join(os.getcwd(), "static")), name="static")
2425

2526
# Initialize Jinja2 templates
2627
templates = Jinja2Templates(directory="templates")
2728

2829

2930
@app.get("/")
30-
async def read_home(
31-
):
31+
async def read_home(request: Request):
3232
categories = {
3333
"Basic chat": "basic-chat",
3434
"File search": "file-search",
3535
"Function calling": "function-calling",
3636
"All": "all",
3737
}
38-
return templates.TemplateResponse("index.html", {"categories": categories})
38+
return templates.TemplateResponse("index.html", {"request": request, "categories": categories})
39+
40+
41+
@app.get("/basic-chat")
42+
async def read_basic_chat(request: Request):
43+
messages = []
44+
45+
return templates.TemplateResponse("examples/basic-chat.html", {"request": request, "messages": messages})
3946

4047

4148
@app.get("/file-search")
42-
async def read_file_search(
43-
):
44-
return templates.TemplateResponse("file-search.html")
49+
async def read_file_search(request: Request):
50+
return templates.TemplateResponse("examples/file-search.html", {"request": request})
4551

4652

4753
@app.get("/function-calling")
48-
async def read_function_calling():
54+
async def read_function_calling(request: Request):
4955
# Define the condition class map
5056
conditionClassMap = {
5157
"Cloudy": "weatherBGCloudy",
@@ -63,7 +69,7 @@ async def read_function_calling():
6369

6470
# Pass all necessary context variables to the template
6571
return templates.TemplateResponse(
66-
"function-calling.html",
72+
"examples/function-calling.html",
6773
{
6874
"conditionClassMap": conditionClassMap,
6975
"location": location,
@@ -75,9 +81,8 @@ async def read_function_calling():
7581

7682

7783
@app.get("/all")
78-
async def read_all(
79-
):
80-
return templates.TemplateResponse("all.html")
84+
async def read_all(request: Request):
85+
return templates.TemplateResponse("examples/all.html", {"request": request})
8186

8287

8388
if __name__ == "__main__":

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
[project]
2-
name = "openai-assistants-quickstart"
2+
name = "openai-assistants-python-quickstart"
33
version = "0.1.0"
44
description = "Add your description here"
55
readme = "README.md"
6-
requires-python = ">=3.11"
6+
requires-python = ">=3.12"
77
dependencies = [
88
"fastapi>=0.115.3",
99
"jinja2>=3.1.4",

templates/components/chat.html

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
{% extends "base.html" %}
2-
3-
{% block content %}
41
<div class="chatContainer">
52
<div class="messages">
63
{% for msg in messages %}
@@ -39,4 +36,3 @@
3936
</button>
4037
</form>
4138
</div>
42-
{% endblock %}

templates/components/file-viewer.html

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
{% extends "base.html" %}
2-
3-
{% block content %}
41
<div class="fileViewer">
52
<div class="filesList {{ 'grow' if files|length != 0 else '' }}">
63
{% if files|length == 0 %}
@@ -34,6 +31,4 @@
3431
<button type="submit">Upload</button>
3532
</form>
3633
</div>
37-
</div>
38-
{% endblock %}
39-
34+
</div>

templates/components/warnings.html

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,22 @@
1-
{% extends "base.html" %}
2-
3-
{% block content %}
4-
{% if not assistant_id %}
5-
<div class="warningsContainer">
6-
<h1>Start by creating your assistant</h1>
7-
<div class="warningsMessage">
8-
Create an assistant and set its ID in
9-
<span>app/assistant-config.ts</span>
10-
</div>
11-
{% if not new_assistant_id %}
12-
<form method="post" action="/api/assistants">
13-
<button type="submit" class="warningsButton">
14-
{% if loading %}
15-
Loading...
16-
{% else %}
17-
Create Assistant
18-
{% endif %}
19-
</button>
20-
</form>
21-
{% else %}
22-
<div class="warningsResult">{{ new_assistant_id }}</div>
23-
{% endif %}
1+
{% if not assistant_id %}
2+
<div class="warningsContainer">
3+
<h1>Start by creating your assistant</h1>
4+
<div class="warningsMessage">
5+
Create an assistant and set its ID in
6+
<span>app/assistant-config.ts</span>
247
</div>
25-
{% endif %}
26-
{% endblock %}
27-
8+
{% if not new_assistant_id %}
9+
<form method="post" action="/api/assistants">
10+
<button type="submit" class="warningsButton">
11+
{% if loading %}
12+
Loading...
13+
{% else %}
14+
Create Assistant
15+
{% endif %}
16+
</button>
17+
</form>
18+
{% else %}
19+
<div class="warningsResult">{{ new_assistant_id }}</div>
20+
{% endif %}
21+
</div>
22+
{% endif %}
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
{% extends "base.html" %}
2-
3-
{% block content %}
41
<div class="{{ 'weatherWidget' }} {{ 'weatherEmptyState' if isEmpty else conditionClassMap.get(conditions, 'weatherBGSunny') }}">
52
<div class="weatherWidgetData">
63
{% if isEmpty %}
@@ -12,6 +9,4 @@ <h2>{{ temperature if temperature != '---' else temperature }}°F</h2>
129
<p>{{ conditions }}</p>
1310
{% endif %}
1411
</div>
15-
</div>
16-
{% endblock %}
17-
12+
</div>

templates/examples/file-search.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<main class="main">
55
<div class="container">
66
<div class="column">
7-
{% include "components/file-viewer.html" with files=files %}
7+
{% include "components/file-viewer.html" %}
88
</div>
99
<div class="chatContainer">
1010
<div class="chat">

templates/examples/function-calling.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
<main class="main">
55
<div class="container">
66
<div class="column">
7-
{% include "components/weather-widget.html" with context %}
7+
{% include "components/weather-widget.html" %}
88
</div>
99
<div class="chatContainer">
1010
<div class="chat">
11-
{% include "components/chat.html" with context %}
11+
{% include "components/chat.html" %}
1212
</div>
1313
</div>
1414
</div>

templates/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</div>
88
<div class="container">
99
{% for name, url in categories.items() %}
10-
<a class="category" href="/examples/{{ url }}">
10+
<a class="category" href="/{{ url }}">
1111
{{ name }}
1212
</a>
1313
{% endfor %}

0 commit comments

Comments
 (0)