crabllm-core 0.0.22

Core types for the crabllm LLM API gateway
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
use crate::{ByteStream, ChatCompletionChunk, Error};
use futures::stream::{Stream, StreamExt};

/// Parse an SSE byte stream into `ChatCompletionChunk` items. Each `data:`
/// payload is one chunk; the `[DONE]` sentinel ends the stream.
pub fn sse_stream(
    byte_stream: ByteStream,
) -> impl Stream<Item = Result<ChatCompletionChunk, Error>> {
    crate::codec::sse::data_lines(byte_stream).map(|line| {
        crate::json::from_str::<ChatCompletionChunk>(&line?)
            .map_err(|e| Error::Decode(format!("SSE parse error: {e}")))
    })
}