From 28891e1a4a8ff4658f8debfa834a6da5683ce6e9 Mon Sep 17 00:00:00 2001 From: Alexander Kozlovskiy Date: Sat, 7 Dec 2024 23:51:55 -0600 Subject: [PATCH] Chat - add ai chat bot demo for Vue --- .../Chat/AIAndChatbotIntegration/Vue/App.vue | 269 ++++++++++++++++++ .../Chat/AIAndChatbotIntegration/Vue/data.ts | 74 +++++ .../AIAndChatbotIntegration/Vue/index.html | 29 ++ .../Chat/AIAndChatbotIntegration/Vue/index.ts | 4 + 4 files changed, 376 insertions(+) create mode 100644 apps/demos/Demos/Chat/AIAndChatbotIntegration/Vue/App.vue create mode 100644 apps/demos/Demos/Chat/AIAndChatbotIntegration/Vue/data.ts create mode 100644 apps/demos/Demos/Chat/AIAndChatbotIntegration/Vue/index.html create mode 100644 apps/demos/Demos/Chat/AIAndChatbotIntegration/Vue/index.ts diff --git a/apps/demos/Demos/Chat/AIAndChatbotIntegration/Vue/App.vue b/apps/demos/Demos/Chat/AIAndChatbotIntegration/Vue/App.vue new file mode 100644 index 000000000000..da33cdf4fba3 --- /dev/null +++ b/apps/demos/Demos/Chat/AIAndChatbotIntegration/Vue/App.vue @@ -0,0 +1,269 @@ + + + + + diff --git a/apps/demos/Demos/Chat/AIAndChatbotIntegration/Vue/data.ts b/apps/demos/Demos/Chat/AIAndChatbotIntegration/Vue/data.ts new file mode 100644 index 000000000000..c4a995f167f1 --- /dev/null +++ b/apps/demos/Demos/Chat/AIAndChatbotIntegration/Vue/data.ts @@ -0,0 +1,74 @@ +import CustomStore from "devextreme/data/custom_store"; +import DataSource from "devextreme/data/data_source"; +import { unified } from 'unified'; +import remarkParse from 'remark-parse'; +import remarkRehype from 'remark-rehype'; +import rehypeStringify from 'rehype-stringify'; + +export const dictionary = { + en: { + 'dxChat-emptyListMessage': 'Chat is Empty', + 'dxChat-emptyListPrompt': 'AI Assistant is ready to answer your questions.', + 'dxChat-textareaPlaceholder': 'Ask AI Assistant...', + }, +} + +export const AzureOpenAIConfig = { + dangerouslyAllowBrowser: true, + deployment: 'gpt-4o-mini', + apiVersion: '2024-02-01', + endpoint: 'https://public-api.devexpress.com/demo-openai', + apiKey: 'DEMO', +} + +export const REGENERATION_TEXT = 'Regeneration...'; +export const CHAT_DISABLED_CLASS = 'dx-chat-disabled'; +export const ALERT_TIMEOUT = 1000 * 60; + +export const user = { + id: 'c94c0e76-fb49-4b9b-8f07-9f93ed93b4f3', + name: 'John Doe', +}; + +export const assistant = { + id: 'assistant', + name: 'Virtual Assistant', +}; + +export const store = []; +export const messages = []; + +const customStore = new CustomStore({ + key: 'id', + load: () => { + return new Promise((resolve) => { + setTimeout(() => { + resolve([...store]); + }, 0); + }); + }, + insert: (message) => { + return new Promise((resolve) => { + setTimeout(() => { + store.push(message); + resolve(message); + }); + }); + }, +}); + +export const dataSource = new DataSource({ + store: customStore, + paginate: false, +}) + +export function convertToHtml(value: string) { + const result = unified() + .use(remarkParse) + .use(remarkRehype) + .use(rehypeStringify) + .processSync(value) + .toString(); + + return result; +} diff --git a/apps/demos/Demos/Chat/AIAndChatbotIntegration/Vue/index.html b/apps/demos/Demos/Chat/AIAndChatbotIntegration/Vue/index.html new file mode 100644 index 000000000000..2413f2254bf1 --- /dev/null +++ b/apps/demos/Demos/Chat/AIAndChatbotIntegration/Vue/index.html @@ -0,0 +1,29 @@ + + + + DevExtreme Demo + + + + + + + + + + + + + + +
+
+
+ + diff --git a/apps/demos/Demos/Chat/AIAndChatbotIntegration/Vue/index.ts b/apps/demos/Demos/Chat/AIAndChatbotIntegration/Vue/index.ts new file mode 100644 index 000000000000..684d04215d72 --- /dev/null +++ b/apps/demos/Demos/Chat/AIAndChatbotIntegration/Vue/index.ts @@ -0,0 +1,4 @@ +import { createApp } from 'vue'; +import App from './App.vue'; + +createApp(App).mount('#app');