halbot 1993.2.65 → 1993.2.66

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
@@ -19,31 +19,30 @@ const init = async (options = {}) => {
19
19
  }
20
20
  // use openai embedding, dall-e, tts if openai is enabled
21
21
  if (options.openaiApiKey) {
22
- const apiKey = { apiKey: options.openaiApiKey };
22
+ const apiKey = { apiKey: options.openaiApiKey, provider: 'OPENAI' };
23
23
  await alan.init({
24
- provider: 'OPENAI', model: options.openaiModel || '*',
25
- ...apiKey, priority: options.openaiPriority, ...options
24
+ ...apiKey, model: options.openaiModel || '*',
25
+ priority: options.openaiPriority, ...options
26
26
  });
27
27
  await image.init(apiKey);
28
- await speech.init({ ...apiKey, provider: 'OPENAI', ...speechOptions });
28
+ await speech.init({ ...apiKey, ...speechOptions });
29
29
  _speech.tts = speech.tts;
30
30
  }
31
31
  // use gemini embedding if gemini is enabled and chatgpt is not enabled
32
32
  // use google tts if google api key is ready
33
33
  if (options.googleApiKey) {
34
- const apiKey = { apiKey: options.googleApiKey };
34
+ const apiKey = { apiKey: options.googleApiKey, provider: 'GOOGLE' };
35
35
  await alan.init({
36
- provider: 'GEMINI', model: options.geminiModel || '*',
37
- ...apiKey, priority: options.geminiPriority, ...options
36
+ ...apiKey, provider: 'GEMINI', model: options.geminiModel || '*',
37
+ priority: options.geminiPriority, ...options
38
38
  });
39
+ await image.init({ ...apiKey, provider: 'GEMINI' });
39
40
  if (!_speech.tts) {
40
- await speech.init({
41
- provider: 'GOOGLE', ...apiKey, ...speechOptions,
42
- });
41
+ await speech.init({ ...apiKey, ...speechOptions });
43
42
  _speech.tts = speech.tts;
44
43
  }
45
44
  options.googleCx && await web.initSearch({
46
- provider: 'GOOGLE', ...apiKey, cx: options.googleCx
45
+ ...apiKey, cx: options.googleCx,
47
46
  });
48
47
  }
49
48
  if (options.anthropicApiKey) {
@@ -92,10 +91,13 @@ const init = async (options = {}) => {
92
91
  });
93
92
  }
94
93
  const { ais } = await alan.initChat({ sessions: options?.storage });
94
+ const cmds = options?.cmds || [];
95
95
  // config multimodal engines
96
- const supportedMimeTypes = new Set(Object.values(ais).map(
97
- x => x.model
98
- ).map(x => [
96
+ const supportedMimeTypes = new Set(Object.values(ais).map(x => {
97
+ // init instant ai selection
98
+ cmds.push(bot.newCommand(`ai_${x.id}`, `${x.name}: ${x.features}`));
99
+ return x.model;
100
+ }).map(x => [
99
101
  ...x.supportedMimeTypes || [], ...x.supportedAudioTypes || [],
100
102
  ]).flat().map(x => x.toLowerCase()));
101
103
  // init bot
@@ -104,7 +106,7 @@ const init = async (options = {}) => {
104
106
  auth: options?.auth,
105
107
  botToken: options?.telegramToken,
106
108
  chatType: options?.chatType,
107
- cmds: options?.cmds,
109
+ cmds,
108
110
  database: options?.storage?.client && options?.storage,
109
111
  embedding: ais.find(x => x.embedding)?.embedding,
110
112
  supportedMimeTypes,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "halbot",
3
3
  "description": "Just another `ChatGPT` / `Gemini` / `Ollama` Telegram bob, which is simple design, easy to use, extendable and fun.",
4
- "version": "1993.2.65",
4
+ "version": "1993.2.66",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/Leask/halbot",
7
7
  "type": "module",
@@ -36,7 +36,7 @@
36
36
  "@google-cloud/speech": "^7.0.1",
37
37
  "@google-cloud/text-to-speech": "^6.0.1",
38
38
  "@google-cloud/vision": "^5.1.0",
39
- "@google/genai": "^0.4.0",
39
+ "@google/genai": "^0.6.0",
40
40
  "@mozilla/readability": "^0.6.0",
41
41
  "fluent-ffmpeg": "^2.1.3",
42
42
  "ioredis": "^5.6.0",
@@ -51,7 +51,7 @@
51
51
  "pgvector": "^0.2.0",
52
52
  "telegraf": "^4.16.3",
53
53
  "tesseract.js": "^6.0.0",
54
- "utilitas": "^1999.1.29",
54
+ "utilitas": "^1999.1.37",
55
55
  "youtube-transcript": "^1.2.1"
56
56
  }
57
57
  }
@@ -4,13 +4,20 @@ 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];
8
- const images = await ctx._.image.generate(ctx.cmd.args, { expected: 'URL' });
7
+ let [objMsg, tts, images] = [(await ctx.ok('💭'))[0], null, null];
8
+ try {
9
+ images = await ctx._.image.generate(ctx.cmd.args, { expected: 'URL' });
10
+ } catch (err) {
11
+ return await ctx.er(err.message || 'Error generating image.',
12
+ { lastMessageId: objMsg.message_id });
13
+ }
9
14
  await ctx.deleteMessage(objMsg.message_id);
10
- for (let image of images) {
11
- await ctx.image(image.url, { caption: image.revised_prompt });
12
- await ctx.shouldSpeech(image.revised_prompt)
15
+ for (let image of images || []) {
16
+ tts = image.tts || '';
17
+ await ctx.image(image.data, { caption: image.caption || '' });
18
+ await ctx.timeout();
13
19
  }
20
+ await ctx.shouldSpeech(tts);
14
21
  };
15
22
 
16
23
  export const { name, run, priority, func, cmds, help } = {
@@ -19,10 +26,16 @@ export const { name, run, priority, func, cmds, help } = {
19
26
  priority: 40,
20
27
  func: action,
21
28
  help: bot.lines([
22
- 'Use DALL-E to generate images.',
23
- 'Example: /dream a cat',
29
+ 'Use Google `Imagen` (default) or OpenAI `DALL-E` to generate images.',
30
+ 'Example 1: /dream a cat in a rocket',
31
+ '¶ Use `Imagen` to generate images.',
32
+ 'Example 2: /imagen a cat in a car',
33
+ '¶ Use `DALL-E` to generate images.',
34
+ 'Example: /dalle a cat on a bike',
24
35
  ]),
25
36
  cmds: {
26
- dream: 'Use DALL-E to generate images: /dream `PROMPT`',
37
+ dream: 'Generate images with default model: /dream `PROMPT`',
38
+ imagen: 'Generate images with `Imagen`: /imagen `PROMPT`',
39
+ dalle: 'Generate images with `DALL-E`: /dalle `PROMPT`',
27
40
  },
28
41
  };