-
Notifications
You must be signed in to change notification settings - Fork 671
AI Assistant: DataGrid - write JQuery demo #33562
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4fa4b6c
Add AI Assistant demo
Raushen ad8ea98
Fix comments
Raushen fce979d
Merge branch '26_1' of https://github.com/DevExpress/DevExtreme into …
Raushen 931946c
Update suggestions
Raushen 24b822c
Fix sizes
Raushen e1f5d50
Add etalons
Raushen e90346f
Update options
Raushen 6fb0f1d
Merge branch '26_1' of https://github.com/DevExpress/DevExtreme into …
Raushen 530b610
Fix condition
Raushen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
16,887 changes: 16,887 additions & 0 deletions
16,887
apps/demos/Demos/DataGrid/AIAssistant/jQuery/data.js
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| <!DOCTYPE html> | ||
| <html xmlns="http://www.w3.org/1999/xhtml" lang="en"> | ||
| <head> | ||
| <title>DevExtreme Demo</title> | ||
| <meta http-equiv="X-UA-Compatible" content="IE=edge" /> | ||
| <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0" /> | ||
| <link rel="stylesheet" type="text/css" href="../../../../node_modules/devextreme/dist/css/dx.light.css" /> | ||
| <script src="../../../../node_modules/jquery/dist/jquery.min.js"></script> | ||
| <script src="../../../../node_modules/devextreme-dist/js/dx.all.js"></script> | ||
| <script src="../../../../node_modules/devextreme-dist/js/dx.ai-integration.js"></script> | ||
| <script type="module"> | ||
| import { AzureOpenAI } from "https://esm.sh/openai@4.73.1"; | ||
|
|
||
| window.AzureOpenAI = AzureOpenAI; | ||
| </script> | ||
| <script src="data.js"></script> | ||
| <script src="index.js"></script> | ||
| </head> | ||
| <body class="dx-viewport"> | ||
| <div class="demo-container"> | ||
| <div id="data-grid-demo"> | ||
| <div id="gridContainer"></div> | ||
| </div> | ||
| </div> | ||
| </body> | ||
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,199 @@ | ||
| $(() => { | ||
| const deployment = 'gpt-4o-mini'; | ||
| const apiVersion = '2024-02-01'; | ||
| const endpoint = 'https://public-api.devexpress.com/demo-openai'; | ||
| const apiKey = 'DEMO'; | ||
|
|
||
| const aiService = new AzureOpenAI({ | ||
| dangerouslyAllowBrowser: true, | ||
| deployment, | ||
| endpoint, | ||
| apiVersion, | ||
| apiKey, | ||
| }); | ||
|
|
||
| async function getAIResponse(messages, signal, responseSchema) { | ||
| const params = { | ||
| messages, | ||
| model: deployment, | ||
| max_tokens: 1000, | ||
| temperature: 0.7, | ||
| }; | ||
|
|
||
| params.response_format = { | ||
| type: 'json_schema', | ||
| json_schema: { | ||
| name: 'grid_assistant_response', | ||
| strict: true, | ||
| schema: responseSchema, | ||
| }, | ||
| }; | ||
|
|
||
| const response = await aiService.chat.completions | ||
| .create(params, { signal }); | ||
| const result = response.choices[0].message?.content; | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| async function getAIResponseRecursive(messages, signal, responseSchema) { | ||
| return getAIResponse(messages, signal, responseSchema) | ||
| .catch(async (error) => { | ||
| if (!error.message.includes('Connection error')) { | ||
| return Promise.reject(error); | ||
| } | ||
|
|
||
| DevExpress.ui.notify({ | ||
| message: 'Our demo AI service reached a temporary request limit. Retrying in 30 seconds.', | ||
| width: 'auto', | ||
| type: 'error', | ||
| displayTime: 5000, | ||
| }); | ||
|
|
||
| await new Promise((resolve) => setTimeout(resolve, 30000)); | ||
|
|
||
| return getAIResponseRecursive(messages, signal, responseSchema); | ||
| }); | ||
| } | ||
|
|
||
| const aiIntegration = new DevExpress.aiIntegration.AIIntegration({ | ||
| sendRequest({ prompt, data }) { | ||
| const isValidRequest = JSON.stringify(prompt.user).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 aiPrompt = [ | ||
| { role: 'system', content: prompt.system }, | ||
| { role: 'user', content: prompt.user }, | ||
| ]; | ||
| const promise = getAIResponseRecursive(aiPrompt, signal, data?.responseSchema); | ||
|
|
||
| const result = { | ||
| promise, | ||
| abort: () => { | ||
| controller.abort(); | ||
| }, | ||
| }; | ||
|
|
||
| return result; | ||
| }, | ||
| }); | ||
|
|
||
| let chatInstance; | ||
|
|
||
| $('#gridContainer').dxDataGrid({ | ||
| dataSource: sales, | ||
| showBorders: true, | ||
| keyExpr: 'Id', | ||
| searchPanel: { | ||
| visible: true, | ||
| width: 240, | ||
| placeholder: 'Search...', | ||
| }, | ||
| groupPanel: { | ||
| visible: true, | ||
| }, | ||
| headerFilter: { | ||
| visible: true, | ||
| }, | ||
| filterRow: { | ||
| visible: true, | ||
| }, | ||
| paging: { | ||
| pageSize: 10, | ||
| }, | ||
| pager: { | ||
| visible: true, | ||
| allowedPageSizes: [10, 25, 50, 100], | ||
| showPageSizeSelector: true, | ||
| }, | ||
| aiAssistant: { | ||
| enabled: true, | ||
| aiIntegration, | ||
| chat: { | ||
| onInitialized(e) { | ||
| chatInstance = e.component; | ||
| }, | ||
| 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; | ||
|
|
||
| if (text === '💡 Help') { | ||
| const message = { | ||
| id: Date.now(), | ||
| timestamp: new Date(), | ||
| author: { id: 'user' }, | ||
| text: prompt, | ||
| }; | ||
|
|
||
| chatInstance.getDataSource().store().push([{ type: 'insert', data: message }]); | ||
| } else { | ||
| chatInstance.option('inputFieldText', prompt); | ||
| } | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| 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', | ||
| }, | ||
| ], | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+103 KB
apps/demos/testing/etalons/DataGrid-AIAssistant (fluent.blue.light).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+89.5 KB
apps/demos/testing/etalons/DataGrid-AIAssistant (material.blue.light).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.