halbot 1990.1.119 → 1990.1.121

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/index.mjs CHANGED
@@ -34,6 +34,7 @@ const init = async (options) => {
34
34
  const info = bot.lines([
35
35
  `[${bot.EMOJI_BOT} ${pkg.title}](${pkg.homepage})`, pkg.description
36
36
  ]);
37
+ // init ai engines
37
38
  if (options?.openaiApiKey || options?.chatGptApiKey) {
38
39
  const apiKey = { apiKey: options?.chatGptApiKey || options?.openaiApiKey };
39
40
  await alan.init({
@@ -48,18 +49,6 @@ const init = async (options) => {
48
49
  model: options?.chatGptModel,
49
50
  };
50
51
  }
51
- if (options?.openaiApiKey) {
52
- const apiKey = { apiKey: options.openaiApiKey };
53
- await speech.init({ ...apiKey, provider: 'OPENAI', ...speechOptions });
54
- await image.init(apiKey);
55
- }
56
- if (options?.googleApiKey) {
57
- const apiKey = { apiKey: options.googleApiKey };
58
- await vision.init(apiKey);
59
- options?.openaiApiKey || await speech.init({
60
- ...apiKey, provider: 'GOOGLE', ...speechOptions,
61
- });
62
- }
63
52
  if (options?.googleCredentials && options?.googleProject) {
64
53
  await alan.init({
65
54
  provider: 'VERTEX',
@@ -88,8 +77,26 @@ const init = async (options) => {
88
77
  model: options?.mistralModel,
89
78
  };
90
79
  }
91
- await alan.initChat({ engines, sessions: options?.storage });
92
80
  assert(utilitas.countKeys(ai), 'No AI provider is configured.');
81
+ await alan.initChat({ engines, sessions: options?.storage });
82
+ // init image, speech engines
83
+ if (options?.openaiApiKey) {
84
+ const apiKey = { apiKey: options.openaiApiKey };
85
+ await image.init(apiKey);
86
+ await speech.init({ ...apiKey, provider: 'OPENAI', ...speechOptions });
87
+ } else if (options?.googleApiKey) {
88
+ const apiKey = { apiKey: options.googleApiKey };
89
+ await speech.init({ ...apiKey, provider: 'GOOGLE', ...speechOptions });
90
+ }
91
+ // init vision engine
92
+ const supportedMimeTypes = new Set(Object.values(engines).map(
93
+ x => alan.MODELS[x.model]
94
+ ).map(x => x.supportedMimeTypes || []).flat().map(x => x.toLowerCase()));
95
+ if (options?.googleApiKey) {
96
+ const apiKey = { apiKey: options.googleApiKey };
97
+ await vision.init(apiKey);
98
+ }
99
+ // init bot
93
100
  const _bot = await bot.init({
94
101
  args: options?.args,
95
102
  auth: options?.auth,
@@ -107,6 +114,7 @@ const init = async (options) => {
107
114
  skillPath: options?.skillPath || skillPath,
108
115
  speech: (options?.openaiApiKey || options?.googleApiKey) && speech,
109
116
  vision: options?.googleApiKey && vision,
117
+ supportedMimeTypes,
110
118
  });
111
119
  _bot._.ai = ai; // Should be an array of a map of AIs.
112
120
  _bot._.lang = options?.lang || 'English';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "halbot",
3
3
  "description": "Just another ChatGPT/Bing Chat Telegram bob, which is simple design, easy to use, extendable and fun.",
4
- "version": "1990.1.119",
4
+ "version": "1990.1.121",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/Leask/halbot",
7
7
  "type": "module",
@@ -46,7 +46,7 @@
46
46
  "openai": "^4.24.1",
47
47
  "telegraf": "^4.15.3",
48
48
  "tesseract.js": "^5.0.4",
49
- "utilitas": "^1995.2.47",
49
+ "utilitas": "^1995.2.51",
50
50
  "youtube-transcript": "^1.0.6"
51
51
  }
52
52
  }
@@ -4,7 +4,7 @@ const action = async (ctx, next) => {
4
4
  if (!ctx.cmd.args) {
5
5
  return await ctx.ok('Please input your prompt.');
6
6
  }
7
- const objMsg = (await ctx.ok('✍️'))[0];
7
+ const objMsg = (await ctx.ok('💭'))[0];
8
8
  const images = await ctx._.image.generate(ctx.cmd.args, { expected: 'URL' });
9
9
  await ctx.deleteMessage(objMsg.message_id);
10
10
  for (let image of images) {
@@ -14,15 +14,15 @@ const action = async (ctx, next) => {
14
14
  };
15
15
 
16
16
  export const { name, run, priority, func, cmds, help } = {
17
- name: 'Image',
17
+ name: 'Dream',
18
18
  run: true,
19
19
  priority: 40,
20
20
  func: action,
21
21
  help: bot.lines([
22
22
  'Use DALL-E to generate images.',
23
- 'Example: /image a cat',
23
+ 'Example: /dream a cat',
24
24
  ]),
25
25
  cmds: {
26
- image: 'Use DALL-E to generate images: /image `PROMPT`',
26
+ image: 'Use DALL-E to generate images: /dream `PROMPT`',
27
27
  },
28
28
  };
@@ -17,15 +17,16 @@ const action = async (ctx, next) => {
17
17
  }
18
18
  // prompt
19
19
  const maxInputTokens = alan.getMaxChatPromptLimit();
20
- const additionInfo = ctx.collected.length ? ctx.collected.map(
21
- x => x.content
22
- ).join('\n').split(' ') : [];
20
+ const additionInfo = ctx.collected.filter(
21
+ x => String.isString(x.content)
22
+ ).map(x => x.content).join('\n').split(' ').filter(x => x);
23
23
  ctx.prompt = (ctx.text || '') + '\n\n';
24
24
  while (alan.countTokens(ctx.prompt) < maxInputTokens
25
25
  && additionInfo.length) {
26
26
  ctx.prompt += ` ${additionInfo.shift()}`;
27
27
  }
28
28
  ctx.prompt = utilitas.trim(ctx.prompt);
29
+ ctx.carry.attachments = ctx.collected.filter(x => x.type === 'PROMPT').map(x => x.content);
29
30
  additionInfo.filter(x => x).length && (ctx.prompt += '...');
30
31
  // next
31
32
  await next();