Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit dc39cc0

Browse filesBrowse files
committed
Use server sent events function for streaming completion
1 parent f0ec6e6 commit dc39cc0
Copy full SHA for dc39cc0

File tree

Expand file treeCollapse file tree

1 file changed

+8
-1
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+8
-1
lines changed

‎llama_cpp/server/app.py

Copy file name to clipboardExpand all lines: llama_cpp/server/app.py
+8-1Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,15 @@ def create_completion(
259259
)
260260
)
261261
if request.stream:
262+
263+
async def server_sent_events(
264+
chunks: Iterator[llama_cpp.CompletionChunk],
265+
):
266+
for chunk in chunks:
267+
yield dict(data=json.dumps(chunk))
268+
262269
chunks: Iterator[llama_cpp.CompletionChunk] = completion_or_chunks # type: ignore
263-
return EventSourceResponse(dict(data=json.dumps(chunk)) for chunk in chunks)
270+
return EventSourceResponse(server_sent_events(chunks))
264271
completion: llama_cpp.Completion = completion_or_chunks # type: ignore
265272
return completion
266273

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.