@botonic/plugin-knowledge-bases 0.23.0-alpha.0 → 0.23.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 +73 -0
- package/lib/cjs/hubtype-knowledge-api-service.d.ts +5 -2
- package/lib/cjs/hubtype-knowledge-api-service.js +1 -1
- package/lib/cjs/hubtype-knowledge-api-service.js.map +1 -1
- package/lib/cjs/index.d.ts +3 -3
- package/lib/cjs/index.js +9 -6
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/types.d.ts +2 -2
- package/lib/esm/hubtype-knowledge-api-service.d.ts +5 -2
- package/lib/esm/hubtype-knowledge-api-service.js +1 -1
- package/lib/esm/hubtype-knowledge-api-service.js.map +1 -1
- package/lib/esm/index.d.ts +3 -3
- package/lib/esm/index.js +8 -5
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/types.d.ts +2 -2
- package/package.json +3 -2
- package/src/hubtype-knowledge-api-service.ts +8 -4
- package/src/index.ts +10 -7
- package/src/types.ts +2 -2
package/README.md
CHANGED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# Botonic Plugin Knowledge Bases
|
|
2
|
+
|
|
3
|
+
## What Does This Plugin Do?
|
|
4
|
+
|
|
5
|
+
This plugin allows you to integrate Hubtype Knowledge bases in your Botonic project. It works like any other AI services plugin, like Hubtype Babel, Dialogflow, Watson, etc.
|
|
6
|
+
|
|
7
|
+
## Setup
|
|
8
|
+
|
|
9
|
+
1. Install the plugin from npm (or yarn):
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
npm i --save @botonic/plugin-hubtype-knowledge-bases
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
2. Add it to the `src/plugins.js` file defining the projectId of the Project you want to use:
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
export const plugins = [
|
|
19
|
+
{
|
|
20
|
+
id: 'hubtype-knowledge-bases',
|
|
21
|
+
resolve: require('@botonic/plugin-hubtype-knowledge-bases'),
|
|
22
|
+
options: {
|
|
23
|
+
knowledgeBaseId: '6800762a-03b5-419e-be97-67feac7bc5b9',
|
|
24
|
+
host: 'https://www.api.hubtype.com'
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
]
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Use
|
|
31
|
+
|
|
32
|
+
The plugin response contains 3 attributes ai, hasKnowledge, sources. If hasKnowledge is true the response will be in ai and source will be the name of the document from which the response was obtained. If the hasKnowledge parameter is false then it does not have enough knowledge to answer and in that case the answer should not be shown to the user.
|
|
33
|
+
|
|
34
|
+
You can use it in your actions:
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
import React from 'react'
|
|
38
|
+
import { Text } from '@botonic/react'
|
|
39
|
+
|
|
40
|
+
export default class OrderLocation extends React.Component {
|
|
41
|
+
static async botonicInit(request) {
|
|
42
|
+
const knowledgePlugin = request.plugins.knwoledgePlugin
|
|
43
|
+
const response = await knowladgeBasePlugin.getIaResponse(request.session)
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
text: response.hasKnowledge
|
|
47
|
+
? response.ai
|
|
48
|
+
: "I don't know what you're talking about",
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
render() {
|
|
52
|
+
return <Text>{this.props.text}</Text>
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Plugin Options
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
interface PluginKnowledgeBaseOptions {
|
|
61
|
+
knowledgeBaseId: string
|
|
62
|
+
host: string
|
|
63
|
+
authToken?: string
|
|
64
|
+
timeout?: number
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
- **`knowledgeBaseId`**: Id of the knowledge base previously uploaded to the desk under ai/knowledgebases.
|
|
69
|
+
- **`[host]`**: Host uri where to request inference.
|
|
70
|
+
- Default: *https://api.hubtype.com.*
|
|
71
|
+
- **`[authToken]`**: Authorization Token to being able to run inference. Only needed when using the plugin locally.
|
|
72
|
+
- **`[timeout]`**: timeout of the call to the knowledgebases inferrence endpoint.
|
|
73
|
+
- Default: 10 seconds
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { AxiosResponse } from 'axios';
|
|
2
|
-
import { KnowledgebaseResppnse } from './types';
|
|
3
2
|
export declare class HubtypeApiService {
|
|
4
3
|
private knowledgeBaseId;
|
|
5
4
|
private host;
|
|
6
5
|
private timeout;
|
|
7
6
|
constructor(knowledgeBaseId: string, host: string, timeout?: number);
|
|
8
|
-
inference(authToken: string, chatId: string): Promise<AxiosResponse<
|
|
7
|
+
inference(authToken: string, chatId: string): Promise<AxiosResponse<{
|
|
8
|
+
ai: string;
|
|
9
|
+
has_knowledge: boolean;
|
|
10
|
+
sources: string[];
|
|
11
|
+
}>>;
|
|
9
12
|
}
|
|
@@ -13,7 +13,7 @@ class HubtypeApiService {
|
|
|
13
13
|
async inference(authToken, chatId) {
|
|
14
14
|
return await (0, axios_1.default)({
|
|
15
15
|
method: 'POST',
|
|
16
|
-
url: `${this.host}
|
|
16
|
+
url: `${this.host}v1/ai/knowledge_bases/${this.knowledgeBaseId}/inference/`,
|
|
17
17
|
headers: {
|
|
18
18
|
Authorization: `Bearer ${authToken}`,
|
|
19
19
|
'Content-Type': 'application/json',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hubtype-knowledge-api-service.js","sourceRoot":"","sources":["../../src/hubtype-knowledge-api-service.ts"],"names":[],"mappings":";;;;AAAA,0DAA4C;
|
|
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,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;QAQd,OAAO,MAAM,IAAA,eAAK,EAAC;YACjB,MAAM,EAAE,MAAM;YACd,GAAG,EAAE,GAAG,IAAI,CAAC,IAAI,yBAAyB,IAAI,CAAC,eAAe,aAAa;YAC3E,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;AAhCD,8CAgCC"}
|
package/lib/cjs/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { HubtypeSession, Plugin, PluginPreRequest } from '@botonic/core';
|
|
2
|
-
import {
|
|
3
|
-
export default class
|
|
2
|
+
import { KnowledgebaseResponse, PluginKnowledgeBaseOptions } from './types';
|
|
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
|
-
getIaResponse(session: HubtypeSession): Promise<
|
|
8
|
+
getIaResponse(session: HubtypeSession): Promise<KnowledgebaseResponse>;
|
|
9
9
|
}
|
|
10
10
|
export { PluginKnowledgeBaseOptions } from './types';
|
package/lib/cjs/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const hubtype_knowledge_api_service_1 = require("./hubtype-knowledge-api-service");
|
|
4
4
|
const isProd = process.env.NODE_ENV === 'production';
|
|
5
|
-
class
|
|
5
|
+
class BotonicPluginKnowledgeBases {
|
|
6
6
|
constructor(options) {
|
|
7
7
|
this.apiService = new hubtype_knowledge_api_service_1.HubtypeApiService(options.knowledgeBaseId, options.host, options.timeout);
|
|
8
8
|
this.authToken = options.authToken || '';
|
|
@@ -14,18 +14,21 @@ class BotonicPluginKnowledgeBase {
|
|
|
14
14
|
try {
|
|
15
15
|
const authToken = isProd ? session._access_token : this.authToken;
|
|
16
16
|
const response = await this.apiService.inference(authToken, session.user.id);
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
return {
|
|
18
|
+
ai: response.data.ai,
|
|
19
|
+
hasKnowledge: response.data.has_knowledge,
|
|
20
|
+
sources: response.data.sources,
|
|
21
|
+
};
|
|
19
22
|
}
|
|
20
23
|
catch (e) {
|
|
21
|
-
console.
|
|
24
|
+
console.error(e);
|
|
22
25
|
return {
|
|
23
|
-
|
|
26
|
+
ai: '',
|
|
24
27
|
hasKnowledge: false,
|
|
25
28
|
sources: [],
|
|
26
29
|
};
|
|
27
30
|
}
|
|
28
31
|
}
|
|
29
32
|
}
|
|
30
|
-
exports.default =
|
|
33
|
+
exports.default = BotonicPluginKnowledgeBases;
|
|
31
34
|
//# sourceMappingURL=index.js.map
|
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,
|
|
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,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;gBACL,EAAE,EAAE,QAAQ,CAAC,IAAI,CAAC,EAAE;gBACpB,YAAY,EAAE,QAAQ,CAAC,IAAI,CAAC,aAAa;gBACzC,OAAO,EAAE,QAAQ,CAAC,IAAI,CAAC,OAAO;aAC/B,CAAA;SACF;QAAC,OAAO,CAAC,EAAE;YACV,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;YAChB,OAAO;gBACL,EAAE,EAAE,EAAE;gBACN,YAAY,EAAE,KAAK;gBACnB,OAAO,EAAE,EAAE;aACZ,CAAA;SACF;IACH,CAAC;CACF;AAtCD,8CAsCC"}
|
package/lib/cjs/types.d.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { AxiosResponse } from 'axios';
|
|
2
|
-
import { KnowledgebaseResppnse } from './types';
|
|
3
2
|
export declare class HubtypeApiService {
|
|
4
3
|
private knowledgeBaseId;
|
|
5
4
|
private host;
|
|
6
5
|
private timeout;
|
|
7
6
|
constructor(knowledgeBaseId: string, host: string, timeout?: number);
|
|
8
|
-
inference(authToken: string, chatId: string): Promise<AxiosResponse<
|
|
7
|
+
inference(authToken: string, chatId: string): Promise<AxiosResponse<{
|
|
8
|
+
ai: string;
|
|
9
|
+
has_knowledge: boolean;
|
|
10
|
+
sources: string[];
|
|
11
|
+
}>>;
|
|
9
12
|
}
|
|
@@ -9,7 +9,7 @@ export class HubtypeApiService {
|
|
|
9
9
|
async inference(authToken, chatId) {
|
|
10
10
|
return await axios({
|
|
11
11
|
method: 'POST',
|
|
12
|
-
url: `${this.host}
|
|
12
|
+
url: `${this.host}v1/ai/knowledge_bases/${this.knowledgeBaseId}/inference/`,
|
|
13
13
|
headers: {
|
|
14
14
|
Authorization: `Bearer ${authToken}`,
|
|
15
15
|
'Content-Type': 'application/json',
|
|
@@ -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;
|
|
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,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;QAQd,OAAO,MAAM,KAAK,CAAC;YACjB,MAAM,EAAE,MAAM;YACd,GAAG,EAAE,GAAG,IAAI,CAAC,IAAI,yBAAyB,IAAI,CAAC,eAAe,aAAa;YAC3E,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"}
|
package/lib/esm/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { HubtypeSession, Plugin, PluginPreRequest } from '@botonic/core';
|
|
2
|
-
import {
|
|
3
|
-
export default class
|
|
2
|
+
import { KnowledgebaseResponse, PluginKnowledgeBaseOptions } from './types';
|
|
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
|
-
getIaResponse(session: HubtypeSession): Promise<
|
|
8
|
+
getIaResponse(session: HubtypeSession): Promise<KnowledgebaseResponse>;
|
|
9
9
|
}
|
|
10
10
|
export { PluginKnowledgeBaseOptions } from './types';
|
package/lib/esm/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { HubtypeApiService } from './hubtype-knowledge-api-service';
|
|
2
2
|
const isProd = process.env.NODE_ENV === 'production';
|
|
3
|
-
export default class
|
|
3
|
+
export default class BotonicPluginKnowledgeBases {
|
|
4
4
|
constructor(options) {
|
|
5
5
|
this.apiService = new HubtypeApiService(options.knowledgeBaseId, options.host, options.timeout);
|
|
6
6
|
this.authToken = options.authToken || '';
|
|
@@ -12,13 +12,16 @@ export default class BotonicPluginKnowledgeBase {
|
|
|
12
12
|
try {
|
|
13
13
|
const authToken = isProd ? session._access_token : this.authToken;
|
|
14
14
|
const response = await this.apiService.inference(authToken, session.user.id);
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
return {
|
|
16
|
+
ai: response.data.ai,
|
|
17
|
+
hasKnowledge: response.data.has_knowledge,
|
|
18
|
+
sources: response.data.sources,
|
|
19
|
+
};
|
|
17
20
|
}
|
|
18
21
|
catch (e) {
|
|
19
|
-
console.
|
|
22
|
+
console.error(e);
|
|
20
23
|
return {
|
|
21
|
-
|
|
24
|
+
ai: '',
|
|
22
25
|
hasKnowledge: false,
|
|
23
26
|
sources: [],
|
|
24
27
|
};
|
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,
|
|
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,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;gBACL,EAAE,EAAE,QAAQ,CAAC,IAAI,CAAC,EAAE;gBACpB,YAAY,EAAE,QAAQ,CAAC,IAAI,CAAC,aAAa;gBACzC,OAAO,EAAE,QAAQ,CAAC,IAAI,CAAC,OAAO;aAC/B,CAAA;SACF;QAAC,OAAO,CAAC,EAAE;YACV,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;YAChB,OAAO;gBACL,EAAE,EAAE,EAAE;gBACN,YAAY,EAAE,KAAK;gBACnB,OAAO,EAAE,EAAE;aACZ,CAAA;SACF;IACH,CAAC;CACF"}
|
package/lib/esm/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@botonic/plugin-knowledge-bases",
|
|
3
|
-
"version": "0.23.0
|
|
3
|
+
"version": "0.23.0",
|
|
4
4
|
"description": "Use a Hubtype to make the bot respond through a knowledge base.",
|
|
5
|
-
"main": "index.
|
|
5
|
+
"main": "./lib/cjs/index.js",
|
|
6
|
+
"module": "./lib/esm/index.js",
|
|
6
7
|
"scripts": {
|
|
7
8
|
"build": "rm -rf lib && ../../node_modules/.bin/tsc -p tsconfig.json && ../../node_modules/.bin/tsc -p tsconfig.esm.json",
|
|
8
9
|
"build:watch": "npm run build -- --watch",
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import axios, { AxiosResponse } from 'axios'
|
|
2
2
|
|
|
3
|
-
import { KnowledgebaseResppnse } from './types'
|
|
4
|
-
|
|
5
3
|
const DEFAULT_TIMEOUT = 10000
|
|
6
4
|
|
|
7
5
|
export class HubtypeApiService {
|
|
@@ -18,10 +16,16 @@ export class HubtypeApiService {
|
|
|
18
16
|
async inference(
|
|
19
17
|
authToken: string,
|
|
20
18
|
chatId: string
|
|
21
|
-
): Promise<
|
|
19
|
+
): Promise<
|
|
20
|
+
AxiosResponse<{
|
|
21
|
+
ai: string
|
|
22
|
+
has_knowledge: boolean
|
|
23
|
+
sources: string[]
|
|
24
|
+
}>
|
|
25
|
+
> {
|
|
22
26
|
return await axios({
|
|
23
27
|
method: 'POST',
|
|
24
|
-
url: `${this.host}
|
|
28
|
+
url: `${this.host}v1/ai/knowledge_bases/${this.knowledgeBaseId}/inference/`,
|
|
25
29
|
headers: {
|
|
26
30
|
Authorization: `Bearer ${authToken}`,
|
|
27
31
|
'Content-Type': 'application/json',
|
package/src/index.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
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
|
|
|
8
|
-
export default class
|
|
8
|
+
export default class BotonicPluginKnowledgeBases implements Plugin {
|
|
9
9
|
private readonly apiService: HubtypeApiService
|
|
10
10
|
private readonly authToken: string
|
|
11
11
|
|
|
@@ -22,19 +22,22 @@ export default class BotonicPluginKnowledgeBase implements Plugin {
|
|
|
22
22
|
return
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
async getIaResponse(session: HubtypeSession): Promise<
|
|
25
|
+
async getIaResponse(session: HubtypeSession): Promise<KnowledgebaseResponse> {
|
|
26
26
|
try {
|
|
27
27
|
const authToken = isProd ? session._access_token : this.authToken
|
|
28
28
|
const response = await this.apiService.inference(
|
|
29
29
|
authToken,
|
|
30
30
|
session.user.id
|
|
31
31
|
)
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
return {
|
|
33
|
+
ai: response.data.ai,
|
|
34
|
+
hasKnowledge: response.data.has_knowledge,
|
|
35
|
+
sources: response.data.sources,
|
|
36
|
+
}
|
|
34
37
|
} catch (e) {
|
|
35
|
-
console.
|
|
38
|
+
console.error(e)
|
|
36
39
|
return {
|
|
37
|
-
|
|
40
|
+
ai: '',
|
|
38
41
|
hasKnowledge: false,
|
|
39
42
|
sources: [],
|
|
40
43
|
}
|
package/src/types.ts
CHANGED