Skip to main content
All docs
V25.1
  • AIIntegration.CustomPromptAsync(IAIExtensionsContainer, CustomPromptRequest, CancellationToken) Method

    Generates or manipulates text based on the specified prompt.

    Namespace: DevExpress.AIIntegration

    Assembly: DevExpress.AIIntegration.v25.1.dll

    NuGet Package: DevExpress.AIIntegration

    Declaration

    public static Task<TextResponse> CustomPromptAsync(
        this IAIExtensionsContainer container,
        CustomPromptRequest request,
        CancellationToken cancellationToken = default(CancellationToken)
    )

    Parameters

    Name Type Description
    container IAIExtensionsContainer

    The AI extensions container.

    request CustomPromptRequest

    The request to transform text.

    Optional Parameters

    Name Type Default Description
    cancellationToken CancellationToken null

    The token that cancels the task.

    Returns

    Type Description
    Task<TextResponse>

    The response that contains AI-generated text.

    Remarks

    The following example registers an Azure OpenAI client to use an AI-powered extension to transform originalText based on a custom prompt:

    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 = "Specify the original text to transform...";
    var response = await defaultAIExtensionsContainer.CustomPromptAsync(
        new CustomPromptRequest("Specify a prompt...", originalText)
    );
    
    Console.WriteLine(response);
    
    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