@tiledesk/tiledesk-tybot-connector 2.0.6 → 2.0.7

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tiledesk/tiledesk-tybot-connector",
3
- "version": "2.0.6",
3
+ "version": "2.0.7",
4
4
  "description": "Tiledesk Tybot connector",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -4,38 +4,63 @@ let API_ENDPOINT = process.env.API_ENDPOINT;
4
4
 
5
5
  class IntegrationService {
6
6
 
7
- constructor() {}
8
-
9
- async getKeyFromIntegrations(id_project, integration_name, token) {
10
- return new Promise((resolve) => {
11
-
12
- const INTEGRATIONS_HTTPREQUEST = {
13
- url: API_ENDPOINT + "/" + id_project + "/integration/name/" + integration_name,
14
- headers: {
15
- 'Content-Type': 'application/json',
16
- 'Authorization': 'JWT ' + token
17
- },
18
- method: "GET"
7
+ constructor() { }
8
+
9
+ async getKeyFromIntegrations(id_project, integration_name, token) {
10
+ return new Promise((resolve) => {
11
+
12
+ const INTEGRATIONS_HTTPREQUEST = {
13
+ url: API_ENDPOINT + "/" + id_project + "/integration/name/" + integration_name,
14
+ headers: {
15
+ 'Content-Type': 'application/json',
16
+ 'Authorization': 'JWT ' + token
17
+ },
18
+ method: "GET"
19
+ }
20
+ winston.debug("Integration HttpRequest ", INTEGRATIONS_HTTPREQUEST)
21
+
22
+ httpUtils.request(
23
+ INTEGRATIONS_HTTPREQUEST, async (err, integration) => {
24
+ if (err) {
25
+ resolve(null);
26
+ } else {
27
+
28
+ if (integration &&
29
+ integration.value) {
30
+ resolve(integration.value.apikey)
31
+ }
32
+ else {
33
+ resolve(null)
34
+ }
19
35
  }
20
- winston.debug("Integration HttpRequest ", INTEGRATIONS_HTTPREQUEST)
21
-
22
- httpUtils.request(
23
- INTEGRATIONS_HTTPREQUEST, async (err, integration) => {
24
- if (err) {
25
- resolve(null);
26
- } else {
27
-
28
- if (integration &&
29
- integration.value) {
30
- resolve(integration.value.apikey)
31
- }
32
- else {
33
- resolve(null)
34
- }
35
- }
36
- })
37
36
  })
37
+ })
38
+ }
39
+
40
+ async getIntegration(id_project, integration_name, token) {
41
+
42
+ return new Promise((resolve) => {
43
+
44
+ const INTEGRATIONS_HTTPREQUEST = {
45
+ url: API_ENDPOINT + "/" + id_project + "/integration/name/" + integration_name,
46
+ headers: {
47
+ 'Content-Type': 'application/json',
48
+ 'Authorization': 'JWT ' + token
49
+ },
50
+ method: "GET"
38
51
  }
52
+ winston.debug("Integration HttpRequest ", INTEGRATIONS_HTTPREQUEST)
53
+
54
+ httpUtils.request(
55
+ INTEGRATIONS_HTTPREQUEST, async (err, integration) => {
56
+ if (err) {
57
+ resolve(null);
58
+ } else {
59
+ resolve(integration)
60
+ }
61
+ })
62
+ })
63
+ }
39
64
 
40
65
  }
41
66
 
@@ -100,21 +100,43 @@ class DirAiPrompt {
100
100
  }
101
101
  }
102
102
 
103
- const AI_endpoint = process.env.AI_ENDPOINT
103
+ let AI_endpoint = process.env.AI_ENDPOINT;
104
104
  winston.verbose("DirAiPrompt AI_endpoint " + AI_endpoint);
105
105
 
106
- let key = await integrationService.getKeyFromIntegrations(this.projectId, action.llm, this.token);
107
-
108
- if (!key) {
109
- winston.error("Error: DirAiPrompt llm key not found in integrations");
110
- await this.chatbot.addParameter("flowError", "AiPrompt Error: missing key for llm " + action.llm);
111
- if (falseIntent) {
112
- await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
113
- callback(true);
106
+ let headers = {
107
+ 'Content-Type': 'application/json'
108
+ }
109
+
110
+ let key;
111
+ let ollama_integration;
112
+
113
+ if (action.llm === 'ollama') {
114
+ ollama_integration = await integrationService.getIntegration(this.projectId, action.llm, this.token).catch( async (err) => {
115
+ winston.error("DirAiPrompt Error getting ollama integration: ", err);
116
+ await this.chatbot.addParameter("flowError", "Ollama integration not found");
117
+ if (falseIntent) {
118
+ await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
119
+ callback(true);
120
+ return;
121
+ }
122
+ callback();
123
+ return;
124
+ });
125
+
126
+ } else {
127
+ key = await integrationService.getKeyFromIntegrations(this.projectId, action.llm, this.token);
128
+
129
+ if (!key) {
130
+ winston.error("Error: DirAiPrompt llm key not found in integrations");
131
+ await this.chatbot.addParameter("flowError", "AiPrompt Error: missing key for llm " + action.llm);
132
+ if (falseIntent) {
133
+ await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
134
+ callback(true);
135
+ return;
136
+ }
137
+ callback();
114
138
  return;
115
139
  }
116
- callback();
117
- return;
118
140
  }
119
141
 
120
142
  let json = {
@@ -133,13 +155,22 @@ class DirAiPrompt {
133
155
  json.chat_history_dict = await this.transcriptToLLM(transcript);
134
156
  }
135
157
 
158
+ if (action.llm === 'ollama') {
159
+ json.llm_key = "";
160
+ json.model = {
161
+ name: action.model,
162
+ url: ollama_integration.value.url,
163
+ token: ollama_integration.value.token
164
+ }
165
+ json.stream = false
166
+
167
+ }
168
+
136
169
  winston.debug("DirAiPrompt json: ", json);
137
170
 
138
171
  const HTTPREQUEST = {
139
- url: AI_endpoint + '/ask',
140
- headers: {
141
- 'Content-Type': 'application/json'
142
- },
172
+ url: AI_endpoint + "/ask",
173
+ headers: headers,
143
174
  json: json,
144
175
  method: 'POST'
145
176
  }
@@ -148,7 +179,7 @@ class DirAiPrompt {
148
179
  httpUtils.request(
149
180
  HTTPREQUEST, async (err, resbody) => {
150
181
  if (err) {
151
- winston.error("DirAiPrompt openai err:", err.response.data);
182
+ winston.error("DirAiPrompt openai err: ", err);
152
183
  await this.#assignAttributes(action, answer);
153
184
  let error;
154
185
  if (err.response?.data?.detail[0]) {