chat Completion
Sends a chat completion request to the DeepSeek API.
This is a low-level function that handles the direct HTTP communication with the API. Most users will prefer the higher-level chat functions instead.
Example:
val request = chatCompletionParams { model = ChatModel.DEEPSEEK_CHAT }
.createRequest(listOf(UserMessage("Hello!")))
val response = client.chatCompletion(request)Return
A ChatCompletion containing the model's response
Parameters
The fully configured request object containing all parameters for the API call
Throws
if the API returns a non-2xx status
Sends a fully customizable chat completion request.
This approach gives you complete control over all aspects of the request through a convenient builder pattern.
Example:
val response = client.chatCompletion {
params {
model = ChatModel.DEEPSEEK_CHAT
temperature = 0.7
maxTokens = 2000
frequencyPenalty = 0.5
}
messages {
system("You are a Kotlin expert")
user("How do I use flow in Kotlin?")
}
}Return
A ChatCompletion containing the model's response
Parameters
A builder block for constructing the complete request
Throws
if the API returns a non-2xx status
Streams a fully customizable chat completion request.
This approach gives you complete control over all aspects of the streaming request through a dedicated builder pattern.
Example:
client.chatCompletion {
params {
model = ChatModel.DEEPSEEK_CHAT
temperature = 0.7
maxTokens = 2000
}
messages {
system("You are an expert programmer")
user("Show me how to implement a binary search tree in Kotlin")
}
}.collect { chunk ->
print(chunk.choices.firstOrNull()?.delta?.content ?: "")
}Return
A Flow of ChatCompletionChunk objects representing the streaming response
Parameters
A builder block for constructing the complete streaming request
Throws
from the returned Flow's collector if the API returns a non-2xx status