@cobrowser/chatgpt 0.7.41 → 0.7.42-beta.1
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,11 @@ 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({ conversation, suggestionLanguage }, ':: CopilotServicee.suggest :: Suggestion Language ::');
|
|
65
67
|
if (!(conversation === null || conversation === void 0 ? void 0 : conversation.length)) {
|
|
66
68
|
logger_1.default.error('Conversation must be provided');
|
|
67
69
|
return Promise.reject(new Error('Conversation must be provided'));
|
|
@@ -78,11 +80,11 @@ class CopilotService extends BaseService_1.default {
|
|
|
78
80
|
}
|
|
79
81
|
// Route based on id shape: asst_* => Assistant API, prompt_* => Responses API
|
|
80
82
|
if (yield this.isAssistantIdFormat(this.assistantId)) {
|
|
81
|
-
return yield this.getAssistantSuggestions(conversation);
|
|
83
|
+
return yield this.getAssistantSuggestions(conversation, suggestionLanguage);
|
|
82
84
|
}
|
|
83
|
-
return yield this.getPromptSuggestions(conversation);
|
|
85
|
+
return yield this.getPromptSuggestions(conversation, suggestionLanguage);
|
|
84
86
|
}
|
|
85
|
-
return yield this.getChatCompletionSuggestions(conversation);
|
|
87
|
+
return yield this.getChatCompletionSuggestions(conversation, suggestionLanguage);
|
|
86
88
|
}
|
|
87
89
|
catch (e) {
|
|
88
90
|
this.handleErrors(e);
|
|
@@ -95,14 +97,19 @@ class CopilotService extends BaseService_1.default {
|
|
|
95
97
|
*
|
|
96
98
|
* @param message
|
|
97
99
|
*/
|
|
98
|
-
getChatCompletionSuggestions(conversation) {
|
|
100
|
+
getChatCompletionSuggestions(conversation, suggestionLanguage) {
|
|
99
101
|
return __awaiter(this, void 0, void 0, function* () {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
102
|
+
const mainPrompt = `
|
|
103
|
+
Propose some quick replies for the agent to be used on the following conversation:
|
|
104
|
+
|
|
105
|
+
${conversation}
|
|
106
|
+
|
|
107
|
+
Your response must only contain a valid JSON array of strings. For example:
|
|
108
|
+
|
|
109
|
+
["Reply 1", "Reply 2", "Reply 3"]
|
|
110
|
+
|
|
111
|
+
${suggestionLanguage ? `The replies must be in ${suggestionLanguage}.` : ''}
|
|
112
|
+
`.trim(), mainPromptMessage = {
|
|
106
113
|
role: ChatGPTMessage_1.ChatGPTRole.USER,
|
|
107
114
|
content: mainPrompt,
|
|
108
115
|
},
|
|
@@ -122,11 +129,10 @@ class CopilotService extends BaseService_1.default {
|
|
|
122
129
|
*
|
|
123
130
|
* @param message
|
|
124
131
|
*/
|
|
125
|
-
getAssistantSuggestions(conversation) {
|
|
132
|
+
getAssistantSuggestions(conversation, suggestionLanguage) {
|
|
126
133
|
var _a, _b;
|
|
127
134
|
return __awaiter(this, void 0, void 0, function* () {
|
|
128
|
-
const conversationLines = conversation.split('\n').filter(line => line.trim());
|
|
129
|
-
const messages = [];
|
|
135
|
+
const conversationLines = conversation.split('\n').filter(line => line.trim()), messages = [];
|
|
130
136
|
for (const line of conversationLines) {
|
|
131
137
|
if (line.includes('customer:')) {
|
|
132
138
|
messages.push({
|
|
@@ -188,9 +194,10 @@ class CopilotService extends BaseService_1.default {
|
|
|
188
194
|
lastMessageIndex: (messages.length - 1).toString()
|
|
189
195
|
}
|
|
190
196
|
});
|
|
191
|
-
const run = yield openai.beta.threads.runs.create(this.threadId, {
|
|
192
|
-
|
|
193
|
-
|
|
197
|
+
const run = yield openai.beta.threads.runs.create(this.threadId, Object.assign({ assistant_id: (_b = this.assistantId) !== null && _b !== void 0 ? _b : '' }, (suggestionLanguage ? {
|
|
198
|
+
additional_instructions: `IMPORTANT: You must respond in ${suggestionLanguage} language only.
|
|
199
|
+
Regardless of the language used in the conversation, your response must be in ${suggestionLanguage}.`
|
|
200
|
+
} : {})));
|
|
194
201
|
let currentRun = run;
|
|
195
202
|
while (['queued', 'in_progress', 'cancelling'].includes(currentRun.status)) {
|
|
196
203
|
yield new Promise(resolve => setTimeout(resolve, 500));
|
|
@@ -216,7 +223,7 @@ class CopilotService extends BaseService_1.default {
|
|
|
216
223
|
isPromptIdFormat(id) {
|
|
217
224
|
return !!id && /^pmpt_[A-Za-z0-9]+$/.test(id);
|
|
218
225
|
}
|
|
219
|
-
getPromptSuggestions(conversation) {
|
|
226
|
+
getPromptSuggestions(conversation, suggestionLanguage) {
|
|
220
227
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
221
228
|
return __awaiter(this, void 0, void 0, function* () {
|
|
222
229
|
const conversationLines = conversation.split('\n').filter(line => line.trim());
|
|
@@ -321,12 +328,10 @@ class CopilotService extends BaseService_1.default {
|
|
|
321
328
|
const fullContext = [...contextMessages, ...allNewMessages].join('\n');
|
|
322
329
|
inputWithContext = fullContext;
|
|
323
330
|
}
|
|
324
|
-
const request = {
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
include: ['file_search_call.results'],
|
|
329
|
-
};
|
|
331
|
+
const request = Object.assign({ input: inputWithContext, store: true, conversation: { id: conversationId }, include: ['file_search_call.results'] }, (suggestionLanguage ? {
|
|
332
|
+
instructions: `IMPORTANT: You must respond in ${suggestionLanguage} language only.
|
|
333
|
+
Regardless of the language used in the conversation, your response must be in ${suggestionLanguage}.`
|
|
334
|
+
} : {}));
|
|
330
335
|
if (this.assistantId && (yield this.isPromptIdFormat(this.assistantId))) {
|
|
331
336
|
request.prompt = { id: this.assistantId };
|
|
332
337
|
}
|
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.1",
|
|
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": "1f4318b0c31d19c651c89e548b58841c060617af"
|
|
44
44
|
}
|