blazor-devexpress-dot-aiintegration-dot-blazor-dot-chat-dot-aichatfunctioncall-0ce84a71.md
Returns execution results of an AI-invoked function.
Namespace : DevExpress.AIIntegration.Blazor.Chat
Assembly : DevExpress.AIIntegration.Blazor.Chat.v25.2.dll
NuGet Package : DevExpress.AIIntegration.Blazor.Chat
public FunctionResultContent Result { get; set; }
| Type | Description |
|---|---|
| Microsoft.Extensions.AI.FunctionResultContent |
The function results.
|
Access the execution results of an AI-invoked function from the MessageContentTemplate context. Refer to the FunctionResultContent class description for details.
The following code snippet appends information about each invoked function to the AI chat response:
@using DevExpress.AIIntegration.Blazor.Chat
@using DevExpress.AIIntegration.Tools
@inject AIToolsContextContainer aiToolsContextContainer
<DxAIChat>
<MessageContentTemplate>
@context.Content
@if(context.FunctionCalls.Count > 0) {
<ul>
@foreach(var functionCall in context.FunctionCalls) {
<li>
Called function: <b>@functionCall.Request.Name</b>
Return value: <b>@functionCall.Result.Result.ToString()</b>
</li>
}
</ul>
}
</MessageContentTemplate>
</DxAIChat>
@code {
protected override void OnAfterRender(bool firstRender) {
if(firstRender) {
var context = new AIToolsContextBuilder()
.WithToolMethods(MyAITools.Greet, MyAITools.AddNumbers)
.Build();
aiToolsContextContainer.Add(context);
}
}
}
using DevExpress.AIIntegration;
using System.ComponentModel;
public class MyAITools
{
[AIIntegrationTool("Generic_Greeting")]
[Description("Greets a user with their name.")]
public static string Greet(
[Description("The name of the user.")] string name) {
var now = DateTime.Now;
if(now.Hour < 7)
return $"Good night, {name}!";
else if(now.Hour < 12)
return $"Good morning, {name}!";
else if(now.Hour < 18)
return $"Good afternoon, {name}!";
else
return $"Good evening, {name}!";
}
[AIIntegrationTool("Generic_Calculator")]
[Description("Adds two numbers.")]
public static int AddNumbers(
[Description("First number")] int a,
[Description("Second number")] int b) {
return a + b;
}
}
using Azure.AI.OpenAI;
using DevExpress.AIIntegration;
using DxAI.Components;
using Microsoft.Extensions.AI;
using System.ClientModel;
/* ... */
string azureOpenAiKey = Environment.GetEnvironmentVariable("AZURE_OPENAI_KEY")
?? throw new InvalidOperationException("AZURE_OPENAI_KEY environment variable is not set.");
string azureOpenAiEndpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT")
?? throw new InvalidOperationException("AZURE_OPENAI_ENDPOINT environment variable is not set.");
string azureOpenAiModel = Environment.GetEnvironmentVariable("AZURE_OPENAI_MODEL")
?? throw new InvalidOperationException("AZURE_OPENAI_MODEL environment variable is not set.");
AzureOpenAIClient azureOpenAIClient = new(
new Uri(azureOpenAiEndpoint),
new ApiKeyCredential(azureOpenAiKey)
);
IChatClient azureOpenAIChatClient = azureOpenAIClient.GetChatClient(azureOpenAiModel).AsIChatClient();
/** Register scoped chat client with DevExpress AI tool calling */
builder.Services.AddScoped((sp) => {
return azureOpenAIChatClient.AsBuilder()
.UseDXTools()
.UseFunctionInvocation()
.Build(sp);
});
/** Register DevExpress AI services */
builder.Services.AddDevExpressAI();
/** Register DevExpress Blazor services */
builder.Services.AddDevExpressBlazor();
See Also