@cobrowser/chatgpt 0.7.25 → 0.7.26
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.
- package/dist/services/AssistantService/AssistantService.d.ts +1 -1
- package/dist/services/AssistantService/AssistantService.js +1 -1
- package/dist/services/BaseService/BaseService.d.ts +1 -1
- package/dist/services/BaseService/BaseService.js +11 -5
- package/dist/services/ChatService/ChatService.js +1 -1
- package/dist/services/CopilotService/CopilotService.d.ts +3 -3
- package/dist/services/CopilotService/CopilotService.js +5 -5
- package/dist/services/TranslationService/TranslationService.js +3 -3
- package/package.json +2 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { AssistantResponseFormatOption } from 'openai/resources/beta/threads/threads';
|
|
1
2
|
import ChatGptResponse from '../../models/ChatGptResponse';
|
|
2
3
|
import BaseService from '../BaseService/BaseService';
|
|
3
|
-
import { AssistantResponseFormatOption } from 'openai/resources/beta/threads/threads';
|
|
4
4
|
export declare class AssistantService extends BaseService {
|
|
5
5
|
assistantId: string | undefined;
|
|
6
6
|
threadId: string | undefined;
|
|
@@ -99,7 +99,7 @@ class AssistantService extends BaseService_1.default {
|
|
|
99
99
|
const messages = data.flatMap((message) => message === null || message === void 0 ? void 0 : message.content.map((content) => ((content.type === 'text' && message.role === 'assistant') ? content.text : '')));
|
|
100
100
|
const assistantMessages = messages.filter(message => typeof message === 'object' && 'value' in message && typeof message.value === 'string');
|
|
101
101
|
if (assistantMessages.length) {
|
|
102
|
-
let answer = assistantMessages.map(message => message.value).join('\n');
|
|
102
|
+
let answer = assistantMessages.map(message => this.output(message.value, true)).join('\n');
|
|
103
103
|
return {
|
|
104
104
|
firstChoice: answer.replace(/【.*?】/g, ''),
|
|
105
105
|
threadId: run.thread_id,
|
|
@@ -105,14 +105,20 @@ class BaseService {
|
|
|
105
105
|
*
|
|
106
106
|
* @param data
|
|
107
107
|
*/
|
|
108
|
-
output(data) {
|
|
108
|
+
output(data, shouldStringify = false) {
|
|
109
109
|
if (!data) {
|
|
110
110
|
return;
|
|
111
111
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
112
|
+
// Data could be plain string or JSON string.
|
|
113
|
+
if (typeof data === 'string') {
|
|
114
|
+
try {
|
|
115
|
+
data = JSON.parse(data);
|
|
116
|
+
}
|
|
117
|
+
catch (error) { }
|
|
118
|
+
}
|
|
119
|
+
const sanitized = xss_validation_1.XSSProtector.sanitize(data), encoded = xss_validation_1.XSSProtector.encode(sanitized);
|
|
120
|
+
logger_1.default.info({ data, sanitized, encoded }, ':: Sanitized Response ::');
|
|
121
|
+
return shouldStringify ? JSON.stringify(encoded) : encoded;
|
|
116
122
|
}
|
|
117
123
|
}
|
|
118
124
|
exports.default = BaseService;
|
|
@@ -48,7 +48,7 @@ class ChatService extends BaseService_1.default {
|
|
|
48
48
|
logger_1.default.info(`:: ChatService.ask :: ${JSON.stringify(requestBody)}`);
|
|
49
49
|
try {
|
|
50
50
|
const response = yield this.request.post('', requestBody);
|
|
51
|
-
return this.getResponseFirstChoice(response);
|
|
51
|
+
return this.output(this.getResponseFirstChoice(response), true);
|
|
52
52
|
}
|
|
53
53
|
catch (e) {
|
|
54
54
|
this.handleErrors(e);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import ChatGptResponse from '../../models/ChatGptResponse';
|
|
2
|
-
import BaseService from '../BaseService/BaseService';
|
|
3
1
|
import ChatGptMessage from '../../models/ChatGptMessage';
|
|
4
2
|
import Item from '../../models/Item';
|
|
3
|
+
import BaseService from '../BaseService/BaseService';
|
|
4
|
+
import ChatGptResponse from '../../models/ChatGptResponse';
|
|
5
5
|
export declare class CopilotService extends BaseService {
|
|
6
6
|
assistantId: string | undefined;
|
|
7
7
|
threadId: string | undefined;
|
|
@@ -24,7 +24,7 @@ export declare class CopilotService extends BaseService {
|
|
|
24
24
|
* @param conversation the whole chat conversation
|
|
25
25
|
* @param items the items to recommend from
|
|
26
26
|
*/
|
|
27
|
-
recommend(conversation: ChatGptMessage[], items: Item[]): Promise<
|
|
27
|
+
recommend(conversation: ChatGptMessage[], items: Item[]): Promise<any>;
|
|
28
28
|
/**
|
|
29
29
|
* Get the reply of the assistant if the assistant_id is available
|
|
30
30
|
*
|
|
@@ -13,10 +13,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.CopilotService = void 0;
|
|
16
|
-
const BaseService_1 = __importDefault(require("../BaseService/BaseService"));
|
|
17
|
-
const logger_1 = __importDefault(require("../logger"));
|
|
18
16
|
const ChatGptMessage_1 = require("../../models/ChatGptMessage");
|
|
17
|
+
const logger_1 = __importDefault(require("../logger"));
|
|
19
18
|
const openai_1 = __importDefault(require("openai"));
|
|
19
|
+
const BaseService_1 = __importDefault(require("../BaseService/BaseService"));
|
|
20
20
|
class CopilotService extends BaseService_1.default {
|
|
21
21
|
constructor(apiKey, model, assistantId, threadId, apiUrl, maxNumberOfChoices) {
|
|
22
22
|
super(apiKey, model, apiUrl, maxNumberOfChoices);
|
|
@@ -80,7 +80,7 @@ class CopilotService extends BaseService_1.default {
|
|
|
80
80
|
messages: [mainPromptMessage],
|
|
81
81
|
}, response = yield this.request.post('', requestBody);
|
|
82
82
|
return {
|
|
83
|
-
firstChoice: this.getResponseFirstChoice(response),
|
|
83
|
+
firstChoice: this.output(this.getResponseFirstChoice(response), true),
|
|
84
84
|
usageTokens: this.getResponseUsageTokens(response),
|
|
85
85
|
};
|
|
86
86
|
}
|
|
@@ -114,7 +114,7 @@ class CopilotService extends BaseService_1.default {
|
|
|
114
114
|
model: this.chatGptModel,
|
|
115
115
|
messages: [firstMessage, ...conversation],
|
|
116
116
|
}, response = yield this.request.post('', requestBody);
|
|
117
|
-
return this.getResponseFirstChoice(response);
|
|
117
|
+
return this.output(this.getResponseFirstChoice(response), true);
|
|
118
118
|
}
|
|
119
119
|
catch (e) {
|
|
120
120
|
this.handleErrors(e);
|
|
@@ -158,7 +158,7 @@ class CopilotService extends BaseService_1.default {
|
|
|
158
158
|
if (assistantMessages.length) {
|
|
159
159
|
let answers = assistantMessages.map(message => message.value);
|
|
160
160
|
return {
|
|
161
|
-
firstChoice:
|
|
161
|
+
firstChoice: this.output((answers), true),
|
|
162
162
|
threadId: run.thread_id,
|
|
163
163
|
usageTokens: run.usage,
|
|
164
164
|
};
|
|
@@ -55,7 +55,7 @@ class TranslationService extends BaseService_1.default {
|
|
|
55
55
|
logger_1.default.info({ requestBody }, ':: TranslationServicee.translate :: Translating ::');
|
|
56
56
|
const response = yield this.request.post('', requestBody);
|
|
57
57
|
return {
|
|
58
|
-
firstChoice: this.output(this.getResponseFirstChoice(response)),
|
|
58
|
+
firstChoice: this.output(this.getResponseFirstChoice(response), true),
|
|
59
59
|
usageTokens: this.getResponseUsageTokens(response),
|
|
60
60
|
};
|
|
61
61
|
}
|
|
@@ -94,7 +94,7 @@ class TranslationService extends BaseService_1.default {
|
|
|
94
94
|
logger_1.default.info({ requestBody }, ':: TranslationServicee.findTextLanguage :: Finding text language ::');
|
|
95
95
|
const response = yield this.request.post('', requestBody);
|
|
96
96
|
return {
|
|
97
|
-
firstChoice: this.getResponseFirstChoice(response),
|
|
97
|
+
firstChoice: this.output(this.getResponseFirstChoice(response), true),
|
|
98
98
|
usageTokens: this.getResponseUsageTokens(response),
|
|
99
99
|
};
|
|
100
100
|
}
|
|
@@ -133,7 +133,7 @@ class TranslationService extends BaseService_1.default {
|
|
|
133
133
|
logger_1.default.info({ requestBody }, ':: TranslationServicee.findTextLanguageBasedOnFrequency :: Finding text language ::');
|
|
134
134
|
const response = yield this.request.post('', requestBody);
|
|
135
135
|
return {
|
|
136
|
-
firstChoice: this.getResponseFirstChoice(response),
|
|
136
|
+
firstChoice: this.output(this.getResponseFirstChoice(response), true),
|
|
137
137
|
usageTokens: this.getResponseUsageTokens(response),
|
|
138
138
|
};
|
|
139
139
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cobrowser/chatgpt",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.26",
|
|
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": "c2f7354d047df3043a1caa770b4ac509ca60bf32"
|
|
44
44
|
}
|