@cobrowser/chatgpt 0.7.23-beta.1 → 0.7.23

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.
@@ -33,8 +33,8 @@ declare class BaseService {
33
33
  /**
34
34
  * Sanitize ChatGPT response with our XSS validation package
35
35
  *
36
- * @param message
36
+ * @param data
37
37
  */
38
- output(message: string | undefined): string | undefined;
38
+ output(data: string | undefined): string | undefined;
39
39
  }
40
40
  export default BaseService;
@@ -4,8 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const axios_1 = __importDefault(require("axios"));
7
- const logger_1 = __importDefault(require("../logger"));
8
7
  const xss_validation_1 = require("@cobrowser/xss-validation");
8
+ const logger_1 = __importDefault(require("../logger"));
9
9
  class BaseService {
10
10
  /**
11
11
  *
@@ -103,13 +103,16 @@ class BaseService {
103
103
  /**
104
104
  * Sanitize ChatGPT response with our XSS validation package
105
105
  *
106
- * @param message
106
+ * @param data
107
107
  */
108
- output(message) {
109
- if (!message) {
108
+ output(data) {
109
+ if (!data) {
110
110
  return;
111
111
  }
112
- return xss_validation_1.XSSProtector.sanitize(message);
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
+ logger_1.default.info({ data, parsed, sanitized, encoded }, ':: Sanitized Response ::');
115
+ return JSON.stringify(parsed);
113
116
  }
114
117
  }
115
118
  exports.default = BaseService;
@@ -52,6 +52,7 @@ class TranslationService extends BaseService_1.default {
52
52
  ],
53
53
  };
54
54
  try {
55
+ logger_1.default.info({ requestBody }, ':: TranslationServicee.translate :: Translating ::');
55
56
  const response = yield this.request.post('', requestBody);
56
57
  return {
57
58
  firstChoice: this.output(this.getResponseFirstChoice(response)),
@@ -90,6 +91,7 @@ class TranslationService extends BaseService_1.default {
90
91
  ],
91
92
  };
92
93
  try {
94
+ logger_1.default.info({ requestBody }, ':: TranslationServicee.findTextLanguage :: Finding text language ::');
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({ requestBody }, ':: TranslationServicee.findTextLanguageBasedOnFrequency :: Finding text language ::');
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.23-beta.1",
3
+ "version": "0.7.23",
4
4
  "description": "chatgpt services to connect our projects with chatgpt api",
5
5
  "keywords": [
6
6
  "chatgpt",
@@ -22,7 +22,7 @@
22
22
  },
23
23
  "dependencies": {
24
24
  "@cobrowser/logger": "^2.0.2",
25
- "@cobrowser/xss-validation": "^1.0.8",
25
+ "@cobrowser/xss-validation": "^2.0.0",
26
26
  "axios": "^1.6.1",
27
27
  "axios-mock-adapter": "^1.22.0",
28
28
  "openai": "^4.86.2"
@@ -40,5 +40,5 @@
40
40
  "bugs": {
41
41
  "url": "https://bitbucket.org/cobrowser/cb_utils/issues"
42
42
  },
43
- "gitHead": "7d9d8c6fe2a6beab099ee60a685d38599f443d25"
43
+ "gitHead": "6b093f7acf641fade9f42d98011172182eba6cc4"
44
44
  }