Sapling Logo

AI Content Detection in Scala

Scala

Scala is a programming language designed to run on the JVM, supporting both functional and object-oriented programming patterns. It is designed to be more concise than Java.

Sapling: AI Generated Content Detector

How do you distinguish or determine between text written by a human and text written by Large Language Model generative AIs? With Sapling, you can integrate AI Content Detection to an existing Scala application. You can also add grammar, spell checking, and other text AI functionality.

This page demonstrates a quick way to integrate AI writing and AI text checking functionality into a Scala application using Sapling's API. If you are not looking for a Scala guide, click here for guides for other programming languages.

Sapling does not currently maintain a Scala-specific SDK, but you can access the Sapling AI Detection HTTP API using any programming language that supports HTTP POST requests. An example of an AI text detector is shown below.

Setup Steps

Distinguish human text from AI text using Scala:

Scala Grammar Check Quickstart

This is an example of doing an HTTP Post request using scalaj-http, which is now deprecated

import scalaj.http.{Http, HttpOptions}

object Main {
  def main(args: Array[String]): Unit = {
    println("Hello world!")
    val data : String = """{"key":"API_KEY","text":"I am an artificial intelligence system designed to help people solve complex problems. My capabilities include natural language processing, machine learning, and predictive analytics."}"""
    val url : String = "https://api.sapling.ai/api/v1/aidetect"
    val result = Http(url).postData(data)
      .header("Content-Type", "application/json")
      .header("Charset", "UTF-8")
      .option(HttpOptions.readTimeout(30000)).asString
  }
}

You can also use the native Java HTTPClient to reduce dependancies

import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;


object Main {
  def main(args: Array[String]): Unit = {
    println("Hello world!")
    val params : String = """{"key":"API_KEY","text":"I am an artificial intelligence system designed to help people solve complex problems. My capabilities include natural language processing, machine learning, and predictive analytics."}"""

    HttpClient client = HttpClient.newHttpClient();
    HttpRequest request = HttpRequest.newBuilder()
        .uri(URI.create(url))
        .header("Content-Type", "application/json")
        .POST(HttpRequest.BodyPublishers.ofString(params))
        .build();

    client.sendAsync(request, HttpResponse.BodyHandlers.ofString())
        .thenApply(HttpResponse::body)
        .thenAccept(System.out::println)
        .join();
  }
}

Returned result:

{
  "score":0.9989707556330055,
  "sentence_scores":[
    {
      "score":0.9764397893790885,
      "sentence": "I am an artificial intelligence system designed to help people solve complex problems."
    },
    {
      "score":0.9923806397189778,
      "sentence":"My capabilities include natural language processing, machine learning, and predictive analytics."
    }
  ],
  "text":"I am an artificial intelligence system designed to help people solve complex problems. My capabilities include natural language processing, machine learning, and predictive analytics."
}

Documentation

Addtional parameters and Sapling's full API documentation can be accessed here: https://sapling.ai/docs/api/detector