chat

Sends a chat request with custom parameters and messages.

This is a versatile function that gives you control over both the model's behavior and the conversation context.

Example:

// Create custom parameters
val params = chatCompletionParams {
temperature = 0.7
maxTokens = 1000
}

// Define the conversation
val messages = listOf(
SystemMessage("You are a helpful assistant specialized in Kotlin"),
UserMessage("What are coroutines?")
)

// Get the response
val response = client.chat(params, messages)
println(response.choices.first().message.content)

Return

A ChatCompletion containing the model's response

Parameters

params

Configuration parameters that control the model's behavior

messages

The conversation history as a list of messages


Sends a chat request with default parameters.

This simplified version uses the default model settings and only requires providing the conversation history.

Example:

val messages = listOf(
SystemMessage("You are a helpful assistant"),
UserMessage("What is Kotlin?")
)
val response = client.chat(messages)

Return

A ChatCompletion containing the model's response

Parameters

messages

The conversation history as a list of messages


suspend fun DeepSeekClient.chat(message: String): ChatCompletion

Sends a single user message to the chat API.

This is the simplest way to interact with the DeepSeek chat API, perfect for quick queries.

Example:

val response = client.chat("What's the capital of France?")
println(response.choices.first().message.content)

Return

A ChatCompletion containing the model's response

Parameters

message

The message text to send to the model


Sends a chat request with custom parameters and a DSL for building messages.

This approach combines the flexibility of custom parameters with an intuitive way to construct the conversation.

Example:

val params = chatCompletionParams {
temperature = 0.8
maxTokens = 2000
}

val response = client.chat(params) {
system("You are a Kotlin expert")
user("Explain extension functions")
}

Return

A ChatCompletion containing the model's response

Parameters

params

Configuration parameters that control the model's behavior

blockMessage

A builder block for constructing the conversation


Sends a chat request with default parameters and a DSL for building messages.

This approach provides a clean, readable way to construct conversations with default model settings.

Example:

val response = client.chat {
system("You are a helpful AI assistant")
user("Tell me about Kotlin")
assistant("Kotlin is a modern programming language")
user("What about its coroutines?")
}

Return

A ChatCompletion containing the model's response

Parameters

blockMessage

A builder block for constructing the conversation


Streams chat responses using custom parameters and messages.

This function lets you specify both behavioral parameters and conversation messages while getting real-time streaming responses from the model.

Example:

val params = chatCompletionStreamParams {
temperature = 0.8
maxTokens = 2000
}

val messages = listOf(
SystemMessage("You are a storyteller"),
UserMessage("Tell me a short sci-fi story")
)

client.chat(params, messages).collect { chunk ->
print(chunk.choices.firstOrNull()?.delta?.content ?: "")
}

Return

A Flow of ChatCompletionChunk objects representing the streaming response

Parameters

params

Parameters controlling the model's behavior

messages

The conversation history as a list of messages


Streams chat responses using default parameters.

This simplified function uses the default DEEPSEEK_CHAT model with streaming enabled, providing a clean way to get streaming responses with minimal configuration.

Example:

val messages = listOf(
SystemMessage("You are a coding assistant"),
UserMessage("Explain how to use Flows in Kotlin")
)

client.chat(messages).collect { chunk ->
print(chunk.choices.firstOrNull()?.delta?.content ?: "")
}

Return

A Flow of ChatCompletionChunk objects representing the streaming response

Parameters

messages

The conversation history as a list of messages


Streams chat responses for a single user message.

This is the most straightforward way to get streaming responses from the model, requiring only a simple text message.

Example:

client.chat("Write a poem about programming").collect { chunk ->
print(chunk.choices.firstOrNull()?.delta?.content ?: "")
}

Return

A Flow of ChatCompletionChunk objects representing the streaming response

Parameters

message

The message text to send to the model


Streams chat responses using custom parameters and a message builder DSL.

This approach combines custom parameters with an intuitive way to build the conversation history.

Example:

val params = chatCompletionStreamParams {
temperature = 0.7
maxTokens = 1000
}

client.chat(params) {
system("You are a technical writer")
user("Create a tutorial introduction for Kotlin coroutines")
}.collect { chunk ->
print(chunk.choices.firstOrNull()?.delta?.content ?: "")
}

Return

A Flow of ChatCompletionChunk objects representing the streaming response

Parameters

params

Parameters controlling the model's behavior

blockMessage

A builder block for constructing the conversation


Streams chat responses using default parameters and a message builder DSL.

This function offers a clean, readable way to build conversations with default streaming settings.

Example:

client.chat {
system("You are a helpful assistant")
user("Explain quantum computing")
}.collect { chunk ->
print(chunk.choices.firstOrNull()?.delta?.content ?: "")
}

Return

A Flow of ChatCompletionChunk objects representing the streaming response

Parameters

blockMessage

A builder block for constructing the conversation