halbot 1992.1.8 → 1992.1.9

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
@@ -91,6 +91,7 @@ const init = async (options) => {
91
91
  }
92
92
  assert(utilitas.countKeys(ai), 'No AI provider is configured.');
93
93
  await alan.initChat({ engines, sessions: options?.storage });
94
+ for (const i in ai) { ai[i].model = engines[ai[i].engine].model; }
94
95
  // init image, speech, embedding engines
95
96
  if (options?.openaiApiKey) {
96
97
  const apiKey = { apiKey: options.openaiApiKey };
@@ -102,10 +103,12 @@ const init = async (options) => {
102
103
  await speech.init({ ...apiKey, provider: 'GOOGLE', ...speechOptions });
103
104
  embedding = alan.createGeminiEmbedding;
104
105
  }
105
- // init vision engine
106
+ // init vision / audio engine
106
107
  const supportedMimeTypes = new Set(Object.values(engines).map(
107
108
  x => alan.MODELS[x.model]
108
- ).map(x => x.supportedMimeTypes || []).flat().map(x => x.toLowerCase()));
109
+ ).map(x => [
110
+ ...x.supportedMimeTypes || [], ...x.supportedAudioTypes || [],
111
+ ]).flat().map(x => x.toLowerCase()));
109
112
  if (options?.googleApiKey) {
110
113
  const apiKey = { apiKey: options.googleApiKey };
111
114
  await vision.init(apiKey);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "halbot",
3
3
  "description": "Just another `ChatGPT` / `Gemini` / `Mistral (by ollama)` Telegram bob, which is simple design, easy to use, extendable and fun.",
4
- "version": "1992.1.8",
4
+ "version": "1992.1.9",
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": "^5.1.1",
54
- "utilitas": "^1997.1.32",
54
+ "utilitas": "^1997.1.34",
55
55
  "youtube-transcript": "^1.2.1"
56
56
  }
57
57
  }
@@ -1,4 +1,4 @@
1
- import { bot, utilitas } from 'utilitas';
1
+ import { alan, bot, utilitas } from 'utilitas';
2
2
 
3
3
  let configuredAi;
4
4
 
@@ -9,10 +9,31 @@ const action = async (ctx, next) => {
9
9
  ).sort((x, y) => x[1] - y[1]);
10
10
  ctx.firstAi = arrSort[0][0];
11
11
  switch (ctx.session.config?.ai) {
12
- case '': ctx.selectedAi = [ctx.firstAi]; break;
13
12
  case '@': ctx.selectedAi = configuredAi; break;
14
- default: ctx.selectedAi = [configuredAi.includes(ctx.session.config?.ai)
15
- ? ctx.session.config?.ai : ctx.firstAi];
13
+ default:
14
+ ctx.selectedAi = [ctx.session.config?.ai];
15
+ const foundAi = configuredAi.includes(ctx.session.config?.ai);
16
+ if (foundAi) {
17
+ } else if (!ctx.collected?.length) {
18
+ ctx.selectedAi = [ctx.firstAi];
19
+ } else {
20
+ const supported = {};
21
+ for (const i of configuredAi) {
22
+ const supportedMimeTypes = [
23
+ ...alan.MODELS[ctx._.ai[i].model]?.supportedMimeTypes || [],
24
+ ...alan.MODELS[ctx._.ai[i].model]?.supportedAudioTypes || [],
25
+ ];
26
+ for (const j of ctx.collected) {
27
+ if (supportedMimeTypes.includes(j?.content?.mime_type)) {
28
+ supported[i] || (supported[i] = 0);
29
+ supported[i]++;
30
+ }
31
+ }
32
+ }
33
+ ctx.selectedAi = [Object.keys(supported).sort(
34
+ (x, y) => supported[y] - supported[x]
35
+ )?.[0] || ctx.firstAi];
36
+ }
16
37
  }
17
38
  ctx.multiAi = ctx.selectedAi.length > 1;
18
39
  await next();
@@ -25,8 +25,9 @@ const action = async (ctx, next) => {
25
25
  x => String.isString(x.content)
26
26
  ).map(x => x.content).join('\n').split(' ').filter(x => x);
27
27
  ctx.prompt = (ctx.txt || '') + '\n\n';
28
- while (await alan.countTokens(ctx.prompt) < maxInputTokens
29
- && additionInfo.length) {
28
+ while (await alan.countTokens(
29
+ `${ctx.prompt}${additionInfo?.[0] || ''}`
30
+ ) < maxInputTokens && additionInfo.length) {
30
31
  ctx.prompt += ` ${additionInfo.shift()}`;
31
32
  }
32
33
  ctx.prompt = utilitas.trim(ctx.prompt);
@@ -9,7 +9,7 @@ const [BOT, BOTS, LN2] = [`${bot.EMOJI_BOT} `, {
9
9
  }, '\n\n'];
10
10
 
11
11
  const action = async (ctx, next) => {
12
- if (!ctx.prompt) { return await next(); }
12
+ if (!ctx.prompt && !ctx.carry.attachments.length) { return await next(); }
13
13
  const [YOU, msgs, tts, pms, extra]
14
14
  = [`${ctx.avatar} You:`, {}, {}, [], { buttons: [] }];
15
15
  let [lastMsg, lastSent, references] = [null, 0, null];