MCPcopy Create free account
hub / github.com/abetlen/llama-cpp-python / stream_sse_chunks

Function stream_sse_chunks

examples/server/server.py:15830–15864  ·  view source on GitHub ↗
(
        formatter: OpenAIFormatter,
        http_request: Request,
        stream: CompletionStream,
        cancel: Callable[[], None],
        chunk_payloads: Callable[[CompletionChunk], Iterable[Any]],
    )

Source from the content-addressed store, hash-verified

15828 stream.close()
15829
15830 async def stream_sse_chunks(
15831 formatter: OpenAIFormatter,
15832 http_request: Request,
15833 stream: CompletionStream,
15834 cancel: Callable[[], None],
15835 chunk_payloads: Callable[[CompletionChunk], Iterable[Any]],
15836 ) -> AsyncIterator[bytes]:
15837 disconnect_task = asyncio.create_task(
15838 watch_http_disconnect(http_request, cancel)
15839 )
15840 try:
15841 while True:
15842 done, chunk = await asyncio.to_thread(
15843 formatter.next_stream_chunk,
15844 stream,
15845 )
15846 if done:
15847 break
15848 assert chunk is not None
15849 for payload in chunk_payloads(chunk):
15850 yield formatter.encode_sse_payload(payload)
15851 yield b"data: [DONE]\n\n"
15852 except asyncio.CancelledError:
15853 cancel()
15854 raise
15855 except BaseException as exc:
15856 cancel()
15857 if (
15858 isinstance(exc, CompletionRequestCancelledError)
15859 and await http_request.is_disconnected()
15860 ):
15861 return
15862 raise
15863 finally:
15864 disconnect_task.cancel()
15865
15866 async def stream_sse_outputs(
15867 formatter: OpenAIFormatter,

Callers 2

create_completionFunction · 0.85
create_chat_completionFunction · 0.85

Calls 3

watch_http_disconnectFunction · 0.85
encode_sse_payloadMethod · 0.80
cancelMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…