Haskell 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.
Haskell
/api/v1/tone
This example uses http-conduit and aeson.
{-# LANGUAGE OverloadedStrings #-}
import Data.Aeson (Value, object, (.=))
import qualified Data.ByteString.Char8 as B8
import Network.HTTP.Simple
import System.Environment (getEnv)
main :: IO ()
main = do
apiKey <- getEnv "SAPLING_API_KEY"
initialRequest <- parseRequest "https://api.sapling.ai/api/v1/tone"
let payload = object
[ "text" .= ("Really stoked about this! Will it be ready by next week?" :: String)
]
request =
setRequestMethod "POST" $
setRequestHeader "Authorization" [B8.pack ("Bearer " ++ apiKey)] $
setRequestBodyJSON payload initialRequest
response <- httpJSON request :: IO (Response Value)
print (getResponseBody response)
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 Haskell
Haskell is a popular programming language in industry and academia. It is purely functional, declarative, and statically typed.