@botonic/plugin-knowledge-bases 0.26.1-alpha.0 → 0.27.0-alpha.1
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 +5 -4
- package/lib/cjs/hubtype-knowledge-api-service.js +5 -5
- package/lib/cjs/hubtype-knowledge-api-service.js.map +1 -1
- package/lib/cjs/index.d.ts +1 -1
- package/lib/cjs/index.js +10 -7
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/types.d.ts +4 -2
- package/lib/esm/hubtype-knowledge-api-service.d.ts +5 -4
- package/lib/esm/hubtype-knowledge-api-service.js +5 -5
- package/lib/esm/hubtype-knowledge-api-service.js.map +1 -1
- package/lib/esm/index.d.ts +1 -1
- package/lib/esm/index.js +10 -7
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/types.d.ts +4 -2
- package/package.json +2 -2
- package/src/hubtype-knowledge-api-service.ts +9 -7
- package/src/index.ts +18 -11
- package/src/types.ts +4 -2
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import { AxiosResponse } from 'axios';
|
|
2
2
|
export declare class HubtypeApiService {
|
|
3
3
|
private host;
|
|
4
|
-
private knowledgeBaseId;
|
|
5
4
|
private timeout;
|
|
6
|
-
constructor(host: string,
|
|
7
|
-
inference(authToken: string,
|
|
5
|
+
constructor(host: string, timeout?: number);
|
|
6
|
+
inference(authToken: string, question: string, sources: string[]): Promise<AxiosResponse<{
|
|
7
|
+
inference_id: string;
|
|
8
8
|
question: string;
|
|
9
9
|
answer: string;
|
|
10
10
|
has_knowledge: boolean;
|
|
11
11
|
is_faithful: boolean;
|
|
12
12
|
sources: {
|
|
13
|
+
knowledge_base_id: string;
|
|
13
14
|
knowledge_source_id: string;
|
|
14
|
-
|
|
15
|
+
knowledge_chunk_id: string;
|
|
15
16
|
}[];
|
|
16
17
|
}>>;
|
|
17
18
|
}
|
|
@@ -6,22 +6,22 @@ const tslib_1 = require("tslib");
|
|
|
6
6
|
const axios_1 = tslib_1.__importDefault(require("axios"));
|
|
7
7
|
const DEFAULT_TIMEOUT = 10000;
|
|
8
8
|
class HubtypeApiService {
|
|
9
|
-
constructor(host,
|
|
10
|
-
this.knowledgeBaseId = knowledgeBaseId;
|
|
9
|
+
constructor(host, timeout) {
|
|
11
10
|
this.host = host;
|
|
12
11
|
this.timeout = timeout || DEFAULT_TIMEOUT;
|
|
13
12
|
}
|
|
14
|
-
inference(authToken,
|
|
13
|
+
inference(authToken, question, sources) {
|
|
15
14
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
16
15
|
return yield (0, axios_1.default)({
|
|
17
16
|
method: 'POST',
|
|
18
|
-
url: `${this.host}/external/v1/ai/knowledge_bases
|
|
17
|
+
url: `${this.host}/external/v1/ai/knowledge_bases/inference/`,
|
|
19
18
|
headers: {
|
|
20
19
|
Authorization: `Bearer ${authToken}`,
|
|
21
20
|
'Content-Type': 'application/json',
|
|
22
21
|
},
|
|
23
22
|
data: {
|
|
24
|
-
|
|
23
|
+
question,
|
|
24
|
+
sources,
|
|
25
25
|
},
|
|
26
26
|
timeout: this.timeout,
|
|
27
27
|
});
|
|
@@ -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;AAE5C,MAAM,eAAe,GAAG,KAAK,CAAA;AAE7B,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;AAE5C,MAAM,eAAe,GAAG,KAAK,CAAA;AAE7B,MAAa,iBAAiB;IAI5B,YAAY,IAAY,EAAE,OAAgB;QACxC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,OAAO,GAAG,OAAO,IAAI,eAAe,CAAA;IAC3C,CAAC;IAEK,SAAS,CACb,SAAiB,EACjB,QAAgB,EAChB,OAAiB;;YAejB,OAAO,MAAM,IAAA,eAAK,EAAC;gBACjB,MAAM,EAAE,MAAM;gBACd,GAAG,EAAE,GAAG,IAAI,CAAC,IAAI,4CAA4C;gBAC7D,OAAO,EAAE;oBACP,aAAa,EAAE,UAAU,SAAS,EAAE;oBACpC,cAAc,EAAE,kBAAkB;iBACnC;gBACD,IAAI,EAAE;oBACJ,QAAQ;oBACR,OAAO;iBACR;gBACD,OAAO,EAAE,IAAI,CAAC,OAAO;aACtB,CAAC,CAAA;QACJ,CAAC;KAAA;CACF;AAzCD,8CAyCC"}
|
package/lib/cjs/index.d.ts
CHANGED
|
@@ -5,6 +5,6 @@ export default class BotonicPluginKnowledgeBases implements Plugin {
|
|
|
5
5
|
private readonly authToken;
|
|
6
6
|
constructor(options: PluginKnowledgeBaseOptions);
|
|
7
7
|
pre(_request: PluginPreRequest): Promise<void>;
|
|
8
|
-
getInference(session: Session): Promise<KnowledgeBaseResponse>;
|
|
8
|
+
getInference(session: Session, userInput: string, sources: string[]): Promise<KnowledgeBaseResponse>;
|
|
9
9
|
}
|
|
10
10
|
export { PluginKnowledgeBaseOptions } from './types';
|
package/lib/cjs/index.js
CHANGED
|
@@ -5,7 +5,7 @@ const hubtype_knowledge_api_service_1 = require("./hubtype-knowledge-api-service
|
|
|
5
5
|
const isProd = process.env.NODE_ENV === 'production';
|
|
6
6
|
class BotonicPluginKnowledgeBases {
|
|
7
7
|
constructor(options) {
|
|
8
|
-
this.apiService = new hubtype_knowledge_api_service_1.HubtypeApiService(options.host, options.
|
|
8
|
+
this.apiService = new hubtype_knowledge_api_service_1.HubtypeApiService(options.host, options.timeout);
|
|
9
9
|
this.authToken = options.authToken || '';
|
|
10
10
|
}
|
|
11
11
|
pre(_request) {
|
|
@@ -13,21 +13,24 @@ class BotonicPluginKnowledgeBases {
|
|
|
13
13
|
return;
|
|
14
14
|
});
|
|
15
15
|
}
|
|
16
|
-
getInference(session) {
|
|
16
|
+
getInference(session, userInput, sources) {
|
|
17
17
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
18
18
|
const authToken = isProd ? session._access_token : this.authToken;
|
|
19
|
-
const response = yield this.apiService.inference(authToken,
|
|
20
|
-
const
|
|
19
|
+
const response = yield this.apiService.inference(authToken, userInput, sources);
|
|
20
|
+
const responseSources = response.data.sources.map(source => {
|
|
21
21
|
return {
|
|
22
|
+
knowledgeBaseId: source.knowledge_base_id,
|
|
22
23
|
knowledgeSourceId: source.knowledge_source_id,
|
|
23
|
-
|
|
24
|
+
knowledgeChunkId: source.knowledge_chunk_id,
|
|
24
25
|
};
|
|
25
26
|
});
|
|
26
27
|
return {
|
|
28
|
+
inferenceId: response.data.inference_id,
|
|
27
29
|
question: response.data.question,
|
|
28
30
|
answer: response.data.answer,
|
|
29
|
-
hasKnowledge: response.data.has_knowledge
|
|
30
|
-
|
|
31
|
+
hasKnowledge: response.data.has_knowledge,
|
|
32
|
+
isFaithuful: response.data.is_faithful,
|
|
33
|
+
sources: responseSources,
|
|
31
34
|
};
|
|
32
35
|
});
|
|
33
36
|
}
|
package/lib/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAEA,mFAAmE;AAGnE,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,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":";;;AAEA,mFAAmE;AAGnE,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,CAAA;AAEpD,MAAqB,2BAA2B;IAI9C,YAAY,OAAmC;QAC7C,IAAI,CAAC,UAAU,GAAG,IAAI,iDAAiB,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,CAAA;QACtE,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,EAAE,CAAA;IAC1C,CAAC;IAEK,GAAG,CAAC,QAA0B;;YAClC,OAAM;QACR,CAAC;KAAA;IAEK,YAAY,CAChB,OAAgB,EAChB,SAAiB,EACjB,OAAiB;;YAEjB,MAAM,SAAS,GAAG,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAA;YAEjE,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,SAAS,CAC9C,SAAS,EACT,SAAS,EACT,OAAO,CACR,CAAA;YAED,MAAM,eAAe,GAAG,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE;gBACzD,OAAO;oBACL,eAAe,EAAE,MAAM,CAAC,iBAAiB;oBACzC,iBAAiB,EAAE,MAAM,CAAC,mBAAmB;oBAC7C,gBAAgB,EAAE,MAAM,CAAC,kBAAkB;iBAC5C,CAAA;YACH,CAAC,CAAC,CAAA;YAEF,OAAO;gBACL,WAAW,EAAE,QAAQ,CAAC,IAAI,CAAC,YAAY;gBACvC,QAAQ,EAAE,QAAQ,CAAC,IAAI,CAAC,QAAQ;gBAChC,MAAM,EAAE,QAAQ,CAAC,IAAI,CAAC,MAAM;gBAC5B,YAAY,EAAE,QAAQ,CAAC,IAAI,CAAC,aAAa;gBACzC,WAAW,EAAE,QAAQ,CAAC,IAAI,CAAC,WAAW;gBACtC,OAAO,EAAE,eAAe;aACzB,CAAA;QACH,CAAC;KAAA;CACF;AA3CD,8CA2CC"}
|
package/lib/cjs/types.d.ts
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
export interface PluginKnowledgeBaseOptions {
|
|
2
|
-
knowledgeBaseId: string;
|
|
3
2
|
host: string;
|
|
4
3
|
authToken?: string;
|
|
5
4
|
timeout?: number;
|
|
6
5
|
}
|
|
7
6
|
export interface KnowledgeBaseResponse {
|
|
7
|
+
inferenceId: string;
|
|
8
8
|
question: string;
|
|
9
9
|
answer: string;
|
|
10
10
|
hasKnowledge: boolean;
|
|
11
|
+
isFaithuful: boolean;
|
|
11
12
|
sources: {
|
|
13
|
+
knowledgeBaseId: string;
|
|
12
14
|
knowledgeSourceId: string;
|
|
13
|
-
|
|
15
|
+
knowledgeChunkId: string;
|
|
14
16
|
}[];
|
|
15
17
|
}
|
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import { AxiosResponse } from 'axios';
|
|
2
2
|
export declare class HubtypeApiService {
|
|
3
3
|
private host;
|
|
4
|
-
private knowledgeBaseId;
|
|
5
4
|
private timeout;
|
|
6
|
-
constructor(host: string,
|
|
7
|
-
inference(authToken: string,
|
|
5
|
+
constructor(host: string, timeout?: number);
|
|
6
|
+
inference(authToken: string, question: string, sources: string[]): Promise<AxiosResponse<{
|
|
7
|
+
inference_id: string;
|
|
8
8
|
question: string;
|
|
9
9
|
answer: string;
|
|
10
10
|
has_knowledge: boolean;
|
|
11
11
|
is_faithful: boolean;
|
|
12
12
|
sources: {
|
|
13
|
+
knowledge_base_id: string;
|
|
13
14
|
knowledge_source_id: string;
|
|
14
|
-
|
|
15
|
+
knowledge_chunk_id: string;
|
|
15
16
|
}[];
|
|
16
17
|
}>>;
|
|
17
18
|
}
|
|
@@ -3,22 +3,22 @@ import { __awaiter } from "tslib";
|
|
|
3
3
|
import axios from 'axios';
|
|
4
4
|
const DEFAULT_TIMEOUT = 10000;
|
|
5
5
|
export class HubtypeApiService {
|
|
6
|
-
constructor(host,
|
|
7
|
-
this.knowledgeBaseId = knowledgeBaseId;
|
|
6
|
+
constructor(host, timeout) {
|
|
8
7
|
this.host = host;
|
|
9
8
|
this.timeout = timeout || DEFAULT_TIMEOUT;
|
|
10
9
|
}
|
|
11
|
-
inference(authToken,
|
|
10
|
+
inference(authToken, question, sources) {
|
|
12
11
|
return __awaiter(this, void 0, void 0, function* () {
|
|
13
12
|
return yield axios({
|
|
14
13
|
method: 'POST',
|
|
15
|
-
url: `${this.host}/external/v1/ai/knowledge_bases
|
|
14
|
+
url: `${this.host}/external/v1/ai/knowledge_bases/inference/`,
|
|
16
15
|
headers: {
|
|
17
16
|
Authorization: `Bearer ${authToken}`,
|
|
18
17
|
'Content-Type': 'application/json',
|
|
19
18
|
},
|
|
20
19
|
data: {
|
|
21
|
-
|
|
20
|
+
question,
|
|
21
|
+
sources,
|
|
22
22
|
},
|
|
23
23
|
timeout: this.timeout,
|
|
24
24
|
});
|
|
@@ -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;AAE5C,MAAM,eAAe,GAAG,KAAK,CAAA;AAE7B,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;AAE5C,MAAM,eAAe,GAAG,KAAK,CAAA;AAE7B,MAAM,OAAO,iBAAiB;IAI5B,YAAY,IAAY,EAAE,OAAgB;QACxC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,OAAO,GAAG,OAAO,IAAI,eAAe,CAAA;IAC3C,CAAC;IAEK,SAAS,CACb,SAAiB,EACjB,QAAgB,EAChB,OAAiB;;YAejB,OAAO,MAAM,KAAK,CAAC;gBACjB,MAAM,EAAE,MAAM;gBACd,GAAG,EAAE,GAAG,IAAI,CAAC,IAAI,4CAA4C;gBAC7D,OAAO,EAAE;oBACP,aAAa,EAAE,UAAU,SAAS,EAAE;oBACpC,cAAc,EAAE,kBAAkB;iBACnC;gBACD,IAAI,EAAE;oBACJ,QAAQ;oBACR,OAAO;iBACR;gBACD,OAAO,EAAE,IAAI,CAAC,OAAO;aACtB,CAAC,CAAA;QACJ,CAAC;KAAA;CACF"}
|
package/lib/esm/index.d.ts
CHANGED
|
@@ -5,6 +5,6 @@ export default class BotonicPluginKnowledgeBases implements Plugin {
|
|
|
5
5
|
private readonly authToken;
|
|
6
6
|
constructor(options: PluginKnowledgeBaseOptions);
|
|
7
7
|
pre(_request: PluginPreRequest): Promise<void>;
|
|
8
|
-
getInference(session: Session): Promise<KnowledgeBaseResponse>;
|
|
8
|
+
getInference(session: Session, userInput: string, sources: string[]): Promise<KnowledgeBaseResponse>;
|
|
9
9
|
}
|
|
10
10
|
export { PluginKnowledgeBaseOptions } from './types';
|
package/lib/esm/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import { HubtypeApiService } from './hubtype-knowledge-api-service';
|
|
|
3
3
|
const isProd = process.env.NODE_ENV === 'production';
|
|
4
4
|
export default class BotonicPluginKnowledgeBases {
|
|
5
5
|
constructor(options) {
|
|
6
|
-
this.apiService = new HubtypeApiService(options.host, options.
|
|
6
|
+
this.apiService = new HubtypeApiService(options.host, options.timeout);
|
|
7
7
|
this.authToken = options.authToken || '';
|
|
8
8
|
}
|
|
9
9
|
pre(_request) {
|
|
@@ -11,21 +11,24 @@ export default class BotonicPluginKnowledgeBases {
|
|
|
11
11
|
return;
|
|
12
12
|
});
|
|
13
13
|
}
|
|
14
|
-
getInference(session) {
|
|
14
|
+
getInference(session, userInput, sources) {
|
|
15
15
|
return __awaiter(this, void 0, void 0, function* () {
|
|
16
16
|
const authToken = isProd ? session._access_token : this.authToken;
|
|
17
|
-
const response = yield this.apiService.inference(authToken,
|
|
18
|
-
const
|
|
17
|
+
const response = yield this.apiService.inference(authToken, userInput, sources);
|
|
18
|
+
const responseSources = response.data.sources.map(source => {
|
|
19
19
|
return {
|
|
20
|
+
knowledgeBaseId: source.knowledge_base_id,
|
|
20
21
|
knowledgeSourceId: source.knowledge_source_id,
|
|
21
|
-
|
|
22
|
+
knowledgeChunkId: source.knowledge_chunk_id,
|
|
22
23
|
};
|
|
23
24
|
});
|
|
24
25
|
return {
|
|
26
|
+
inferenceId: response.data.inference_id,
|
|
25
27
|
question: response.data.question,
|
|
26
28
|
answer: response.data.answer,
|
|
27
|
-
hasKnowledge: response.data.has_knowledge
|
|
28
|
-
|
|
29
|
+
hasKnowledge: response.data.has_knowledge,
|
|
30
|
+
isFaithuful: response.data.is_faithful,
|
|
31
|
+
sources: responseSources,
|
|
29
32
|
};
|
|
30
33
|
});
|
|
31
34
|
}
|
package/lib/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAA;AAGnE,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,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":";AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAA;AAGnE,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,CAAA;AAEpD,MAAM,CAAC,OAAO,OAAO,2BAA2B;IAI9C,YAAY,OAAmC;QAC7C,IAAI,CAAC,UAAU,GAAG,IAAI,iBAAiB,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,CAAA;QACtE,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,EAAE,CAAA;IAC1C,CAAC;IAEK,GAAG,CAAC,QAA0B;;YAClC,OAAM;QACR,CAAC;KAAA;IAEK,YAAY,CAChB,OAAgB,EAChB,SAAiB,EACjB,OAAiB;;YAEjB,MAAM,SAAS,GAAG,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAA;YAEjE,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,SAAS,CAC9C,SAAS,EACT,SAAS,EACT,OAAO,CACR,CAAA;YAED,MAAM,eAAe,GAAG,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE;gBACzD,OAAO;oBACL,eAAe,EAAE,MAAM,CAAC,iBAAiB;oBACzC,iBAAiB,EAAE,MAAM,CAAC,mBAAmB;oBAC7C,gBAAgB,EAAE,MAAM,CAAC,kBAAkB;iBAC5C,CAAA;YACH,CAAC,CAAC,CAAA;YAEF,OAAO;gBACL,WAAW,EAAE,QAAQ,CAAC,IAAI,CAAC,YAAY;gBACvC,QAAQ,EAAE,QAAQ,CAAC,IAAI,CAAC,QAAQ;gBAChC,MAAM,EAAE,QAAQ,CAAC,IAAI,CAAC,MAAM;gBAC5B,YAAY,EAAE,QAAQ,CAAC,IAAI,CAAC,aAAa;gBACzC,WAAW,EAAE,QAAQ,CAAC,IAAI,CAAC,WAAW;gBACtC,OAAO,EAAE,eAAe;aACzB,CAAA;QACH,CAAC;KAAA;CACF"}
|
package/lib/esm/types.d.ts
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
export interface PluginKnowledgeBaseOptions {
|
|
2
|
-
knowledgeBaseId: string;
|
|
3
2
|
host: string;
|
|
4
3
|
authToken?: string;
|
|
5
4
|
timeout?: number;
|
|
6
5
|
}
|
|
7
6
|
export interface KnowledgeBaseResponse {
|
|
7
|
+
inferenceId: string;
|
|
8
8
|
question: string;
|
|
9
9
|
answer: string;
|
|
10
10
|
hasKnowledge: boolean;
|
|
11
|
+
isFaithuful: boolean;
|
|
11
12
|
sources: {
|
|
13
|
+
knowledgeBaseId: string;
|
|
12
14
|
knowledgeSourceId: string;
|
|
13
|
-
|
|
15
|
+
knowledgeChunkId: string;
|
|
14
16
|
}[];
|
|
15
17
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@botonic/plugin-knowledge-bases",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.27.0-alpha.1",
|
|
4
4
|
"description": "Use a Hubtype to make the bot respond through a knowledge base.",
|
|
5
5
|
"main": "./lib/cjs/index.js",
|
|
6
6
|
"module": "./lib/esm/index.js",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@babel/runtime": "^7.23.9",
|
|
18
|
-
"@botonic/core": "0.
|
|
18
|
+
"@botonic/core": "0.27.0-alpha.1",
|
|
19
19
|
"axios": "^1.6.8"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
@@ -5,39 +5,41 @@ const DEFAULT_TIMEOUT = 10000
|
|
|
5
5
|
|
|
6
6
|
export class HubtypeApiService {
|
|
7
7
|
private host: string
|
|
8
|
-
private knowledgeBaseId: string
|
|
9
8
|
private timeout: number
|
|
10
9
|
|
|
11
|
-
constructor(host: string,
|
|
12
|
-
this.knowledgeBaseId = knowledgeBaseId
|
|
10
|
+
constructor(host: string, timeout?: number) {
|
|
13
11
|
this.host = host
|
|
14
12
|
this.timeout = timeout || DEFAULT_TIMEOUT
|
|
15
13
|
}
|
|
16
14
|
|
|
17
15
|
async inference(
|
|
18
16
|
authToken: string,
|
|
19
|
-
|
|
17
|
+
question: string,
|
|
18
|
+
sources: string[]
|
|
20
19
|
): Promise<
|
|
21
20
|
AxiosResponse<{
|
|
21
|
+
inference_id: string
|
|
22
22
|
question: string
|
|
23
23
|
answer: string
|
|
24
24
|
has_knowledge: boolean
|
|
25
25
|
is_faithful: boolean
|
|
26
26
|
sources: {
|
|
27
|
+
knowledge_base_id: string
|
|
27
28
|
knowledge_source_id: string
|
|
28
|
-
|
|
29
|
+
knowledge_chunk_id: string
|
|
29
30
|
}[]
|
|
30
31
|
}>
|
|
31
32
|
> {
|
|
32
33
|
return await axios({
|
|
33
34
|
method: 'POST',
|
|
34
|
-
url: `${this.host}/external/v1/ai/knowledge_bases
|
|
35
|
+
url: `${this.host}/external/v1/ai/knowledge_bases/inference/`,
|
|
35
36
|
headers: {
|
|
36
37
|
Authorization: `Bearer ${authToken}`,
|
|
37
38
|
'Content-Type': 'application/json',
|
|
38
39
|
},
|
|
39
40
|
data: {
|
|
40
|
-
|
|
41
|
+
question,
|
|
42
|
+
sources,
|
|
41
43
|
},
|
|
42
44
|
timeout: this.timeout,
|
|
43
45
|
})
|
package/src/index.ts
CHANGED
|
@@ -10,11 +10,7 @@ export default class BotonicPluginKnowledgeBases implements Plugin {
|
|
|
10
10
|
private readonly authToken: string
|
|
11
11
|
|
|
12
12
|
constructor(options: PluginKnowledgeBaseOptions) {
|
|
13
|
-
this.apiService = new HubtypeApiService(
|
|
14
|
-
options.host,
|
|
15
|
-
options.knowledgeBaseId,
|
|
16
|
-
options.timeout
|
|
17
|
-
)
|
|
13
|
+
this.apiService = new HubtypeApiService(options.host, options.timeout)
|
|
18
14
|
this.authToken = options.authToken || ''
|
|
19
15
|
}
|
|
20
16
|
|
|
@@ -22,23 +18,34 @@ export default class BotonicPluginKnowledgeBases implements Plugin {
|
|
|
22
18
|
return
|
|
23
19
|
}
|
|
24
20
|
|
|
25
|
-
async getInference(
|
|
21
|
+
async getInference(
|
|
22
|
+
session: Session,
|
|
23
|
+
userInput: string,
|
|
24
|
+
sources: string[]
|
|
25
|
+
): Promise<KnowledgeBaseResponse> {
|
|
26
26
|
const authToken = isProd ? session._access_token : this.authToken
|
|
27
27
|
|
|
28
|
-
const response = await this.apiService.inference(
|
|
28
|
+
const response = await this.apiService.inference(
|
|
29
|
+
authToken,
|
|
30
|
+
userInput,
|
|
31
|
+
sources
|
|
32
|
+
)
|
|
29
33
|
|
|
30
|
-
const
|
|
34
|
+
const responseSources = response.data.sources.map(source => {
|
|
31
35
|
return {
|
|
36
|
+
knowledgeBaseId: source.knowledge_base_id,
|
|
32
37
|
knowledgeSourceId: source.knowledge_source_id,
|
|
33
|
-
|
|
38
|
+
knowledgeChunkId: source.knowledge_chunk_id,
|
|
34
39
|
}
|
|
35
40
|
})
|
|
36
41
|
|
|
37
42
|
return {
|
|
43
|
+
inferenceId: response.data.inference_id,
|
|
38
44
|
question: response.data.question,
|
|
39
45
|
answer: response.data.answer,
|
|
40
|
-
hasKnowledge: response.data.has_knowledge
|
|
41
|
-
|
|
46
|
+
hasKnowledge: response.data.has_knowledge,
|
|
47
|
+
isFaithuful: response.data.is_faithful,
|
|
48
|
+
sources: responseSources,
|
|
42
49
|
}
|
|
43
50
|
}
|
|
44
51
|
}
|
package/src/types.ts
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
export interface PluginKnowledgeBaseOptions {
|
|
2
|
-
knowledgeBaseId: string
|
|
3
2
|
host: string
|
|
4
3
|
authToken?: string
|
|
5
4
|
timeout?: number
|
|
6
5
|
}
|
|
7
6
|
|
|
8
7
|
export interface KnowledgeBaseResponse {
|
|
8
|
+
inferenceId: string
|
|
9
9
|
question: string
|
|
10
10
|
answer: string
|
|
11
11
|
hasKnowledge: boolean
|
|
12
|
+
isFaithuful: boolean
|
|
12
13
|
sources: {
|
|
14
|
+
knowledgeBaseId: string
|
|
13
15
|
knowledgeSourceId: string
|
|
14
|
-
|
|
16
|
+
knowledgeChunkId: string
|
|
15
17
|
}[]
|
|
16
18
|
}
|