@@ -61,6 +61,9 @@ builder.Services.AddDevExpressAI(config =>
61
61
});
62
62
```
63
63
64
+ > [ !NOTE]
65
+ > The availability of Azure Open AI Assistants depends on region. For additional guidance in this regard, refer to the following document: [ Azure OpenAI Service models -- Assistants (Preview)] ( https://learn.microsoft.com/en-us/azure/ai-services/openai/concepts/models?tabs=global-standard%2Cstandard-chat-completions#assistants-preview ) .
66
+
64
67
Files to Review:
65
68
- [ Program.cs] ( ./CS/ReportingApp/Program.cs )
66
69
@@ -127,7 +130,7 @@ Once the document is ready, the `DocumentReady` event handler sends a request to
127
130
``` js
128
131
async function DocumentReady (sender , args ) {
129
132
const response = await sender .PerformCustomDocumentOperation (null , true );
130
- if (response .customData ) {
133
+ if (response .customData && aiTab ? . model ) {
131
134
aiTab .model .chatId = response .customData ;
132
135
aiTab .visible = true ;
133
136
}
@@ -142,23 +145,31 @@ Each time a user sends a message, the [`onMessageEntered`](https://js.devexpress
142
145
143
146
` ` ` js
144
147
// ...
145
- onMessageEntered : (e ) => {
146
- const instance = e .component ;
147
- instance .renderMessage (e .message );
148
+ async function getAIResponse (text , id ) {
148
149
const formData = new FormData ();
149
- formData .append (' text' , e .message .text );
150
- formData .append (' chatId' , model .chatId );
151
- fetch (` /AI/GetAnswer` , {
150
+ formData .append (' text' , text);
151
+ formData .append (' chatId' , id);
152
+ lastUserQuery = text;
153
+ const response = await fetch (` /AI/GetAnswer` , {
152
154
method: ' POST' ,
153
155
body: formData
154
- }).then ((x ) => {
155
- x .text ().then ((res ) => {
156
- instance .renderMessage ({
157
- text: res,
158
- author: { id: ' Assistant' }
159
- }, { id: ' Assistant' });
160
- });
161
156
});
157
+ return await response .text ();
158
+ }
159
+ // ...
160
+ function RenderAssistantMessage (instance , message ) {
161
+ instance .option ({ typingUsers: [] });
162
+ instance .renderMessage ({ timestamp: new Date (), text: message, author: assistant .name , id: assistant .id });
163
+ }
164
+ // ...
165
+ onMessageEntered: async (e ) => {
166
+ const instance = e .component ;
167
+ instance .renderMessage (e .message );
168
+ instance .option ({ typingUsers: [assistant] });
169
+ const userInput = e .message .text ;
170
+
171
+ var response = await getAIResponse (userInput, assistant .id );
172
+ RenderAssistantMessage (instance, response);
162
173
}
163
174
// ...
164
175
` ` `
@@ -242,23 +253,31 @@ Each time a user sends a message, the [`onMessageEntered`](https://js.devexpress
242
253
243
254
` ` ` js
244
255
// ...
245
- onMessageEntered : (e ) => {
246
- const instance = e .component ;
247
- instance .renderMessage (e .message );
256
+ async function getAIResponse (text , id ) {
248
257
const formData = new FormData ();
249
- formData .append (' text' , e .message .text );
250
- formData .append (' chatId' , model .chatId );
251
- fetch (` /AI/GetAnswer` , {
258
+ formData .append (' text' , text);
259
+ formData .append (' chatId' , id);
260
+ lastUserQuery = text;
261
+ const response = await fetch (` /AI/GetAnswer` , {
252
262
method: ' POST' ,
253
263
body: formData
254
- }).then ((x ) => {
255
- x .text ().then ((res ) => {
256
- instance .renderMessage ({
257
- text: res,
258
- author: { id: ' Assistant' }
259
- }, { id: ' Assistant' });
260
- });
261
264
});
265
+ return await response .text ();
266
+ }
267
+ // ...
268
+ function RenderAssistantMessage (instance , message ) {
269
+ instance .option ({ typingUsers: [] });
270
+ instance .renderMessage ({ timestamp: new Date (), text: message, author: assistant .name , id: assistant .id });
271
+ }
272
+ // ...
273
+ onMessageEntered: async (e ) => {
274
+ const instance = e .component ;
275
+ instance .renderMessage (e .message );
276
+ instance .option ({ typingUsers: [assistant] });
277
+ const userInput = e .message .text ;
278
+
279
+ var response = await getAIResponse (userInput, assistant .id );
280
+ RenderAssistantMessage (instance, response);
262
281
}
263
282
// ...
264
283
` ` `
0 commit comments