@cobrowser/chatgpt 0.7.20 → 0.7.22

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.
@@ -58,12 +58,13 @@ class AssistantService extends BaseService_1.default {
58
58
  * @param message
59
59
  */
60
60
  getReply(message, runOptions = {}) {
61
- var _a;
61
+ var _a, _b;
62
62
  return __awaiter(this, void 0, void 0, function* () {
63
63
  if (!this.assistantId || !this.threadId) {
64
64
  logger_1.default.error('Assistant and Thread are required');
65
65
  return Promise.reject(new Error('Assistant and Thread are required'));
66
66
  }
67
+ logger_1.default.info(`New run with message: ${message} & options: ${JSON.stringify(runOptions)}`);
67
68
  const openai = new openai_1.default({ apiKey: this.openaiApiKey });
68
69
  let run;
69
70
  if (runOptions.functionOutputs && this.runId) {
@@ -78,7 +79,12 @@ class AssistantService extends BaseService_1.default {
78
79
  }
79
80
  else {
80
81
  yield openai.beta.threads.messages.create(this.threadId, { role: "user", content: message });
81
- run = yield openai.beta.threads.runs.create(this.threadId, Object.assign(Object.assign({ assistant_id: (_a = this.assistantId) !== null && _a !== void 0 ? _a : '', additional_instructions: runOptions.instructions }, (runOptions.definedSchema ? { response_format: runOptions.definedSchema } : {})), { tools: runOptions.tools }));
82
+ run = yield openai.beta.threads.runs.create(this.threadId, {
83
+ assistant_id: (_a = this.assistantId) !== null && _a !== void 0 ? _a : '',
84
+ additional_instructions: runOptions.instructions,
85
+ response_format: (_b = runOptions.definedSchema) !== null && _b !== void 0 ? _b : { type: 'text' },
86
+ tools: runOptions.tools
87
+ });
82
88
  }
83
89
  }
84
90
  if (run) {
@@ -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
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cobrowser/chatgpt",
3
- "version": "0.7.20",
3
+ "version": "0.7.22",
4
4
  "description": "chatgpt services to connect our projects with chatgpt api",
5
5
  "keywords": [
6
6
  "chatgpt",
@@ -39,5 +39,5 @@
39
39
  "bugs": {
40
40
  "url": "https://bitbucket.org/cobrowser/cb_utils/issues"
41
41
  },
42
- "gitHead": "6633e2fd243d8ca83fce1eda3f96249f9efa426e"
42
+ "gitHead": "28e27011208c1da21cc0de3aa4cb35246bbd8e05"
43
43
  }