@cobrowser/chatgpt 0.7.22 → 0.7.23-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.
|
@@ -30,5 +30,11 @@ declare class BaseService {
|
|
|
30
30
|
* @param error
|
|
31
31
|
*/
|
|
32
32
|
handleErrors(error: AxiosError): void;
|
|
33
|
+
/**
|
|
34
|
+
* Sanitize ChatGPT response with our XSS validation package
|
|
35
|
+
*
|
|
36
|
+
* @param data
|
|
37
|
+
*/
|
|
38
|
+
output(data: string | undefined): string | undefined;
|
|
33
39
|
}
|
|
34
40
|
export default BaseService;
|
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const axios_1 = __importDefault(require("axios"));
|
|
7
7
|
const logger_1 = __importDefault(require("../logger"));
|
|
8
|
+
const xss_validation_1 = require("@cobrowser/xss-validation");
|
|
8
9
|
class BaseService {
|
|
9
10
|
/**
|
|
10
11
|
*
|
|
@@ -99,5 +100,23 @@ class BaseService {
|
|
|
99
100
|
}
|
|
100
101
|
logger_1.default.error(`error message ${error.message}`);
|
|
101
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* Sanitize ChatGPT response with our XSS validation package
|
|
105
|
+
*
|
|
106
|
+
* @param data
|
|
107
|
+
*/
|
|
108
|
+
output(data) {
|
|
109
|
+
if (!data) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
const parsed = JSON.parse(data), translation = parsed.data[0].translation, sanitized = xss_validation_1.XSSProtector.sanitize(translation), encoded = xss_validation_1.XSSProtector.encode(sanitized);
|
|
113
|
+
parsed.data[0].translation = encoded;
|
|
114
|
+
console.log('data: ', data);
|
|
115
|
+
console.log('parsed: ', parsed);
|
|
116
|
+
console.log('sanitized: ', sanitized);
|
|
117
|
+
console.log('encoded: ', encoded);
|
|
118
|
+
logger_1.default.info({ data, parsed, sanitized, encoded }, ':: Sanitizing Response ::');
|
|
119
|
+
return JSON.stringify(parsed);
|
|
120
|
+
}
|
|
102
121
|
}
|
|
103
122
|
exports.default = BaseService;
|
|
@@ -52,9 +52,10 @@ class TranslationService extends BaseService_1.default {
|
|
|
52
52
|
],
|
|
53
53
|
};
|
|
54
54
|
try {
|
|
55
|
+
logger_1.default.info(`:: TranslationServicee.translate :: Translating...`);
|
|
55
56
|
const response = yield this.request.post('', requestBody);
|
|
56
57
|
return {
|
|
57
|
-
firstChoice: this.getResponseFirstChoice(response),
|
|
58
|
+
firstChoice: this.output(this.getResponseFirstChoice(response)),
|
|
58
59
|
usageTokens: this.getResponseUsageTokens(response),
|
|
59
60
|
};
|
|
60
61
|
}
|
|
@@ -90,6 +91,7 @@ class TranslationService extends BaseService_1.default {
|
|
|
90
91
|
],
|
|
91
92
|
};
|
|
92
93
|
try {
|
|
94
|
+
logger_1.default.info(`:: TranslationServicee.findTextLanguage :: Translating...`);
|
|
93
95
|
const response = yield this.request.post('', requestBody);
|
|
94
96
|
return {
|
|
95
97
|
firstChoice: this.getResponseFirstChoice(response),
|
|
@@ -128,6 +130,7 @@ class TranslationService extends BaseService_1.default {
|
|
|
128
130
|
],
|
|
129
131
|
};
|
|
130
132
|
try {
|
|
133
|
+
logger_1.default.info(`:: TranslationServicee.findTextLanguageBasedOnFrequency :: Translating...`);
|
|
131
134
|
const response = yield this.request.post('', requestBody);
|
|
132
135
|
return {
|
|
133
136
|
firstChoice: this.getResponseFirstChoice(response),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cobrowser/chatgpt",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.23-beta.2",
|
|
4
4
|
"description": "chatgpt services to connect our projects with chatgpt api",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"chatgpt",
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@cobrowser/logger": "^2.0.2",
|
|
25
|
+
"@cobrowser/xss-validation": "^2.0.0",
|
|
25
26
|
"axios": "^1.6.1",
|
|
26
27
|
"axios-mock-adapter": "^1.22.0",
|
|
27
28
|
"openai": "^4.86.2"
|
|
@@ -39,5 +40,5 @@
|
|
|
39
40
|
"bugs": {
|
|
40
41
|
"url": "https://bitbucket.org/cobrowser/cb_utils/issues"
|
|
41
42
|
},
|
|
42
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "15eb4c0a791004426ce3232ffb862fc1bd3de443"
|
|
43
44
|
}
|