halbot 1993.2.56 → 1993.2.58

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/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.56",
4
+ "version": "1993.2.58",
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.6",
54
+ "utilitas": "^1999.1.9",
55
55
  "youtube-transcript": "^1.2.1"
56
56
  }
57
57
  }
@@ -35,8 +35,8 @@ const action = async (ctx, next) => {
35
35
  }
36
36
  // prompt
37
37
  await checkUnsupportedMimeType(ctx);
38
- const maxInputTokens = alan.getMaxChatPromptLimit()
39
- - alan.ATTACHMENT_TOKEN_COST * ctx.carry.attachments.length;
38
+ const maxInputTokens = await alan.getChatPromptLimit()
39
+ - await alan.getChatAttachmentCost() * ctx.carry.attachments.length;
40
40
  const additionInfo = ctx.collected.filter(
41
41
  x => String.isString(x.content)
42
42
  ).map(x => x.content).join('\n').split(' ').filter(x => x);
@@ -1,4 +1,4 @@
1
- import { alan, bot, utilitas } from 'utilitas';
1
+ import { alan, bot, storage, utilitas } from 'utilitas';
2
2
 
3
3
  const onProgress = { onProgress: true };
4
4
  const [joinL1, joinL2] = [a => a.join(LN2), a => a.join(LN2)];
@@ -12,8 +12,10 @@ const [BOT, BOTS, LN2] = [`${bot.EMOJI_BOT} `, {
12
12
 
13
13
  const action = async (ctx, next) => {
14
14
  if (!ctx.prompt && !ctx.carry.attachments.length) { return await next(); }
15
- const [YOU, msgs, tts, rsm, pms, extra, firstResp]
16
- = [`${ctx.avatar} You:`, {}, {}, {}, [], { buttons: [] }, Date.now()];
15
+ const [YOU, msgs, tts, rsm, pms, extra, firstResp, lock] = [
16
+ `${ctx.avatar} You:`, {}, {}, {}, [], { buttons: [] }, Date.now(),
17
+ 1000 * 5
18
+ ];
17
19
  let [lastMsg, lastSent, references, audio] = [null, 0, null, null];
18
20
  const packMsg = options => {
19
21
  const said = !options?.tts && ctx.result ? ctx.result : '';
@@ -34,10 +36,9 @@ const action = async (ctx, next) => {
34
36
  const ok = async options => {
35
37
  const [curTime, curMsg] = [Date.now(), packMsg(options)];
36
38
  if (options?.onProgress && (
37
- (curTime - lastSent) < (ctx.limit * (curTime - firstResp > 1000 * 60 ? 2 : 1))
38
- || lastMsg === curMsg
39
+ curTime - lastSent < ctx.limit || lastMsg === curMsg
39
40
  )) { return; }
40
- [lastSent, lastMsg] = [curTime, curMsg];
41
+ [lastSent, lastMsg] = [curTime + lock, curMsg];
41
42
  const cmd = ctx.session.context?.cmd;
42
43
  if (options?.final) {
43
44
  (references?.links || []).map((x, i) => extra.buttons.push({
@@ -47,10 +48,12 @@ const action = async (ctx, next) => {
47
48
  label: `❎ End context: \`${cmd}\``, text: '/clear',
48
49
  }));
49
50
  }
50
- return await ctx.ok(curMsg, {
51
+ const resp = await ctx.ok(curMsg, {
51
52
  ...ctx.carry.keyboards ? { keyboards: ctx.carry.keyboards } : {},
52
53
  md: true, ...extra, ...options || {},
53
54
  });
55
+ lastSent = curTime;
56
+ return resp;
54
57
  };
55
58
  ctx.carry.threadInfo.length || await ok(onProgress);
56
59
  for (const n of ctx.selectedAi) {
@@ -69,6 +72,10 @@ const action = async (ctx, next) => {
69
72
  && !msgs[ai].split('\n').some(x => /^\s*```/.test(x))
70
73
  ? resp.spoken : '';
71
74
  rsm[ai] = resp.model;
75
+ for (let img of resp?.images || []) {
76
+ await ctx.image(img.data, { caption: `🎨 by ${resp.model}` });
77
+ await ctx.timeout();
78
+ }
72
79
  return resp;
73
80
  } catch (err) {
74
81
  msgs[ai] = `⚠️ ${err?.message || err}`;