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

cc.unitmesh.rag.HttpDsl.kt Maven / Gradle / Ivy

Go to download

Chocolate Factory is a cutting-edge LLM toolkit designed to empower you in creating your very own AI assistant.

The newest version!
package cc.unitmesh.rag


import io.ktor.client.*
import io.ktor.client.call.*
import io.ktor.client.request.*
import io.ktor.client.statement.*
import kotlinx.coroutines.runBlocking
import java.io.File

object Http {
    private val client = HttpClient()

    /**
     * @param url
     */
    fun get(url: String = "", init: () -> Unit) {
        runBlocking {
            client.get(url) {
                init()
            }
        }
    }

    fun download(url: String): File {
        val fileName = url.substringAfterLast("/")
        val file = File("temp", fileName)

        if (!File("temp").exists()) {
            File("temp").mkdir()
        }

        if (file.exists()) {
            return file
        }

        runBlocking {
            val httpResponse: HttpResponse = client.get(url) {}
            val responseBody: ByteArray = httpResponse.body()
            file.writeBytes(responseBody)
        }

        return file
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy