You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: MAUI/DataForm/AI-Powered-Smart-Paste-DataForm.md
+64-17Lines changed: 64 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -28,19 +28,28 @@ To enable AI functionality in your .NET MAUI Scheduler, first ensure that you ha
28
28
29
29
To connect your .NET MAUI app to Azure OpenAI, create a service class that handles communication with the AI model.
30
30
31
-
```
31
+
{% tabs %}
32
+
33
+
{% highlight c# %}
34
+
32
35
/// <summary>
33
36
/// Helper class to interact with Azure AI.
34
37
/// </summary>
35
38
internal class AzureOpenAIServiceConnector : AzureBaseService
36
39
{
37
40
38
41
}
39
-
```
42
+
43
+
{% endhighlight %}
44
+
45
+
{% endtabs %}
40
46
41
47
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.
42
48
43
-
```
49
+
{% tabs %}
50
+
51
+
{% highlight c# %}
52
+
44
53
/// <summary>
45
54
/// Helper class to interact with Azure AI.
46
55
/// </summary>
@@ -77,11 +86,17 @@ internal class AzureOpenAIServiceConnector : AzureBaseService
77
86
return "";
78
87
}
79
88
}
80
-
```
89
+
90
+
{% endhighlight %}
91
+
92
+
{% endtabs %}
81
93
82
94
Within the base service class (AzureBaseService), initialize the OpenAIClient with your Azure endpoint, deployment name, and API key.
83
95
84
-
```
96
+
{% tabs %}
97
+
98
+
{% highlight c# %}
99
+
85
100
public abstract class AzureBaseService
86
101
{
87
102
#region Fields
@@ -139,15 +154,21 @@ Within the base service class (AzureBaseService), initialize the OpenAIClient wi
139
154
}
140
155
}
141
156
}
142
-
```
157
+
158
+
{% endhighlight %}
159
+
160
+
{% endtabs %}
143
161
144
162
## Integrating AI-powered Smart Paste in .NET MAUI DataForm
145
163
146
164
### Step 1: Create the DataForm Model
147
165
148
166
Define a model class (FeedBackForm) that represents the fields of the form. Add properties such as Name, Email, Product Name, Product Version, Rating and Comments. Use data annotations to configure display labels and validation rules.
149
167
150
-
```
168
+
{% tabs %}
169
+
170
+
{% highlight c# %}
171
+
151
172
/// <summary>
152
173
/// Feedback form model class
153
174
/// </summary>
@@ -188,7 +209,10 @@ public class FeedBackForm
188
209
[Display(ShortName = "Describe your feedback in detail", Name = "Comments")]
189
210
public string Comments { get; set; }
190
211
}
191
-
```
212
+
213
+
{% endhighlight %}
214
+
215
+
{% endtabs %}
192
216
193
217
### Step 2: Bind the model to the dataform
194
218
@@ -198,7 +222,10 @@ Create a view model containing an instance of the model. Assign this instance to
198
222
199
223
In XAML, set up the form layout - including labels, images, dataform control. Add a smart paste button that triggers that triggers the AI functionality and a submit button for data validation.
@@ -331,7 +358,10 @@ In XAML, set up the form layout - including labels, images, dataform control. Ad
331
358
</Border>
332
359
</Grid>
333
360
</Grid>
334
-
```
361
+
362
+
{% endhighlight %}
363
+
364
+
{% endtabs %}
335
365
336
366
### Step 4: Implement Smart Paste Functionality.
337
367
@@ -341,7 +371,10 @@ To implement this, the application first checks whether the clipboard contains a
341
371
342
372
Once the AI returns a response, the application deserialize the JSON string into a FeedBackForm object. The deserialized values are then assigned to the model bound to the DataForm, automatically updating the form fields with the extracted values.
@@ -430,14 +469,19 @@ Once the AI returns a response, the application deserialize the JSON string into
430
469
this.dataForm!.UpdateEditor(filedNames[i]);
431
470
}
432
471
}
433
-
}
434
-
```
472
+
473
+
{% endhighlight %}
474
+
475
+
{% endtabs %}
435
476
436
477
### Step 5: Validate and Submit the form
437
478
438
479
Enable DataForm validation for all the fields during submission using the Validate method. If validation passes, display a confirmation message. If validation fails, show appropriate error messages.
0 commit comments