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-DataForm.md
+88-22Lines changed: 88 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,18 +25,28 @@ To enable AI functionality in your .NET MAUI Scheduler, first ensure that you ha
25
25
26
26
To connect your .NET MAUI app to Azure OpenAI, create a service class that handles communication with the AI model.
27
27
28
-
```
28
+
{% tabs %}
29
+
30
+
{% highlight c# %}
31
+
29
32
/// <summary>
30
33
/// Represents Class to interact with Azure AI.
31
34
/// </summary>
32
35
internal class DataFormAIService : AzureBaseService
33
36
{
34
37
35
38
}
36
-
```
39
+
40
+
{% endhighlight %}
41
+
42
+
{% endtabs %}
43
+
37
44
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.
38
45
39
-
```
46
+
{% tabs %}
47
+
48
+
{% highlight c# %}
49
+
40
50
/// <summary>
41
51
/// Represents Class to interact with Azure AI.
42
52
/// </summary>
@@ -81,11 +91,17 @@ In this service, define a method called `GetAnswerFromGPT`. This method takes a
81
91
}
82
92
}
83
93
}
84
-
```
94
+
95
+
{% endhighlight %}
96
+
97
+
{% endtabs %}
85
98
86
99
Within the base service class (AzureBaseService), initialize the OpenAIClient with your Azure endpoint, deployment name, and API key.
87
100
88
-
```
101
+
{% tabs %}
102
+
103
+
{% highlight c# %}
104
+
89
105
public abstract class AzureBaseService
90
106
{
91
107
#region Fields
@@ -143,7 +159,10 @@ Within the base service class (AzureBaseService), initialize the OpenAIClient wi
143
159
}
144
160
}
145
161
}
146
-
```
162
+
163
+
{% endhighlight %}
164
+
165
+
{% endtabs %}
147
166
148
167
## Integrating AI-powered smart DataForm Generation in .NET MAUI DataForm
149
168
@@ -153,7 +172,10 @@ Within the base service class (AzureBaseService), initialize the OpenAIClient wi
153
172
154
173
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.
@@ -246,13 +292,19 @@ We first create a button click event that triggers the AI-powered form item gene
246
292
}
247
293
248
294
}
249
-
```
295
+
296
+
{% endhighlight %}
297
+
298
+
{% endtabs %}
250
299
251
300
#### Generate Items from User Prompts
252
301
253
302
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.
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";
0 commit comments