backend-manager 4.2.20 → 4.2.22
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/CHANGELOG.md +4 -0
- package/package.json +1 -1
- package/src/manager/index.js +24 -3
- package/src/manager/libraries/openai.js +13 -0
package/CHANGELOG.md
CHANGED
|
@@ -15,6 +15,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|
|
15
15
|
- `Security` in case of vulnerabilities.
|
|
16
16
|
|
|
17
17
|
---#
|
|
18
|
+
# [4.2.22] - 2024-12-19
|
|
19
|
+
### Changed
|
|
20
|
+
- `Manager.install()` now automatically binds the fn with the proper `this` context (this may be breaking).
|
|
21
|
+
|
|
18
22
|
# [4.1.0] - 2024-12-19
|
|
19
23
|
### Changed
|
|
20
24
|
- Attach `schema` to `bm-properties` response header.
|
package/package.json
CHANGED
package/src/manager/index.js
CHANGED
|
@@ -619,18 +619,39 @@ Manager.prototype.install = function (controller, options) {
|
|
|
619
619
|
self.assistant.log(`Installing from ${options.dir}, prefix=${options.prefix}, isDirectory=${isDirectory}...`);
|
|
620
620
|
}
|
|
621
621
|
|
|
622
|
+
// function _install(prefix, file) {
|
|
623
|
+
// if (!file.includes('.js')) {return}
|
|
624
|
+
// const name = file.replace('.js', '');
|
|
625
|
+
// const _prefix = prefix ? `${prefix}_${name}` : name;
|
|
626
|
+
|
|
627
|
+
// const fullPath = path.resolve(options.dir, file);
|
|
628
|
+
|
|
629
|
+
// if (options.log) {
|
|
630
|
+
// self.assistant.log(`Installing ${_prefix} from ${fullPath}...`);
|
|
631
|
+
// }
|
|
632
|
+
|
|
633
|
+
// controller[`${_prefix}`] = require(fullPath);
|
|
634
|
+
// }
|
|
635
|
+
|
|
622
636
|
function _install(prefix, file) {
|
|
623
|
-
if (!file.includes('.js'))
|
|
637
|
+
if (!file.includes('.js')) return;
|
|
638
|
+
|
|
624
639
|
const name = file.replace('.js', '');
|
|
625
640
|
const _prefix = prefix ? `${prefix}_${name}` : name;
|
|
626
|
-
|
|
627
641
|
const fullPath = path.resolve(options.dir, file);
|
|
628
642
|
|
|
629
643
|
if (options.log) {
|
|
630
644
|
self.assistant.log(`Installing ${_prefix} from ${fullPath}...`);
|
|
631
645
|
}
|
|
632
646
|
|
|
633
|
-
|
|
647
|
+
const mod = require(fullPath);
|
|
648
|
+
|
|
649
|
+
// If module exports a function, bind it to controller
|
|
650
|
+
if (typeof mod === 'function') {
|
|
651
|
+
controller[_prefix] = mod.bind(controller);
|
|
652
|
+
} else {
|
|
653
|
+
controller[_prefix] = mod;
|
|
654
|
+
}
|
|
634
655
|
}
|
|
635
656
|
|
|
636
657
|
if (isDirectory) {
|
|
@@ -385,6 +385,13 @@ OpenAI.prototype.request = function (options) {
|
|
|
385
385
|
images: options.message.images,
|
|
386
386
|
});
|
|
387
387
|
|
|
388
|
+
// Trim all history content
|
|
389
|
+
history.forEach((m) => {
|
|
390
|
+
if (typeof m.content === 'string') {
|
|
391
|
+
m.content = m.content.trim();
|
|
392
|
+
}
|
|
393
|
+
});
|
|
394
|
+
|
|
388
395
|
// Format history
|
|
389
396
|
history.map((m) => {
|
|
390
397
|
const originalContent = m.content;
|
|
@@ -541,6 +548,12 @@ OpenAI.prototype.request = function (options) {
|
|
|
541
548
|
// Request
|
|
542
549
|
_request('chatgpt', options)
|
|
543
550
|
.then((r) => {
|
|
551
|
+
// Trim response
|
|
552
|
+
if (typeof r === 'string') {
|
|
553
|
+
r = r.trim();
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
// Log
|
|
544
557
|
_log('Response', r.length, typeof r, r);
|
|
545
558
|
_log('Tokens', self.tokens);
|
|
546
559
|
|