mirror of
https://github.com/abetlen/llama-cpp-python.git
synced 2023-09-07 17:34:22 +03:00
Use server sent events function for streaming completion
This commit is contained in:
@@ -259,8 +259,15 @@ def create_completion(
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
if request.stream:
|
if request.stream:
|
||||||
|
|
||||||
|
async def server_sent_events(
|
||||||
|
chunks: Iterator[llama_cpp.CompletionChunk],
|
||||||
|
):
|
||||||
|
for chunk in chunks:
|
||||||
|
yield dict(data=json.dumps(chunk))
|
||||||
|
|
||||||
chunks: Iterator[llama_cpp.CompletionChunk] = completion_or_chunks # type: ignore
|
chunks: Iterator[llama_cpp.CompletionChunk] = completion_or_chunks # type: ignore
|
||||||
return EventSourceResponse(dict(data=json.dumps(chunk)) for chunk in chunks)
|
return EventSourceResponse(server_sent_events(chunks))
|
||||||
completion: llama_cpp.Completion = completion_or_chunks # type: ignore
|
completion: llama_cpp.Completion = completion_or_chunks # type: ignore
|
||||||
return completion
|
return completion
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user