@botonic/plugin-knowledge-bases 0.39.0 → 0.39.2
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/cjs/hubtype-knowledge-api-service.d.ts +2 -9
- package/lib/cjs/hubtype-knowledge-api-service.js +22 -27
- package/lib/cjs/hubtype-knowledge-api-service.js.map +1 -1
- package/lib/cjs/index.d.ts +0 -2
- package/lib/cjs/index.js +3 -23
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/types.d.ts +1 -0
- package/lib/esm/hubtype-knowledge-api-service.d.ts +2 -9
- package/lib/esm/hubtype-knowledge-api-service.js +22 -27
- package/lib/esm/hubtype-knowledge-api-service.js.map +1 -1
- package/lib/esm/index.d.ts +0 -2
- package/lib/esm/index.js +3 -23
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/types.d.ts +1 -0
- package/package.json +1 -1
- package/src/hubtype-knowledge-api-service.ts +25 -39
- package/src/index.ts +8 -43
- package/src/types.ts +1 -0
|
@@ -11,15 +11,8 @@ export interface HtApiKnowledgeBaseResponse {
|
|
|
11
11
|
export declare class HubtypeApiService {
|
|
12
12
|
private host;
|
|
13
13
|
private timeout;
|
|
14
|
-
|
|
14
|
+
private verbose;
|
|
15
|
+
constructor(host: string, timeout?: number, verbose?: boolean);
|
|
15
16
|
inferenceV2(authToken: string, sources: string[], instructions: string, messageId: string, memoryLength: number): Promise<AxiosResponse<HtApiKnowledgeBaseResponse>>;
|
|
16
17
|
testInference(authToken: string, instructions: string, messages: any[], sources: string[]): Promise<AxiosResponse<HtApiKnowledgeBaseResponse>>;
|
|
17
|
-
inferenceV1(authToken: string, question: string, sources: string[]): Promise<AxiosResponse<{
|
|
18
|
-
inference_id: string;
|
|
19
|
-
question: string;
|
|
20
|
-
answer: string;
|
|
21
|
-
has_knowledge: boolean;
|
|
22
|
-
is_faithful: boolean;
|
|
23
|
-
chunk_ids: string[];
|
|
24
|
-
}>>;
|
|
25
18
|
}
|
|
@@ -4,29 +4,41 @@ exports.HubtypeApiService = void 0;
|
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
/* eslint-disable @typescript-eslint/naming-convention */
|
|
6
6
|
const axios_1 = tslib_1.__importDefault(require("axios"));
|
|
7
|
-
const DEFAULT_TIMEOUT =
|
|
7
|
+
const DEFAULT_TIMEOUT = 20000;
|
|
8
8
|
class HubtypeApiService {
|
|
9
|
-
constructor(host, timeout) {
|
|
9
|
+
constructor(host, timeout, verbose) {
|
|
10
10
|
this.host = host;
|
|
11
11
|
this.timeout = timeout || DEFAULT_TIMEOUT;
|
|
12
|
+
this.verbose = verbose || false;
|
|
12
13
|
}
|
|
13
14
|
inferenceV2(authToken, sources, instructions, messageId, memoryLength) {
|
|
14
15
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
15
|
-
|
|
16
|
+
const url = `${this.host}/external/v2/ai/knowledge_base/inference/`;
|
|
17
|
+
const data = {
|
|
18
|
+
sources,
|
|
19
|
+
instructions,
|
|
20
|
+
message: messageId,
|
|
21
|
+
memory_length: memoryLength,
|
|
22
|
+
};
|
|
23
|
+
const response = yield (0, axios_1.default)({
|
|
16
24
|
method: 'POST',
|
|
17
|
-
url
|
|
25
|
+
url,
|
|
18
26
|
headers: {
|
|
19
27
|
Authorization: `Bearer ${authToken}`,
|
|
20
28
|
'Content-Type': 'application/json',
|
|
21
29
|
},
|
|
22
|
-
data
|
|
23
|
-
sources,
|
|
24
|
-
instructions,
|
|
25
|
-
message: messageId,
|
|
26
|
-
memory_length: memoryLength,
|
|
27
|
-
},
|
|
30
|
+
data,
|
|
28
31
|
timeout: this.timeout,
|
|
29
32
|
});
|
|
33
|
+
if (this.verbose) {
|
|
34
|
+
console.log('Data and response', {
|
|
35
|
+
url,
|
|
36
|
+
data,
|
|
37
|
+
timeout: this.timeout,
|
|
38
|
+
response,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
return response;
|
|
30
42
|
});
|
|
31
43
|
}
|
|
32
44
|
testInference(authToken, instructions, messages, sources) {
|
|
@@ -47,23 +59,6 @@ class HubtypeApiService {
|
|
|
47
59
|
});
|
|
48
60
|
});
|
|
49
61
|
}
|
|
50
|
-
inferenceV1(authToken, question, sources) {
|
|
51
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
52
|
-
return yield (0, axios_1.default)({
|
|
53
|
-
method: 'POST',
|
|
54
|
-
url: `${this.host}/external/v1/ai/knowledge_base/inference/`,
|
|
55
|
-
headers: {
|
|
56
|
-
Authorization: `Bearer ${authToken}`,
|
|
57
|
-
'Content-Type': 'application/json',
|
|
58
|
-
},
|
|
59
|
-
data: {
|
|
60
|
-
question,
|
|
61
|
-
sources,
|
|
62
|
-
},
|
|
63
|
-
timeout: this.timeout,
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
62
|
}
|
|
68
63
|
exports.HubtypeApiService = HubtypeApiService;
|
|
69
64
|
//# sourceMappingURL=hubtype-knowledge-api-service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hubtype-knowledge-api-service.js","sourceRoot":"","sources":["../../src/hubtype-knowledge-api-service.ts"],"names":[],"mappings":";;;;AAAA,yDAAyD;AACzD,0DAA4C;AAI5C,MAAM,eAAe,GAAG,KAAK,CAAA;AAU7B,MAAa,iBAAiB;
|
|
1
|
+
{"version":3,"file":"hubtype-knowledge-api-service.js","sourceRoot":"","sources":["../../src/hubtype-knowledge-api-service.ts"],"names":[],"mappings":";;;;AAAA,yDAAyD;AACzD,0DAA4C;AAI5C,MAAM,eAAe,GAAG,KAAK,CAAA;AAU7B,MAAa,iBAAiB;IAK5B,YAAY,IAAY,EAAE,OAAgB,EAAE,OAAiB;QAC3D,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,OAAO,GAAG,OAAO,IAAI,eAAe,CAAA;QACzC,IAAI,CAAC,OAAO,GAAG,OAAO,IAAI,KAAK,CAAA;IACjC,C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|
|
|
7
7
|
pre(_request: PluginPreRequest): Promise<void>;
|
|
8
8
|
getInference(request: BotContext, sources: string[], instructions: string, messageId: string, memoryLength: number): Promise<KnowledgeBasesResponse>;
|
|
9
9
|
getTestInference(authToken: string, request: BotContext, instructions: string, sources: string[]): Promise<KnowledgeBasesResponse>;
|
|
10
|
-
getInferenceV1(authToken: string, request: BotContext, sources: string[]): Promise<KnowledgeBasesResponse>;
|
|
11
|
-
getInferenceV2(authToken: string, sources: string[], instructions: string, messageId: string, memoryLength: number): Promise<KnowledgeBasesResponse>;
|
|
12
10
|
private mapApiResponse;
|
|
13
11
|
}
|
|
14
12
|
export { PluginKnowledgeBaseOptions } from './types';
|
package/lib/cjs/index.js
CHANGED
|
@@ -6,7 +6,7 @@ const isProd = process.env.NODE_ENV === 'production';
|
|
|
6
6
|
const isDev = process.env.NODE_ENV === 'development';
|
|
7
7
|
class BotonicPluginKnowledgeBases {
|
|
8
8
|
constructor(options) {
|
|
9
|
-
this.apiService = new hubtype_knowledge_api_service_1.HubtypeApiService(options.host, options.timeout);
|
|
9
|
+
this.apiService = new hubtype_knowledge_api_service_1.HubtypeApiService(options.host, options.timeout, options.verbose);
|
|
10
10
|
this.authToken = options.authToken || '';
|
|
11
11
|
}
|
|
12
12
|
pre(_request) {
|
|
@@ -20,10 +20,8 @@ class BotonicPluginKnowledgeBases {
|
|
|
20
20
|
if (isDev) {
|
|
21
21
|
return this.getTestInference(authToken, request, instructions, sources);
|
|
22
22
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
return this.getInferenceV2(authToken, sources, instructions, messageId, memoryLength);
|
|
23
|
+
const response = yield this.apiService.inferenceV2(authToken, sources, instructions, messageId, memoryLength);
|
|
24
|
+
return this.mapApiResponse(response);
|
|
27
25
|
});
|
|
28
26
|
}
|
|
29
27
|
getTestInference(authToken, request, instructions, sources) {
|
|
@@ -33,24 +31,6 @@ class BotonicPluginKnowledgeBases {
|
|
|
33
31
|
return this.mapApiResponse(response);
|
|
34
32
|
});
|
|
35
33
|
}
|
|
36
|
-
getInferenceV1(authToken, request, sources) {
|
|
37
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
38
|
-
const response = yield this.apiService.inferenceV1(authToken, request.input.data, sources);
|
|
39
|
-
return {
|
|
40
|
-
inferenceId: response.data.inference_id,
|
|
41
|
-
answer: response.data.answer,
|
|
42
|
-
hasKnowledge: response.data.has_knowledge,
|
|
43
|
-
isFaithful: response.data.is_faithful,
|
|
44
|
-
chunkIds: response.data.chunk_ids,
|
|
45
|
-
};
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
getInferenceV2(authToken, sources, instructions, messageId, memoryLength) {
|
|
49
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
50
|
-
const response = yield this.apiService.inferenceV2(authToken, sources, instructions, messageId, memoryLength);
|
|
51
|
-
return this.mapApiResponse(response);
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
34
|
mapApiResponse(response) {
|
|
55
35
|
return {
|
|
56
36
|
inferenceId: response.data.inference_id,
|
package/lib/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAGA,mFAGwC;AAGxC,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,CAAA;AACpD,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,aAAa,CAAA;AAEpD,MAAqB,2BAA2B;IAI9C,YAAY,OAAmC;QAC7C,IAAI,CAAC,UAAU,GAAG,IAAI,iDAAiB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAGA,mFAGwC;AAGxC,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,CAAA;AACpD,MAAM,KAAK,GAAG,O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CAAC,CAAA;QACtC,CAAC;KAAA;IAEO,cAAc,CACpB,QAAmD;QAEnD,OAAO;YACL,WAAW,EAAE,QAAQ,CAAC,IAAI,CAAC,YAAY;YACvC,QAAQ,EAAE,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC;YACrD,YAAY,EAAE,QAAQ,CAAC,IAAI,CAAC,aAAa;YACzC,UAAU,EAAE,QAAQ,CAAC,IAAI,CAAC,WAAW;YACrC,MAAM,EAAE,QAAQ,CAAC,IAAI,CAAC,MAAM;SAC7B,CAAA;IACH,CAAC;CACF;AAtED,8CAsEC"}
|
package/lib/cjs/types.d.ts
CHANGED
|
@@ -11,15 +11,8 @@ export interface HtApiKnowledgeBaseResponse {
|
|
|
11
11
|
export declare class HubtypeApiService {
|
|
12
12
|
private host;
|
|
13
13
|
private timeout;
|
|
14
|
-
|
|
14
|
+
private verbose;
|
|
15
|
+
constructor(host: string, timeout?: number, verbose?: boolean);
|
|
15
16
|
inferenceV2(authToken: string, sources: string[], instructions: string, messageId: string, memoryLength: number): Promise<AxiosResponse<HtApiKnowledgeBaseResponse>>;
|
|
16
17
|
testInference(authToken: string, instructions: string, messages: any[], sources: string[]): Promise<AxiosResponse<HtApiKnowledgeBaseResponse>>;
|
|
17
|
-
inferenceV1(authToken: string, question: string, sources: string[]): Promise<AxiosResponse<{
|
|
18
|
-
inference_id: string;
|
|
19
|
-
question: string;
|
|
20
|
-
answer: string;
|
|
21
|
-
has_knowledge: boolean;
|
|
22
|
-
is_faithful: boolean;
|
|
23
|
-
chunk_ids: string[];
|
|
24
|
-
}>>;
|
|
25
18
|
}
|
|
@@ -1,29 +1,41 @@
|
|
|
1
1
|
import { __awaiter } from "tslib";
|
|
2
2
|
/* eslint-disable @typescript-eslint/naming-convention */
|
|
3
3
|
import axios from 'axios';
|
|
4
|
-
const DEFAULT_TIMEOUT =
|
|
4
|
+
const DEFAULT_TIMEOUT = 20000;
|
|
5
5
|
export class HubtypeApiService {
|
|
6
|
-
constructor(host, timeout) {
|
|
6
|
+
constructor(host, timeout, verbose) {
|
|
7
7
|
this.host = host;
|
|
8
8
|
this.timeout = timeout || DEFAULT_TIMEOUT;
|
|
9
|
+
this.verbose = verbose || false;
|
|
9
10
|
}
|
|
10
11
|
inferenceV2(authToken, sources, instructions, messageId, memoryLength) {
|
|
11
12
|
return __awaiter(this, void 0, void 0, function* () {
|
|
12
|
-
|
|
13
|
+
const url = `${this.host}/external/v2/ai/knowledge_base/inference/`;
|
|
14
|
+
const data = {
|
|
15
|
+
sources,
|
|
16
|
+
instructions,
|
|
17
|
+
message: messageId,
|
|
18
|
+
memory_length: memoryLength,
|
|
19
|
+
};
|
|
20
|
+
const response = yield axios({
|
|
13
21
|
method: 'POST',
|
|
14
|
-
url
|
|
22
|
+
url,
|
|
15
23
|
headers: {
|
|
16
24
|
Authorization: `Bearer ${authToken}`,
|
|
17
25
|
'Content-Type': 'application/json',
|
|
18
26
|
},
|
|
19
|
-
data
|
|
20
|
-
sources,
|
|
21
|
-
instructions,
|
|
22
|
-
message: messageId,
|
|
23
|
-
memory_length: memoryLength,
|
|
24
|
-
},
|
|
27
|
+
data,
|
|
25
28
|
timeout: this.timeout,
|
|
26
29
|
});
|
|
30
|
+
if (this.verbose) {
|
|
31
|
+
console.log('Data and response', {
|
|
32
|
+
url,
|
|
33
|
+
data,
|
|
34
|
+
timeout: this.timeout,
|
|
35
|
+
response,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
return response;
|
|
27
39
|
});
|
|
28
40
|
}
|
|
29
41
|
testInference(authToken, instructions, messages, sources) {
|
|
@@ -44,22 +56,5 @@ export class HubtypeApiService {
|
|
|
44
56
|
});
|
|
45
57
|
});
|
|
46
58
|
}
|
|
47
|
-
inferenceV1(authToken, question, sources) {
|
|
48
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
-
return yield axios({
|
|
50
|
-
method: 'POST',
|
|
51
|
-
url: `${this.host}/external/v1/ai/knowledge_base/inference/`,
|
|
52
|
-
headers: {
|
|
53
|
-
Authorization: `Bearer ${authToken}`,
|
|
54
|
-
'Content-Type': 'application/json',
|
|
55
|
-
},
|
|
56
|
-
data: {
|
|
57
|
-
question,
|
|
58
|
-
sources,
|
|
59
|
-
},
|
|
60
|
-
timeout: this.timeout,
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
59
|
}
|
|
65
60
|
//# sourceMappingURL=hubtype-knowledge-api-service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hubtype-knowledge-api-service.js","sourceRoot":"","sources":["../../src/hubtype-knowledge-api-service.ts"],"names":[],"mappings":";AAAA,yDAAyD;AACzD,OAAO,KAAwB,MAAM,OAAO,CAAA;AAI5C,MAAM,eAAe,GAAG,KAAK,CAAA;AAU7B,MAAM,OAAO,iBAAiB;
|
|
1
|
+
{"version":3,"file":"hubtype-knowledge-api-service.js","sourceRoot":"","sources":["../../src/hubtype-knowledge-api-service.ts"],"names":[],"mappings":";AAAA,yDAAyD;AACzD,OAAO,KAAwB,MAAM,OAAO,CAAA;AAI5C,MAAM,eAAe,GAAG,KAAK,CAAA;AAU7B,MAAM,OAAO,iBAAiB;IAK5B,YAAY,IAAY,EAAE,OAAgB,EAAE,OAAiB;QAC3D,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,OAAO,GAAG,OAAO,IAAI,eAAe,CAAA;QACzC,IAAI,CAAC,OAAO,GAAG,OAAO,IAAI,KAAK,CAAA;IACjC,CAAC;IAEK,WAAW,CACf,SAAiB,EACjB,OAAiB,EACjB,YAAoB,EACpB,SAAiB,EACjB,YAAoB;;YAEpB,MAAM,GAAG,GAAG,GAAG,IAAI,CAAC,IAAI,2CAA2C,CAAA;YACnE,MAAM,IAAI,GAAG;gBACX,OAAO;gBACP,YAAY;gBACZ,OAAO,EAAE,SAAS;gBAClB,aAAa,EAAE,YAAY;aAC5B,CAAA;YACD,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC;gBAC3B,MAAM,EAAE,MAAM;gBACd,GAAG;gBACH,OAAO,EAAE;oBACP,aAAa,EAAE,UAAU,SAAS,EAAE;oBACpC,cAAc,EAAE,kBAAkB;iBACnC;gBACD,IAAI;gBACJ,OAAO,EAAE,IAAI,CAAC,OAAO;aACtB,CAAC,CAAA;YAEF,IAAI,IAAI,CAAC,OAAO,EAAE;gBAChB,OAAO,CAAC,GAAG,CAAC,mBAAmB,EAAE;oBAC/B,GAAG;oBACH,IAAI;oBACJ,OAAO,EAAE,IAAI,CAAC,OAAO;oBACrB,QAAQ;iBACT,CAAC,CAAA;aACH;YAED,OAAO,QAAQ,CAAA;QACjB,CAAC;KAAA;IAEK,aAAa,CACjB,SAAiB,EACjB,YAAoB,EACpB,QAAe,EACf,OAAiB;;YAEjB,OAAO,MAAM,KAAK,CAAC;gBACjB,MAAM,EAAE,MAAM;gBACd,GAAG,EAAE,GAAG,IAAI,CAAC,IAAI,gDAAgD;gBACjE,OAAO,EAAE;oBACP,aAAa,EAAE,UAAU,SAAS,EAAE;oBACpC,cAAc,EAAE,kBAAkB;iBACnC;gBACD,IAAI,EAAE;oBACJ,OAAO;oBACP,YAAY;oBACZ,QAAQ;iBACT;gBACD,OAAO,EAAE,IAAI,CAAC,OAAO;aACtB,CAAC,CAAA;QACJ,CAAC;KAAA;CACF"}
|
package/lib/esm/index.d.ts
CHANGED
|
@@ -7,8 +7,6 @@ export default class BotonicPluginKnowledgeBases implements Plugin {
|
|
|
7
7
|
pre(_request: PluginPreRequest): Promise<void>;
|
|
8
8
|
getInference(request: BotContext, sources: string[], instructions: string, messageId: string, memoryLength: number): Promise<KnowledgeBasesResponse>;
|
|
9
9
|
getTestInference(authToken: string, request: BotContext, instructions: string, sources: string[]): Promise<KnowledgeBasesResponse>;
|
|
10
|
-
getInferenceV1(authToken: string, request: BotContext, sources: string[]): Promise<KnowledgeBasesResponse>;
|
|
11
|
-
getInferenceV2(authToken: string, sources: string[], instructions: string, messageId: string, memoryLength: number): Promise<KnowledgeBasesResponse>;
|
|
12
10
|
private mapApiResponse;
|
|
13
11
|
}
|
|
14
12
|
export { PluginKnowledgeBaseOptions } from './types';
|
package/lib/esm/index.js
CHANGED
|
@@ -4,7 +4,7 @@ const isProd = process.env.NODE_ENV === 'production';
|
|
|
4
4
|
const isDev = process.env.NODE_ENV === 'development';
|
|
5
5
|
export default class BotonicPluginKnowledgeBases {
|
|
6
6
|
constructor(options) {
|
|
7
|
-
this.apiService = new HubtypeApiService(options.host, options.timeout);
|
|
7
|
+
this.apiService = new HubtypeApiService(options.host, options.timeout, options.verbose);
|
|
8
8
|
this.authToken = options.authToken || '';
|
|
9
9
|
}
|
|
10
10
|
pre(_request) {
|
|
@@ -18,10 +18,8 @@ export default class BotonicPluginKnowledgeBases {
|
|
|
18
18
|
if (isDev) {
|
|
19
19
|
return this.getTestInference(authToken, request, instructions, sources);
|
|
20
20
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
return this.getInferenceV2(authToken, sources, instructions, messageId, memoryLength);
|
|
21
|
+
const response = yield this.apiService.inferenceV2(authToken, sources, instructions, messageId, memoryLength);
|
|
22
|
+
return this.mapApiResponse(response);
|
|
25
23
|
});
|
|
26
24
|
}
|
|
27
25
|
getTestInference(authToken, request, instructions, sources) {
|
|
@@ -31,24 +29,6 @@ export default class BotonicPluginKnowledgeBases {
|
|
|
31
29
|
return this.mapApiResponse(response);
|
|
32
30
|
});
|
|
33
31
|
}
|
|
34
|
-
getInferenceV1(authToken, request, sources) {
|
|
35
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
-
const response = yield this.apiService.inferenceV1(authToken, request.input.data, sources);
|
|
37
|
-
return {
|
|
38
|
-
inferenceId: response.data.inference_id,
|
|
39
|
-
answer: response.data.answer,
|
|
40
|
-
hasKnowledge: response.data.has_knowledge,
|
|
41
|
-
isFaithful: response.data.is_faithful,
|
|
42
|
-
chunkIds: response.data.chunk_ids,
|
|
43
|
-
};
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
getInferenceV2(authToken, sources, instructions, messageId, memoryLength) {
|
|
47
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
-
const response = yield this.apiService.inferenceV2(authToken, sources, instructions, messageId, memoryLength);
|
|
49
|
-
return this.mapApiResponse(response);
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
32
|
mapApiResponse(response) {
|
|
53
33
|
return {
|
|
54
34
|
inferenceId: response.data.inference_id,
|
package/lib/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAGA,OAAO,EAEL,iBAAiB,GAClB,MAAM,iCAAiC,CAAA;AAGxC,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,CAAA;AACpD,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,aAAa,CAAA;AAEpD,MAAM,CAAC,OAAO,OAAO,2BAA2B;IAI9C,YAAY,OAAmC;QAC7C,IAAI,CAAC,UAAU,GAAG,IAAI,iBAAiB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAGA,OAAO,EAEL,iBAAiB,GAClB,MAAM,iCAAiC,CAAA;AAGxC,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,CAAA;AACpD,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,aAAa,CAAA;AAEpD,MAAM,CAAC,OAAO,OAAO,2BAA2B;IAI9C,YAAY,OAAmC;QAC7C,IAAI,CAAC,UAAU,GAAG,IAAI,iBAAiB,CACrC,OAAO,CAAC,IAAI,EACZ,OAAO,CAAC,OAAO,EACf,OAAO,CAAC,OA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AAC,KAAK,CAAC,EAAE,CAAC;YACrD,YAAY,EAAE,QAAQ,CAAC,IAAI,CAAC,aAAa;YACzC,UAAU,EAAE,QAAQ,CAAC,IAAI,CAAC,WAAW;YACrC,MAAM,EAAE,QAAQ,CAAC,IAAI,CAAC,MAAM;SAC7B,CAAA;IACH,CAAC;CACF"}
|
package/lib/esm/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@ import axios, { AxiosResponse } from 'axios'
|
|
|
3
3
|
|
|
4
4
|
import { Chunk } from './types'
|
|
5
5
|
|
|
6
|
-
const DEFAULT_TIMEOUT =
|
|
6
|
+
const DEFAULT_TIMEOUT = 20000
|
|
7
7
|
|
|
8
8
|
export interface HtApiKnowledgeBaseResponse {
|
|
9
9
|
inference_id: string
|
|
@@ -16,10 +16,12 @@ export interface HtApiKnowledgeBaseResponse {
|
|
|
16
16
|
export class HubtypeApiService {
|
|
17
17
|
private host: string
|
|
18
18
|
private timeout: number
|
|
19
|
+
private verbose: boolean
|
|
19
20
|
|
|
20
|
-
constructor(host: string, timeout?: number) {
|
|
21
|
+
constructor(host: string, timeout?: number, verbose?: boolean) {
|
|
21
22
|
this.host = host
|
|
22
23
|
this.timeout = timeout || DEFAULT_TIMEOUT
|
|
24
|
+
this.verbose = verbose || false
|
|
23
25
|
}
|
|
24
26
|
|
|
25
27
|
async inferenceV2(
|
|
@@ -29,21 +31,34 @@ export class HubtypeApiService {
|
|
|
29
31
|
messageId: string,
|
|
30
32
|
memoryLength: number
|
|
31
33
|
): Promise<AxiosResponse<HtApiKnowledgeBaseResponse>> {
|
|
32
|
-
|
|
34
|
+
const url = `${this.host}/external/v2/ai/knowledge_base/inference/`
|
|
35
|
+
const data = {
|
|
36
|
+
sources,
|
|
37
|
+
instructions,
|
|
38
|
+
message: messageId,
|
|
39
|
+
memory_length: memoryLength,
|
|
40
|
+
}
|
|
41
|
+
const response = await axios({
|
|
33
42
|
method: 'POST',
|
|
34
|
-
url
|
|
43
|
+
url,
|
|
35
44
|
headers: {
|
|
36
45
|
Authorization: `Bearer ${authToken}`,
|
|
37
46
|
'Content-Type': 'application/json',
|
|
38
47
|
},
|
|
39
|
-
data
|
|
40
|
-
sources,
|
|
41
|
-
instructions,
|
|
42
|
-
message: messageId,
|
|
43
|
-
memory_length: memoryLength,
|
|
44
|
-
},
|
|
48
|
+
data,
|
|
45
49
|
timeout: this.timeout,
|
|
46
50
|
})
|
|
51
|
+
|
|
52
|
+
if (this.verbose) {
|
|
53
|
+
console.log('Data and response', {
|
|
54
|
+
url,
|
|
55
|
+
data,
|
|
56
|
+
timeout: this.timeout,
|
|
57
|
+
response,
|
|
58
|
+
})
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return response
|
|
47
62
|
}
|
|
48
63
|
|
|
49
64
|
async testInference(
|
|
@@ -67,33 +82,4 @@ export class HubtypeApiService {
|
|
|
67
82
|
timeout: this.timeout,
|
|
68
83
|
})
|
|
69
84
|
}
|
|
70
|
-
|
|
71
|
-
async inferenceV1(
|
|
72
|
-
authToken: string,
|
|
73
|
-
question: string,
|
|
74
|
-
sources: string[]
|
|
75
|
-
): Promise<
|
|
76
|
-
AxiosResponse<{
|
|
77
|
-
inference_id: string
|
|
78
|
-
question: string
|
|
79
|
-
answer: string
|
|
80
|
-
has_knowledge: boolean
|
|
81
|
-
is_faithful: boolean
|
|
82
|
-
chunk_ids: string[]
|
|
83
|
-
}>
|
|
84
|
-
> {
|
|
85
|
-
return await axios({
|
|
86
|
-
method: 'POST',
|
|
87
|
-
url: `${this.host}/external/v1/ai/knowledge_base/inference/`,
|
|
88
|
-
headers: {
|
|
89
|
-
Authorization: `Bearer ${authToken}`,
|
|
90
|
-
'Content-Type': 'application/json',
|
|
91
|
-
},
|
|
92
|
-
data: {
|
|
93
|
-
question,
|
|
94
|
-
sources,
|
|
95
|
-
},
|
|
96
|
-
timeout: this.timeout,
|
|
97
|
-
})
|
|
98
|
-
}
|
|
99
85
|
}
|
package/src/index.ts
CHANGED
|
@@ -15,7 +15,11 @@ export default class BotonicPluginKnowledgeBases implements Plugin {
|
|
|
15
15
|
private readonly authToken: string
|
|
16
16
|
|
|
17
17
|
constructor(options: PluginKnowledgeBaseOptions) {
|
|
18
|
-
this.apiService = new HubtypeApiService(
|
|
18
|
+
this.apiService = new HubtypeApiService(
|
|
19
|
+
options.host,
|
|
20
|
+
options.timeout,
|
|
21
|
+
options.verbose
|
|
22
|
+
)
|
|
19
23
|
this.authToken = options.authToken || ''
|
|
20
24
|
}
|
|
21
25
|
|
|
@@ -36,17 +40,15 @@ export default class BotonicPluginKnowledgeBases implements Plugin {
|
|
|
36
40
|
return this.getTestInference(authToken, request, instructions, sources)
|
|
37
41
|
}
|
|
38
42
|
|
|
39
|
-
|
|
40
|
-
return this.getInferenceV1(authToken, request, sources)
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return this.getInferenceV2(
|
|
43
|
+
const response = await this.apiService.inferenceV2(
|
|
44
44
|
authToken,
|
|
45
45
|
sources,
|
|
46
46
|
instructions,
|
|
47
47
|
messageId,
|
|
48
48
|
memoryLength
|
|
49
49
|
)
|
|
50
|
+
|
|
51
|
+
return this.mapApiResponse(response)
|
|
50
52
|
}
|
|
51
53
|
|
|
52
54
|
async getTestInference(
|
|
@@ -67,43 +69,6 @@ export default class BotonicPluginKnowledgeBases implements Plugin {
|
|
|
67
69
|
return this.mapApiResponse(response)
|
|
68
70
|
}
|
|
69
71
|
|
|
70
|
-
async getInferenceV1(
|
|
71
|
-
authToken: string,
|
|
72
|
-
request: BotContext,
|
|
73
|
-
sources: string[]
|
|
74
|
-
): Promise<KnowledgeBasesResponse> {
|
|
75
|
-
const response = await this.apiService.inferenceV1(
|
|
76
|
-
authToken,
|
|
77
|
-
request.input.data!,
|
|
78
|
-
sources
|
|
79
|
-
)
|
|
80
|
-
return {
|
|
81
|
-
inferenceId: response.data.inference_id,
|
|
82
|
-
answer: response.data.answer,
|
|
83
|
-
hasKnowledge: response.data.has_knowledge,
|
|
84
|
-
isFaithful: response.data.is_faithful,
|
|
85
|
-
chunkIds: response.data.chunk_ids,
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
async getInferenceV2(
|
|
90
|
-
authToken: string,
|
|
91
|
-
sources: string[],
|
|
92
|
-
instructions: string,
|
|
93
|
-
messageId: string,
|
|
94
|
-
memoryLength: number
|
|
95
|
-
): Promise<KnowledgeBasesResponse> {
|
|
96
|
-
const response = await this.apiService.inferenceV2(
|
|
97
|
-
authToken,
|
|
98
|
-
sources,
|
|
99
|
-
instructions,
|
|
100
|
-
messageId,
|
|
101
|
-
memoryLength
|
|
102
|
-
)
|
|
103
|
-
|
|
104
|
-
return this.mapApiResponse(response)
|
|
105
|
-
}
|
|
106
|
-
|
|
107
72
|
private mapApiResponse(
|
|
108
73
|
response: AxiosResponse<HtApiKnowledgeBaseResponse>
|
|
109
74
|
): KnowledgeBasesResponse {
|