Method CorrectAsync
- Namespace
- LMKit.TextEnhancement
- Assembly
- LM-Kit.NET.dll
CorrectAsync(string, CancellationToken)
Asynchronously corrects grammar and spelling errors in the specified text.
public Task<string> CorrectAsync(string text, CancellationToken cancellationToken = default)
Parameters
text
stringThe text to correct.
cancellationToken
CancellationTokenOptional. A CancellationToken to handle cancellation requests.
Returns
Examples
using LMKit.TextEnhancement;
using LMKit.Model;
using System.Threading.Tasks;
// Initialize the language model (LLM)
LLM languageModel = new LLM("path/to/your/model");
// Create an instance of TextCorrection using the LLM
TextCorrection textCorrection = new TextCorrection(languageModel);
// Text to correct
string text = "Ths is an exampel of a sentnce with speling erors.";
// Correct the text asynchronously
string correctedText = await textCorrection.CorrectAsync(text);
Console.WriteLine(correctedText);
// Output: "This is an example of a sentence with spelling errors."
Remarks
This method handles text of any size and preserves the original content's structure and formatting.
Exceptions
- ArgumentException
Thrown if the input
text
is null or whitespace.