halbot 1993.2.76 → 1993.2.78

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 +2 -2
  2. package/skills/10_ai.mjs +30 -31
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "halbot",
3
3
  "description": "Just another `ChatGPT` / `Gemini` / `Claude` / `Azure` / `Jina` / `Ollama` Telegram bob, which is simple design, easy to use, extendable and fun.",
4
- "version": "1993.2.76",
4
+ "version": "1993.2.78",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/Leask/halbot",
7
7
  "type": "module",
@@ -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.46",
54
+ "utilitas": "^1999.1.48",
55
55
  "youtube-transcript": "^1.2.1"
56
56
  }
57
57
  }
package/skills/10_ai.mjs CHANGED
@@ -21,38 +21,37 @@ const action = async (ctx, next) => {
21
21
  switch (ctx.cmd?.cmd) {
22
22
  case 'ai': return await listAIs(ctx);
23
23
  }
24
- switch (ctx.session.config?.ai) {
25
- case '@': ctx.selectedAi = ais.map(x => x.id); break;
26
- default:
27
- ctx.selectedAi = [ctx.session.config?.ai];
28
- const foundAi = ais.map(x => x.id).includes(ctx.session.config?.ai);
29
- if (foundAi) {
30
- } else if (!ctx.collected?.length) {
31
- ctx.selectedAi = [ais[0].id];
32
- } else {
33
- const supported = {};
34
- for (const x of ais) {
35
- const supportedMimeTypes = [
36
- ...x.model.supportedMimeTypes || [],
37
- ...x.model.supportedAudioTypes || [],
38
- ];
39
- for (const i of ctx.collected) {
40
- supported[x.id] || (supported[x.id] = 0);
41
- if (supportedMimeTypes.includes(i?.content?.mime_type)) {
42
- supported[x.id]++;
43
- }
44
- if (ctx.checkSpeech() && (
45
- x.model.supportedAudioTypes || []
46
- ).includes(i?.content?.mime_type)) {
47
- ctx.carry.audioMode = true;
48
- x.model.audio && (supported[x.id]++); // Priority for audio models
49
- }
50
- }
51
- }
52
- ctx.selectedAi = [Object.keys(supported).sort(
53
- (x, y) => supported[y] - supported[x]
54
- )?.[0] || ais[0].id];
24
+ if (ctx.session.config?.ai === '@') {
25
+ ctx.selectedAi = ais.map(x => x.id);
26
+ } else if (ctx.collected?.length) {
27
+ const supported = {};
28
+ for (const x of ais) {
29
+ const supportedMimeTypes = [
30
+ ...x.model.supportedMimeTypes || [],
31
+ ...x.model.supportedAudioTypes || [],
32
+ ];
33
+ for (const i of ctx.collected) {
34
+ supported[x.id] || (supported[x.id] = 0);
35
+ // Priority for supported mime types
36
+ supportedMimeTypes.includes(i?.content?.mime_type)
37
+ && supported[x.id]++;
38
+ // Priority for user selected AI
39
+ x.id === ctx.session.config?.ai && supported[x.id]++;
40
+ // Priority for audio models
41
+ ctx.checkSpeech() && (
42
+ x.model.supportedAudioTypes || []
43
+ ).includes(i?.content?.mime_type)
44
+ && (ctx.carry.audioMode = true)
45
+ && x.model.audio && supported[x.id]++;
55
46
  }
47
+ }
48
+ ctx.selectedAi = [Object.keys(supported).sort(
49
+ (x, y) => supported[y] - supported[x]
50
+ )?.[0] || ais[0].id];
51
+ } else if (ais.map(x => x.id).includes(ctx.session.config?.ai)) {
52
+ ctx.selectedAi = [ctx.session.config.ai];
53
+ } else {
54
+ ctx.selectedAi = [ais[0].id];
56
55
  }
57
56
  await next();
58
57
  };