openkbs 0.0.30 → 0.0.31
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/MODIFY.md +17 -6
- package/package.json +1 -1
- package/src/utils.js +2 -2
package/MODIFY.md
CHANGED
|
@@ -15,7 +15,7 @@ A typical OpenKBS project has the following key directories:
|
|
|
15
15
|
|
|
16
16
|
* **`src/`**: Contains your custom source code.
|
|
17
17
|
* **`Events/`**: Houses backend event handlers.
|
|
18
|
-
* `actions.js`: Often used for shared logic/tool definitions.
|
|
18
|
+
* `actions.js`: Often used for shared logic/tool definitions (does not have own NPM dependencies).
|
|
19
19
|
* `onRequest.js`: Handles incoming user messages before LLM processing.
|
|
20
20
|
* `onRequest.json`: NPM dependencies for `onRequest.js`.
|
|
21
21
|
* `onResponse.js`: Handles LLM responses before sending to the user.
|
|
@@ -32,14 +32,24 @@ A typical OpenKBS project has the following key directories:
|
|
|
32
32
|
* `instructions.txt`: Instructions for the LLM.
|
|
33
33
|
* `icon.png`: Application icon.
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
#### onRequest and onResponse Handlers
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
The core of the OpenKBS backend framework revolves around the `onRequest` and `onResponse` event handlers.
|
|
38
|
+
These handlers act as middleware, intercepting messages before and after they are processed by the LLM.
|
|
39
|
+
|
|
40
|
+
* **`onRequest` Handler:** This handler is invoked every time a user sends a message to the chat. It provides an opportunity to pre-process the user's input, extract commands and perform actions based on the user's message.
|
|
41
|
+
|
|
42
|
+
* **`onResponse` Handler:** This handler is invoked after the LLM generates a response. It allows post-processing of the LLM's output, execution of commands based on the LLM's intentions.
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
## Backend Dependencies
|
|
46
|
+
|
|
47
|
+
To use external NPM packages in your backend event handlers, you must declare them in the corresponding `.json` file.
|
|
38
48
|
OpenKBS also provides a secure way to handle sensitive information using the `{{secrets.your_secret_name}}` syntax.
|
|
39
49
|
|
|
40
50
|
**Example: Using axios with an API key**
|
|
41
51
|
|
|
42
|
-
1.
|
|
52
|
+
1. **Declare dependencies** in both `src/Events/onRequest.json` and `src/Events/onResponse.json` (as each handler have separate build):
|
|
43
53
|
```json
|
|
44
54
|
{
|
|
45
55
|
"dependencies": {
|
|
@@ -68,5 +78,6 @@ OpenKBS also provides a secure way to handle sensitive information using the `{{
|
|
|
68
78
|
];
|
|
69
79
|
};
|
|
70
80
|
```
|
|
71
|
-
|
|
72
|
-
Define `news_api_key` in your application's secrets manager on the OpenKBS platform.
|
|
81
|
+
## Secrets Management
|
|
82
|
+
Define `news_api_key` in your application's secrets manager on the OpenKBS platform.
|
|
83
|
+
The platform will inject the actual value at runtime, keeping your credentials secure while enabling you to make API calls with authenticated services.
|
package/package.json
CHANGED
package/src/utils.js
CHANGED
|
@@ -332,10 +332,10 @@ async function modifyKB(kbToken, kbData, prompt, files, options) {
|
|
|
332
332
|
console.error('Error getting files from directories:', error);
|
|
333
333
|
}
|
|
334
334
|
}
|
|
335
|
-
|
|
335
|
+
|
|
336
336
|
// Add MODIFY.md to files list if it exists
|
|
337
337
|
if (hasModifyFile && !files.includes(modifyFilePath)) {
|
|
338
|
-
files.
|
|
338
|
+
files.unshift(modifyFilePath);
|
|
339
339
|
}
|
|
340
340
|
|
|
341
341
|
const fileContents = await Promise.all(files.map(async (filePath) => {
|