-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
171 lines (162 loc) · 4.2 KB
/
Copy pathindex.js
File metadata and controls
171 lines (162 loc) · 4.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
$(() => {
function createSendRequest(url) {
return ({ prompt, data }) => {
const isValidRequest = JSON.stringify(prompt.user || prompt).length < 5000;
if (!isValidRequest) {
return {
promise: Promise.reject(new Error('Request is too long. Specify a shorter prompt.')),
abort: () => {},
};
}
const controller = new AbortController();
const signal = controller.signal;
const promise = fetch(url, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ prompt, data }),
signal,
})
.then(response => response.json())
.then(result => {
return result.content;
});
return {
promise,
abort: () => controller.abort(),
};
};
}
const columnAiIntegration = new DevExpress.aiIntegration.AIIntegration({
sendRequest: createSendRequest(AI_COLUMN_URL),
});
const assistantAiIntegration = new DevExpress.aiIntegration.AIIntegration({
sendRequest: createSendRequest(AI_ASSISTANT_URL),
});
let chatInstance;
$('#grid-container').dxDataGrid({
dataSource: sales,
aiIntegration: columnAiIntegration,
showBorders: true,
keyExpr: 'Id',
searchPanel: {
visible: true,
width: 240,
placeholder: 'Search...',
},
groupPanel: {
visible: true,
},
headerFilter: {
visible: true,
},
filterRow: {
visible: true,
},
filterSyncEnabled: true,
paging: {
pageSize: 10,
},
pager: {
visible: true,
allowedPageSizes: [10, 25, 50, 100],
showPageSizeSelector: true,
},
aiAssistant: {
enabled: true,
aiIntegration: assistantAiIntegration,
chat: {
onInitialized(e) {
chatInstance = e.component;
},
user: {
id: 'user',
},
suggestions: {
items: [
{
text: '💡 Help',
prompt: `💡 The DataGrid AI Assistant allows you to control the component using natural language. You can execute commands such as the following:
• Sort records
• Apply a filter
• Search for a specific value
• Group records by a field
• Focus and select rows
• Modify paging settings
• Pin, resize, and reorder columns
• Configure data summaries
• Pick a suggestion or enter a custom request to get started.`,
},
{
text: '🔍 Filter Sector by Health',
prompt: 'Filter Sector by Health',
},
{
text: '↕️ Sort by Region',
prompt: 'Sort by Region',
},
{
text: '🧩 Group by Product',
prompt: 'Group by Product',
width: 170,
},
],
onItemClick(e) {
const { prompt, text } = e.itemData;
const userId = text === '💡 Help' ? 'help' : 'user';
const message = {
id: Date.now(),
timestamp: new Date(),
author: { id: userId },
text: prompt,
};
chatInstance.getDataSource().store().push([{
type: 'insert',
data: message,
}]);
},
},
},
},
columns: [
{
dataField: 'Product',
},
{
dataField: 'Amount',
caption: 'Sale Amount',
dataType: 'number',
format: 'currency',
},
{
dataField: 'Region',
dataType: 'string',
},
{
dataField: 'Sector',
dataType: 'string',
},
{
dataField: 'SaleDate',
dataType: 'date',
},
{
dataField: 'Customer',
dataType: 'string',
},
{
name: 'AI column',
caption: 'AI Column',
type: 'ai',
ai: {
prompt: 'Identify the country where product is manufactured. When looking up a country, consider Sector and Customers.',
mode: 'auto',
noDataText: 'No data',
},
width: 200,
fixed: true,
fixedPosition: 'right',
cssClass: 'ai-cell',
},
],
});
});