fim

Generates a completion using the Fill-In-the-Middle capability with custom parameters.

FIM allows the model to complete text given a prompt and optional parameters like suffix text, temperature, and other generation controls.

Example:

val params = fimCompletionParams {
temperature = 0.7
maxTokens = 200
suffix = "}" // The code should end with a closing bracket
}

val completion = client.fim(params, "function calculateArea(radius) {")
println(completion.choices.first().text)

Return

A FIMCompletion containing the model's response

Parameters

params

Parameters controlling the completion behavior

prompt

The text to start completion from

Throws

if the API returns a non-2xx status


suspend fun DeepSeekClient.fim(prompt: String): FIMCompletion

Generates a completion using the Fill-In-the-Middle capability with default parameters.

This is the simplest way to use FIM completions when you only need to specify the starting text.

Example:

val completion = client.fim("def sort_array(arr):")
println(completion.choices.first().text)

Return

A FIMCompletion containing the model's response

Parameters

prompt

The text to start completion from

Throws

if the API returns a non-2xx status


Streams FIM completions using custom parameters and a prompt.

This function gives you control over generation behavior while receiving streaming responses for Fill-In-the-Middle completions.

Example:

val params = fimCompletionStreamParams {
temperature = 0.7
maxTokens = 500
suffix = "}"
}

client.fim(params, "class Calculator {").collect { chunk ->
print(chunk.choices.firstOrNull()?.text ?: "")
}

Return

A Flow of FIMCompletion objects representing the streaming response

Parameters

params

Parameters controlling the completion behavior

prompt

The text to start the completion from

Throws

from the returned Flow's collector if the API returns a non-2xx status


Streams FIM completions with default parameters.

This simplified function streams completions with default settings, requiring only the prompt text to get started.

Example:

client.fim("def calculate_area(radius):").collect { chunk ->
print(chunk.choices.firstOrNull()?.text ?: "")
}

Return

A Flow of FIMCompletion objects representing the streaming response

Parameters

prompt

The text to start the completion from

Throws

from the returned Flow's collector if the API returns a non-2xx status