Skip to content

Commit d3e2615

Browse files
authored
Update README.md
1 parent f2601c1 commit d3e2615

File tree

1 file changed

+46
-27
lines changed

1 file changed

+46
-27
lines changed

README.md

+46-27
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ builder.Services.AddDevExpressAI(config =>
6161
});
6262
```
6363

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+
6467
Files to Review:
6568
- [Program.cs](./CS/ReportingApp/Program.cs)
6669

@@ -127,7 +130,7 @@ Once the document is ready, the `DocumentReady` event handler sends a request to
127130
```js
128131
async function DocumentReady(sender, args) {
129132
const response = await sender.PerformCustomDocumentOperation(null, true);
130-
if (response.customData) {
133+
if (response.customData && aiTab?.model) {
131134
aiTab.model.chatId = response.customData;
132135
aiTab.visible = true;
133136
}
@@ -142,23 +145,31 @@ Each time a user sends a message, the [`onMessageEntered`](https://js.devexpress
142145
143146
```js
144147
//...
145-
onMessageEntered: (e) => {
146-
const instance = e.component;
147-
instance.renderMessage(e.message);
148+
async function getAIResponse(text, id) {
148149
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`, {
152154
method: 'POST',
153155
body: formData
154-
}).then((x) => {
155-
x.text().then((res) => {
156-
instance.renderMessage({
157-
text: res,
158-
author: { id: 'Assistant' }
159-
}, { id: 'Assistant' });
160-
});
161156
});
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);
162173
}
163174
// ...
164175
```
@@ -242,23 +253,31 @@ Each time a user sends a message, the [`onMessageEntered`](https://js.devexpress
242253
243254
```js
244255
//...
245-
onMessageEntered: (e) => {
246-
const instance = e.component;
247-
instance.renderMessage(e.message);
256+
async function getAIResponse(text, id) {
248257
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`, {
252262
method: 'POST',
253263
body: formData
254-
}).then((x) => {
255-
x.text().then((res) => {
256-
instance.renderMessage({
257-
text: res,
258-
author: { id: 'Assistant' }
259-
}, { id: 'Assistant' });
260-
});
261264
});
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);
262281
}
263282
// ...
264283
```

0 commit comments

Comments
 (0)