corelibraries-devexpress-dot-aiintegration-dot-extensions-dot-prompttoexpressionrequest-dot-constantinfo-x29.md
Initializes a new instance of the PromptToExpressionRequest class with specified settings.
Namespace : DevExpress.AIIntegration.Extensions
Assembly : DevExpress.AIIntegration.v25.2.dll
NuGet Package : DevExpress.AIIntegration
public PromptToExpressionRequest(
string userPrompt,
string currentExpression,
IEnumerable<PromptToExpressionRequestBase.ColumnInfo> columns,
IEnumerable<PromptToExpressionRequestBase.FunctionInfo> functions,
IEnumerable<PromptToExpressionRequestBase.ParameterInfo> parameters,
IEnumerable<PromptToExpressionRequestBase.ConstantInfo> constants
)
Public Sub New(
userPrompt As String,
currentExpression As String,
columns As IEnumerable(Of PromptToExpressionRequestBase.ColumnInfo),
functions As IEnumerable(Of PromptToExpressionRequestBase.FunctionInfo),
parameters As IEnumerable(Of PromptToExpressionRequestBase.ParameterInfo),
constants As IEnumerable(Of PromptToExpressionRequestBase.ConstantInfo)
)
| Name | Type | Description |
|---|---|---|
| userPrompt | String |
Natural-language description of the desired logic. This value is assigned to the UserPrompt property.
| | currentExpression | String |
The existing expression (filter or unbound column expression). This value is assigned to the CurrentExpression property.
| | columns | IEnumerable<PromptToExpressionRequestBase.ColumnInfo> |
Data columns that the AI is allowed to reference. This value is assigned to the Columns property.
| | functions | IEnumerable<PromptToExpressionRequestBase.FunctionInfo> |
Functions that the AI can use when generating the expression. This value is assigned to the Functions property.
| | parameters | IEnumerable<PromptToExpressionRequestBase.ParameterInfo> |
Report parameters that the AI can use when generating the expression. This value is assigned to the Parameters property.
| | constants | IEnumerable<PromptToExpressionRequestBase.ConstantInfo> |
Report constants that the AI can use when generating the expression. This value is assigned to the Constants property.
|
The following code snippet registers an Azure OpenAI client to use the AI-powered Prompt to Expression extension in a .NET Console application to generate a valid filter expression:
using Azure.AI.OpenAI;
using DevExpress.AIIntegration;
using DevExpress.AIIntegration.Extensions;
using Microsoft.Extensions.AI;
// Register an Azure OpenAI client.
AIExtensionsContainerDefault defaultAIExtensionsContainer = RegisterAzureOpenAIClient(
Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT"),
Environment.GetEnvironmentVariable("AZURE_OPENAI_APIKEY")
);
// PromptToExpressionAsync converts a human-readable request into
// a machine-readable expression based on the available columns and functions.
var response = await defaultAIExtensionsContainer.PromptToExpressionAsync(
new PromptToExpressionRequest(
"Display orders from the last month where the total amount is greater than $500.", // The user's instruction written in natural language.
string.Empty,
new List<PromptToExpressionRequestBase.ColumnInfo>(){ // Describes data fields that the AI is allowed
new PromptToExpressionRequestBase.ColumnInfo(){ ColumnName = "OrderID" }, // to reference in the generated expression.
new PromptToExpressionRequestBase.ColumnInfo(){ ColumnName = "Price" },
new PromptToExpressionRequestBase.ColumnInfo(){ ColumnName = "OrderDate"}
},
null) // (optional) Specifies custom or supported functions
// that the AI can use when building expressions.
);
Console.WriteLine("Generated Expression: " + response);
// Expected output (the actual output may vary):
// Generated Expression: [OrderDate] >= DateTime.Now.AddMonths(-1) && [Price] > 500
AIExtensionsContainerDefault RegisterAzureOpenAIClient(string azureOpenAIEndpoint, string azureOpenAIKey) {
IChatClient client = new 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
PromptToExpressionRequest Class