Class: EmotionDetectionService

EmotionDetectionService()

Detect selected emotions within the provided text. The original text is chunked to passages of a specified sentence length. Smaller chunks yield better accuracy.

Constructor

new EmotionDetectionService()

Source:

Methods

call(user, text, sentence_splitopt, sentence_overlapopt, emotion_choicesopt, engineopt) → {Promise.<Object>}

Parameters:
Name Type Attributes Default Description
user string The ID of the user accessing the Soffos API. Soffos assumes that the owner of the api is an application (app) and that app has users. Soffos API will accept any string.
text string Text to detect emotions from.
sentence_split number <optional>
4 The number of sentences of each chunk when splitting the input text.
sentence_overlap number <optional>
false Whether to overlap adjacent chunks by 1 sentence. For example, with sentence_split 3 and sentence_overlap=true : [[s1, s2, s3], [s3, s4, s5], [s5, s6, s7]]
emotion_choices Array.<string> <optional>
List of emotions to detect in the text. If the field is not provided in the payload, or set as null or empty list, it will default to all emotion choices. Currently supported emotions are listed above in the default emotion values.
engine string <optional>
null The LLM engine to be used.
Source:
Returns:
spans - dictionary list
A list of spans resulting from the specified chunking parameters. Each span contains the following fields:
text: The text of the span.
detected_emotions: A list of the emotions detected for the specific span.
span_start: The starting character index of the span in the original input text.
span_end: The ending character index of the span in the original input text.
Type
Promise.<Object>
Example
import { SoffosServices } from "soffosai";

const my_apiKey = "Token <put your api key here>";
const service = new SoffosServices.EmotionDetectionService({apiKey:my_apiKey});
let response = await service.call("client_a_happy_one", "I am excited about my birthday!");
console.log(JSON.stringify(response, null, 2));

// returns
// {
//     "spans": [
//       {
//         "detected_emotions": [
//           "joy"
//         ],
//         "text": "I am excited about my birthday!",
//         "span_start": 0,
//         "span_end": 31
//       }
//     ],
//     "cost": {
//       "api_call_cost": 0.005,
//       "character_volume_cost": 0.005,
//       "total_cost": 0.01
//     },
//     "charged_character_count": 100,
//     "unit_price": "0.000050"
// }

setInputConfigs(name, text, sentence_splitopt, sentence_overlapopt, emotion_choicesopt, engineopt)

Parameters:
Name Type Attributes Default Description
name string Reference name of this Service. It will be used by the Pipeline to reference this Service.
text string | InputConfig Text to detect emotions from.
sentence_split number | InputConfig <optional>
4 The number of sentences of each chunk when splitting the input text.
sentence_overlap boolean | InputConfig <optional>
false Whether to overlap adjacent chunks by 1 sentence. For example, with sentence_split 3 and sentence_overlap=true : [[s1, s2, s3], [s3, s4, s5], [s5, s6, s7]]
emotion_choices Array.<string> | InputConfig <optional>
_EMOTION_LIST List of emotions to detect in the text. If the field is not provided in the payload, or set as null or empty list, it will default to all emotion choices. Currently supported emotions are listed above in the default emotion values.
engine string <optional>
null The LLM engine to be used.
Source: