@sprucelabs/sprucebot-llm 7.0.19 → 8.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.
@@ -1,13 +1,15 @@
1
- import { BotOptions, SkillOptions, SprucebotLlmBot, SprucebotLLmSkill } from '../llm.types';
1
+ import { BotOptions, LlmAdapter, SkillOptions, SprucebotLlmBot, SprucebotLLmSkill } from '../llm.types';
2
2
  export default class SprucebotLlmFactory {
3
3
  private instance?;
4
+ protected adapter: LlmAdapter;
4
5
  static FactoryClass?: typeof SprucebotLlmFactory;
5
6
  static BotClass?: new (options: any) => SprucebotLlmBot;
6
7
  static SkillClass?: new (options: any) => SprucebotLLmSkill;
7
- Bot(options: BotOptions): SprucebotLlmBot;
8
+ protected constructor(adapter: LlmAdapter);
9
+ Bot(options: Omit<BotOptions, 'adapter'>): SprucebotLlmBot;
8
10
  Skill(options: SkillOptions): SprucebotLLmSkill;
9
11
  getBotInstance(): SprucebotLlmBot<import("@sprucelabs/schema").Schema, Pick<import("@sprucelabs/schema").SchemaStaticValues<import("@sprucelabs/schema").Schema, false, never, import("@sprucelabs/schema").StaticSchemaAllValues<import("@sprucelabs/schema").Schema, false>>, never>>;
10
12
  setBotInstance(bot: SprucebotLlmBot): void;
11
- static Factory(): SprucebotLlmFactory;
13
+ static Factory(adapter: LlmAdapter): SprucebotLlmFactory;
12
14
  static reset(): void;
13
15
  }
@@ -8,16 +8,21 @@ 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
+ constructor(adapter) {
12
+ this.adapter = adapter;
13
+ }
11
14
  Bot(options) {
12
- (0, schema_1.assertOptions)(options, ['youAre', 'adapter']);
15
+ (0, schema_1.assertOptions)(options, ['youAre']);
13
16
  const { Class } = options;
14
17
  return new (Class ??
15
18
  SprucebotLlmFactory.BotClass ??
16
- SprucebotLlmBotImpl_1.default)(options);
19
+ SprucebotLlmBotImpl_1.default)({ ...options, adapter: this.adapter });
17
20
  }
18
21
  Skill(options) {
19
22
  (0, schema_1.assertOptions)(options, ['yourJobIfYouChooseToAcceptItIs']);
20
- return new (SprucebotLlmFactory.SkillClass ?? SprucebotLlmSkillImpl_1.default)(options);
23
+ return new (SprucebotLlmFactory.SkillClass ?? SprucebotLlmSkillImpl_1.default)({
24
+ ...options,
25
+ });
21
26
  }
