@botonic/plugin-knowledge-bases 0.23.0 → 0.23.1-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 +7 -4
- package/lib/cjs/hubtype-knowledge-api-service.js +6 -3
- package/lib/cjs/hubtype-knowledge-api-service.js.map +1 -1
- package/lib/cjs/index.d.ts +2 -2
- package/lib/cjs/index.js +13 -17
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/types.d.ts +6 -3
- package/lib/esm/hubtype-knowledge-api-service.d.ts +7 -4
- package/lib/esm/hubtype-knowledge-api-service.js +6 -3
- package/lib/esm/hubtype-knowledge-api-service.js.map +1 -1
- package/lib/esm/index.d.ts +2 -2
- package/lib/esm/index.js +13 -17
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/types.d.ts +6 -3
- package/package.json +2 -2
- package/src/hubtype-knowledge-api-service.ts +12 -6
- package/src/index.ts +16 -19
- package/src/types.ts +6 -3
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { AxiosResponse } from 'axios';
|
|
2
2
|
export declare class HubtypeApiService {
|
|
3
|
-
private knowledgeBaseId;
|
|
4
3
|
private host;
|
|
4
|
+
private knowledgeBaseId;
|
|
5
5
|
private timeout;
|
|
6
|
-
constructor(
|
|
6
|
+
constructor(host: string, knowledgeBaseId: string, timeout?: number);
|
|
7
7
|
inference(authToken: string, chatId: string): Promise<AxiosResponse<{
|
|
8
|
-
|
|
8
|
+
answer: string;
|
|
9
9
|
has_knowledge: boolean;
|
|
10
|
-
sources:
|
|
10
|
+
sources: {
|
|
11
|
+
knowledge_source_id: string;
|
|
12
|
+
page?: number;
|
|
13
|
+
}[];
|
|
11
14
|
}>>;
|
|
12
15
|
}
|
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.HubtypeApiService = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
5
6
|
const axios_1 = tslib_1.__importDefault(require("axios"));
|
|
6
7
|
const DEFAULT_TIMEOUT = 10000;
|
|
7
8
|
class HubtypeApiService {
|
|
8
|
-
constructor(
|
|
9
|
+
constructor(host, knowledgeBaseId, timeout) {
|
|
9
10
|
this.knowledgeBaseId = knowledgeBaseId;
|
|
10
11
|
this.host = host;
|
|
11
12
|
this.timeout = timeout || DEFAULT_TIMEOUT;
|
|
@@ -13,12 +14,14 @@ class HubtypeApiService {
|
|
|
13
14
|
async inference(authToken, chatId) {
|
|
14
15
|
return await (0, axios_1.default)({
|
|
15
16
|
method: 'POST',
|
|
16
|
-
url: `${this.host}v1/ai/knowledge_bases/${this.knowledgeBaseId}/inference/`,
|
|
17
|
+
url: `${this.host}/external/v1/ai/knowledge_bases/${this.knowledgeBaseId}/inference/`,
|
|
17
18
|
headers: {
|
|
18
19
|
Authorization: `Bearer ${authToken}`,
|
|
19
20
|
'Content-Type': 'application/json',
|
|
20
21
|
},
|
|
21
|
-
data: {
|
|
22
|
+
data: {
|
|
23
|
+
chat_id: chatId,
|
|
24
|
+
},
|
|
22
25
|
timeout: this.timeout,
|
|
23
26
|
});
|
|
24
27
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hubtype-knowledge-api-service.js","sourceRoot":"","sources":["../../src/hubtype-knowledge-api-service.ts"],"names":[],"mappings":";;;;AAAA,0DAA4C;AAE5C,MAAM,eAAe,GAAG,KAAK,CAAA;AAE7B,MAAa,iBAAiB;IAK5B,YAAY,
|
|
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;IAK5B,YAAY,IAAY,EAAE,eAAuB,EAAE,OAAgB;QACjE,IAAI,CAAC,eAAe,GAAG,eAAe,CAAA;QACtC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,OAAO,GAAG,OAAO,IAAI,eAAe,CAAA;IAC3C,CAAC;IAED,KAAK,CAAC,SAAS,CACb,SAAiB,EACjB,MAAc;QAWd,OAAO,MAAM,IAAA,eAAK,EAAC;YACjB,MAAM,EAAE,MAAM;YACd,GAAG,EAAE,GAAG,IAAI,CAAC,IAAI,mCAAmC,IAAI,CAAC,eAAe,aAAa;YACrF,OAAO,EAAE;gBACP,aAAa,EAAE,UAAU,SAAS,EAAE;gBACpC,cAAc,EAAE,kBAAkB;aACnC;YACD,IAAI,EAAE;gBACJ,OAAO,EAAE,MAAM;aAChB;YACD,OAAO,EAAE,IAAI,CAAC,OAAO;SACtB,CAAC,CAAA;IACJ,CAAC;CACF;AArCD,8CAqCC"}
|
package/lib/cjs/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { HubtypeSession, Plugin, PluginPreRequest } from '@botonic/core';
|
|
2
|
-
import {
|
|
2
|
+
import { KnowledgeBaseResponse, PluginKnowledgeBaseOptions } from './types';
|
|
3
3
|
export default class BotonicPluginKnowledgeBases implements Plugin {
|
|
4
4
|
private readonly apiService;
|
|
5
5
|
private readonly authToken;
|
|
6
6
|
constructor(options: PluginKnowledgeBaseOptions);
|
|
7
7
|
pre(_request: PluginPreRequest): Promise<void>;
|
|
8
|
-
|
|
8
|
+
getInference(session: HubtypeSession): Promise<KnowledgeBaseResponse>;
|
|
9
9
|
}
|
|
10
10
|
export { PluginKnowledgeBaseOptions } from './types';
|
package/lib/cjs/index.js
CHANGED
|
@@ -4,30 +4,26 @@ const hubtype_knowledge_api_service_1 = require("./hubtype-knowledge-api-service
|
|
|
4
4
|
const isProd = process.env.NODE_ENV === 'production';
|
|
5
5
|
class BotonicPluginKnowledgeBases {
|
|
6
6
|
constructor(options) {
|
|
7
|
-
this.apiService = new hubtype_knowledge_api_service_1.HubtypeApiService(options.
|
|
7
|
+
this.apiService = new hubtype_knowledge_api_service_1.HubtypeApiService(options.host, options.knowledgeBaseId, options.timeout);
|
|
8
8
|
this.authToken = options.authToken || '';
|
|
9
9
|
}
|
|
10
10
|
async pre(_request) {
|
|
11
11
|
return;
|
|
12
12
|
}
|
|
13
|
-
async
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
async getInference(session) {
|
|
14
|
+
const authToken = isProd ? session._access_token : this.authToken;
|
|
15
|
+
const response = await this.apiService.inference(authToken, session.user.id);
|
|
16
|
+
const sources = response.data.sources.map(source => {
|
|
17
17
|
return {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
sources: response.data.sources,
|
|
18
|
+
knowledgeSourceId: source.knowledge_source_id,
|
|
19
|
+
page: source.page,
|
|
21
20
|
};
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
sources: [],
|
|
29
|
-
};
|
|
30
|
-
}
|
|
21
|
+
});
|
|
22
|
+
return {
|
|
23
|
+
answer: response.data.answer,
|
|
24
|
+
hasKnowledge: response.data.has_knowledge,
|
|
25
|
+
sources,
|
|
26
|
+
};
|
|
31
27
|
}
|
|
32
28
|
}
|
|
33
29
|
exports.default = BotonicPluginKnowledgeBases;
|
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,CACrC,OAAO,CAAC,
|
|
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,CACrC,OAAO,CAAC,IAAI,EACZ,OAAO,CAAC,eAAe,EACvB,OAAO,CAAC,OAAO,CAChB,CAAA;QACD,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,EAAE,CAAA;IAC1C,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,QAA0B;QAClC,OAAM;IACR,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,OAAuB;QACxC,MAAM,SAAS,GAAG,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAA;QAEjE,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,SAAS,EAAE,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;QAE5E,MAAM,OAAO,GAAG,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE;YACjD,OAAO;gBACL,iBAAiB,EAAE,MAAM,CAAC,mBAAmB;gBAC7C,IAAI,EAAE,MAAM,CAAC,IAAI;aAClB,CAAA;QACH,CAAC,CAAC,CAAA;QAEF,OAAO;YACL,MAAM,EAAE,QAAQ,CAAC,IAAI,CAAC,MAAM;YAC5B,YAAY,EAAE,QAAQ,CAAC,IAAI,CAAC,aAAa;YACzC,OAAO;SACR,CAAA;IACH,CAAC;CACF;AAnCD,8CAmCC"}
|
package/lib/cjs/types.d.ts
CHANGED
|
@@ -4,8 +4,11 @@ export interface PluginKnowledgeBaseOptions {
|
|
|
4
4
|
authToken?: string;
|
|
5
5
|
timeout?: number;
|
|
6
6
|
}
|
|
7
|
-
export interface
|
|
8
|
-
|
|
7
|
+
export interface KnowledgeBaseResponse {
|
|
8
|
+
answer: string;
|
|
9
9
|
hasKnowledge: boolean;
|
|
10
|
-
sources:
|
|
10
|
+
sources: {
|
|
11
|
+
knowledgeSourceId: string;
|
|
12
|
+
page?: number;
|
|
13
|
+
}[];
|
|
11
14
|
}
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { AxiosResponse } from 'axios';
|
|
2
2
|
export declare class HubtypeApiService {
|
|
3
|
-
private knowledgeBaseId;
|
|
4
3
|
private host;
|
|
4
|
+
private knowledgeBaseId;
|
|
5
5
|
private timeout;
|
|
6
|
-
constructor(
|
|
6
|
+
constructor(host: string, knowledgeBaseId: string, timeout?: number);
|
|
7
7
|
inference(authToken: string, chatId: string): Promise<AxiosResponse<{
|
|
8
|
-
|
|
8
|
+
answer: string;
|
|
9
9
|
has_knowledge: boolean;
|
|
10
|
-
sources:
|
|
10
|
+
sources: {
|
|
11
|
+
knowledge_source_id: string;
|
|
12
|
+
page?: number;
|
|
13
|
+
}[];
|
|
11
14
|
}>>;
|
|
12
15
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
1
2
|
import axios from 'axios';
|
|
2
3
|
const DEFAULT_TIMEOUT = 10000;
|
|
3
4
|
export class HubtypeApiService {
|
|
4
|
-
constructor(
|
|
5
|
+
constructor(host, knowledgeBaseId, timeout) {
|
|
5
6
|
this.knowledgeBaseId = knowledgeBaseId;
|
|
6
7
|
this.host = host;
|
|
7
8
|
this.timeout = timeout || DEFAULT_TIMEOUT;
|
|
@@ -9,12 +10,14 @@ export class HubtypeApiService {
|
|
|
9
10
|
async inference(authToken, chatId) {
|
|
10
11
|
return await axios({
|
|
11
12
|
method: 'POST',
|
|
12
|
-
url: `${this.host}v1/ai/knowledge_bases/${this.knowledgeBaseId}/inference/`,
|
|
13
|
+
url: `${this.host}/external/v1/ai/knowledge_bases/${this.knowledgeBaseId}/inference/`,
|
|
13
14
|
headers: {
|
|
14
15
|
Authorization: `Bearer ${authToken}`,
|
|
15
16
|
'Content-Type': 'application/json',
|
|
16
17
|
},
|
|
17
|
-
data: {
|
|
18
|
+
data: {
|
|
19
|
+
chat_id: chatId,
|
|
20
|
+
},
|
|
18
21
|
timeout: this.timeout,
|
|
19
22
|
});
|
|
20
23
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hubtype-knowledge-api-service.js","sourceRoot":"","sources":["../../src/hubtype-knowledge-api-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAwB,MAAM,OAAO,CAAA;AAE5C,MAAM,eAAe,GAAG,KAAK,CAAA;AAE7B,MAAM,OAAO,iBAAiB;IAK5B,YAAY,
|
|
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;IAK5B,YAAY,IAAY,EAAE,eAAuB,EAAE,OAAgB;QACjE,IAAI,CAAC,eAAe,GAAG,eAAe,CAAA;QACtC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,OAAO,GAAG,OAAO,IAAI,eAAe,CAAA;IAC3C,CAAC;IAED,KAAK,CAAC,SAAS,CACb,SAAiB,EACjB,MAAc;QAWd,OAAO,MAAM,KAAK,CAAC;YACjB,MAAM,EAAE,MAAM;YACd,GAAG,EAAE,GAAG,IAAI,CAAC,IAAI,mCAAmC,IAAI,CAAC,eAAe,aAAa;YACrF,OAAO,EAAE;gBACP,aAAa,EAAE,UAAU,SAAS,EAAE;gBACpC,cAAc,EAAE,kBAAkB;aACnC;YACD,IAAI,EAAE;gBACJ,OAAO,EAAE,MAAM;aAChB;YACD,OAAO,EAAE,IAAI,CAAC,OAAO;SACtB,CAAC,CAAA;IACJ,CAAC;CACF"}
|
package/lib/esm/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { HubtypeSession, Plugin, PluginPreRequest } from '@botonic/core';
|
|
2
|
-
import {
|
|
2
|
+
import { KnowledgeBaseResponse, PluginKnowledgeBaseOptions } from './types';
|
|
3
3
|
export default class BotonicPluginKnowledgeBases implements Plugin {
|
|
4
4
|
private readonly apiService;
|
|
5
5
|
private readonly authToken;
|
|
6
6
|
constructor(options: PluginKnowledgeBaseOptions);
|
|
7
7
|
pre(_request: PluginPreRequest): Promise<void>;
|
|
8
|
-
|
|
8
|
+
getInference(session: HubtypeSession): Promise<KnowledgeBaseResponse>;
|
|
9
9
|
}
|
|
10
10
|
export { PluginKnowledgeBaseOptions } from './types';
|
package/lib/esm/index.js
CHANGED
|
@@ -2,30 +2,26 @@ import { HubtypeApiService } from './hubtype-knowledge-api-service';
|
|
|
2
2
|
const isProd = process.env.NODE_ENV === 'production';
|
|
3
3
|
export default class BotonicPluginKnowledgeBases {
|
|
4
4
|
constructor(options) {
|
|
5
|
-
this.apiService = new HubtypeApiService(options.
|
|
5
|
+
this.apiService = new HubtypeApiService(options.host, options.knowledgeBaseId, options.timeout);
|
|
6
6
|
this.authToken = options.authToken || '';
|
|
7
7
|
}
|
|
8
8
|
async pre(_request) {
|
|
9
9
|
return;
|
|
10
10
|
}
|
|
11
|
-
async
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
async getInference(session) {
|
|
12
|
+
const authToken = isProd ? session._access_token : this.authToken;
|
|
13
|
+
const response = await this.apiService.inference(authToken, session.user.id);
|
|
14
|
+
const sources = response.data.sources.map(source => {
|
|
15
15
|
return {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
sources: response.data.sources,
|
|
16
|
+
knowledgeSourceId: source.knowledge_source_id,
|
|
17
|
+
page: source.page,
|
|
19
18
|
};
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
sources: [],
|
|
27
|
-
};
|
|
28
|
-
}
|
|
19
|
+
});
|
|
20
|
+
return {
|
|
21
|
+
answer: response.data.answer,
|
|
22
|
+
hasKnowledge: response.data.has_knowledge,
|
|
23
|
+
sources,
|
|
24
|
+
};
|
|
29
25
|
}
|
|
30
26
|
}
|
|
31
27
|
//# sourceMappingURL=index.js.map
|
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,CACrC,OAAO,CAAC,
|
|
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,CACrC,OAAO,CAAC,IAAI,EACZ,OAAO,CAAC,eAAe,EACvB,OAAO,CAAC,OAAO,CAChB,CAAA;QACD,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,EAAE,CAAA;IAC1C,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,QAA0B;QAClC,OAAM;IACR,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,OAAuB;QACxC,MAAM,SAAS,GAAG,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAA;QAEjE,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,SAAS,EAAE,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;QAE5E,MAAM,OAAO,GAAG,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE;YACjD,OAAO;gBACL,iBAAiB,EAAE,MAAM,CAAC,mBAAmB;gBAC7C,IAAI,EAAE,MAAM,CAAC,IAAI;aAClB,CAAA;QACH,CAAC,CAAC,CAAA;QAEF,OAAO;YACL,MAAM,EAAE,QAAQ,CAAC,IAAI,CAAC,MAAM;YAC5B,YAAY,EAAE,QAAQ,CAAC,IAAI,CAAC,aAAa;YACzC,OAAO;SACR,CAAA;IACH,CAAC;CACF"}
|
package/lib/esm/types.d.ts
CHANGED
|
@@ -4,8 +4,11 @@ export interface PluginKnowledgeBaseOptions {
|
|
|
4
4
|
authToken?: string;
|
|
5
5
|
timeout?: number;
|
|
6
6
|
}
|
|
7
|
-
export interface
|
|
8
|
-
|
|
7
|
+
export interface KnowledgeBaseResponse {
|
|
8
|
+
answer: string;
|
|
9
9
|
hasKnowledge: boolean;
|
|
10
|
-
sources:
|
|
10
|
+
sources: {
|
|
11
|
+
knowledgeSourceId: string;
|
|
12
|
+
page?: number;
|
|
13
|
+
}[];
|
|
11
14
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@botonic/plugin-knowledge-bases",
|
|
3
|
-
"version": "0.23.
|
|
3
|
+
"version": "0.23.1-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",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
],
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@babel/runtime": "^7.22.5",
|
|
32
|
-
"@botonic/core": "
|
|
32
|
+
"@botonic/core": "0.23.1-alpha.0",
|
|
33
33
|
"axios": "^1.4.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
1
2
|
import axios, { AxiosResponse } from 'axios'
|
|
2
3
|
|
|
3
4
|
const DEFAULT_TIMEOUT = 10000
|
|
4
5
|
|
|
5
6
|
export class HubtypeApiService {
|
|
6
|
-
private knowledgeBaseId: string
|
|
7
7
|
private host: string
|
|
8
|
+
private knowledgeBaseId: string
|
|
8
9
|
private timeout: number
|
|
9
10
|
|
|
10
|
-
constructor(
|
|
11
|
+
constructor(host: string, knowledgeBaseId: string, timeout?: number) {
|
|
11
12
|
this.knowledgeBaseId = knowledgeBaseId
|
|
12
13
|
this.host = host
|
|
13
14
|
this.timeout = timeout || DEFAULT_TIMEOUT
|
|
@@ -18,19 +19,24 @@ export class HubtypeApiService {
|
|
|
18
19
|
chatId: string
|
|
19
20
|
): Promise<
|
|
20
21
|
AxiosResponse<{
|
|
21
|
-
|
|
22
|
+
answer: string
|
|
22
23
|
has_knowledge: boolean
|
|
23
|
-
sources:
|
|
24
|
+
sources: {
|
|
25
|
+
knowledge_source_id: string
|
|
26
|
+
page?: number
|
|
27
|
+
}[]
|
|
24
28
|
}>
|
|
25
29
|
> {
|
|
26
30
|
return await axios({
|
|
27
31
|
method: 'POST',
|
|
28
|
-
url: `${this.host}v1/ai/knowledge_bases/${this.knowledgeBaseId}/inference/`,
|
|
32
|
+
url: `${this.host}/external/v1/ai/knowledge_bases/${this.knowledgeBaseId}/inference/`,
|
|
29
33
|
headers: {
|
|
30
34
|
Authorization: `Bearer ${authToken}`,
|
|
31
35
|
'Content-Type': 'application/json',
|
|
32
36
|
},
|
|
33
|
-
data: {
|
|
37
|
+
data: {
|
|
38
|
+
chat_id: chatId,
|
|
39
|
+
},
|
|
34
40
|
timeout: this.timeout,
|
|
35
41
|
})
|
|
36
42
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { HubtypeSession, Plugin, PluginPreRequest } from '@botonic/core'
|
|
2
2
|
|
|
3
3
|
import { HubtypeApiService } from './hubtype-knowledge-api-service'
|
|
4
|
-
import {
|
|
4
|
+
import { KnowledgeBaseResponse, PluginKnowledgeBaseOptions } from './types'
|
|
5
5
|
|
|
6
6
|
const isProd = process.env.NODE_ENV === 'production'
|
|
7
7
|
|
|
@@ -11,8 +11,8 @@ export default class BotonicPluginKnowledgeBases implements Plugin {
|
|
|
11
11
|
|
|
12
12
|
constructor(options: PluginKnowledgeBaseOptions) {
|
|
13
13
|
this.apiService = new HubtypeApiService(
|
|
14
|
-
options.knowledgeBaseId,
|
|
15
14
|
options.host,
|
|
15
|
+
options.knowledgeBaseId,
|
|
16
16
|
options.timeout
|
|
17
17
|
)
|
|
18
18
|
this.authToken = options.authToken || ''
|
|
@@ -22,25 +22,22 @@ export default class BotonicPluginKnowledgeBases implements Plugin {
|
|
|
22
22
|
return
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
async
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
)
|
|
32
|
-
return {
|
|
33
|
-
ai: response.data.ai,
|
|
34
|
-
hasKnowledge: response.data.has_knowledge,
|
|
35
|
-
sources: response.data.sources,
|
|
36
|
-
}
|
|
37
|
-
} catch (e) {
|
|
38
|
-
console.error(e)
|
|
25
|
+
async getInference(session: HubtypeSession): Promise<KnowledgeBaseResponse> {
|
|
26
|
+
const authToken = isProd ? session._access_token : this.authToken
|
|
27
|
+
|
|
28
|
+
const response = await this.apiService.inference(authToken, session.user.id)
|
|
29
|
+
|
|
30
|
+
const sources = response.data.sources.map(source => {
|
|
39
31
|
return {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
sources: [],
|
|
32
|
+
knowledgeSourceId: source.knowledge_source_id,
|
|
33
|
+
page: source.page,
|
|
43
34
|
}
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
answer: response.data.answer,
|
|
39
|
+
hasKnowledge: response.data.has_knowledge,
|
|
40
|
+
sources,
|
|
44
41
|
}
|
|
45
42
|
}
|
|
46
43
|
}
|
package/src/types.ts
CHANGED
|
@@ -5,8 +5,11 @@ export interface PluginKnowledgeBaseOptions {
|
|
|
5
5
|
timeout?: number
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
export interface
|
|
9
|
-
|
|
8
|
+
export interface KnowledgeBaseResponse {
|
|
9
|
+
answer: string
|
|
10
10
|
hasKnowledge: boolean
|
|
11
|
-
sources:
|
|
11
|
+
sources: {
|
|
12
|
+
knowledgeSourceId: string
|
|
13
|
+
page?: number
|
|
14
|
+
}[]
|
|
12
15
|
}
|