@sprucelabs/sprucebot-llm 4.0.84 → 5.0.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/build/.spruce/errors/errors.types.js +0 -2
- package/build/.spruce/errors/options.types.d.ts +2 -2
- package/build/.spruce/errors/sprucebotLlm/noBotInstanceSet.schema.js +1 -1
- package/build/.spruce/schemas/fields/fields.types.d.ts +1 -1
- package/build/bots/PromptGenerator.js +16 -24
- package/build/bots/SprucebotLlmBotImpl.js +21 -15
- package/build/bots/SprucebotLlmFactory.js +9 -6
- package/build/bots/SprucebotLlmSkillImpl.js +15 -17
- package/build/bots/adapters/OpenAi.js +7 -6
- package/build/bots/adapters/SpyOpenAiApi.js +4 -1
- package/build/chat.js +1 -1
- package/build/errors/SpruceError.d.ts +1 -1
- package/build/errors/SpruceError.js +1 -1
- package/build/esm/.spruce/errors/errors.types.js +0 -2
- package/build/esm/.spruce/errors/options.types.d.ts +2 -2
- package/build/esm/bots/PromptGenerator.js +0 -1
- package/build/esm/chat.js +1 -1
- package/build/esm/errors/SpruceError.d.ts +1 -1
- package/build/esm/examples/buildCallbackSkill.js +9 -1
- package/build/esm/fineTuningSprucebot/constants/TOPICS.js +5 -1
- package/build/esm/fineTuningSprucebot/generateSamples.js +1 -2
- package/build/esm/llm.types.d.ts +1 -3
- package/build/examples/buildCallbackSkill.js +9 -1
- package/build/fineTuningSprucebot/constants/TOPICS.js +5 -1
- package/build/fineTuningSprucebot/generateSamples.js +1 -2
- package/build/llm.types.d.ts +1 -3
- package/build/parsingResponses/ResponseParser.js +5 -6
- package/package.json +27 -27
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { ErrorOptions as ISpruceErrorOptions } from '@sprucelabs/error';
|
|
2
|
+
import { SpruceErrors } from './errors.types';
|
|
3
3
|
export interface NoBotInstanceSetErrorOptions extends SpruceErrors.SprucebotLlm.NoBotInstanceSet, ISpruceErrorOptions {
|
|
4
4
|
code: 'NO_BOT_INSTANCE_SET';
|
|
5
5
|
}
|
|
@@ -5,7 +5,7 @@ const noBotInstanceSetSchema = {
|
|
|
5
5
|
id: 'noBotInstanceSet',
|
|
6
6
|
namespace: 'SprucebotLlm',
|
|
7
7
|
name: 'No bot instance set',
|
|
8
|
-
fields: {}
|
|
8
|
+
fields: {},
|
|
9
9
|
};
|
|
10
10
|
schema_1.SchemaRegistry.getInstance().trackSchema(noBotInstanceSetSchema);
|
|
11
11
|
exports.default = noBotInstanceSetSchema;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { FieldDefinitions, FieldDefinitionMap, FieldValueTypeGeneratorMap, FieldMap } from '@sprucelabs/schema';
|
|
1
|
+
export { FieldDefinitions, FieldDefinitionMap, FieldValueTypeGeneratorMap, FieldMap, } from '@sprucelabs/schema';
|
|
@@ -1,40 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
-
var t = {};
|
|
4
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
-
t[p] = s[p];
|
|
6
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
-
t[p[i]] = s[p[i]];
|
|
10
|
-
}
|
|
11
|
-
return t;
|
|
12
|
-
};
|
|
13
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
3
|
exports.setUndefinedToNull = void 0;
|
|
15
4
|
const schema_1 = require("@sprucelabs/schema");
|
|
16
5
|
const eta_1 = require("eta");
|
|
17
6
|
const templates_1 = require("./templates");
|
|
18
7
|
class PromptGenerator {
|
|
8
|
+
bot;
|
|
9
|
+
eta = new eta_1.Eta();
|
|
10
|
+
log = process.env.SHOULD_LOG_GENERATED_PROMPTS === 'true'
|
|
11
|
+
? console.info
|
|
12
|
+
: () => { };
|
|
13
|
+
static Class;
|
|
14
|
+
promptTemplate;
|
|
19
15
|
constructor(bot, options) {
|
|
20
|
-
var _a;
|
|
21
|
-
this.eta = new eta_1.Eta();
|
|
22
|
-
this.log = process.env.SHOULD_LOG_GENERATED_PROMPTS === 'true'
|
|
23
|
-
? console.info
|
|
24
|
-
: () => { };
|
|
25
16
|
(0, schema_1.assertOptions)({ bot }, ['bot']);
|
|
26
17
|
this.bot = bot;
|
|
27
|
-
this.promptTemplate =
|
|
18
|
+
this.promptTemplate = options?.promptTemplate ?? templates_1.PROMPT_TEMPLATE;
|
|
28
19
|
}
|
|
29
20
|
static Generator(bot, options) {
|
|
30
|
-
|
|
31
|
-
return new ((_a = this.Class) !== null && _a !== void 0 ? _a : PromptGenerator)(bot, options);
|
|
21
|
+
return new (this.Class ?? PromptGenerator)(bot, options);
|
|
32
22
|
}
|
|
33
23
|
async generate() {
|
|
34
|
-
const
|
|
24
|
+
const { stateSchema, state, ...rest } = this.bot.serialize();
|
|
35
25
|
const { stateSchemaJson, stateJson } = this.stringifyState(stateSchema, state);
|
|
36
|
-
const rendered = await this.eta.renderStringAsync(this.promptTemplate,
|
|
37
|
-
|
|
26
|
+
const rendered = await this.eta.renderStringAsync(this.promptTemplate, {
|
|
27
|
+
stateSchemaJson,
|
|
28
|
+
stateJson,
|
|
29
|
+
...rest,
|
|
30
|
+
});
|
|
38
31
|
this.log('Generated prompt:', rendered);
|
|
39
32
|
return rendered;
|
|
40
33
|
}
|
|
@@ -45,7 +38,7 @@ class PromptGenerator {
|
|
|
45
38
|
stateJson: null,
|
|
46
39
|
};
|
|
47
40
|
}
|
|
48
|
-
const normalizedState = (0, schema_1.normalizeSchemaValues)(stateSchema, state
|
|
41
|
+
const normalizedState = (0, schema_1.normalizeSchemaValues)(stateSchema, state ?? {}, {});
|
|
49
42
|
setUndefinedToNull(normalizedState);
|
|
50
43
|
const stateSchemaJson = JSON.stringify(stateSchema);
|
|
51
44
|
const stateJson = JSON.stringify(normalizedState);
|
|
@@ -55,7 +48,6 @@ class PromptGenerator {
|
|
|
55
48
|
exports.default = PromptGenerator;
|
|
56
49
|
function setUndefinedToNull(obj) {
|
|
57
50
|
for (const key in obj) {
|
|
58
|
-
// eslint-disable-next-line no-prototype-builtins
|
|
59
51
|
if (obj.hasOwnProperty(key)) {
|
|
60
52
|
if (obj[key] === undefined) {
|
|
61
53
|
obj[key] = null;
|
|
@@ -8,17 +8,26 @@ const schema_1 = require("@sprucelabs/schema");
|
|
|
8
8
|
const llm_types_1 = require("../llm.types");
|
|
9
9
|
const ResponseParser_1 = __importDefault(require("../parsingResponses/ResponseParser"));
|
|
10
10
|
class SprucebotLlmBotImpl extends mercury_event_emitter_1.AbstractEventEmitter {
|
|
11
|
+
static messageMemoryLimit = 10;
|
|
12
|
+
adapter;
|
|
13
|
+
youAre;
|
|
14
|
+
stateSchema;
|
|
15
|
+
state;
|
|
16
|
+
isDone = false;
|
|
17
|
+
messages = [];
|
|
18
|
+
skill;
|
|
11
19
|
constructor(options) {
|
|
12
20
|
const { adapter, youAre, stateSchema, state, skill } = options;
|
|
13
21
|
super(llm_types_1.llmEventContract);
|
|
14
|
-
this.isDone = false;
|
|
15
|
-
this.messages = [];
|
|
16
22
|
this.adapter = adapter;
|
|
17
23
|
this.youAre = youAre;
|
|
18
24
|
this.stateSchema = stateSchema;
|
|
19
25
|
this.skill = skill;
|
|
20
26
|
this.state = stateSchema
|
|
21
|
-
?
|
|
27
|
+
? {
|
|
28
|
+
...(0, schema_1.defaultSchemaValues)(stateSchema),
|
|
29
|
+
...state,
|
|
30
|
+
}
|
|
22
31
|
: undefined;
|
|
23
32
|
}
|
|
24
33
|
clearMessageHistory() {
|
|
@@ -31,36 +40,34 @@ class SprucebotLlmBotImpl extends mercury_event_emitter_1.AbstractEventEmitter {
|
|
|
31
40
|
return this.isDone;
|
|
32
41
|
}
|
|
33
42
|
serialize() {
|
|
34
|
-
|
|
35
|
-
const skill = (_a = this.skill) === null || _a === void 0 ? void 0 : _a.serialize();
|
|
43
|
+
const skill = this.skill?.serialize();
|
|
36
44
|
return {
|
|
37
45
|
youAre: this.youAre,
|
|
38
|
-
stateSchema:
|
|
39
|
-
state:
|
|
46
|
+
stateSchema: this.stateSchema ?? skill?.stateSchema,
|
|
47
|
+
state: this.state ?? skill?.state,
|
|
40
48
|
messages: this.messages,
|
|
41
49
|
skill,
|
|
42
50
|
};
|
|
43
51
|
}
|
|
44
52
|
async sendMessage(message) {
|
|
45
|
-
var _a, _b;
|
|
46
53
|
(0, schema_1.assertOptions)({ message }, ['message']);
|
|
47
54
|
this.trackMessage({
|
|
48
55
|
from: 'Me',
|
|
49
56
|
message,
|
|
50
57
|
});
|
|
51
|
-
const serializedSkill =
|
|
58
|
+
const serializedSkill = this.skill?.serialize();
|
|
52
59
|
const response = await this.adapter.sendMessage(this, {
|
|
53
|
-
model: serializedSkill
|
|
54
|
-
promptTemplate: serializedSkill
|
|
60
|
+
model: serializedSkill?.model,
|
|
61
|
+
promptTemplate: serializedSkill?.promptTemplate,
|
|
55
62
|
});
|
|
56
63
|
const parser = ResponseParser_1.default.getInstance();
|
|
57
|
-
const { isDone, message: parsedResponse, state, } = await parser.parse(response, serializedSkill
|
|
64
|
+
const { isDone, message: parsedResponse, state, } = await parser.parse(response, serializedSkill?.callbacks);
|
|
58
65
|
this.isDone = isDone;
|
|
59
66
|
if (this.stateSchema && state) {
|
|
60
67
|
await this.updateState(state);
|
|
61
68
|
}
|
|
62
69
|
else if (state) {
|
|
63
|
-
await
|
|
70
|
+
await this.skill?.updateState(state);
|
|
64
71
|
}
|
|
65
72
|
this.trackMessage({
|
|
66
73
|
from: 'You',
|
|
@@ -75,7 +82,7 @@ class SprucebotLlmBotImpl extends mercury_event_emitter_1.AbstractEventEmitter {
|
|
|
75
82
|
this.messages.push(m);
|
|
76
83
|
}
|
|
77
84
|
async updateState(newState) {
|
|
78
|
-
this.state =
|
|
85
|
+
this.state = { ...this.state, ...newState };
|
|
79
86
|
await this.emit('did-update-state');
|
|
80
87
|
}
|
|
81
88
|
setSkill(skill) {
|
|
@@ -83,5 +90,4 @@ class SprucebotLlmBotImpl extends mercury_event_emitter_1.AbstractEventEmitter {
|
|
|
83
90
|
this.isDone = false;
|
|
84
91
|
}
|
|
85
92
|
}
|
|
86
|
-
SprucebotLlmBotImpl.messageMemoryLimit = 10;
|
|
87
93
|
exports.default = SprucebotLlmBotImpl;
|
|
@@ -8,16 +8,20 @@ const SpruceError_1 = __importDefault(require("../errors/SpruceError"));
|
|
|
8
8
|
const SprucebotLlmBotImpl_1 = __importDefault(require("./SprucebotLlmBotImpl"));
|
|
9
9
|
const SprucebotLlmSkillImpl_1 = __importDefault(require("./SprucebotLlmSkillImpl"));
|
|
10
10
|
class SprucebotLlmFactory {
|
|
11
|
+
instance;
|
|
12
|
+
static FactoryClass;
|
|
13
|
+
static BotClass;
|
|
14
|
+
static SkillClass;
|
|
11
15
|
Bot(options) {
|
|
12
|
-
var _a;
|
|
13
16
|
(0, schema_1.assertOptions)(options, ['youAre', 'adapter']);
|
|
14
17
|
const { Class } = options;
|
|
15
|
-
return new (
|
|
18
|
+
return new (Class ??
|
|
19
|
+
SprucebotLlmFactory.BotClass ??
|
|
20
|
+
SprucebotLlmBotImpl_1.default)(options);
|
|
16
21
|
}
|
|
17
22
|
Skill(options) {
|
|
18
|
-
var _a;
|
|
19
23
|
(0, schema_1.assertOptions)(options, ['yourJobIfYouChooseToAcceptItIs']);
|
|
20
|
-
return new (
|
|
24
|
+
return new (SprucebotLlmFactory.SkillClass ?? SprucebotLlmSkillImpl_1.default)(options);
|
|
21
25
|
}
|
|
22
26
|
getBotInstance() {
|
|
23
27
|
if (!this.instance) {
|
|
@@ -31,8 +35,7 @@ class SprucebotLlmFactory {
|
|
|
31
35
|
this.instance = bot;
|
|
32
36
|
}
|
|
33
37
|
static Factory() {
|
|
34
|
-
|
|
35
|
-
return new ((_a = this.FactoryClass) !== null && _a !== void 0 ? _a : this)();
|
|
38
|
+
return new (this.FactoryClass ?? this)();
|
|
36
39
|
}
|
|
37
40
|
static reset() {
|
|
38
41
|
this.BotClass = undefined;
|
|
@@ -1,39 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
-
var t = {};
|
|
4
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
-
t[p] = s[p];
|
|
6
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
-
t[p[i]] = s[p[i]];
|
|
10
|
-
}
|
|
11
|
-
return t;
|
|
12
|
-
};
|
|
13
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
3
|
const mercury_event_emitter_1 = require("@sprucelabs/mercury-event-emitter");
|
|
15
4
|
const schema_1 = require("@sprucelabs/schema");
|
|
16
5
|
const llm_types_1 = require("../llm.types");
|
|
17
6
|
class SprucebotLlmSkillImpl extends mercury_event_emitter_1.AbstractEventEmitter {
|
|
7
|
+
options;
|
|
8
|
+
state = {};
|
|
9
|
+
stateSchema;
|
|
18
10
|
constructor(options) {
|
|
19
11
|
super(llm_types_1.llmEventContract);
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
this.options = Object.assign(Object.assign({}, rest), { stateSchema });
|
|
12
|
+
const { state, stateSchema, ...rest } = options;
|
|
13
|
+
this.options = { ...rest, stateSchema };
|
|
23
14
|
this.stateSchema = stateSchema;
|
|
24
15
|
this.state = stateSchema
|
|
25
|
-
?
|
|
16
|
+
? {
|
|
17
|
+
...(0, schema_1.defaultSchemaValues)(stateSchema),
|
|
18
|
+
...state,
|
|
19
|
+
}
|
|
26
20
|
: undefined;
|
|
27
21
|
}
|
|
28
22
|
async updateState(updates) {
|
|
29
23
|
await this.emit('did-update-state');
|
|
30
|
-
this.state =
|
|
24
|
+
this.state = { ...this.state, ...updates };
|
|
31
25
|
}
|
|
32
26
|
getState() {
|
|
33
27
|
return this.state;
|
|
34
28
|
}
|
|
35
29
|
serialize() {
|
|
36
|
-
return
|
|
30
|
+
return {
|
|
31
|
+
...this.options,
|
|
32
|
+
stateSchema: this.stateSchema,
|
|
33
|
+
state: this.state,
|
|
34
|
+
};
|
|
37
35
|
}
|
|
38
36
|
}
|
|
39
37
|
exports.default = SprucebotLlmSkillImpl;
|
|
@@ -8,27 +8,28 @@ const schema_1 = require("@sprucelabs/schema");
|
|
|
8
8
|
const openai_1 = require("openai");
|
|
9
9
|
const PromptGenerator_1 = __importDefault(require("../PromptGenerator"));
|
|
10
10
|
class OpenAiAdapter {
|
|
11
|
+
static Configuration = openai_1.Configuration;
|
|
12
|
+
static OpenAIApi = openai_1.OpenAIApi;
|
|
13
|
+
api;
|
|
11
14
|
constructor(apiKey) {
|
|
12
15
|
(0, schema_1.assertOptions)({ apiKey }, ['apiKey']);
|
|
13
16
|
const config = new OpenAiAdapter.Configuration({ apiKey });
|
|
14
17
|
this.api = new OpenAiAdapter.OpenAIApi(config);
|
|
15
18
|
}
|
|
16
19
|
async sendMessage(bot, options) {
|
|
17
|
-
var _a, _b, _c, _d;
|
|
18
20
|
const generator = PromptGenerator_1.default.Generator(bot, {
|
|
19
|
-
promptTemplate: options
|
|
21
|
+
promptTemplate: options?.promptTemplate,
|
|
20
22
|
});
|
|
21
23
|
const prompt = await generator.generate();
|
|
22
24
|
const response = await this.api.createCompletion({
|
|
23
25
|
prompt,
|
|
24
|
-
model:
|
|
26
|
+
model: options?.model ?? 'text-davinci-003',
|
|
25
27
|
max_tokens: 250,
|
|
26
28
|
stop: ['__Me__:'],
|
|
27
29
|
});
|
|
28
|
-
return (
|
|
30
|
+
return (response.data.choices[0]?.text?.trim() ??
|
|
31
|
+
exports.MESSAGE_RESPONSE_ERROR_MESSAGE);
|
|
29
32
|
}
|
|
30
33
|
}
|
|
31
34
|
exports.OpenAiAdapter = OpenAiAdapter;
|
|
32
|
-
OpenAiAdapter.Configuration = openai_1.Configuration;
|
|
33
|
-
OpenAiAdapter.OpenAIApi = openai_1.OpenAIApi;
|
|
34
35
|
exports.MESSAGE_RESPONSE_ERROR_MESSAGE = "Oh no! Something went wrong and I can't talk right now!";
|
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const openai_1 = require("openai");
|
|
4
4
|
class SpyOpenAiApi extends openai_1.OpenAIApi {
|
|
5
|
+
static config;
|
|
6
|
+
static lastMessage;
|
|
7
|
+
static lastModel;
|
|
8
|
+
static responseMessage = 'hello!';
|
|
5
9
|
constructor(config) {
|
|
6
10
|
super(config);
|
|
7
11
|
SpyOpenAiApi.config = config;
|
|
@@ -30,5 +34,4 @@ class SpyOpenAiApi extends openai_1.OpenAIApi {
|
|
|
30
34
|
};
|
|
31
35
|
}
|
|
32
36
|
}
|
|
33
|
-
SpyOpenAiApi.responseMessage = 'hello!';
|
|
34
37
|
exports.default = SpyOpenAiApi;
|
package/build/chat.js
CHANGED
|
@@ -38,7 +38,7 @@ const buildProfileSkill_1 = __importDefault(require("./examples/buildProfileSkil
|
|
|
38
38
|
const buildReceptionistSkill_1 = __importDefault(require("./examples/buildReceptionistSkill"));
|
|
39
39
|
dotenv_1.default.config();
|
|
40
40
|
const rl = readline.createInterface({ input: node_process_1.stdin, output: node_process_1.stdout });
|
|
41
|
-
(async () => {
|
|
41
|
+
void (async () => {
|
|
42
42
|
console.clear();
|
|
43
43
|
const adapter = new OpenAi_1.OpenAiAdapter(process.env.OPEN_AI_API_KEY);
|
|
44
44
|
const bots = SprucebotLlmFactory_1.default.Factory();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import BaseSpruceError from '@sprucelabs/error';
|
|
2
|
-
import ErrorOptions from
|
|
2
|
+
import ErrorOptions from './../.spruce/errors/options.types';
|
|
3
3
|
export default class SpruceError extends BaseSpruceError<ErrorOptions> {
|
|
4
4
|
/** an easy to understand version of the errors */
|
|
5
5
|
friendlyMessage(): string;
|
|
@@ -9,7 +9,7 @@ class SpruceError extends error_1.default {
|
|
|
9
9
|
friendlyMessage() {
|
|
10
10
|
const { options } = this;
|
|
11
11
|
let message;
|
|
12
|
-
switch (options
|
|
12
|
+
switch (options?.code) {
|
|
13
13
|
case 'NO_BOT_INSTANCE_SET':
|
|
14
14
|
message = `You must create a bot and set it using 'SprucebotLlmFactory.setInstance(bot)' before you can get an instance of it.`;
|
|
15
15
|
break;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { ErrorOptions as ISpruceErrorOptions } from '@sprucelabs/error';
|
|
2
|
+
import { SpruceErrors } from './errors.types';
|
|
3
3
|
export interface NoBotInstanceSetErrorOptions extends SpruceErrors.SprucebotLlm.NoBotInstanceSet, ISpruceErrorOptions {
|
|
4
4
|
code: 'NO_BOT_INSTANCE_SET';
|
|
5
5
|
}
|
package/build/esm/chat.js
CHANGED
|
@@ -19,7 +19,7 @@ import buildProfileSkill from './examples/buildProfileSkill.js';
|
|
|
19
19
|
import buildReceptionistSkill from './examples/buildReceptionistSkill.js';
|
|
20
20
|
dotenv.config();
|
|
21
21
|
const rl = readline.createInterface({ input, output });
|
|
22
|
-
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
22
|
+
void (() => __awaiter(void 0, void 0, void 0, function* () {
|
|
23
23
|
console.clear();
|
|
24
24
|
const adapter = new OpenAiAdapter(process.env.OPEN_AI_API_KEY);
|
|
25
25
|
const bots = SprucebotLlmFactory.Factory();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import BaseSpruceError from '@sprucelabs/error';
|
|
2
|
-
import ErrorOptions from
|
|
2
|
+
import ErrorOptions from './../.spruce/errors/options.types';
|
|
3
3
|
export default class SpruceError extends BaseSpruceError<ErrorOptions> {
|
|
4
4
|
/** an easy to understand version of the errors */
|
|
5
5
|
friendlyMessage(): string;
|
|
@@ -17,7 +17,15 @@ export default function buildCallbackSkill(bots) {
|
|
|
17
17
|
callbacks: {
|
|
18
18
|
availableTimes: {
|
|
19
19
|
cb: () => __awaiter(this, void 0, void 0, function* () {
|
|
20
|
-
return [
|
|
20
|
+
return [
|
|
21
|
+
'9am',
|
|
22
|
+
'10am',
|
|
23
|
+
'11am',
|
|
24
|
+
'1pm',
|
|
25
|
+
'4pm',
|
|
26
|
+
'5pm',
|
|
27
|
+
'12am.',
|
|
28
|
+
].join('\n');
|
|
21
29
|
}),
|
|
22
30
|
useThisWhenever: 'your are showing what times i can pick from.',
|
|
23
31
|
},
|
|
@@ -58,7 +58,11 @@ export const TOPICS = [
|
|
|
58
58
|
],
|
|
59
59
|
},
|
|
60
60
|
{
|
|
61
|
-
name: [
|
|
61
|
+
name: [
|
|
62
|
+
'Booking a haircut',
|
|
63
|
+
'Haircut appointment',
|
|
64
|
+
'Book an appointment',
|
|
65
|
+
],
|
|
62
66
|
conversations: [
|
|
63
67
|
{
|
|
64
68
|
messages: [
|
|
@@ -19,8 +19,7 @@ new Array(1000).fill(0).forEach(() => {
|
|
|
19
19
|
const randomIndex = Math.floor(Math.random() * randomLengthOfTopics.length);
|
|
20
20
|
output.push(generateCompletion(randomLengthOfTopics, randomIndex));
|
|
21
21
|
});
|
|
22
|
-
for (
|
|
23
|
-
const off = OFF_THE_RAILS_CONVERSATIONS[c];
|
|
22
|
+
for (const off of OFF_THE_RAILS_CONVERSATIONS) {
|
|
24
23
|
new Array(20)
|
|
25
24
|
.fill(0)
|
|
26
25
|
.forEach(() => output.push(generateOffTheRails(off, TOPICS)));
|
package/build/esm/llm.types.d.ts
CHANGED
|
@@ -60,9 +60,7 @@ export interface SprucebotLLmSkill<StateSchema extends Schema = Schema, State ex
|
|
|
60
60
|
}
|
|
61
61
|
export interface SerializedSkill<StateSchema extends Schema = Schema, State extends SchemaValues<StateSchema> = SchemaValues<StateSchema>> extends SkillOptions<StateSchema, State> {
|
|
62
62
|
}
|
|
63
|
-
export
|
|
64
|
-
[key: string]: LlmCallback;
|
|
65
|
-
}
|
|
63
|
+
export type LlmCallbackMap = Record<string, LlmCallback>;
|
|
66
64
|
export interface LlmCallback {
|
|
67
65
|
cb: () => string | Promise<string>;
|
|
68
66
|
useThisWhenever: string;
|
|
@@ -10,7 +10,15 @@ function buildCallbackSkill(bots) {
|
|
|
10
10
|
callbacks: {
|
|
11
11
|
availableTimes: {
|
|
12
12
|
cb: async () => {
|
|
13
|
-
return [
|
|
13
|
+
return [
|
|
14
|
+
'9am',
|
|
15
|
+
'10am',
|
|
16
|
+
'11am',
|
|
17
|
+
'1pm',
|
|
18
|
+
'4pm',
|
|
19
|
+
'5pm',
|
|
20
|
+
'12am.',
|
|
21
|
+
].join('\n');
|
|
14
22
|
},
|
|
15
23
|
useThisWhenever: 'your are showing what times i can pick from.',
|
|
16
24
|
},
|
|
@@ -45,8 +45,7 @@ new Array(1000).fill(0).forEach(() => {
|
|
|
45
45
|
const randomIndex = Math.floor(Math.random() * randomLengthOfTopics.length);
|
|
46
46
|
output.push((0, support_1.generateCompletion)(randomLengthOfTopics, randomIndex));
|
|
47
47
|
});
|
|
48
|
-
for (
|
|
49
|
-
const off = OFF_THE_RAILS_CONVERSATIONS_1.OFF_THE_RAILS_CONVERSATIONS[c];
|
|
48
|
+
for (const off of OFF_THE_RAILS_CONVERSATIONS_1.OFF_THE_RAILS_CONVERSATIONS) {
|
|
50
49
|
new Array(20)
|
|
51
50
|
.fill(0)
|
|
52
51
|
.forEach(() => output.push((0, support_1.generateOffTheRails)(off, TOPICS_1.TOPICS)));
|
package/build/llm.types.d.ts
CHANGED
|
@@ -60,9 +60,7 @@ export interface SprucebotLLmSkill<StateSchema extends Schema = Schema, State ex
|
|
|
60
60
|
}
|
|
61
61
|
export interface SerializedSkill<StateSchema extends Schema = Schema, State extends SchemaValues<StateSchema> = SchemaValues<StateSchema>> extends SkillOptions<StateSchema, State> {
|
|
62
62
|
}
|
|
63
|
-
export
|
|
64
|
-
[key: string]: LlmCallback;
|
|
65
|
-
}
|
|
63
|
+
export type LlmCallbackMap = Record<string, LlmCallback>;
|
|
66
64
|
export interface LlmCallback {
|
|
67
65
|
cb: () => string | Promise<string>;
|
|
68
66
|
useThisWhenever: string;
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const templates_1 = require("../bots/templates");
|
|
7
7
|
const renderPlaceholder_1 = __importDefault(require("./renderPlaceholder"));
|
|
8
8
|
class ResponseParser {
|
|
9
|
+
static instance = new ResponseParser();
|
|
9
10
|
static setInstance(parser) {
|
|
10
11
|
this.instance = parser;
|
|
11
12
|
}
|
|
@@ -33,9 +34,8 @@ class ResponseParser {
|
|
|
33
34
|
};
|
|
34
35
|
}
|
|
35
36
|
async invokeCallback(callbacks, key, message) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
message = message.replace((0, renderPlaceholder_1.default)(key), v !== null && v !== void 0 ? v : '').trim();
|
|
37
|
+
const v = await callbacks?.[key]?.cb();
|
|
38
|
+
message = message.replace((0, renderPlaceholder_1.default)(key), v ?? '').trim();
|
|
39
39
|
return message;
|
|
40
40
|
}
|
|
41
41
|
doesIncludeDoneToken(response) {
|
|
@@ -45,9 +45,8 @@ class ResponseParser {
|
|
|
45
45
|
const ESCAPED_BOUNDARY = templates_1.STATE_BOUNDARY.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
|
|
46
46
|
const searchRegex = new RegExp(`${ESCAPED_BOUNDARY}(.*?)${ESCAPED_BOUNDARY}`);
|
|
47
47
|
const stateMatches = message.match(searchRegex);
|
|
48
|
-
const match = stateMatches
|
|
49
|
-
return { match, fullMatch: stateMatches
|
|
48
|
+
const match = stateMatches?.[1];
|
|
49
|
+
return { match, fullMatch: stateMatches?.[0] };
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
|
-
ResponseParser.instance = new ResponseParser();
|
|
53
52
|
exports.default = ResponseParser;
|
package/package.json
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"openai"
|
|
11
11
|
]
|
|
12
12
|
},
|
|
13
|
-
"version": "
|
|
13
|
+
"version": "5.0.0",
|
|
14
14
|
"files": [
|
|
15
15
|
"build"
|
|
16
16
|
],
|
|
@@ -26,15 +26,15 @@
|
|
|
26
26
|
"sprucelabs"
|
|
27
27
|
],
|
|
28
28
|
"scripts": {
|
|
29
|
-
"build.ci": "yarn build.tsc && yarn build.resolve-paths && yarn lint",
|
|
29
|
+
"build.ci": "yarn run build.tsc && yarn run build.resolve-paths && yarn run lint",
|
|
30
30
|
"build.copy-files": "mkdir -p build && rsync -avzq --exclude='*.ts' ./src/ ./build/",
|
|
31
|
-
"build.dev": "yarn build.tsc --sourceMap ; yarn resolve-paths.lint",
|
|
31
|
+
"build.dev": "yarn run build.tsc --sourceMap ; yarn run resolve-paths.lint",
|
|
32
32
|
"build.dist": "tsc --project tsconfig.dist.json && yarn build.resolve-paths && mv build esm && yarn build.esm-postbuild && yarn build.tsc && yarn build.resolve-paths && mv esm build/ && yarn clean.dist",
|
|
33
33
|
"build.esm-postbuild": "esm-postbuild --target esm --patterns '**/*.js'",
|
|
34
34
|
"build.resolve-paths": "resolve-path-aliases --target build --patterns '**/*.js,**/*.d.ts'",
|
|
35
|
-
"build.tsc": "yarn build.copy-files && tsc",
|
|
36
|
-
"clean": "yarn clean.build",
|
|
37
|
-
"clean.all": "yarn clean.dependencies && yarn clean.build",
|
|
35
|
+
"build.tsc": "yarn run build.copy-files && tsc",
|
|
36
|
+
"clean": "yarn run clean.build",
|
|
37
|
+
"clean.all": "yarn run clean.dependencies && yarn run clean.build",
|
|
38
38
|
"clean.build": "rm -rf build/",
|
|
39
39
|
"clean.dependencies": "rm -rf node_modules/ package-lock.json yarn.lock",
|
|
40
40
|
"clean.dist": "rm -rf build/__tests__ build/esm/__tests__",
|
|
@@ -42,45 +42,45 @@
|
|
|
42
42
|
"generate.samples": "node ./build/fineTuningSprucebot/generateSamples.js ~/output.json",
|
|
43
43
|
"lint": "eslint --cache '**/*.ts'",
|
|
44
44
|
"lint.tsc": "tsc -p . --noEmit",
|
|
45
|
-
"post.watch.build": "yarn build.copy-files && yarn build.resolve-paths",
|
|
46
|
-
"rebuild": "yarn clean.all && yarn && yarn build.dev",
|
|
45
|
+
"post.watch.build": "yarn run build.copy-files && yarn run build.resolve-paths",
|
|
46
|
+
"rebuild": "yarn run clean.all && yarn install && yarn run build.dev",
|
|
47
47
|
"release": "semantic-release",
|
|
48
|
-
"resolve-paths.lint": "yarn build.resolve-paths ; yarn lint",
|
|
48
|
+
"resolve-paths.lint": "yarn run build.resolve-paths ; yarn run lint",
|
|
49
49
|
"test": "jest",
|
|
50
|
-
"update.dependencies": "yarn clean.dependencies && yarn",
|
|
51
|
-
"watch.build.dev": "tsc-watch --sourceMap --onCompilationComplete 'yarn post.watch.build'",
|
|
52
|
-
"watch.lint": "concurrently 'yarn lint' \"chokidar 'src/**/*' -c 'yarn lint.tsc'\"",
|
|
53
|
-
"watch.rebuild": "yarn clean.all && yarn && yarn watch.build.dev",
|
|
50
|
+
"update.dependencies": "yarn run clean.dependencies && yarn",
|
|
51
|
+
"watch.build.dev": "tsc-watch --sourceMap --onCompilationComplete 'yarn run post.watch.build'",
|
|
52
|
+
"watch.lint": "concurrently 'yarn run lint' \"chokidar 'src/**/*' -c 'yarn run lint.tsc'\"",
|
|
53
|
+
"watch.rebuild": "yarn run clean.all && yarn install && yarn run watch.build.dev",
|
|
54
54
|
"watch.tsc": "tsc -w",
|
|
55
55
|
"chat": "node ./build/chat.js"
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
|
-
"@sprucelabs/error": "^
|
|
59
|
-
"@sprucelabs/mercury-event-emitter": "^
|
|
60
|
-
"@sprucelabs/mercury-types": "^
|
|
61
|
-
"@sprucelabs/schema": "^
|
|
58
|
+
"@sprucelabs/error": "^6.0.3",
|
|
59
|
+
"@sprucelabs/mercury-event-emitter": "^42.0.3",
|
|
60
|
+
"@sprucelabs/mercury-types": "^47.0.2",
|
|
61
|
+
"@sprucelabs/schema": "^30.0.4",
|
|
62
62
|
"eta": "^3.4.0",
|
|
63
63
|
"openai": "^3.3.0"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
|
-
"@sprucelabs/esm-postbuild": "^
|
|
67
|
-
"@sprucelabs/jest-json-reporter": "^
|
|
68
|
-
"@sprucelabs/resolve-path-aliases": "^
|
|
69
|
-
"@sprucelabs/semantic-release": "^
|
|
70
|
-
"@sprucelabs/test": "^
|
|
71
|
-
"@sprucelabs/test-utils": "^
|
|
72
|
-
"@types/node": "^20.12.
|
|
66
|
+
"@sprucelabs/esm-postbuild": "^6.0.3",
|
|
67
|
+
"@sprucelabs/jest-json-reporter": "^8.0.1",
|
|
68
|
+
"@sprucelabs/resolve-path-aliases": "^2.0.5",
|
|
69
|
+
"@sprucelabs/semantic-release": "^5.0.1",
|
|
70
|
+
"@sprucelabs/test": "^9.0.4",
|
|
71
|
+
"@sprucelabs/test-utils": "^5.0.3",
|
|
72
|
+
"@types/node": "^20.12.7",
|
|
73
73
|
"chokidar-cli": "^3.0.0",
|
|
74
74
|
"concurrently": "^8.2.2",
|
|
75
75
|
"dotenv": "^16.4.5",
|
|
76
|
-
"eslint": "^
|
|
77
|
-
"eslint-config-spruce": "^
|
|
76
|
+
"eslint": "^9.0.0",
|
|
77
|
+
"eslint-config-spruce": "^11.2.7",
|
|
78
78
|
"jest": "^29.7.0",
|
|
79
79
|
"jest-circus": "^29.7.0",
|
|
80
80
|
"prettier": "^3.2.5",
|
|
81
81
|
"ts-node": "^10.9.2",
|
|
82
82
|
"tsc-watch": "^6.2.0",
|
|
83
|
-
"typescript": "^5.4.
|
|
83
|
+
"typescript": "^5.4.5"
|
|
84
84
|
},
|
|
85
85
|
"jest": {
|
|
86
86
|
"testRunner": "jest-circus/runner",
|