22
27
  getBotInstance() {
23
28
  if (!this.instance) {
@@ -30,8 +35,9 @@ class SprucebotLlmFactory {
30
35
  setBotInstance(bot) {
31
36
  this.instance = bot;
32
37
  }
33
- static Factory() {
34
- return new (this.FactoryClass ?? this)();
38
+ static Factory(adapter) {
39
+ (0, schema_1.assertOptions)({ adapter }, ['adapter']);
40
+ return new (this.FactoryClass ?? this)(adapter);
35
41
  }
36
42
  static reset() {
37
43
  this.BotClass = undefined;
@@ -3,7 +3,8 @@ import { LlmAdapter, SendMessageOptions, SprucebotLlmBot } from '../../llm.types
3
3
  export declare class OpenAiAdapter implements LlmAdapter {
4
4
  static OpenAI: typeof OpenAI;
5
5
  private api;
6
- constructor(apiKey: string);
6
+ protected constructor(apiKey: string);
7
+ static Adapter(apiKey: string): OpenAiAdapter;
7
8
  sendMessage(bot: SprucebotLlmBot, options?: SendMessageOptions): Promise<string>;
8
9
  }
9
10
  export declare const MESSAGE_RESPONSE_ERROR_MESSAGE = "Oh no! Something went wrong and I can't talk right now!";
@@ -12,6 +12,9 @@ class OpenAiAdapter {
12
12
  (0, schema_1.assertOptions)({ apiKey }, ['apiKey']);
13
13
  this.api = new OpenAiAdapter.OpenAI({ apiKey });
14
14
  }
15
+ static Adapter(apiKey) {
16
+ return new this(apiKey);
17
+ }
15
18
  async sendMessage(bot, options) {
16
19
  const messageBuilder = OpenAiMessageBuilder_1.default.Builder(bot);
17
20
  const messages = messageBuilder.buildMessages();
package/build/chat.js CHANGED
@@ -50,8 +50,8 @@ dotenv_1.default.config();
50
50
  const rl = readline.createInterface({ input: node_process_1.stdin, output: node_process_1.stdout });
51
51
  void (async () => {
52
52
  console.clear();
53
- const adapter = new OpenAi_1.OpenAiAdapter(process.env.OPEN_AI_API_KEY);
54
- const bots = SprucebotLlmFactory_1.default.Factory();
53
+ const adapter = OpenAi_1.OpenAiAdapter.Adapter(process.env.OPEN_AI_API_KEY);
54
+ const bots = SprucebotLlmFactory_1.default.Factory(adapter);
55
55
  const skills = {
56
56
  jokes: (0, buildJokeSkill_1.default)(bots),
57
57
  profile: (0, buildProfileSkill_1.default)(bots),
@@ -60,7 +60,6 @@ void (async () => {
60
60
  receptionist: (0, buildReceptionistSkill_1.default)(bots),
61
61
  };
62
62
  const bot = bots.Bot({
63
- adapter,
64
63
  skill: skills.callbacks,
65
64
  youAre: "a bot named Sprucebot that is in test mode. At the start of every conversation, you introduce yourself and announce that you are in test mode so I don't get confused! You are both hip and adorable. You say things like, 'Jeepers' and 'Golly' or even 'Jeezey peezy'!",
66
65
  });
@@ -1,13 +1,15 @@
1
- import { BotOptions, SkillOptions, SprucebotLlmBot, SprucebotLLmSkill } from '../llm.types';
1
+ import { BotOptions, LlmAdapter, SkillOptions, SprucebotLlmBot, SprucebotLLmSkill } from '../llm.types';
2
2
  export default class SprucebotLlmFactory {
3
3
  private instance?;
4
+ protected adapter: LlmAdapter;
4
5
  static FactoryClass?: typeof SprucebotLlmFactory;
5
6
  static BotClass?: new (options: any) => SprucebotLlmBot;
6
7
  static SkillClass?: new (options: any) => SprucebotLLmSkill;
7
- Bot(options: BotOptions): SprucebotLlmBot;
8
+ protected constructor(adapter: LlmAdapter);
9
+ Bot(options: Omit<BotOptions, 'adapter'>): SprucebotLlmBot;
8
10
  Skill(options: SkillOptions): SprucebotLLmSkill;
9
11
  getBotInstance(): SprucebotLlmBot<import("@sprucelabs/schema").Schema, Pick<import("@sprucelabs/schema").SchemaStaticValues<import("@sprucelabs/schema").Schema, false, never, import("@sprucelabs/schema").StaticSchemaAllValues<import("@sprucelabs/schema").Schema, false>>, never>>;
10
12
  setBotInstance(bot: SprucebotLlmBot): void;
11
- static Factory(): SprucebotLlmFactory;
13
+ static Factory(adapter: LlmAdapter): SprucebotLlmFactory;
12
14
  static reset(): void;
13
15
  }
@@ -3,16 +3,19 @@ import SpruceError from '../errors/SpruceError.js';
3
3
  import SprucebotLlmBotImpl from './SprucebotLlmBotImpl.js';
4
4
  import SprucebotLlmSkillImpl from './SprucebotLlmSkillImpl.js';
5
5
  export default class SprucebotLlmFactory {
6
+ constructor(adapter) {
7
+ this.adapter = adapter;
8
+ }
6
9
  Bot(options) {
7
10
  var _a;
8
- assertOptions(options, ['youAre', 'adapter']);
11
+ assertOptions(options, ['youAre']);
9
12
  const { Class } = options;
10
- return new ((_a = Class !== null && Class !== void 0 ? Class : SprucebotLlmFactory.BotClass) !== null && _a !== void 0 ? _a : SprucebotLlmBotImpl)(options);
13
+ return new ((_a = Class !== null && Class !== void 0 ? Class : SprucebotLlmFactory.BotClass) !== null && _a !== void 0 ? _a : SprucebotLlmBotImpl)(Object.assign(Object.assign({}, options), { adapter: this.adapter }));
11
14
  }
12
15
  Skill(options) {
13
16
  var _a;
14
17
  assertOptions(options, ['yourJobIfYouChooseToAcceptItIs']);
15
- return new ((_a = SprucebotLlmFactory.SkillClass) !== null && _a !== void 0 ? _a : SprucebotLlmSkillImpl)(options);
18
+ return new ((_a = SprucebotLlmFactory.SkillClass) !== null && _a !== void 0 ? _a : SprucebotLlmSkillImpl)(Object.assign({}, options));
16
19
  }
17
20
  getBotInstance() {
18
21
  if (!this.instance) {
@@ -25,9 +28,10 @@ export default class SprucebotLlmFactory {
25
28
  setBotInstance(bot) {
26
29
  this.instance = bot;
27
30
  }
28
- static Factory() {
31
+ static Factory(adapter) {
29
32
  var _a;
30
- return new ((_a = this.FactoryClass) !== null && _a !== void 0 ? _a : this)();
33
+ assertOptions({ adapter }, ['adapter']);
34
+ return new ((_a = this.FactoryClass) !== null && _a !== void 0 ? _a : this)(adapter);
31
35
  }
32
36
  static reset() {
33
37
  this.BotClass = undefined;
@@ -3,7 +3,8 @@ import { LlmAdapter, SendMessageOptions, SprucebotLlmBot } from '../../llm.types
3
3
  export declare class OpenAiAdapter implements LlmAdapter {
4
4
  static OpenAI: typeof OpenAI;
5
5
  private api;
6
- constructor(apiKey: string);
6
+ protected constructor(apiKey: string);
7
+ static Adapter(apiKey: string): OpenAiAdapter;
7
8
  sendMessage(bot: SprucebotLlmBot, options?: SendMessageOptions): Promise<string>;
8
9
  }
9
10
  export declare const MESSAGE_RESPONSE_ERROR_MESSAGE = "Oh no! Something went wrong and I can't talk right now!";
@@ -15,6 +15,9 @@ export class OpenAiAdapter {
15
15
  assertOptions({ apiKey }, ['apiKey']);
16
16
  this.api = new OpenAiAdapter.OpenAI({ apiKey });
17
17
  }
18
+ static Adapter(apiKey) {
19
+ return new this(apiKey);
20
+ }
18
21
  sendMessage(bot, options) {
19
22
  return __awaiter(this, void 0, void 0, function* () {
20
23
  var _a, _b, _c, _d, _e, _f;
package/build/esm/chat.js CHANGED
@@ -21,8 +21,8 @@ dotenv.config();
21
21
  const rl = readline.createInterface({ input, output });
22
22
  void (() => __awaiter(void 0, void 0, void 0, function* () {
23
23
  console.clear();
24
- const adapter = new OpenAiAdapter(process.env.OPEN_AI_API_KEY);
25
- const bots = SprucebotLlmFactory.Factory();
24
+ const adapter = OpenAiAdapter.Adapter(process.env.OPEN_AI_API_KEY);
25
+ const bots = SprucebotLlmFactory.Factory(adapter);
26
26
  const skills = {
27
27
  jokes: buildJokeSkill(bots),
28
28
  profile: buildProfileSkill(bots),
@@ -31,7 +31,6 @@ void (() => __awaiter(void 0, void 0, void 0, function* () {
31
31
  receptionist: buildReceptionistSkill(bots),
32
32
  };
33
33
  const bot = bots.Bot({
34
- adapter,
35
34
  skill: skills.callbacks,
36
35
  youAre: "a bot named Sprucebot that is in test mode. At the start of every conversation, you introduce yourself and announce that you are in test mode so I don't get confused! You are both hip and adorable. You say things like, 'Jeepers' and 'Golly' or even 'Jeezey peezy'!",
37
36
  });
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "@sprucelabs/spruce-test-fixtures"
10
10
  ]
11
11
  },
12
- "version": "7.0.19",
12
+ "version": "8.0.0",
13
13
  "files": [
14
14
  "build"
15
15
  ],