Skip to content

Commit 546946c

Browse files
Merge pull request #3598 from syncfusion-content/DataFormSmartAISample
Added tags for code snippets for the MAUI DataForm Smart Data Entry AI Sample UG Document.
2 parents b906332 + 1854393 commit 546946c

File tree

1 file changed

+88
-22
lines changed

1 file changed

+88
-22
lines changed

MAUI/DataForm/AI-Powered-Smart-DataForm.md

Lines changed: 88 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,28 @@ To enable AI functionality in your .NET MAUI Scheduler, first ensure that you ha
2525

2626
To connect your .NET MAUI app to Azure OpenAI, create a service class that handles communication with the AI model.
2727

28-
```
28+
{% tabs %}
29+
30+
{% highlight c# %}
31+
2932
/// <summary>
3033
/// Represents Class to interact with Azure AI.
3134
/// </summary>
3235
internal class DataFormAIService : AzureBaseService
3336
{
3437

3538
}
36-
```
39+
40+
{% endhighlight %}
41+
42+
{% endtabs %}
43+
3744
In this service, define a method called `GetAnswerFromGPT`. This method takes a user prompt from the SfAIAssistView control as input, sends it to the deployed model (e.g., GPT35Turbo), and returns the AI-generated response.
3845

39-
```
46+
{% tabs %}
47+
48+
{% highlight c# %}
49+
4050
/// <summary>
4151
/// Represents Class to interact with Azure AI.
4252
/// </summary>
@@ -81,11 +91,17 @@ In this service, define a method called `GetAnswerFromGPT`. This method takes a
8191
}
8292
}
8393
}
84-
```
94+
95+
{% endhighlight %}
96+
97+
{% endtabs %}
8598

8699
Within the base service class (AzureBaseService), initialize the OpenAIClient with your Azure endpoint, deployment name, and API key.
87100

88-
```
101+
{% tabs %}
102+
103+
{% highlight c# %}
104+
89105
public abstract class AzureBaseService
90106
{
91107
#region Fields
@@ -143,7 +159,10 @@ Within the base service class (AzureBaseService), initialize the OpenAIClient wi
143159
}
144160
}
145161
}
146-
```
162+
163+
{% endhighlight %}
164+
165+
{% endtabs %}
147166

148167
## Integrating AI-powered smart DataForm Generation in .NET MAUI DataForm
149168

@@ -153,7 +172,10 @@ Within the base service class (AzureBaseService), initialize the OpenAIClient wi
153172

154173
Use an Editor to collect natural language prompts and a Button to send the prompt to Azure OpenAI. The Editor allows users to describe the form they want, while the Button triggers the logic to process the prompt and generate the form.
155174

156-
```
175+
{% tabs %}
176+
177+
{% highlight xaml %}
178+
157179
<VerticalStackLayout Margin="20" VerticalOptions="Center" HorizontalOptions="Center">
158180
<Label x:Name="describeLabel"
159181
Text="Create AI-Powered Smart Forms in .NET MAUI for Efficient Productivity."
@@ -173,26 +195,38 @@ Use an Editor to collect natural language prompts and a Button to send the promp
173195
VerticalOptions="Center" HorizontalOptions="Start" />
174196
</Grid>
175197
</VerticalStackLayout>
176-
```
198+
199+
{% endhighlight %}
200+
201+
{% endtabs %}
177202

178203
#### Busy Indicator - Showing Processing Status
179204

180205
The SfBusyIndicator provides visual feedback while the AI processes the prompt. It is shown during form generation and hidden once the form is ready.
181206

182-
```
207+
{% tabs %}
208+
209+
{% highlight xaml %}
210+
183211
xmlns:core="clr-namespace:Syncfusion.Maui.Core;assembly=Syncfusion.Maui.Core"
184212

185213
<core:SfBusyIndicator IsVisible="False"
186214
x:Name="busyIndicator"
187215
IsRunning="False"
188216
AnimationType="Cupertino" />
189-
```
217+
218+
{% endhighlight %}
219+
220+
{% endtabs %}
190221

191222
#### DataForm - Displaying the Generated Form
192223

193224
The SfDataForm renders the generated form dynamically based on the AI response.
194225

