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

.gitbook.1.0.1.source-code.Main.kt Maven / Gradle / Ivy

The newest version!
import com.cjcrafter.gitbook.*
import com.cjcrafter.gitbook.search.AskRequest
import com.cjcrafter.gitbook.search.AskResponse

fun main() {
    val gitbook = GitBookApi.builder()
        .apiKey("gb_api_DNYFGhsLoF79DeJZWo0BHepOkoF3UoLQSfqHH8zm")
        .build()
    val request = AskRequest(query = "Shoot 5 projectiles")
    //val location = SearchLocation.Organization("MgHAZkcfIhs3YcmBjk2r")

    val response = gitbook.ask(request)
    if (response.isFailure) {
        println("Failed to connect to API: ${response.exceptionOrNull()}")
        return
    }

    val answer = response.getOrThrow().answer
    if (answer == null) {
        println("You must have asked for forbidden knowledge, since the wiki could not confidently answer your question.")
        return
    }

    println("The wiki says: ${answer.text}")
    for (source in answer.sources) {
        println("Source: $source")
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy