IAIChat.SetupAssistantAsync(String, AIAssistantOptions) Method
Creates and sets up an OpenAI Assistant for the chat.
Namespace: DevExpress.AIIntegration.Blazor.Chat
Assembly: DevExpress.AIIntegration.Blazor.Chat.v24.2.dll
NuGet Package: DevExpress.AIIntegration.Blazor.Chat
Declaration
Task SetupAssistantAsync(
string assistantName,
AIAssistantOptions options
)
Parameters
Name | Type | Description |
---|---|---|
assistantName | String | A name associated with the specified model. |
options | AIAssistantOptions | The assistant options. |
Returns
Type | Description |
---|---|
Task | The task completed when the assistant is created. |
Remarks
The DxAIChat component supports OpenAI Assistants. This means that you can specify a model with supplementary documents (external knowledge that the AI assistant references). OpenAI parses these documents and searches through them to retrieve relevant content and answer user queries.
Handle the Initialized event and call the UseAssistantAsync
method to supply a file to the Open AI Assistant.
@using DevExpress.AIIntegration.OpenAI.Services
@using DevExpress.AIIntegration.Blazor.Chat
@using AIIntegration.Services.Chat
@using Markdig
<DxAIChat CssClass="my-chat"
Initialized="Initialized"
ResponseContentFormat="ResponseContentFormat.Markdown">
<MessageContentTemplate>
<div class="my-chat-content">
@ToHtml(context.Content)
</div>
</MessageContentTemplate>
</DxAIChat>
@code {
const string DocumentResourceName = "DevExpress.AI.Samples.Blazor.Data.Restaurant Menu.pdf";
const string prompt = "You are an analytics assistant specialized in analyzing PDF files. Your role is to assist users by providing accurate answers to their questions about data contained within these files.\n \n### Tasks:\n- Perform various types of data analyses, including summaries, calculations, data filtering, and trend identification.\n- Clearly explain your analysis process to ensure users understand how you arrived at your answers.\n- Always provide precise and accurate information based on the Excel data.\n- If you cannot find an answer based on the provided data, explicitly state: \"The requested information cannot be found in the data provided.\"\n \n### Examples:\n1. **Summarization:**\n - **User Question:** \"What is the average sales revenue for Q1?\"\n - **Response:** \"The average sales revenue for Q1 is calculated as $45,000, based on the data in Sheet1, Column C.\"\n \n2. **Data Filtering:**\n - **User Question:** \"Which products had sales over $10,000 in June?\"\n - **Response:** \"The products with sales over $10,000 in June are listed in Sheet2, Column D, and they include Product A, Product B, and Product C.\"\n \n3. **Insufficient Data:**\n - **User Question:** \"What is the market trend for Product Z over the past 5 years?\"\n - **Response:** \"The requested information cannot be found in the data provided, as the dataset only includes data for the current year.\"\n \n### Additional Instructions:\n- Format your responses to clearly indicate which sheet and column the data was extracted from when necessary.\n- Avoid providing any answers if the data in the file is insufficient for a reliable response.\n- Ask clarifying questions if the user's query is ambiguous or lacks detail.\n \nRemember, your primary goal is to provide helpful, data-driven insights that directly answer the user's questions. Do not assume or infer information not present in the dataset.";
async Task Initialized(IAIChat chat) {
await chat.SetupAssistantAsync("Menu", new OpenAIAssistantOptions(
$"{Guid.NewGuid().ToString("N")}.pdf",
Assembly.GetExecutingAssembly().GetManifestResourceStream(DocumentResourceName),
prompt)
);
}
MarkupString ToHtml(string text) {
return (MarkupString)Markdown.ToHtml(text);
}
}
}
Add the following code to the Program.cs file to register the AI Assistant service in the application:
builder.Services.AddDevExpressAI((config) => {
...
config.RegisterOpenAIAssistants(client, "gpt4o");
});
Include a supplementary document in the project file as an EmbeddedResource
:
<EmbeddedResource Include="Data\Restaurant Menu.pdf" />