Skip to main content

Caila Java client

It is more convenient to use a special client library to access services in Caila from a Java or Kotlin program. The Caila SDK can be used for the following purposes:

  • accessing services on the Caila platform
  • creating new services for Caila
  • developing complex client applications

The SDK is available on GitHub: https://github.com/just-ai/mlp-java-sdk

Code examples using the SDK can be found here: https://github.com/just-ai/mlp-java-sdk/tree/release/mlp-examples

You can read more about the SDK in the corresponding section.

In this article, we will explore a few simple examples of how to call an Caila service from a Java program.

Example of a call through MlpClientSDK

Add a dependency for the mlp-java-sdk.

<repositories>
<repository>
<id>justai-nexus</id>
<url>https://nexus-open.just-ai.com/repository/maven-releases/</url>
</repository>
</repositories>
<dependency>
<groupId>com.mlp</groupId>
<artifactId>mlp-sdk</artifactId>
<version>1.0.0</version>
</dependency>

Set the MLP_CLIENT_TOKEN environment variable. Insert the API key for access to Caila.

export MLP_CLIENT_TOKEN=<API-token>

Example of calling the vectorizer-caila-roberta service via the standard Caila GRPC client.

// Import Caila client
import com.mlp.sdk.MlpClientSDK
import com.mlp.sdk.MlpExecutionContext.Companion.systemContext
import com.mlp.sdk.utils.JSON
import kotlinx.coroutines.runBlocking

// Declaration of auxiliary classes
data class VectorizerRequest(val texts: List<String>)
data class VectorizerEmbeddings(val vector: List<Double>)
data class VectorizerResponse(val embedded_texts: List<VectorizerEmbeddings>)

fun main() = runBlocking {
// Setting request parameters
val account = "just-ai"
val model = "vectorizer-caila-roberta"

// Initialising client
val sdk = MlpClientSDK(context = systemContext)

// Sending request and outputting response
val req = VectorizerRequest(texts = listOf("hello"))
val res = sdk.predict(account, model, JSON.stringify(req))
println(res)

// Terminating client
sdk.shutdown()
}