Skip to content

Commit baae6a1

Browse files
v0.4.0-beta.1
1 parent 02d7de7 commit baae6a1

File tree

14 files changed

+414
-12
lines changed

14 files changed

+414
-12
lines changed

package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "quickblox-react-ui-kit",
3-
"version": "0.3.1",
3+
"version": "0.4.0-beta.1",
44
"main": "dist/index-ui.js",
55
"license": "MIT",
66
"dependencies": {
@@ -12,7 +12,7 @@
1212
"qb-ai-core": "^0.1.3",
1313
"qb-ai-rephrase": "^0.1.2",
1414
"qb-ai-translate": "^0.1.2",
15-
"quickblox": "^2.16.4",
15+
"quickblox": "^2.17.0-beta.1",
1616
"react": "^18.2.0",
1717
"react-dom": "^18.2.0",
1818
"react-router-dom": "^6.11.1",

src/CommonTypes/CommonTypes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export interface WidgetConfig {
2121
maxTokens: number;
2222
useDefault: boolean;
2323
proxyConfig: ProxyConfig;
24+
smartChatAssistantId: string;
2425
}
2526

2627
export interface AITranslateWidgetConfig extends WidgetConfig {

src/Data/DefaultConfigurations.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ export class DefaultConfigurations {
147147
AIAnswerAssistWidgetConfig: {
148148
organizationName: 'Quickblox',
149149
openAIModel: 'gpt-3.5-turbo',
150+
smartChatAssistantId: '',
150151
apiKey: '',
151152
maxTokens: 3584,
152153
useDefault: true,
@@ -159,6 +160,7 @@ export class DefaultConfigurations {
159160
AITranslateWidgetConfig: {
160161
organizationName: 'Quickblox',
161162
openAIModel: 'gpt-3.5-turbo',
163+
smartChatAssistantId: '',
162164
apiKey: '',
163165
maxTokens: 3584,
164166
useDefault: true,
@@ -178,7 +180,8 @@ export class DefaultConfigurations {
178180
AIRephraseWidgetConfig: {
179181
organizationName: 'Quickblox',
180182
openAIModel: 'gpt-3.5-turbo',
181-
apiKey: '',
183+
smartChatAssistantId: '',
184+
apiKey: '6633a1300fea600001bd6e71',
182185
maxTokens: 3584,
183186
useDefault: true,
184187
defaultTone: 'Professional',

src/Data/repository/ConnectionRepository.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ export default class ConnectionRepository extends SubscriptionPerformer<boolean>
104104
const pingChat = (): Promise<string> => {
105105
return new Promise<string>((resolve, reject) => {
106106
try {
107-
QB.chat.ping((error) => {
107+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
108+
QB.chat.pingchat((error) => {
108109
if (error) {
109110
console.log('ping failed: ', stringifyError(error));
110111
resolve('failed');

src/Data/source/remote/IRemoteDataSource.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import { ChatMessage } from 'qb-ai-core';
2+
import { AIAnswerAssistantSettings } from 'qb-ai-answer-assistant';
3+
import { AITranslateSettings } from 'qb-ai-translate';
4+
import {AIChatHistory, AIChatMessage} from 'quickblox';
15
import { RemoteDialogDTO } from '../../dto/dialog/RemoteDialogDTO';
26
import { RemoteDialogsDTO } from '../../dto/dialog/RemoteDialogsDTO';
37
import { RemoteUserDTO } from '../../dto/user/RemoteUserDTO';
@@ -8,6 +12,7 @@ import { RemoteFileDTO } from '../../dto/file/RemoteFileDTO';
812
import { Pagination } from '../../../Domain/repository/Pagination';
913
import { CallBackFunction } from '../../../Domain/use_cases/base/IUseCase';
1014
import { NotificationTypes } from '../../../Domain/entity/NotificationTypes';
15+
import {AIAnswerResponse} from "../../../qb-api-calls";
1116
// todo list of all actions - for what we need to create tests
1217
/*
1318
0!!! не реализованы эксепшены для createDialog RemouteDataSource и
@@ -111,4 +116,16 @@ export interface IRemoteDataSource extends IRemoteMessaging<RemoteMessageDTO> {
111116
subscribeToChatConnectionEvents(fileId: string): Promise<void>;
112117

113118
updateCurrentDialog(dto: RemoteDialogDTO): void;
119+
120+
createAnswer(
121+
text: string,
122+
messages: AIChatHistory,
123+
smartChatAssistantId: string,
124+
): Promise<AIAnswerResponse>;
125+
126+
translate(
127+
text: string,
128+
languageCode: string,
129+
smartChatAssistantId: string,
130+
): Promise<AIAnswerResponse>;
114131
}

src/Data/source/remote/RemoteDataSource.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import QB, {
1414
QBSystemMessage,
1515
QBUser,
1616
QBMessageStatusParams,
17+
AIChatHistory,
1718
} from 'quickblox/quickblox';
1819
import { RemoteDialogDTO } from '../../dto/dialog/RemoteDialogDTO';
1920
import {
@@ -34,6 +35,8 @@ import { DialogDTOMapper } from './Mapper/DialogDTOMapper';
3435
import { IDTOMapper } from './Mapper/IDTOMapper';
3536
import { Stubs } from '../../Stubs';
3637
import {
38+
AIAnswerResponse,
39+
QBAnswerAssist,
3740
QBChatConnect,
3841
QBChatDisconnect,
3942
qbChatGetMessagesExtended,
@@ -56,6 +59,7 @@ import {
5659
QBLogout,
5760
QBSendIsStopTypingStatus,
5861
QBSendIsTypingStatus,
62+
QBTranslate,
5963
QBUpdateDialog,
6064
QBUsersGet,
6165
QBUsersGetById,
@@ -179,6 +183,24 @@ export class RemoteDataSource implements IRemoteDataSource {
179183
new SubscriptionPerformer<RemoteMessageDTO>();
180184
}
181185

186+
// eslint-disable-next-line class-methods-use-this
187+
createAnswer(
188+
text: string,
189+
messages: AIChatHistory,
190+
smartChatAssistantId: string,
191+
): Promise<AIAnswerResponse> {
192+
return QBAnswerAssist(smartChatAssistantId, text, messages);
193+
}
194+
195+
// eslint-disable-next-line class-methods-use-this
196+
translate(
197+
text: string,
198+
languageCode: string,
199+
smartChatAssistantId: string,
200+
): Promise<AIAnswerResponse> {
201+
return QBTranslate(smartChatAssistantId, text, languageCode);
202+
}
203+
182204
async updateCurrentDialog(dto: RemoteDialogDTO): Promise<void> {
183205
this.currentDialog = dto;
184206
//
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// eslint-disable-next-line import/extensions
2+
import { AIChatMessage, AIRole } from 'quickblox';
3+
import { IChatMessage } from '../../../Data/source/AISource';
4+
import { IUseCase } from '../base/IUseCase';
5+
import { IRemoteDataSource } from '../../../Data/source/remote/IRemoteDataSource';
6+
import { AIAnswerResponse } from '../../../qb-api-calls';
7+
8+
interface AIChatMessageEx extends AIChatMessage {
9+
content: string;
10+
}
11+
export class AIAnswerAssistWithSDKUseCase implements IUseCase<void, string> {
12+
private textToSend: string;
13+
14+
private dialogMessages: IChatMessage[];
15+
16+
private dataSource: IRemoteDataSource;
17+
18+
private smartChatAssistantId: string;
19+
20+
constructor(
21+
textToSend: string,
22+
dialogMessages: IChatMessage[],
23+
dataSource: IRemoteDataSource,
24+
smartChatAssistantId: string,
25+
) {
26+
console.log('CONSTRUCTOR AIAnswerAssistWithSDKUseCase');
27+
this.textToSend = textToSend;
28+
this.dialogMessages = dialogMessages;
29+
this.dataSource = dataSource;
30+
this.smartChatAssistantId = smartChatAssistantId;
31+
}
32+
33+
async execute(): Promise<string> {
34+
console.log('execute AIAnswerAssistWithSDKUseCase');
35+
const history: AIChatMessageEx[] = this.dialogMessages.map(
36+
(msg: IChatMessage) => {
37+
return {
38+
role: msg.role as AIRole,
39+
message: msg.content,
40+
content: msg.content,
41+
} as AIChatMessageEx;
42+
},
43+
);
44+
const response: AIAnswerResponse = await this.dataSource.createAnswer(
45+
this.textToSend,
46+
history,
47+
this.smartChatAssistantId,
48+
);
49+
50+
return response.answer;
51+
}
52+
}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
// eslint-disable-next-line import/extensions
2+
import { IUseCase } from '../base/IUseCase';
3+
import { IRemoteDataSource } from '../../../Data/source/remote/IRemoteDataSource';
4+
import { AIAnswerResponse } from '../../../qb-api-calls';
5+
6+
export class AITranslateWithSDKUseCase implements IUseCase<void, string> {
7+
private languageCodes: { [key: string]: string } = {
8+
English: 'en',
9+
Spanish: 'es',
10+
'Chinese simplified': 'zh-Hans',
11+
'Chinese traditional': 'zh-Hant',
12+
French: 'fr',
13+
German: 'de',
14+
Japanese: 'ja',
15+
Korean: 'ko',
16+
Italian: 'it',
17+
Russian: 'ru',
18+
Portuguese: 'pt',
19+
Arabic: 'ar',
20+
Hindi: 'hi',
21+
Turkish: 'tr',
22+
Dutch: 'nl',
23+
Polish: 'pl',
24+
Ukrainian: 'uk',
25+
Albanian: 'sq',
26+
Armenian: 'hy',
27+
Azerbaijani: 'az',
28+
Basque: 'eu',
29+
Belarusian: 'be',
30+
Bengali: 'bn',
31+
Bosnian: 'bs',
32+
Bulgarian: 'bg',
33+
Catalan: 'ca',
34+
Croatian: 'hr',
35+
Czech: 'cs',
36+
Danish: 'da',
37+
Estonian: 'et',
38+
Finnish: 'fi',
39+
Galician: 'gl',
40+
Georgian: 'ka',
41+
Greek: 'el',
42+
Gujarati: 'gu',
43+
Hungarian: 'hu',
44+
Indonesian: 'id',
45+
Irish: 'ga',
46+
Kannada: 'kn',
47+
Kazakh: 'kk',
48+
Latvian: 'lv',
49+
Lithuanian: 'lt',
50+
Macedonian: 'mk',
51+
Malay: 'ms',
52+
Maltese: 'mt',
53+
Mongolian: 'mn',
54+
Nepali: 'ne',
55+
Norwegian: 'no',
56+
Pashto: 'ps',
57+
Persian: 'fa',
58+
Punjabi: 'pa',
59+
Romanian: 'ro',
60+
Sanskrit: 'sa',
61+
Serbian: 'sr',
62+
Sindhi: 'sd',
63+
Sinhala: 'si',
64+
Slovak: 'sk',
65+
Slovenian: 'sl',
66+
Uzbek: 'uz',
67+
Vietnamese: 'vi',
68+
Welsh: 'cy',
69+
};
70+
71+
private textToSend: string;
72+
73+
private language: string;
74+
75+
private dataSource: IRemoteDataSource;
76+
77+
private smartChatAssistantId: string;
78+
79+
constructor(
80+
textToSend: string,
81+
language: string,
82+
dataSource: IRemoteDataSource,
83+
smartChatAssistantId: string,
84+
) {
85+
console.log('CONSTRUCTOR AITranslateWithSDKUseCase');
86+
this.dataSource = dataSource;
87+
this.textToSend = textToSend;
88+
this.language = language;
89+
this.smartChatAssistantId = smartChatAssistantId;
90+
}
91+
92+
getLanguageCode(language: string): string {
93+
return this.languageCodes[language] || 'en';
94+
}
95+
96+
async execute(): Promise<string> {
97+
console.log('execute AITranslateWithSDKUseCase');
98+
99+
const response: AIAnswerResponse = await this.dataSource.translate(
100+
this.textToSend,
101+
this.getLanguageCode(this.language),
102+
this.smartChatAssistantId,
103+
);
104+
105+
return response.answer;
106+
}
107+
}

0 commit comments

Comments
 (0)