chat Completion Stream
suspend 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 = ChatCompletionRequest(
model = "deepseek-chat",
messages = listOf(UseMessage("Write a story")),
stream = true
)
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