All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.frtu.kotlin.ai.os.llm.model.Answer.kt Maven / Gradle / Ivy

package com.github.frtu.kotlin.ai.os.llm.model

import com.aallam.openai.api.chat.ChatChoice
import com.aallam.openai.api.chat.ChatMessage
import com.aallam.openai.api.chat.ToolCall
import com.aallam.openai.api.core.FinishReason

/**
 * Response message returned from a chat
 */
data class Answer(private val chatChoice: ChatChoice) {
    /**
     * Returning message content
     */
    val content: String?
        get() = message.content

    /**
     * Returning list of tool calls
     */
    val toolCalls: List?
        get() = message.toolCalls

    /**
     * If answer return tool calls
     */
    val hasToolCall: Boolean
        get() = !toolCalls.isNullOrEmpty()

    /**
     * Returning raw `ChatMessage`
     */
    val message: ChatMessage
        get() = chatChoice.message

    /**
     * Returning the `FinishReason`
     */
    val finishReason: FinishReason?
        get() = chatChoice.finishReason

    /**
     * Internal `ChatChoice` index
     */
    val index: Int
        get() = chatChoice.index

    val invokeFunction: InvokeFunction?
        get() = with(chatChoice.message) {
            functionCall?.let {
                // Function is returned correctly parsed
                InvokeFunction(it)
            } ?: content?.let {
                // Manual parsing using content
                parseContent(content!!)
            }
        }
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy