---
source: crates/alef-backend-kotlin/tests/jni_emitter_test.rs
expression: content
---
// Generated by alef. Do not edit by hand.
@file:Suppress(
    "ktlint:standard:max-line-length",
    "ktlint:standard:trailing-comma-on-declaration-site",
    "ktlint:standard:trailing-comma-on-call-site",
    "ktlint:standard:annotation",
    "MaxLineLength",
    "TooManyFunctions",
    "LongParameterList",
    "LongMethod",
)

package dev.sample_crate

import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

@Suppress("TooManyFunctions")
class DefaultClient internal constructor(internal val handle: Long) : AutoCloseable {
    companion object {
        private val MAPPER = com.fasterxml.jackson.databind.ObjectMapper()
            .registerModule(com.fasterxml.jackson.datatype.jdk8.Jdk8Module())
            .findAndRegisterModules()
            .setPropertyNamingStrategy(com.fasterxml.jackson.databind.PropertyNamingStrategies.SNAKE_CASE)
    }

    suspend fun chat(request: ChatCompletionRequest): ChatCompletionResponse {
        return withContext(Dispatchers.IO) {
            val responseJson = DemoBridge.nativeDefaultClientChat(handle, MAPPER.writeValueAsString(request))
            MAPPER.readValue(responseJson, ChatCompletionResponse::class.java)
        }
    }

    suspend fun embeddings(request: EmbeddingsRequest): EmbeddingsResponse {
        return withContext(Dispatchers.IO) {
            val responseJson = DemoBridge.nativeDefaultClientEmbeddings(handle, MAPPER.writeValueAsString(request))
            MAPPER.readValue(responseJson, EmbeddingsResponse::class.java)
        }
    }

    override fun close() { DemoBridge.nativeFreeDefaultClient(handle) }
}
