@botonic/plugin-knowledge-bases 0.23.0-alpha.0

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/README.md ADDED
File without changes
@@ -0,0 +1,9 @@
1
+ import { AxiosResponse } from 'axios';
2
+ import { KnowledgebaseResppnse } from './types';
3
+ export declare class HubtypeApiService {
4
+ private knowledgeBaseId;
5
+ private host;
6
+ private timeout;
7
+ constructor(knowledgeBaseId: string, host: string, timeout?: number);
8
+ inference(authToken: string, chatId: string): Promise<AxiosResponse<KnowledgebaseResppnse>>;
9
+ }
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HubtypeApiService = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const axios_1 = tslib_1.__importDefault(require("axios"));
6
+ const DEFAULT_TIMEOUT = 10000;
7
+ class HubtypeApiService {
8
+ constructor(knowledgeBaseId, host, timeout) {
9
+ this.knowledgeBaseId = knowledgeBaseId;
10
+ this.host = host;
11
+ this.timeout = timeout || DEFAULT_TIMEOUT;
12
+ }
13
+ async inference(authToken, chatId) {
14
+ return await (0, axios_1.default)({
15
+ method: 'POST',
16
+ url: `${this.host}/v1/ai/knowledge_bases/${this.knowledgeBaseId}/inference/`,
17
+ headers: {
18
+ Authorization: `Bearer ${authToken}`,
19
+ 'Content-Type': 'application/json',
20
+ },
21
+ data: { chat_id: chatId },
22
+ timeout: this.timeout,
23
+ });
24
+ }
25
+ }
26
+ exports.HubtypeApiService = HubtypeApiService;
27
+ //# sourceMappingURL=hubtype-knowledge-api-service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hubtype-knowledge-api-service.js","sourceRoot":"","sources":["../../src/hubtype-knowledge-api-service.ts"],"names":[],"mappings":";;;;AAAA,0DAA4C;AAI5C,MAAM,eAAe,GAAG,KAAK,CAAA;AAE7B,MAAa,iBAAiB;IAK5B,YAAY,eAAuB,EAAE,IAAY,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;QAEd,OAAO,MAAM,IAAA,eAAK,EAAC;YACjB,MAAM,EAAE,MAAM;YACd,GAAG,EAAE,GAAG,IAAI,CAAC,IAAI,0BAA0B,IAAI,CAAC,eAAe,aAAa;YAC5E,OAAO,EAAE;gBACP,aAAa,EAAE,UAAU,SAAS,EAAE;gBACpC,cAAc,EAAE,kBAAkB;aACnC;YACD,IAAI,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE;YACzB,OAAO,EAAE,IAAI,CAAC,OAAO;SACtB,CAAC,CAAA;IACJ,CAAC;CACF;AA1BD,8CA0BC"}
@@ -0,0 +1,10 @@
1
+ import { HubtypeSession, Plugin, PluginPreRequest } from '@botonic/core';
2
+ import { KnowledgebaseResppnse, PluginKnowledgeBaseOptions } from './types';
3
+ export default class BotonicPluginKnowledgeBase implements Plugin {
4
+ private readonly apiService;
5
+ private readonly authToken;
6
+ constructor(options: PluginKnowledgeBaseOptions);
7
+ pre(_request: PluginPreRequest): Promise<void>;
8
+ getIaResponse(session: HubtypeSession): Promise<KnowledgebaseResppnse>;
9
+ }
10
+ export { PluginKnowledgeBaseOptions } from './types';
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const hubtype_knowledge_api_service_1 = require("./hubtype-knowledge-api-service");
4
+ const isProd = process.env.NODE_ENV === 'production';
5
+ class BotonicPluginKnowledgeBase {
6
+ constructor(options) {
7
+ this.apiService = new hubtype_knowledge_api_service_1.HubtypeApiService(options.knowledgeBaseId, options.host, options.timeout);
8
+ this.authToken = options.authToken || '';
9
+ }
10
+ async pre(_request) {
11
+ return;
12
+ }
13
+ async getIaResponse(session) {
14
+ try {
15
+ const authToken = isProd ? session._access_token : this.authToken;
16
+ const response = await this.apiService.inference(authToken, session.user.id);
17
+ console.log(response);
18
+ return response.data;
19
+ }
20
+ catch (e) {
21
+ console.log(e);
22
+ return {
23
+ ia: '',
24
+ hasKnowledge: false,
25
+ sources: [],
26
+ };
27
+ }
28
+ }
29
+ }
30
+ exports.default = BotonicPluginKnowledgeBase;
31
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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,0BAA0B;IAI7C,YAAY,OAAmC;QAC7C,IAAI,CAAC,UAAU,GAAG,IAAI,iDAAiB,CACrC,OAAO,CAAC,eAAe,EACvB,OAAO,CAAC,IAAI,EACZ,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,aAAa,CAAC,OAAuB;QACzC,IAAI;YACF,MAAM,SAAS,GAAG,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAA;YACjE,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,SAAS,CAC9C,SAAS,EACT,OAAO,CAAC,IAAI,CAAC,EAAE,CAChB,CAAA;YACD,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;YACrB,OAAO,QAAQ,CAAC,IAAI,CAAA;SACrB;QAAC,OAAO,CAAC,EAAE;YACV,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;YACd,OAAO;gBACL,EAAE,EAAE,EAAE;gBACN,YAAY,EAAE,KAAK;gBACnB,OAAO,EAAE,EAAE;aACZ,CAAA;SACF;IACH,CAAC;CACF;AAnCD,6CAmCC"}
@@ -0,0 +1,11 @@
1
+ export interface PluginKnowledgeBaseOptions {
2
+ knowledgeBaseId: string;
3
+ host: string;
4
+ authToken?: string;
5
+ timeout?: number;
6
+ }
7
+ export interface KnowledgebaseResppnse {
8
+ ia: string;
9
+ hasKnowledge: boolean;
10
+ sources: string[];
11
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,9 @@
1
+ import { AxiosResponse } from 'axios';
2
+ import { KnowledgebaseResppnse } from './types';
3
+ export declare class HubtypeApiService {
4
+ private knowledgeBaseId;
5
+ private host;
6
+ private timeout;
7
+ constructor(knowledgeBaseId: string, host: string, timeout?: number);
8
+ inference(authToken: string, chatId: string): Promise<AxiosResponse<KnowledgebaseResppnse>>;
9
+ }
@@ -0,0 +1,22 @@
1
+ import axios from 'axios';
2
+ const DEFAULT_TIMEOUT = 10000;
3
+ export class HubtypeApiService {
4
+ constructor(knowledgeBaseId, host, timeout) {
5
+ this.knowledgeBaseId = knowledgeBaseId;
6
+ this.host = host;
7
+ this.timeout = timeout || DEFAULT_TIMEOUT;
8
+ }
9
+ async inference(authToken, chatId) {
10
+ return await axios({
11
+ method: 'POST',
12
+ url: `${this.host}/v1/ai/knowledge_bases/${this.knowledgeBaseId}/inference/`,
13
+ headers: {
14
+ Authorization: `Bearer ${authToken}`,
15
+ 'Content-Type': 'application/json',
16
+ },
17
+ data: { chat_id: chatId },
18
+ timeout: this.timeout,
19
+ });
20
+ }
21
+ }
22
+ //# sourceMappingURL=hubtype-knowledge-api-service.js.map
@@ -0,0 +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;AAI5C,MAAM,eAAe,GAAG,KAAK,CAAA;AAE7B,MAAM,OAAO,iBAAiB;IAK5B,YAAY,eAAuB,EAAE,IAAY,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;QAEd,OAAO,MAAM,KAAK,CAAC;YACjB,MAAM,EAAE,MAAM;YACd,GAAG,EAAE,GAAG,IAAI,CAAC,IAAI,0BAA0B,IAAI,CAAC,eAAe,aAAa;YAC5E,OAAO,EAAE;gBACP,aAAa,EAAE,UAAU,SAAS,EAAE;gBACpC,cAAc,EAAE,kBAAkB;aACnC;YACD,IAAI,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE;YACzB,OAAO,EAAE,IAAI,CAAC,OAAO;SACtB,CAAC,CAAA;IACJ,CAAC;CACF"}
@@ -0,0 +1,10 @@
1
+ import { HubtypeSession, Plugin, PluginPreRequest } from '@botonic/core';
2
+ import { KnowledgebaseResppnse, PluginKnowledgeBaseOptions } from './types';
3
+ export default class BotonicPluginKnowledgeBase implements Plugin {
4
+ private readonly apiService;
5
+ private readonly authToken;
6
+ constructor(options: PluginKnowledgeBaseOptions);
7
+ pre(_request: PluginPreRequest): Promise<void>;
8
+ getIaResponse(session: HubtypeSession): Promise<KnowledgebaseResppnse>;
9
+ }
10
+ export { PluginKnowledgeBaseOptions } from './types';
@@ -0,0 +1,28 @@
1
+ import { HubtypeApiService } from './hubtype-knowledge-api-service';
2
+ const isProd = process.env.NODE_ENV === 'production';
3
+ export default class BotonicPluginKnowledgeBase {
4
+ constructor(options) {
5
+ this.apiService = new HubtypeApiService(options.knowledgeBaseId, options.host, options.timeout);
6
+ this.authToken = options.authToken || '';
7
+ }
8
+ async pre(_request) {
9
+ return;
10
+ }
11
+ async getIaResponse(session) {
12
+ try {
13
+ const authToken = isProd ? session._access_token : this.authToken;
14
+ const response = await this.apiService.inference(authToken, session.user.id);
15
+ console.log(response);
16
+ return response.data;
17
+ }
18
+ catch (e) {
19
+ console.log(e);
20
+ return {
21
+ ia: '',
22
+ hasKnowledge: false,
23
+ sources: [],
24
+ };
25
+ }
26
+ }
27
+ }
28
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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,0BAA0B;IAI7C,YAAY,OAAmC;QAC7C,IAAI,CAAC,UAAU,GAAG,IAAI,iBAAiB,CACrC,OAAO,CAAC,eAAe,EACvB,OAAO,CAAC,IAAI,EACZ,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,aAAa,CAAC,OAAuB;QACzC,IAAI;YACF,MAAM,SAAS,GAAG,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAA;YACjE,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,SAAS,CAC9C,SAAS,EACT,OAAO,CAAC,IAAI,CAAC,EAAE,CAChB,CAAA;YACD,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;YACrB,OAAO,QAAQ,CAAC,IAAI,CAAA;SACrB;QAAC,OAAO,CAAC,EAAE;YACV,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;YACd,OAAO;gBACL,EAAE,EAAE,EAAE;gBACN,YAAY,EAAE,KAAK;gBACnB,OAAO,EAAE,EAAE;aACZ,CAAA;SACF;IACH,CAAC;CACF"}
@@ -0,0 +1,11 @@
1
+ export interface PluginKnowledgeBaseOptions {
2
+ knowledgeBaseId: string;
3
+ host: string;
4
+ authToken?: string;
5
+ timeout?: number;
6
+ }
7
+ export interface KnowledgebaseResppnse {
8
+ ia: string;
9
+ hasKnowledge: boolean;
10
+ sources: string[];
11
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "@botonic/plugin-knowledge-bases",
3
+ "version": "0.23.0-alpha.0",
4
+ "description": "Use a Hubtype to make the bot respond through a knowledge base.",
5
+ "main": "index.ts",
6
+ "scripts": {
7
+ "build": "rm -rf lib && ../../node_modules/.bin/tsc -p tsconfig.json && ../../node_modules/.bin/tsc -p tsconfig.esm.json",
8
+ "build:watch": "npm run build -- --watch",
9
+ "cloc": "../../scripts/qa/cloc-package.sh .",
10
+ "prepare": "node ../../preinstall.js",
11
+ "prepublishOnly": "rm -rf lib && npm run build",
12
+ "lint": "npm run lint_core -- --fix",
13
+ "lint_ci": "npm run lint_core -- -c ../.eslintrc_slow.js",
14
+ "lint_core": "../../node_modules/.bin/eslint_d --cache --quiet 'src/**/*.ts*'"
15
+ },
16
+ "engines": {
17
+ "node": ">=14.0.0"
18
+ },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/hubtype/botonic.git"
22
+ },
23
+ "author": "",
24
+ "files": [
25
+ "lib/**",
26
+ "src/**",
27
+ "README.md"
28
+ ],
29
+ "dependencies": {
30
+ "@babel/runtime": "^7.22.5",
31
+ "@botonic/core": "^0.23.0",
32
+ "axios": "^1.4.0"
33
+ },
34
+ "devDependencies": {
35
+ "@types/node": "^18.16.0"
36
+ },
37
+ "keywords": [
38
+ "bot-framework",
39
+ "chatbot",
40
+ "knowledge-base",
41
+ "gpt",
42
+ "conversational-app",
43
+ "conversational-ui",
44
+ "typescript"
45
+ ],
46
+ "eslintConfig": {
47
+ "extends": "../.eslintrc.js",
48
+ "root": true
49
+ },
50
+ "license": "MIT"
51
+ }
@@ -0,0 +1,33 @@
1
+ import axios, { AxiosResponse } from 'axios'
2
+
3
+ import { KnowledgebaseResppnse } from './types'
4
+
5
+ const DEFAULT_TIMEOUT = 10000
6
+
7
+ export class HubtypeApiService {
8
+ private knowledgeBaseId: string
9
+ private host: string
10
+ private timeout: number
11
+
12
+ constructor(knowledgeBaseId: string, host: string, timeout?: number) {
13
+ this.knowledgeBaseId = knowledgeBaseId
14
+ this.host = host
15
+ this.timeout = timeout || DEFAULT_TIMEOUT
16
+ }
17
+
18
+ async inference(
19
+ authToken: string,
20
+ chatId: string
21
+ ): Promise<AxiosResponse<KnowledgebaseResppnse>> {
22
+ return await axios({
23
+ method: 'POST',
24
+ url: `${this.host}/v1/ai/knowledge_bases/${this.knowledgeBaseId}/inference/`,
25
+ headers: {
26
+ Authorization: `Bearer ${authToken}`,
27
+ 'Content-Type': 'application/json',
28
+ },
29
+ data: { chat_id: chatId },
30
+ timeout: this.timeout,
31
+ })
32
+ }
33
+ }
package/src/index.ts ADDED
@@ -0,0 +1,45 @@
1
+ import { HubtypeSession, Plugin, PluginPreRequest } from '@botonic/core'
2
+
3
+ import { HubtypeApiService } from './hubtype-knowledge-api-service'
4
+ import { KnowledgebaseResppnse, PluginKnowledgeBaseOptions } from './types'
5
+
6
+ const isProd = process.env.NODE_ENV === 'production'
7
+
8
+ export default class BotonicPluginKnowledgeBase implements Plugin {
9
+ private readonly apiService: HubtypeApiService
10
+ private readonly authToken: string
11
+
12
+ constructor(options: PluginKnowledgeBaseOptions) {
13
+ this.apiService = new HubtypeApiService(
14
+ options.knowledgeBaseId,
15
+ options.host,
16
+ options.timeout
17
+ )
18
+ this.authToken = options.authToken || ''
19
+ }
20
+
21
+ async pre(_request: PluginPreRequest): Promise<void> {
22
+ return
23
+ }
24
+
25
+ async getIaResponse(session: HubtypeSession): Promise<KnowledgebaseResppnse> {
26
+ try {
27
+ const authToken = isProd ? session._access_token : this.authToken
28
+ const response = await this.apiService.inference(
29
+ authToken,
30
+ session.user.id
31
+ )
32
+ console.log(response)
33
+ return response.data
34
+ } catch (e) {
35
+ console.log(e)
36
+ return {
37
+ ia: '',
38
+ hasKnowledge: false,
39
+ sources: [],
40
+ }
41
+ }
42
+ }
43
+ }
44
+
45
+ export { PluginKnowledgeBaseOptions } from './types'
package/src/types.ts ADDED
@@ -0,0 +1,12 @@
1
+ export interface PluginKnowledgeBaseOptions {
2
+ knowledgeBaseId: string
3
+ host: string
4
+ authToken?: string
5
+ timeout?: number
6
+ }
7
+
8
+ export interface KnowledgebaseResppnse {
9
+ ia: string
10
+ hasKnowledge: boolean
11
+ sources: string[]
12
+ }