@tiledesk/tiledesk-tybot-connector 0.2.91-rc3 → 0.2.91

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.
@@ -435,14 +435,15 @@ class TiledeskChatbotUtil {
435
435
  let fullName = message.senderFullname;
436
436
  if (fullName.trim() === chatbot_name) {
437
437
  fullName = "bot:" + fullName;
438
- } else {
438
+ }
439
+ else {
439
440
  fullName = "user:" + fullName;
440
441
  }
441
442
  return "<" + fullName + ">";
442
443
  }
443
444
  }
444
445
 
445
- static async transcriptJSON(transcript) {
446
+ static transcriptJSON(transcript) {
446
447
  const regexp = /(<.*>)/gm;
447
448
  const parts = transcript.split(regexp);
448
449
  // console.log("parts:", parts);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tiledesk/tiledesk-tybot-connector",
3
- "version": "0.2.91-rc3",
3
+ "version": "0.2.91",
4
4
  "description": "Tiledesk Tybot connector",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -3,8 +3,6 @@ const { TiledeskChatbot } = require("../../models/TiledeskChatbot");
3
3
  const { Filler } = require("../Filler");
4
4
  let https = require("https");
5
5
  const { DirIntent } = require("./DirIntent");
6
- const { TiledeskChatbotConst } = require("../../models/TiledeskChatbotConst");
7
- const { TiledeskChatbotUtil } = require("../../models/TiledeskChatbotUtil");
8
6
  require('dotenv').config();
9
7
 
10
8
  class DirGptTask {
@@ -14,7 +12,6 @@ class DirGptTask {
14
12
  throw new Error('context object is mandatory');
15
13
  }
16
14
  this.context = context;
17
- this.chatbot = this.context.chatbot;
18
15
  this.tdcache = this.context.tdcache;
19
16
  this.requestId = this.context.requestId;
20
17
  this.intentDir = new DirIntent(context);
@@ -50,7 +47,6 @@ class DirGptTask {
50
47
  let falseIntent = action.falseIntent;
51
48
  let trueIntentAttributes = action.trueIntentAttributes;
52
49
  let falseIntentAttributes = action.falseIntentAttributes;
53
- let transcript;
54
50
 
55
51
  if (this.log) {
56
52
  console.log("DirGptTask trueIntent", trueIntent)
@@ -66,7 +62,6 @@ class DirGptTask {
66
62
  if (!action.question || action.question === '') {
67
63
  console.error("Error: DirGptTask question attribute is mandatory. Executing condition false...")
68
64
  if (falseIntent) {
69
- await this.chatbot.addParameter("flowError", "GPT Error: question attribute is undefined");
70
65
  await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
71
66
  callback(true);
72
67
  return;
@@ -97,18 +92,6 @@ class DirGptTask {
97
92
  console.log("DirGptTask temperature: ", temperature);
98
93
  }
99
94
 
100
- if (action.history) {
101
- let transcript_string = await TiledeskChatbot.getParameterStatic(
102
- this.context.tdcache,
103
- this.context.requestId,
104
- TiledeskChatbotConst.REQ_TRANSCRIPT_KEY);
105
- if (this.log) { console.log("DirGptTask transcript string: ", transcript_string) }
106
-
107
- transcript = await TiledeskChatbotUtil.transcriptJSON(transcript_string);
108
- if (this.log) { console.log("DirGptTask transcript: ", transcript) }
109
- }
110
-
111
-
112
95
  const server_base_url = process.env.API_ENDPOINT || process.env.API_URL;
113
96
  const openai_url = process.env.OPENAI_ENDPOINT + "/chat/completions";
114
97
  if (this.log) {
@@ -132,7 +115,6 @@ class DirGptTask {
132
115
  console.error("DirGptTask gptkey is mandatory");
133
116
  await this.#assignAttributes(action, answer);
134
117
  if (falseIntent) {
135
- await this.chatbot.addParameter("flowError", "GPT Error: gpt apikey is undefined");
136
118
  await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
137
119
  callback(true);
138
120
  return;
@@ -152,34 +134,22 @@ class DirGptTask {
152
134
 
153
135
  let json = {
154
136
  model: action.model,
155
- messages: [],
156
- // messages: [
157
- // {
158
- // role: "user",
159
- // content: filled_question
160
- // }
161
- // ],
137
+ messages: [
138
+ {
139
+ role: "user",
140
+ content: filled_question
141
+ }
142
+ ],
162
143
  max_tokens: action.max_tokens,
163
- temperature: action.temperature,
144
+ temperature: action.temperature
164
145
  }
165
146
 
147
+ let message = { role: "", content: "" };
166
148
  if (action.context) {
167
- let message = { role: "system", content: filled_context }
168
- json.messages.push(message);
149
+ message.role = "system";
150
+ message.content = filled_context;
151
+ json.messages.unshift(message);
169
152
  }
170
-
171
- if (transcript) {
172
- transcript.forEach(msg => {
173
- if (!msg.content.startsWith('/')) {
174
- let message = { role: msg.role, content: msg.content }
175
- json.messages.push(message)
176
- }
177
- })
178
- } else {
179
- let message = { role: "user", content: filled_question };
180
- json.messages.push(message);
181
- }
182
-
183
153
  if (this.log) { console.log("DirGptTask json: ", json) }
184
154
 
185
155
  const HTTPREQUEST = {
@@ -197,11 +167,10 @@ class DirGptTask {
197
167
  if (err) {
198
168
  if (this.log) {
199
169
  console.error("(httprequest) DirGptTask openai err:", err);
200
- console.error("(httprequest) DirGptTask openai err:", err.response?.data?.error?.message);
170
+ console.error("(httprequest) DirGptTask openai err:", err.response.data);
201
171
  }
202
172
  await this.#assignAttributes(action, answer);
203
173
  if (falseIntent) {
204
- await this.chatbot.addParameter("flowError", "GPT Error: " + err.response?.data?.error?.message);
205
174
  await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
206
175
  callback(true);
207
176
  return;