195-
```
226+
{% tabs %}
227+
228+
{% highlight xaml %}
229+
196230
xmlns:dataform="clr-namespace:Syncfusion.Maui.DataForm;assembly=Syncfusion.Maui.DataForm"
197231

198232
<dataform:SfDataForm x:Name="dataForm"
@@ -205,13 +239,19 @@ xmlns:dataform="clr-namespace:Syncfusion.Maui.DataForm;assembly=Syncfusion.Maui.
205239
<dataform:TextInputLayoutSettings ShowHelperText="True"/>
206240
</dataform:SfDataForm.TextInputLayoutSettings>
207241
</dataform:SfDataForm>
208-
```
242+
243+
{% endhighlight %}
244+
245+
{% endtabs %}
209246

210247
#### AI AssistView - Providing Suggestions
211248

212249
The SfAIAssistView offers contextual help, such as real-time suggestions or chatbot-style assistance.
213250

214-
```
251+
{% tabs %}
252+
253+
{% highlight xaml %}
254+
215255
<aiassistview:SfAIAssistView x:Name="aiAssistView"
216256
Grid.Row="1" HorizontalOptions="Fill"
217257
ShowHeader="False"
@@ -221,15 +261,21 @@ The SfAIAssistView offers contextual help, such as real-time suggestions or chat
221261
DataFormNameLabel="{x:Reference dataFormNameLabel}" BusyIndicator="{x:Reference busyIndicator}" DataForm="{x:Reference dataForm}" DataFormGeneratorModel="{x:Reference dataFormGeneratorModel}" Entry="{x:Reference entry}" CreateButton="{x:Reference createButton}"/>
222262
</aiassistview:SfAIAssistView.Behaviors>
223263
</aiassistview:SfAIAssistView>
224-
```
264+
265+
{% endhighlight %}
266+
267+
{% endtabs %}
225268

226269
### Step 2: Create and Edit Data Form Items using Azure OpenAI
227270

228271
#### Creating Data Form Items
229272

230273
We first create a button click event that triggers the AI-powered form item generation process.
231274

232-
```
275+
{% tabs %}
276+
277+
{% highlight c# %}
278+
233279
private async void OnCreateButtonClicked(object? sender, EventArgs e)
234280
{
235281
UpdateBusyIndicator(true);
@@ -246,13 +292,19 @@ We first create a button click event that triggers the AI-powered form item gene
246292
}
247293

248294
}
249-
```
295+
296+
{% endhighlight %}
297+
298+
{% endtabs %}
250299

251300
#### Generate Items from User Prompts
252301

253302
The following method sends the user’s prompt to Azure OpenAI and processes the response to generate actions such as New Form, Change Title, Add, Remove, or Replace.
254303

255-
```
304+
{% tabs %}
305+
306+
{% highlight c# %}
307+
256308
internal async void GetDataFormFromAI(string userPrompt)
257309
{
258310
string prompt = $"Given the user's input: {userPrompt}, determine the most appropriate single action to take. " +
@@ -302,9 +354,15 @@ internal async void GetDataFormFromAI(string userPrompt)
302354
}
303355
}
304356
}
305-
```
306357

307-
```
358+
{% endhighlight %}
359+
360+
{% endtabs %}
361+
362+
{% tabs %}
363+
364+
{% highlight c# %}
365+
308366
private async void GenerateAIDataForm(string userPrompt)
309367
{
310368
string dataFormNamePrompt = $"Generate a title for a data form based on the following string: {userPrompt}. The title should clearly reflect the purpose of the data form in general term. Provide only the title, with no additional explanation";
@@ -342,7 +400,10 @@ private async void GenerateAIDataForm(string userPrompt)
342400
UpdateCreateVisibility();
343401
UpdateBusyIndicator(false);
344402
}
345-
```
403+
404+
{% endhighlight %}
405+
406+
{% endtabs %}
346407

347408
#### Generating a New Data Form
348409

@@ -374,7 +435,10 @@ Finally, the `Request` event in AIAssistView listens to user inputs and invokes
374435

375436
With these implementations, the DataForm becomes AI-powered, enabling users to create and modify form structures dynamically via Azure OpenAI.
376437

377-
```
438+
{% tabs %}
439+
440+
{% highlight c# %}
441+
378442
private async void OnAssistViewRequest(object? sender, RequestEventArgs e)
379443
{
380444
string requestText = e.RequestItem.Text;
@@ -388,7 +452,9 @@ With these implementations, the DataForm becomes AI-powered, enabling users to c
388452
await CreateOfflineDataForm(requestText);
389453
}
390454

391-
```
455+
{% endhighlight %}
456+
457+
{% endtabs %}
392458

393459
![AI powered Smart .NET MAUI Dataform](images/smart-ai-samples/Create-Data-Form-with-AI-technology-in-.NET-MAUI.gif)
394460

0 commit comments

Comments
 (0)