Skip to content

Commit 6cb7ff1

Browse files
authored
✨ AI Column: fix jQuery, React, Angular demos on the AZ server (#31780)
1 parent 0259a99 commit 6cb7ff1

File tree

14 files changed

+169
-170
lines changed

14 files changed

+169
-170
lines changed

apps/demos/Demos/DataGrid/AIColumns/Angular/app/ai.service.ts renamed to apps/demos/Demos/DataGrid/AIColumns/Angular/app/ai/ai.service.ts

File renamed without changes.

apps/demos/Demos/DataGrid/AIColumns/Angular/app/app.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
44
import { DxDataGridModule, DxPopupModule } from 'devextreme-angular';
55
import type { AIIntegration } from 'devextreme-angular/common/ai-integration';
66
import { Service, type Vehicle } from './app.service';
7-
import { AiService } from './ai.service';
7+
import { AiService } from './ai/ai.service';
88
import { Trademark } from './trademark/trademark.component';
99
import { Category } from './category/category.component';
1010
import { LicenseInfo } from './license-info/license-info.component';

apps/demos/Demos/DataGrid/AIColumns/React/App.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import DataGrid, {
33
Column,
44
Paging,
55
Grouping,
6-
Ai,
6+
AI,
77
} from 'devextreme-react/data-grid';
88
import Popup, { Position } from 'devextreme-react/popup';
99
import { vehicles } from './data.ts';
@@ -91,7 +91,7 @@ export default function App() {
9191
fixedPosition="right"
9292
cssClass="ai__cell"
9393
>
94-
<Ai
94+
<AI
9595
mode="auto"
9696
noDataText="No data"
9797
prompt="Identify the country where this vehicle model is originally manufactured or developed, based on its brand, model, and specifications."

apps/demos/Demos/DataGrid/AIColumns/ReactJs/App.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { useCallback, useState } from 'react';
22
import DataGrid, {
3-
Column, Paging, Grouping, Ai,
3+
Column, Paging, Grouping, AI,
44
} from 'devextreme-react/data-grid';
55
import Popup, { Position } from 'devextreme-react/popup';
66
import { vehicles } from './data.js';
@@ -83,7 +83,7 @@ export default function App() {
8383
fixedPosition="right"
8484
cssClass="ai__cell"
8585
>
86-
<Ai
86+
<AI
8787
mode="auto"
8888
noDataText="No data"
8989
prompt="Identify the country where this vehicle model is originally manufactured or developed, based on its brand, model, and specifications."

apps/demos/Demos/DataGrid/AIColumns/jQuery/index.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
window.AzureOpenAI = AzureOpenAI;
1616
</script>
17-
<script type="module" src="service.js"></script>
1817
<script src="data.js"></script>
1918
<script src="index.js"></script>
2019
<link rel="stylesheet" type="text/css" href="styles.css" />

apps/demos/Demos/DataGrid/AIColumns/jQuery/index.js

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,81 @@
11
$(() => {
2+
const deployment = 'gpt-4o-mini';
3+
const apiVersion = '2024-02-01';
4+
const endpoint = 'https://public-api.devexpress.com/demo-openai';
5+
const apiKey = 'DEMO';
6+
7+
const aiService = new AzureOpenAI({
8+
dangerouslyAllowBrowser: true,
9+
deployment,
10+
endpoint,
11+
apiVersion,
12+
apiKey,
13+
});
14+
15+
async function getAIResponse(messages, signal) {
16+
const params = {
17+
messages,
18+
model: deployment,
19+
max_tokens: 1000,
20+
temperature: 0.7,
21+
};
22+
const response = await aiService.chat.completions
23+
.create(params, { signal });
24+
const result = response.choices[0].message?.content;
25+
26+
return result;
27+
}
28+
29+
async function getAIResponseRecursive(messages, signal) {
30+
return getAIResponse(messages, signal)
31+
.catch(async (error) => {
32+
if (!error.message.includes('Connection error')) {
33+
return Promise.reject(error);
34+
}
35+
36+
DevExpress.ui.notify({
37+
message: 'You have reached the AI rate limits of this demo. Retrying in 30 seconds...',
38+
width: 'auto',
39+
type: 'error',
40+
displayTime: 5000,
41+
});
42+
43+
await new Promise((resolve) => setTimeout(resolve, 30000));
44+
45+
return getAIResponseRecursive(messages, signal);
46+
});
47+
}
48+
49+
const aiIntegration = new DevExpress.aiIntegration({
50+
sendRequest({ prompt }) {
51+
const isValidRequest = JSON.stringify(prompt.user).length < 5000;
52+
if (!isValidRequest) {
53+
return {
54+
promise: Promise.reject(new Error('Request is too large')),
55+
abort: () => {},
56+
};
57+
}
58+
const controller = new AbortController();
59+
const signal = controller.signal;
60+
61+
const aiPrompt = [
62+
{ role: 'system', content: prompt.system },
63+
{ role: 'user', content: prompt.user },
64+
];
65+
66+
const promise = getAIResponseRecursive(aiPrompt, signal);
67+
68+
const result = {
69+
promise,
70+
abort: () => {
71+
controller.abort();
72+
},
73+
};
74+
75+
return result;
76+
},
77+
});
78+
279
const popupContentTemplate = function (vehicle) {
380
const {
481
Source,

apps/demos/Demos/DataGrid/AIColumns/jQuery/service.js

Lines changed: 0 additions & 79 deletions
This file was deleted.

apps/demos/Demos/TreeList/AIColumns/Angular/app/ai.service.ts renamed to apps/demos/Demos/TreeList/AIColumns/Angular/app/ai/ai.service.ts

File renamed without changes.

apps/demos/Demos/TreeList/AIColumns/Angular/app/app.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
44
import { DxTreeListModule } from 'devextreme-angular';
55
import type { AIIntegration } from 'devextreme-angular/common/ai-integration';
66
import { Service, type IEmployee } from './app.service';
7-
import { AiService } from './ai.service';
7+
import { AiService } from './ai/ai.service';
88
import { Email } from './email/email.component';
99
import { Employee } from './employee/employee.component';
1010
import { Status } from './status/status.component';

apps/demos/Demos/TreeList/AIColumns/React/App.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import React from 'react';
2-
import TreeList, { Column, Scrolling, Paging, Ai } from 'devextreme-react/tree-list';
2+
import TreeList, {
3+
Column,
4+
Scrolling,
5+
Paging,
6+
AI,
7+
} from 'devextreme-react/tree-list';
38
import { employees } from './data.ts';
49
import { aiIntegration } from './service.ts';
510
import Employee from './Employee.tsx';
@@ -67,7 +72,7 @@ export default function App() {
6772
fixedPosition="right"
6873
cssClass="ai__cell"
6974
>
70-
<Ai
75+
<AI
7176
mode="auto"
7277
noDataText="No data"
7378
prompt="Identify department for each employee. It should be one of the following department types: 'Management', 'Human Resources', 'IT', 'Shipping', 'Support', 'Sales', 'Engineering'. Use 'Engineering' by default."

0 commit comments

Comments
 (0)