Back to Devexpress

ShortenRequest(String) Constructor

corelibraries-devexpress-dot-aiintegration-dot-extensions-dot-shortenrequest-dot-ctor-x28-system-dot-string-x29.md

latest3.2 KB
Original Source

ShortenRequest(String) Constructor

Initializes a new instance of the ShortenRequest class with specified settings.

Namespace : DevExpress.AIIntegration.Extensions

Assembly : DevExpress.AIIntegration.v25.2.dll

NuGet Package : DevExpress.AIIntegration

Declaration

csharp
public ShortenRequest(
    string text
)
vb
Public Sub New(
    text As String
)

Parameters

NameTypeDescription
textString

The text to be managed. This value is assigned to the Text property.

|

Remarks

The following example registers an Azure OpenAI client and uses the AI-powered extension to shorten originalText:

csharp
using Azure;
using Azure.AI.OpenAI;
using Microsoft.Extensions.AI;
using DevExpress.AIIntegration;
using DevExpress.AIIntegration.Extensions;

SetEnvironmentVariables();

// Register an Azure OpenAI client
AIExtensionsContainerDefault defaultAIExtensionsContainer = RegisterAzureOpenAIClient(
    Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT"),
    Environment.GetEnvironmentVariable("AZURE_OPENAI_APIKEY")
);

string originalText = "Effective communication is essential in any professional setting, as it ensures that all parties involved are on the same page and working toward the same goals. Without clear communication, misunderstandings can arise, leading to errors, delays, and even conflict among team members.";
var response = await defaultAIExtensionsContainer.ShortenAsync(
    new ShortenRequest(originalText)
);

Console.WriteLine(response);

/* Output:
 * Effective communication is crucial in professional settings for aligning all parties toward common goals.
 * Lack of clear communication can result in misunderstandings, errors, delays, and conflicts among team members.
 */

AIExtensionsContainerDefault RegisterAzureOpenAIClient(string azureOpenAIEndpoint, string azureOpenAIKey) {
    IChatClient client = new Azure.AI.OpenAI.AzureOpenAIClient(new Uri(azureOpenAIEndpoint),
        new System.ClientModel.ApiKeyCredential(azureOpenAIKey)).GetChatClient("gpt-4o-mini").AsIChatClient();

    return AIExtensionsContainerConsole.CreateDefaultAIExtensionContainer(client);
}

void SetEnvironmentVariables() {
    Environment.SetEnvironmentVariable("AZURE_OPENAI_ENDPOINT", {SPECIFY_YOUR_AZURE_ENDPOINT});
    Environment.SetEnvironmentVariable("AZURE_OPENAI_APIKEY", {SPECIFY_YOU_AZURE_KEY});
}

See Also

ShortenRequest Class

ShortenRequest Members

DevExpress.AIIntegration.Extensions Namespace