asAssistantMessages

Maps a list of request contents to assistant messages.

Return

A list of Message objects, each with Role.Assistant.

See also

Samples

runBlocking {
    // Create a chat.
    val chat = koryChat(model = "gpt-5.6-sol") {
        user("Hello, who are you?")
    }

    // Create response using asChatRequest() extension function for transform chat to Request.
    val response: ChatResponse = chat(chat.asChatRequest())

    // Process fist choice.
    val firstChoice = response.choices.firstOrNull()

    val exitContents: List<Content.Response?> = firstChoice?.let { choice ->
        choice.contents.map { content ->
            content
        }
    } ?: error("Could not find choice")

    // Convert all contents to Request Content.
    val filteredContents = exitContents.filterIsInstance<Content.Request>()

    // Add filtered contents to chat.
    chat.addMessages(filteredContents.asAssistantMessages())

    chat(chat.asChatRequest())
}