halbot 1993.2.61 → 1993.2.62

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.
Files changed (2) hide show
  1. package/package.json +7 -7
  2. package/skills/10_ai.mjs +36 -18
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.61",
4
+ "version": "1993.2.62",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/Leask/halbot",
7
7
  "type": "module",
@@ -33,9 +33,9 @@
33
33
  "@anthropic-ai/vertex-sdk": "^0.7.0",
34
34
  "@ffmpeg-installer/ffmpeg": "^1.1.0",
35
35
  "@ffprobe-installer/ffprobe": "^2.1.2",
36
- "@google-cloud/speech": "^7.0.0",
37
- "@google-cloud/text-to-speech": "^6.0.0",
38
- "@google-cloud/vision": "^5.0.0",
36
+ "@google-cloud/speech": "^7.0.1",
37
+ "@google-cloud/text-to-speech": "^6.0.1",
38
+ "@google-cloud/vision": "^5.1.0",
39
39
  "@google/genai": "^0.4.0",
40
40
  "@mozilla/readability": "^0.6.0",
41
41
  "fluent-ffmpeg": "^2.1.3",
@@ -44,14 +44,14 @@
44
44
  "jsdom": "^26.0.0",
45
45
  "lorem-ipsum": "^2.0.8",
46
46
  "mime": "^4.0.6",
47
- "mysql2": "^3.13.0",
47
+ "mysql2": "^3.14.0",
48
48
  "office-text-extractor": "^3.0.3",
49
- "openai": "^4.87.4",
49
+ "openai": "^4.88.0",
50
50
  "pg": "^8.14.1",
51
51
  "pgvector": "^0.2.0",
52
52
  "telegraf": "^4.16.3",
53
53
  "tesseract.js": "^6.0.0",
54
- "utilitas": "^1999.1.24",
54
+ "utilitas": "^1999.1.27",
55
55
  "youtube-transcript": "^1.2.1"
56
56
  }
57
57
  }
package/skills/10_ai.mjs CHANGED
@@ -1,26 +1,25 @@
1
1
  import { alan, bot, utilitas } from 'utilitas';
2
2
 
3
+ const ais = await alan.getAi(null, { all: true });
3
4
  const EMIJI_FINISH = '☑️';
4
5
 
6
+ const listAIs = async ctx => {
7
+ const lastMessageId = ctx?.update?.callback_query?.message?.message_id;
8
+ const message = `Features:\n`
9
+ + bot.uList(Object.entries(alan.FEATURE_ICONS).map(
10
+ x => `${x[1]} ${x[0]}`
11
+ )) + `\n\nAI${ais.length > 0 ? 's' : ''}:\n`;
12
+ const buttons = ais.map(x => ({
13
+ label: `${ctx.session.config?.ai === x.id
14
+ ? `${EMIJI_FINISH} ` : ''}${x.name}: ${x.features}`,
15
+ text: `/set --ai=${x.id}`,
16
+ }));
17
+ return await ctx.ok(message, { lastMessageId, buttons });
18
+ };
19
+
5
20
  const action = async (ctx, next) => {
6
- const ais = await alan.getAi(null, { all: true });
7
- const listAIs = async () => {
8
- const lastMessageId = ctx.update?.callback_query?.message?.message_id;
9
- const message = `${bot.EMOJI_BOT} AI${ais.length > 0 ? 's' : ''}:`;
10
- const buttons = ais.map(x => ({
11
- label: `${ctx.session.config?.ai === x.id
12
- ? `${EMIJI_FINISH} ` : ''}${x.name}: ${x.features}`,
13
- text: `/ai ${x.id}`,
14
- }));
15
- return await ctx.ok(message, { lastMessageId, buttons });
16
- };
17
21
  switch (ctx.cmd?.cmd) {
18
- case 'ai':
19
- const aiId = utilitas.trim(ctx.cmd.args);
20
- if (!aiId || aiId === bot.EMOJI_BOT) { return await listAIs(); }
21
- assert(ais.find(x => x.id === aiId), 'No AI engine matched.');
22
- ctx.session.config.ai = aiId;
23
- return await listAIs();
22
+ case 'ai': return await listAIs(ctx);
24
23
  }
25
24
  switch (ctx.session.config?.ai) {
26
25
  case '@': ctx.selectedAi = ais.map(x => x.id); break;
@@ -58,6 +57,16 @@ const action = async (ctx, next) => {
58
57
  await next();
59
58
  };
60
59
 
60
+ const validateAi = async (val, ctx) => {
61
+ for (let name of [...ais.map(x => x.id), '', '@']) {
62
+ if (utilitas.insensitiveCompare(val, name)) {
63
+ ctx && (ctx.sendConfig = async (_c, _o, ctx) => await listAIs(ctx));
64
+ return name;
65
+ }
66
+ }
67
+ utilitas.throwError('No AI engine matched.');
68
+ };
69
+
61
70
  export const { name, run, priority, func, help, args, cmdx } = {
62
71
  name: 'AI',
63
72
  run: true,
@@ -66,12 +75,21 @@ export const { name, run, priority, func, help, args, cmdx } = {
66
75
  help: bot.lines([
67
76
  '¶ Set initial prompt to the AI engine.',
68
77
  "Tip 1: Set `hello=''` to reset to default initial prompt.",
78
+ '¶ Select between AI engines.',
79
+ "Tip 2: Set `ai=''` to use default AI engine.",
80
+ 'Tip 3: Set `ai=[AI_ID]` to use specific AI engine.',
81
+ 'Tip 4: Set `ai=@` to use all AI engines simultaneously.',
69
82
  ]),
70
83
  args: {
71
84
  hello: {
72
- type: 'string', short: 's', default: 'You are a helpful assistant.',
85
+ type: 'string', short: 's', default: 'Hello!',
73
86
  desc: "Change initial prompt: /set --hello 'Bonjour!'",
74
87
  },
88
+ ai: {
89
+ type: 'string', short: 'a', default: '',
90
+ desc: "`(AI_ID, ..., @)` Select AI engine.",
91
+ validate: validateAi,
92
+ },
75
93
  },
76
94
  cmdx: {
77
95
  ai: 'List all available AIs.',