@cobrowser/chatgpt 0.7.41 → 0.7.42-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -17,21 +17,22 @@ export declare class CopilotService extends BaseService {
|
|
|
17
17
|
*
|
|
18
18
|
* this will make it easy to ask chatGpt for quick replies
|
|
19
19
|
* @param conversation
|
|
20
|
+
* @param suggestionLanguage Language we want to get suggestions in
|
|
20
21
|
*/
|
|
21
|
-
suggest(conversation: string): Promise<ChatGPTResponse | undefined>;
|
|
22
|
+
suggest(conversation: string, suggestionLanguage?: string): Promise<ChatGPTResponse | undefined>;
|
|
22
23
|
/**
|
|
23
24
|
* Get suggestions from Chat Completion API.
|
|
24
25
|
*
|
|
25
26
|
* @param message
|
|
26
27
|
*/
|
|
27
|
-
getChatCompletionSuggestions(conversation: string): Promise<ChatGPTResponse | undefined>;
|
|
28
|
+
getChatCompletionSuggestions(conversation: string, suggestionLanguage?: string): Promise<ChatGPTResponse | undefined>;
|
|
28
29
|
/**
|
|
29
30
|
* Get the reply of the assistant if the assistant_id is available
|
|
30
31
|
*
|
|
31
32
|
* @param message
|
|
32
33
|
*/
|
|
33
|
-
getAssistantSuggestions(conversation: string): Promise<ChatGPTResponse | undefined>;
|
|
34
|
+
getAssistantSuggestions(conversation: string, suggestionLanguage?: string): Promise<ChatGPTResponse | undefined>;
|
|
34
35
|
private isAssistantIdFormat;
|
|
35
36
|
private isPromptIdFormat;
|
|
36
|
-
getPromptSuggestions(conversation: string): Promise<ChatGPTResponse | undefined>;
|
|
37
|
+
getPromptSuggestions(conversation: string, suggestionLanguage?: string): Promise<ChatGPTResponse | undefined>;
|
|
37
38
|
}
|
|
@@ -59,9 +59,18 @@ class CopilotService extends BaseService_1.default {
|
|
|
59
59
|
*
|
|
60
60
|
* this will make it easy to ask chatGpt for quick replies
|
|
61
61
|
* @param conversation
|
|
62
|
+
* @param suggestionLanguage Language we want to get suggestions in
|
|
62
63
|
*/
|
|
63
|
-
suggest(conversation) {
|
|
64
|
+
suggest(conversation, suggestionLanguage) {
|
|
64
65
|
return __awaiter(this, void 0, void 0, function* () {
|
|
66
|
+
logger_1.default.info({
|
|
67
|
+
suggestionLanguage,
|
|
68
|
+
conversation,
|
|
69
|
+
model: this.chatGPTModel,
|
|
70
|
+
threadId: this.threadId,
|
|
71
|
+
assistantId: this.assistantId,
|
|
72
|
+
conversationId: this.conversationId,
|
|
73
|
+
}, ':: CopilotServicee.suggest :: Fetching suggestions... ::');
|
|
65
74
|
if (!(conversation === null || conversation === void 0 ? void 0 : conversation.length)) {
|
|
66
75
|
logger_1.default.error('Conversation must be provided');
|
|
67
76
|
return Promise.reject(new Error('Conversation must be provided'));
|
|
@@ -78,11 +87,14 @@ class CopilotService extends BaseService_1.default {
|
|
|
78
87
|
}
|
|
79
88
|
// Route based on id shape: asst_* => Assistant API, prompt_* => Responses API
|
|
80
89
|
if (yield this.isAssistantIdFormat(this.assistantId)) {
|
|
81
|
-
|
|
90
|
+
logger_1.default.info(':: CopilotServicee.suggest :: Fetching suggestion through Assistant API ::');
|
|
91
|
+
return yield this.getAssistantSuggestions(conversation, suggestionLanguage);
|
|
82
92
|
}
|
|
83
|
-
|
|
93
|
+
logger_1.default.info(':: CopilotServicee.suggest :: Fetching suggestion through Responses API ::');
|
|
94
|
+
return yield this.getPromptSuggestions(conversation, suggestionLanguage);
|
|
84
95
|
}
|
|
85
|
-
|
|
96
|
+
logger_1.default.info(':: CopilotServicee.suggest :: Fetching suggestion through Chat Completion API ::');
|
|
97
|
+
return yield this.getChatCompletionSuggestions(conversation, suggestionLanguage);
|
|
86
98
|
}
|
|
87
99
|
catch (e) {
|
|
88
100
|
this.handleErrors(e);
|
|
@@ -95,14 +107,19 @@ class CopilotService extends BaseService_1.default {
|
|
|
95
107
|
*
|
|
96
108
|
* @param message
|
|
97
109
|
*/
|
|
98
|
-
getChatCompletionSuggestions(conversation) {
|
|
110
|
+
getChatCompletionSuggestions(conversation, suggestionLanguage) {
|
|
99
111
|
return __awaiter(this, void 0, void 0, function* () {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
112
|
+
const mainPrompt = `
|
|
113
|
+
Propose some quick replies for the agent to be used on the following conversation:
|
|
114
|
+
|
|
115
|
+
${conversation}
|
|
116
|
+
|
|
117
|
+
Your response must only contain a valid JSON array of strings. For example:
|
|
118
|
+
|
|
119
|
+
["Reply 1", "Reply 2", "Reply 3"]
|
|
120
|
+
|
|
121
|
+
${suggestionLanguage ? `The replies must be in ${suggestionLanguage}.` : ''}
|
|
122
|
+
`.trim(), mainPromptMessage = {
|
|
106
123
|
role: ChatGPTMessage_1.ChatGPTRole.USER,
|
|
107
124
|
content: mainPrompt,
|
|
108
125
|
},
|
|
@@ -122,11 +139,10 @@ class CopilotService extends BaseService_1.default {
|
|
|
122
139
|
*
|
|
123
140
|
* @param message
|
|
124
141
|
*/
|
|
125
|
-
getAssistantSuggestions(conversation) {
|
|
142
|
+
getAssistantSuggestions(conversation, suggestionLanguage) {
|
|
126
143
|
var _a, _b;
|
|
127
144
|
return __awaiter(this, void 0, void 0, function* () {
|
|
128
|
-
const conversationLines = conversation.split('\n').filter(line => line.trim());
|
|
129
|
-
const messages = [];
|
|
145
|
+
const conversationLines = conversation.split('\n').filter(line => line.trim()), messages = [];
|
|
130
146
|
for (const line of conversationLines) {
|
|
131
147
|
if (line.includes('customer:')) {
|
|
132
148
|
messages.push({
|
|
@@ -188,9 +204,10 @@ class CopilotService extends BaseService_1.default {
|
|
|
188
204
|
lastMessageIndex: (messages.length - 1).toString()
|
|
189
205
|
}
|
|
190
206
|
});
|
|
191
|
-
const run = yield openai.beta.threads.runs.create(this.threadId, {
|
|
192
|
-
|
|
193
|
-
|
|
207
|
+
const run = yield openai.beta.threads.runs.create(this.threadId, Object.assign({ assistant_id: (_b = this.assistantId) !== null && _b !== void 0 ? _b : '' }, (suggestionLanguage ? {
|
|
208
|
+
additional_instructions: `IMPORTANT: You must respond in ${suggestionLanguage} language only.
|
|
209
|
+
Regardless of the language used in the conversation, your response must be in ${suggestionLanguage}.`
|
|
210
|
+
} : {})));
|
|
194
211
|
let currentRun = run;
|
|
195
212
|
while (['queued', 'in_progress', 'cancelling'].includes(currentRun.status)) {
|
|
196
213
|
yield new Promise(resolve => setTimeout(resolve, 500));
|
|
@@ -216,7 +233,7 @@ class CopilotService extends BaseService_1.default {
|
|
|
216
233
|
isPromptIdFormat(id) {
|
|
217
234
|
return !!id && /^pmpt_[A-Za-z0-9]+$/.test(id);
|
|
218
235
|
}
|
|
219
|
-
getPromptSuggestions(conversation) {
|
|
236
|
+
getPromptSuggestions(conversation, suggestionLanguage) {
|
|
220
237
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
221
238
|
return __awaiter(this, void 0, void 0, function* () {
|
|
222
239
|
const conversationLines = conversation.split('\n').filter(line => line.trim());
|
|
@@ -321,12 +338,10 @@ class CopilotService extends BaseService_1.default {
|
|
|
321
338
|
const fullContext = [...contextMessages, ...allNewMessages].join('\n');
|
|
322
339
|
inputWithContext = fullContext;
|
|
323
340
|
}
|
|
324
|
-
const request = {
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
include: ['file_search_call.results'],
|
|
329
|
-
};
|
|
341
|
+
const request = Object.assign({ input: inputWithContext, store: true, conversation: { id: conversationId }, include: ['file_search_call.results'] }, (suggestionLanguage ? {
|
|
342
|
+
instructions: `IMPORTANT: You must respond in ${suggestionLanguage} language only.
|
|
343
|
+
Regardless of the language used in the conversation, your response must be in ${suggestionLanguage}.`
|
|
344
|
+
} : {}));
|
|
330
345
|
if (this.assistantId && (yield this.isPromptIdFormat(this.assistantId))) {
|
|
331
346
|
request.prompt = { id: this.assistantId };
|
|
332
347
|
}
|
|
@@ -35,8 +35,14 @@ class TranslationService extends BaseService_1.default {
|
|
|
35
35
|
logger_1.default.error('Translation text should be provided');
|
|
36
36
|
return Promise.reject(new Error('Text must be provided'));
|
|
37
37
|
}
|
|
38
|
+
logger_1.default.info({
|
|
39
|
+
text,
|
|
40
|
+
toLanguage,
|
|
41
|
+
fromLanguage,
|
|
42
|
+
additionalInstructions,
|
|
43
|
+
}, ':: TranslationServicee.translate :: Translation Data ::');
|
|
38
44
|
const translateText = `
|
|
39
|
-
Translate the following text
|
|
45
|
+
Translate the following text to ${toLanguage} if it's not already in ${toLanguage}: ${text}.
|
|
40
46
|
`;
|
|
41
47
|
const requestBody = {
|
|
42
48
|
model: this.chatGPTModel,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cobrowser/chatgpt",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.42-beta.2",
|
|
4
4
|
"description": "chatgpt services to connect our projects with chatgpt api",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"chatgpt",
|
|
@@ -40,5 +40,5 @@
|
|
|
40
40
|
"bugs": {
|
|
41
41
|
"url": "https://bitbucket.org/cobrowser/cb_utils/issues"
|
|
42
42
|
},
|
|
43
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "6dd7d39c92cfce900cf001c2f8a0dba438dc103e"
|
|
44
44
|
}
|