Method GetEmotionCategoryAsync
- Namespace
- LMKit.TextAnalysis
- Assembly
- LM-Kit.NET.dll
GetEmotionCategoryAsync(string, CancellationToken)
Analyzes the emotional tone of a given text and classifies it into a specific category as defined by the EmotionDetection.EmotionCategory enumeration.
public Task<EmotionDetection.EmotionCategory> GetEmotionCategoryAsync(string text, CancellationToken cancellationToken = default)
Parameters
text
stringThe text to analyze for emotional content. This should be a non-empty string representing the textual content whose emotion is to be classified.
cancellationToken
CancellationTokenOptional. A CancellationToken for handling cancellation requests.
Returns
- Task<EmotionDetection.EmotionCategory>
A member of the EmotionDetection.EmotionCategory enumeration that matches the category associated with the plain text.
Examples
using LMKit.TextAnalysis;
using LMKit.Model;
using System;
// Initialize the language model using the specified model path
LLM languageModel = new LLM("https://huggingface.co/lm-kit/phi-3.5-mini-3.8b-instruct-gguf/resolve/main/Phi-3.5-mini-Instruct-Q4_K_M.gguf?download=true");
// Create an instance of EmotionDetection
EmotionDetection emotionDetector = new EmotionDetection(languageModel);
// Asynchronously analyze text emotion
EmotionCategory emotion = await emotionDetector.GetEmotionCategoryAsync("I am scared and anxious.");
Console.WriteLine($"Emotion: {emotion}");
// Output: "Emotion: Fear"
Exceptions
- OperationCanceledException
Thrown when the operation is cancelled based on the CancellationToken.