Perl tone checker quickstart
Send text to the tone endpoint. The response ranks overall tones and returns a separate probability breakdown for every sentence.
No language-specific SDK is required. The example uses a standard or commonly used HTTP client to call Sapling's JSON API.
Perl
/api/v1/tone
This example uses LWP::UserAgent and JSON::MaybeXS.
use strict;
use warnings;
use HTTP::Request;
use JSON::MaybeXS qw(encode_json);
use LWP::UserAgent;
my $api_key = $ENV{SAPLING_API_KEY}
// die "Set SAPLING_API_KEY first.\n";
my $request = HTTP::Request->new(
POST => 'https://api.sapling.ai/api/v1/tone'
);
$request->header('Authorization' => "Bearer $api_key");
$request->header('Content-Type' => 'application/json');
$request->content(encode_json({
text => 'Really stoked about this! Will it be ready by next week?',
}));
my $response = LWP::UserAgent->new->request($request);
die $response->status_line . "\n" . $response->decoded_content
unless $response->is_success;
print $response->decoded_content;
Example response
application/json
{
"overall": [
[0.9247, "curious", "🤓"],
[0.0455, "excited", "😀"],
[0.0057, "confused", "😕"]
],
"results": [
[[0.9937, "excited", "😀"]],
[[0.5469, "confused", "😕"], [0.3993, "curious", "🤓"]]
],
"sents": [
"Really stoked about this!",
"Will it be ready by next week?"
]
}
Probabilities are returned in descending order as probability, tone, and emoji tuples. Use sentence results when a message contains mixed tones.
About Perl
Perl is a family of high-level interpreted scripting languages, including Perl 5 and Perl 6, which was renamed to Raku. It is popular as a scripting language because of its built-in regular expression and string parsing functionality.