@botonic/plugin-knowledge-bases 0.23.0-alpha.1 → 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 +2 -2
- package/lib/cjs/index.js +7 -5
- 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 +2 -2
- package/lib/esm/index.js +7 -5
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/types.d.ts +2 -2
- package/package.json +1 -1
- package/src/hubtype-knowledge-api-service.ts +8 -4
- package/src/index.ts +9 -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 {
|
|
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
|
-
getIaResponse(session: HubtypeSession): Promise<
|
|
8
|
+
getIaResponse(session: HubtypeSession): Promise<KnowledgebaseResponse>;
|
|
9
9
|
}
|
|
10
10
|
export { PluginKnowledgeBaseOptions } from './types';
|
package/lib/cjs/index.js
CHANGED
|
@@ -12,16 +12,18 @@ class BotonicPluginKnowledgeBases {
|
|
|
12
12
|
}
|
|
13
13
|
async getIaResponse(session) {
|
|
14
14
|
try {
|
|
15
|
-
console.log({ isProd });
|
|
16
15
|
const authToken = isProd ? session._access_token : this.authToken;
|
|
17
16
|
const response = await this.apiService.inference(authToken, session.user.id);
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
return {
|
|
18
|
+
ai: response.data.ai,
|
|
19
|
+
hasKnowledge: response.data.has_knowledge,
|
|
20
|
+
sources: response.data.sources,
|
|
21
|
+
};
|
|
20
22
|
}
|
|
21
23
|
catch (e) {
|
|
22
|
-
console.
|
|
24
|
+
console.error(e);
|
|
23
25
|
return {
|
|
24
|
-
|
|
26
|
+
ai: '',
|
|
25
27
|
hasKnowledge: false,
|
|
26
28
|
sources: [],
|
|
27
29
|
};
|
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,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,
|
|
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 {
|
|
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
|
-
getIaResponse(session: HubtypeSession): Promise<
|
|
8
|
+
getIaResponse(session: HubtypeSession): Promise<KnowledgebaseResponse>;
|
|
9
9
|
}
|
|
10
10
|
export { PluginKnowledgeBaseOptions } from './types';
|
package/lib/esm/index.js
CHANGED
|
@@ -10,16 +10,18 @@ export default class BotonicPluginKnowledgeBases {
|
|
|
10
10
|
}
|
|
11
11
|
async getIaResponse(session) {
|
|
12
12
|
try {
|
|
13
|
-
console.log({ isProd });
|
|
14
13
|
const authToken = isProd ? session._access_token : this.authToken;
|
|
15
14
|
const response = await this.apiService.inference(authToken, session.user.id);
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
return {
|
|
16
|
+
ai: response.data.ai,
|
|
17
|
+
hasKnowledge: response.data.has_knowledge,
|
|
18
|
+
sources: response.data.sources,
|
|
19
|
+
};
|
|
18
20
|
}
|
|
19
21
|
catch (e) {
|
|
20
|
-
console.
|
|
22
|
+
console.error(e);
|
|
21
23
|
return {
|
|
22
|
-
|
|
24
|
+
ai: '',
|
|
23
25
|
hasKnowledge: false,
|
|
24
26
|
sources: [],
|
|
25
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,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,
|
|
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,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,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
|
|
|
@@ -22,20 +22,22 @@ export default class BotonicPluginKnowledgeBases 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
|
-
console.log({ isProd })
|
|
28
27
|
const authToken = isProd ? session._access_token : this.authToken
|
|
29
28
|
const response = await this.apiService.inference(
|
|
30
29
|
authToken,
|
|
31
30
|
session.user.id
|
|
32
31
|
)
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
return {
|
|
33
|
+
ai: response.data.ai,
|
|
34
|
+
hasKnowledge: response.data.has_knowledge,
|
|
35
|
+
sources: response.data.sources,
|
|
36
|
+
}
|
|
35
37
|
} catch (e) {
|
|
36
|
-
console.
|
|
38
|
+
console.error(e)
|
|
37
39
|
return {
|
|
38
|
-
|
|
40
|
+
ai: '',
|
|
39
41
|
hasKnowledge: false,
|
|
40
42
|
sources: [],
|
|
41
43
|
}
|
package/src/types.ts
CHANGED