Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Injectable } from '@angular/core';
import { AzureOpenAI } from 'openai';

@Injectable()
export class AiService {
chatService: AzureOpenAI;

AzureOpenAIConfig = {
dangerouslyAllowBrowser: true,
deployment: 'gpt-4o-mini',
apiVersion: '2024-02-01',
endpoint: 'https://public-api.devexpress.com/demo-openai',
apiKey: 'DEMO',
};

constructor() {
this.chatService = new AzureOpenAI(this.AzureOpenAIConfig);
}

async getAIResponse(messages: any[]) {
const params = {
messages,
model: this.AzureOpenAIConfig.deployment,
max_tokens: 1000,
temperature: 0.7,
};

const response = await this.chatService.chat.completions.create(params);
const data = { choices: response.choices };

return data.choices[0].message?.content;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Observable } from 'rxjs';
import { loadMessages } from 'devextreme-angular/common/core/localization';
import { DataSource } from 'devextreme-angular/common/data';
import { AppService } from './app.service';
import { AiService } from './ai/ai.service';

if (!/localhost/.test(document.location.host)) {
enableProdMode();
Expand Down Expand Up @@ -107,5 +108,6 @@ bootstrapApplication(AppComponent, {
providers: [
provideZoneChangeDetection({ eventCoalescing: true, runCoalescing: true }),
AppService,
AiService,
],
});
Original file line number Diff line number Diff line change
@@ -1,28 +1,20 @@
import { Injectable } from '@angular/core';
import { Observable, BehaviorSubject } from 'rxjs';
import { AzureOpenAI } from 'openai';
import { unified } from 'unified';
import remarkParse from 'remark-parse';
import remarkRehype from 'remark-rehype';
import rehypeStringify from 'rehype-stringify';
import rehypeMinifyWhitespace from 'rehype-minify-whitespace';
import { type DxChatTypes } from 'devextreme-angular/ui/chat';
import { DataSource, CustomStore } from 'devextreme-angular/common/data';
import { AiService } from './ai/ai.service';

@Injectable({
providedIn: 'root',
})

export class AppService {
chatService: AzureOpenAI;

AzureOpenAIConfig = {
dangerouslyAllowBrowser: true,
deployment: 'gpt-4o-mini',
apiVersion: '2024-02-01',
endpoint: 'https://public-api.devexpress.com/demo-openai',
apiKey: 'DEMO',
};
aiService: AiService;

REGENERATION_TEXT = 'Regeneration...';

Expand Down Expand Up @@ -51,8 +43,8 @@ export class AppService {

alertsSubject: BehaviorSubject<DxChatTypes.Alert[]> = new BehaviorSubject([]);

constructor() {
this.chatService = new AzureOpenAI(this.AzureOpenAIConfig);
constructor(aiService: AiService) {
this.aiService = aiService;
this.initDataSource();
this.typingUsersSubject.next([]);
this.alertsSubject.next([]);
Expand Down Expand Up @@ -99,17 +91,7 @@ export class AppService {
}

async getAIResponse(messages) {
const params = {
messages,
model: this.AzureOpenAIConfig.deployment,
max_tokens: 1000,
temperature: 0.7,
};

const response = await this.chatService.chat.completions.create(params);
const data = { choices: response.choices };

return data.choices[0].message?.content;
return this.aiService.getAIResponse(messages);
}

async processMessageSending(message) {
Expand Down
8 changes: 0 additions & 8 deletions apps/demos/Demos/Chat/AIAndChatbotIntegration/React/data.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
import type { ChatTypes } from 'devextreme-react/chat';

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 = 'chat-disabled';
export const ALERT_TIMEOUT = 1000 * 60;
Expand Down
41 changes: 41 additions & 0 deletions apps/demos/Demos/Chat/AIAndChatbotIntegration/React/service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { AzureOpenAI, OpenAI } from 'openai';
import type { AIResponse } from 'devextreme/common/ai-integration';

type Message = (OpenAI.ChatCompletionUserMessageParam | OpenAI.ChatCompletionAssistantMessageParam) & {
content: string;
};

export const AzureOpenAIConfig = {
dangerouslyAllowBrowser: true,
deployment: 'gpt-4o-mini',
apiVersion: '2024-02-01',
endpoint: 'https://public-api.devexpress.com/demo-openai',
apiKey: 'DEMO',
};
Comment on lines +8 to +14
Copy link

Copilot AI Jan 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The AzureOpenAIConfig is exported but not used externally based on the data.ts changes. Remove the export keyword to avoid exposing internal implementation details.

Copilot uses AI. Check for mistakes.

const chatService = new AzureOpenAI(AzureOpenAIConfig);

const wait = (delay: number): Promise<void> =>
new Promise((resolve): void => {
setTimeout(resolve, delay);
});

export async function getAIResponse(messages: Message[], delay?: number): Promise<AIResponse> {
const params = {
messages,
model: AzureOpenAIConfig.deployment,
max_tokens: 1000,
temperature: 0.7,
};

const response = await chatService.chat.completions.create(params);
const data = { choices: response.choices };

if (delay) {
await wait(delay);
}

return data.choices[0].message?.content ?? '';
}

export type { Message };
34 changes: 2 additions & 32 deletions apps/demos/Demos/Chat/AIAndChatbotIntegration/React/useApi.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,13 @@
import { useCallback, useState } from 'react';
import { AzureOpenAI, OpenAI } from 'openai';
import type { ChatTypes } from 'devextreme-react/chat';
import { CustomStore, DataSource } from 'devextreme-react/common/data';
import type { AIResponse } from 'devextreme/common/ai-integration';
import {
ALERT_TIMEOUT,
assistant,
AzureOpenAIConfig,
REGENERATION_TEXT,
} from './data.ts';

type Message = (OpenAI.ChatCompletionUserMessageParam | OpenAI.ChatCompletionAssistantMessageParam) & {
content: string;
};

const chatService = new AzureOpenAI(AzureOpenAIConfig);

const wait = (delay: number): Promise<void> =>
new Promise((resolve): void => {
setTimeout(resolve, delay);
});

export async function getAIResponse(messages: Message[], delay?: number): Promise<AIResponse> {
const params = {
messages,
model: AzureOpenAIConfig.deployment,
max_tokens: 1000,
temperature: 0.7,
};

const response = await chatService.chat.completions.create(params);
const data = { choices: response.choices };

if (delay) {
await wait(delay);
}

return data.choices[0].message?.content ?? '';
}
import { getAIResponse } from './service.ts';
import type { Message } from './service.ts';

const store: ChatTypes.Message[] = [];

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
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 = 'chat-disabled';
export const ALERT_TIMEOUT = 1000 * 60;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { AzureOpenAI } from 'openai';

export const AzureOpenAIConfig = {
dangerouslyAllowBrowser: true,
deployment: 'gpt-4o-mini',
apiVersion: '2024-02-01',
endpoint: 'https://public-api.devexpress.com/demo-openai',
apiKey: 'DEMO',
};
Comment on lines +3 to +9
Copy link

Copilot AI Jan 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Chat demos export AzureOpenAIConfig from service files in ReactJs and React implementations, but this config is not used externally based on the data.js and useApi.js changes. The export should be removed to avoid exposing internal implementation details.

Copilot uses AI. Check for mistakes.
const chatService = new AzureOpenAI(AzureOpenAIConfig);
const wait = (delay) =>
new Promise((resolve) => {
setTimeout(resolve, delay);
});
export async function getAIResponse(messages, delay) {
const params = {
messages,
model: AzureOpenAIConfig.deployment,
max_tokens: 1000,
temperature: 0.7,
};
const response = await chatService.chat.completions.create(params);
const data = { choices: response.choices };
if (delay) {
await wait(delay);
}
return data.choices[0].message?.content ?? '';
}
25 changes: 2 additions & 23 deletions apps/demos/Demos/Chat/AIAndChatbotIntegration/ReactJs/useApi.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,8 @@
import { useCallback, useState } from 'react';
import { AzureOpenAI } from 'openai';
import { CustomStore, DataSource } from 'devextreme-react/common/data';
import {
ALERT_TIMEOUT, assistant, AzureOpenAIConfig, REGENERATION_TEXT,
} from './data.js';
import { ALERT_TIMEOUT, assistant, REGENERATION_TEXT } from './data.js';
import { getAIResponse } from './service.js';

const chatService = new AzureOpenAI(AzureOpenAIConfig);
const wait = (delay) =>
new Promise((resolve) => {
setTimeout(resolve, delay);
});
export async function getAIResponse(messages, delay) {
const params = {
messages,
model: AzureOpenAIConfig.deployment,
max_tokens: 1000,
temperature: 0.7,
};
const response = await chatService.chat.completions.create(params);
const data = { choices: response.choices };
if (delay) {
await wait(delay);
}
return data.choices[0].message?.content ?? '';
}
const store = [];
const customStore = new CustomStore({
key: 'id',
Expand Down
19 changes: 1 addition & 18 deletions apps/demos/Demos/Chat/AIAndChatbotIntegration/Vue/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@

<script setup lang="ts">
import { ref, onBeforeMount } from 'vue';
import { AzureOpenAI } from 'openai';
import DxChat, { type DxChatTypes } from 'devextreme-vue/chat';
import DxButton from 'devextreme-vue/button';
import { loadMessages } from 'devextreme-vue/common/core/localization';
Expand All @@ -62,12 +61,10 @@ import {
assistant,
dataSource,
convertToHtml,
AzureOpenAIConfig,
REGENERATION_TEXT,
ALERT_TIMEOUT,
} from './data.ts';

const chatService = new AzureOpenAI(AzureOpenAIConfig);
import { getAIResponse } from './service.ts';

const typingUsers = ref<{ id: string, name: string }[]>([]);
const alerts = ref<{ message: string }[]>([]);
Expand All @@ -78,20 +75,6 @@ onBeforeMount(() => {
loadMessages(dictionary);
});

async function getAIResponse(messages: DxChatTypes.Message[]): Promise<string> {
const params: Record<string, any> = {
messages,
model: AzureOpenAIConfig.deployment,
max_tokens: 1000,
temperature: 0.7,
};

const response = await chatService.chat.completions.create(params as any);
const data = { choices: response.choices };

return data.choices[0].message?.content || '';
}

function toggleDisabledState(disabled: boolean, event?: Events.EventObject): void {
isDisabled.value = disabled;

Expand Down
8 changes: 0 additions & 8 deletions apps/demos/Demos/Chat/AIAndChatbotIntegration/Vue/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@ export const dictionary = {
},
};

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 = 'chat-disabled';
export const ALERT_TIMEOUT = 1000 * 60;
Expand Down
26 changes: 26 additions & 0 deletions apps/demos/Demos/Chat/AIAndChatbotIntegration/Vue/service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { AzureOpenAI } from 'openai';
import { type DxChatTypes } from 'devextreme-vue/chat';

const AzureOpenAIConfig = {
dangerouslyAllowBrowser: true,
deployment: 'gpt-4o-mini',
apiVersion: '2024-02-01',
endpoint: 'https://public-api.devexpress.com/demo-openai',
apiKey: 'DEMO',
};

const chatService = new AzureOpenAI(AzureOpenAIConfig);

export async function getAIResponse(messages: DxChatTypes.Message[]): Promise<string> {
const params: Record<string, any> = {
messages,
model: AzureOpenAIConfig.deployment,
max_tokens: 1000,
temperature: 0.7,
};

const response = await chatService.chat.completions.create(params as any);
const data = { choices: response.choices };

return data.choices[0].message?.content || '';
}
Loading
Loading