@cobrowser/chatgpt 0.7.21 → 0.7.23-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.
@@ -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 message
37
+ */
38
+ output(message: 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,16 @@ 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 message
107
+ */
108
+ output(message) {
109
+ if (!message) {
110
+ return;
111
+ }
112
+ return xss_validation_1.XSSProtector.sanitize(message);
113
+ }
102
114
  }
103
115
  exports.default = BaseService;
@@ -67,7 +67,8 @@ class CopilotService extends BaseService_1.default {
67
67
  }
68
68
  // main prompt used to instruct chatGPT to suggest some quick replies
69
69
  const mainPrompt = `Propose some quick replies for the agent to be used on the following conversation
70
- display your response as unordered list:-\n${conversation}`,
70
+ Your response must only contains a valid JSON array of strings like this:
71
+ ["Reply 1", "Reply 2", "Reply 3"]. the conversation is:-\n${conversation}`,
71
72
  // main prompt will be the whole conversation as string
72
73
  mainPromptMessage = {
73
74
  role: ChatGptMessage_1.ChatGptRole.USER,
@@ -155,9 +156,9 @@ class CopilotService extends BaseService_1.default {
155
156
  const messages = data.flatMap((message) => message === null || message === void 0 ? void 0 : message.content.map((content) => ((content.type === 'text' && message.role === 'assistant') ? content.text : '')));
156
157
  const assistantMessages = messages.filter(message => typeof message === 'object' && 'value' in message && typeof message.value === 'string');
157
158
  if (assistantMessages.length) {
158
- let answers = assistantMessages.map(message => message.value).join('\n');
159
+ let answers = assistantMessages.map(message => message.value);
159
160
  return {
160
- firstChoice: answers,
161
+ firstChoice: JSON.stringify(answers),
161
162
  threadId: run.thread_id,
162
163
  usageTokens: run.usage,
163
164
  };
@@ -54,7 +54,7 @@ class TranslationService extends BaseService_1.default {
54
54
  try {
55
55
  const response = yield this.request.post('', requestBody);
56
56
  return {
57
- firstChoice: this.getResponseFirstChoice(response),
57
+ firstChoice: this.output(this.getResponseFirstChoice(response)),
58
58
  usageTokens: this.getResponseUsageTokens(response),
59
59
  };
60
60
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cobrowser/chatgpt",
3
- "version": "0.7.21",
3
+ "version": "0.7.23-beta.1",
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": "^1.0.8",
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": "3a426ebc382c861be00fdef6455b611075436ece"
43
+ "gitHead": "7d9d8c6fe2a6beab099ee60a685d38599f443d25"
43
44
  }