chat Completion Stream
fun DeepSeekClientBase.chatCompletionStream(request: ChatCompletionRequest): Flow<ChatCompletionChunk>
Streams chat completion responses chunk by chunk from the DeepSeek API.
This function handles the low-level communication with the Server-Sent Events (SSE) endpoint, allowing you to receive and process model responses in real-time as they're generated.
Example:
val request = chatCompletionStreamParams { model = ChatModel.DEEPSEEK_CHAT }
.createRequest(listOf(UserMessage("Write a story")))
client.chatCompletionStream(request).collect { chunk ->
print(chunk.choices.firstOrNull()?.delta?.content ?: "")
}Content copied to clipboard
Return
A Flow of ChatCompletionChunk objects representing incremental updates
Parameters
request
The chat completion request with streaming enabled
Throws
from the returned Flow's collector if the API returns a non-2xx status