ChatChoice
@Serializable
A single completion choice within a io.kory.core.chat.response.ChatResponse.
Each choice contains an ordered list of content items (text, reasoning, tool calls, etc.) and an optional finish reason indicating why the model stopped generating.
See also
Samples
// ChatChoice has a Content.Response array because the API sends the response in JSON,
// including both the tool call and the response at the same time.
val builder = StringBuilder()
// We review all the content and formulate the final message.
if (choice.contents.isNotEmpty()) {
for (content in choice.contents) {
val printMessage = when (content) {
is Content.Parts -> {
val parts = content.parts
if (parts.isNotEmpty()) {
for (part in parts) {
when (part) {
is ContentPart.Image -> "Image part: ${part.source}"
is ContentPart.Text -> "Text part: ${part.value}"
}
}
} else ""
}
is Content.Reasoning -> "Reasoning: ${content.value}"
is Content.Text -> "Output: ${content.text}"
is Content.ToolCall -> "Tool Call: ${content.name}"
}
builder.append("$printMessage\n")
}
if (builder.isNotBlank()) {
println("Choice index: ${choice.index}\nContents:\n${builder.toString().trim()}")
}
} else {
val finishReason = choice.finishReason ?: "unknown"
println("Choice ${choice.index} has no content. Finish reason: $finishReason")
}
builder.clear()Content copied to clipboard