@stackfactor/client-api 1.1.14 → 1.1.15
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/lib/aiAssistant.js +131 -0
- package/package.json +1 -1
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { client } from "./axiosClient.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Ask Question to the AI
|
|
5
|
+
* @param {String} conversationId
|
|
6
|
+
* @param {String} question
|
|
7
|
+
* @param {String} updatedContext
|
|
8
|
+
* @param {String} token Authorization token
|
|
9
|
+
* @returns {Promise}
|
|
10
|
+
*/
|
|
11
|
+
export const askQuestion = (
|
|
12
|
+
conversationId,
|
|
13
|
+
question,
|
|
14
|
+
updatedContext,
|
|
15
|
+
token
|
|
16
|
+
) => {
|
|
17
|
+
return new Promise(function (resolve, reject) {
|
|
18
|
+
let data = {
|
|
19
|
+
conversationId: conversationId,
|
|
20
|
+
question: question,
|
|
21
|
+
updatedContext: updatedContext,
|
|
22
|
+
};
|
|
23
|
+
let confirmationRequest = client.post(
|
|
24
|
+
"/api/v1/aiasistant/askquestion",
|
|
25
|
+
{ data: data },
|
|
26
|
+
{
|
|
27
|
+
headers: { authorization: token },
|
|
28
|
+
}
|
|
29
|
+
);
|
|
30
|
+
confirmationRequest
|
|
31
|
+
.then((response) => {
|
|
32
|
+
resolve(response.data);
|
|
33
|
+
})
|
|
34
|
+
.catch((error) => {
|
|
35
|
+
reject(error);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* End conversation with the AI
|
|
42
|
+
* @param {String} conversationId
|
|
43
|
+
* @param {String} token Authorization token
|
|
44
|
+
* @returns {Promise}
|
|
45
|
+
*/
|
|
46
|
+
export const endConversation = (conversationId, token) => {
|
|
47
|
+
return new Promise(function (resolve, reject) {
|
|
48
|
+
let data = {
|
|
49
|
+
conversationId: conversationId,
|
|
50
|
+
};
|
|
51
|
+
let confirmationRequest = client.post(
|
|
52
|
+
"/api/v1/aiasistant/endconversation",
|
|
53
|
+
{ data: data },
|
|
54
|
+
{
|
|
55
|
+
headers: { authorization: token },
|
|
56
|
+
}
|
|
57
|
+
);
|
|
58
|
+
confirmationRequest
|
|
59
|
+
.then((response) => {
|
|
60
|
+
resolve(response.data);
|
|
61
|
+
})
|
|
62
|
+
.catch((error) => {
|
|
63
|
+
reject(error);
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Get conversation by elementId
|
|
70
|
+
* @param {String} elementId
|
|
71
|
+
* @param {String} token
|
|
72
|
+
* @returns {Promise}
|
|
73
|
+
*/
|
|
74
|
+
const getConversationByElementId = (elementId, token) => {
|
|
75
|
+
return new Promise(function (resolve, reject) {
|
|
76
|
+
let confirmationRequest = client.get(
|
|
77
|
+
`/api/v1/aiasistant/conversation/${elementId}/${userId}`,
|
|
78
|
+
{
|
|
79
|
+
headers: { authorization: token },
|
|
80
|
+
}
|
|
81
|
+
);
|
|
82
|
+
confirmationRequest
|
|
83
|
+
.then((response) => {
|
|
84
|
+
resolve(response.data);
|
|
85
|
+
})
|
|
86
|
+
.catch((error) => {
|
|
87
|
+
reject(error);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Start conversation with the AI
|
|
94
|
+
* @param {String} context
|
|
95
|
+
* @param {String} elementId
|
|
96
|
+
* @param {String} elementType
|
|
97
|
+
* @param {String} token
|
|
98
|
+
* @returns {Promise}
|
|
99
|
+
*/
|
|
100
|
+
const startConversation = (context, elementId, elementType, token) => {
|
|
101
|
+
return new Promise(function (resolve, reject) {
|
|
102
|
+
let data = {
|
|
103
|
+
context: context,
|
|
104
|
+
elementId: elementId,
|
|
105
|
+
elementType: elementType,
|
|
106
|
+
};
|
|
107
|
+
let confirmationRequest = client.post(
|
|
108
|
+
"/api/v1/aiasistant/startconversation",
|
|
109
|
+
{ data: data },
|
|
110
|
+
{
|
|
111
|
+
headers: { authorization: token },
|
|
112
|
+
}
|
|
113
|
+
);
|
|
114
|
+
confirmationRequest
|
|
115
|
+
.then((response) => {
|
|
116
|
+
resolve(response.data);
|
|
117
|
+
})
|
|
118
|
+
.catch((error) => {
|
|
119
|
+
reject(error);
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const aiAssistant = {
|
|
125
|
+
askQuestion,
|
|
126
|
+
endConversation,
|
|
127
|
+
getConversationByElementId,
|
|
128
|
+
startConversation,
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
export default aiAssistant;
|