Table of Contents

Method RewriteAsync

Namespace
LMKit.TextEnhancement
Assembly
LM-Kit.NET.dll

RewriteAsync(string, CommunicationStyle, Language, CancellationToken)

Asynchronously rewrites the specified text into a specified style and language.

public Task<string> RewriteAsync(string text, TextRewriter.CommunicationStyle style, Language language = Language.English, CancellationToken cancellationToken = default)

Parameters

text string

The text to rewrite; cannot be null or whitespace.

style TextRewriter.CommunicationStyle

The communication style to apply.

language Language

The language for the rewritten text. Default is English.

cancellationToken CancellationToken

Optional. A CancellationToken for handling cancellation requests.

Returns

Task<string>

A task representing the asynchronous operation, containing the rewritten text.

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 TextRewriter using the LLM
TextRewriter textRewriter = new TextRewriter(languageModel);

// Text to rewrite
string text = "Hey, what's up? I'm looking to get in touch with HR.";

// Rewrite the text in a professional style asynchronously
string rewrittenText = await textRewriter.RewriteAsync(text, CommunicationStyle.Professional);

Console.WriteLine(rewrittenText);
// Output: "Hello, I would like to get in touch with the HR department."

Remarks

This method handles text of any size, preserving the structure and formatting of the original content.

Exceptions

ArgumentException

Thrown if the input text is null or whitespace.