Skip to content

Commit 35bd4ff

Browse files
Termination of event stream works
1 parent 132a7dd commit 35bd4ff

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

routers/messages.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,16 @@ async def event_generator():
5656
assistant_id=assistant_id,
5757
thread_id=thread_id
5858
)
59+
5960
async with stream as stream_manager:
6061
async for text in stream_manager.text_deltas:
62+
logger.info(text)
6163
yield f"data: {text}\n\n"
6264

65+
logger.info("Sending end message")
66+
6367
# Send a done event when the stream is complete
64-
yield f"event: EndMessage\n\n"
68+
yield "event: EndMessage\ndata: DONE\n\n"
6569

6670
return StreamingResponse(
6771
event_generator(),

static/styles.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@ pre {
158158
height: 100%;
159159
}
160160

161+
.assistantMessage {
162+
white-space: pre-wrap;
163+
}
164+
161165
.fileViewer {
162166
display: flex;
163167
flex-direction: column;

templates/layout.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
<link rel="icon" href="{{ url_for('static', path='openai.svg') }}">
88
<link rel="stylesheet" href="{{ url_for('static', path='styles.css') }}">
99
<link rel="favicon" href="{{ url_for('static', path='favicon.png') }}">
10-
<script src="https://unpkg.com/htmx.org@1.9.10"></script>
11-
<script src="https://unpkg.com/htmx.org/dist/ext/sse.js"></script>
10+
<script src="https://unpkg.com/htmx.org@2.0.4" integrity="sha384-HGfztofotfshcF7+8n44JQL2oJmowVChPTg48S+jvZoztPfvwD79OC/LTtG6dMp+" crossorigin="anonymous"></script>
11+
<script src="https://unpkg.com/htmx-ext[email protected]/sse.js"></script>
1212
</head>
1313
<body>
1414
{% block content %}

0 commit comments

Comments
 (0)