Back to Devexpress

ExplainRequest(String) Constructor

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

latest3.5 KB
Original Source

ExplainRequest(String) Constructor

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

Namespace : DevExpress.AIIntegration.Extensions

Assembly : DevExpress.AIIntegration.v25.2.dll

NuGet Package : DevExpress.AIIntegration

Declaration

csharp
public ExplainRequest(
    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 explain 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 = "Stochastic gradient descent, a variant of gradient descent, updates parameters based on individual training examples.";
var response = await defaultAIExtensionsContainer.ExplainAsync(
    new ExplainRequest(originalText)
);

Console.WriteLine(response);

/* Output:
 * Stochastic gradient descent is a method used in machine learning to adjust parameters of a model.
 * It's similar to another method called gradient descent. The main difference is that stochastic gradient
 * descent updates the parameters of the model after looking at each individual training example, one at a time,
 * instead of using the entire dataset at once.
 * 
 * For example, imagine you are trying to teach a robot to recognize apples. In stochastic gradient descent,
 * you would show the robot one apple picture at a time, update its understanding based on that single picture,
 * then move to the next one. In contrast, traditional gradient descent would look at all of the pictures of apples
 * together before making any updates.
 */

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

ExplainRequest Class

ExplainRequest Members

DevExpress.AIIntegration.Extensions Namespace