halbot 1993.2.90 → 1993.2.91

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/lib/hal.mjs CHANGED
@@ -1,8 +1,5 @@
1
- import {
2
- alan, bot, callosum, dbio, storage, uoid, utilitas, web,
3
- } from 'utilitas';
4
-
5
1
  import { basename, join } from 'path';
2
+ import { bot, callosum, dbio, storage, uoid, utilitas, web } from 'utilitas';
6
3
  import { parseArgs as _parseArgs } from 'node:util';
7
4
  import { readdirSync } from 'fs';
8
5
 
@@ -612,7 +609,11 @@ const subconscious = [{
612
609
  const analyze = async () => {
613
610
  const resp = await utilitas.ignoreErrFunc(async () => {
614
611
  [
615
- alan.mp3, alan.mpega, alan.mp4, alan.mpeg, alan.mpga, alan.m4a, alan.wav, alan.webm, alan.ogg
612
+ storage.MIME_MP3, storage.MIME_MPEGA,
613
+ storage.MIME_MP4, storage.MIME_MPEG,
614
+ storage.MIME_MPGA, storage.MIME_M4A,
615
+ storage.MIME_WAV, storage.MIME_WEBM,
616
+ storage.MIME_OGG,
616
617
  ].includes(audio.mime_type) || (
617
618
  file = await media.convertAudioTo16kNanoPcmWave(
618
619
  file, { input: storage.BUFFER, expected: storage.BUFFER }
@@ -623,9 +624,9 @@ const subconscious = [{
623
624
  log(`STT: '${resp}'`);
624
625
  ctx.collect(resp);
625
626
  };
626
- if (hal._.supportedMimeTypes.has(alan.wav)) {
627
+ if (hal._.supportedMimeTypes.has(MIME_WAV)) {
627
628
  ctx.collect({
628
- mime_type: alan.wav, url, analyze,
629
+ mime_type: MIME_WAV, url, analyze,
629
630
  data: await media.convertAudioTo16kNanoPcmWave(file, {
630
631
  input: storage.BUFFER, expected: storage.BASE64,
631
632
  }),
@@ -736,9 +737,10 @@ const subconscious = [{
736
737
  if (m.photo?.[m.photo?.length - 1]) {
737
738
  const p = m.photo[m.photo.length - 1];
738
739
  files.push({
739
- asPrompt: hal._.supportedMimeTypes.has(alan.jpeg),
740
+ asPrompt: hal._.supportedMimeTypes.has(storage.MIME_JPEG),
740
741
  file_name: `${p.file_id}.jpg`, fileId: p.file_id,
741
- mime_type: alan.jpeg, type: 'PHOTO', ocrFunc: ctx._.vision?.see,
742
+ mime_type: storage.MIME_JPEG, type: 'PHOTO',
743
+ ocrFunc: ctx._.vision?.see,
742
744
  });
743
745
  }
744
746
  if (m.video_note) {
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.90",
4
+ "version": "1993.2.91",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/Leask/halbot",
7
7
  "type": "module",
@@ -46,12 +46,12 @@
46
46
  "mime": "^4.0.7",
47
47
  "mysql2": "^3.14.1",
48
48
  "office-text-extractor": "^3.0.3",
49
- "openai": "^4.96.2",
49
+ "openai": "^4.97.0",
50
50
  "pg": "^8.15.6",
51
51
  "pgvector": "^0.2.0",
52
52
  "telegraf": "^4.16.3",
53
53
  "tesseract.js": "^6.0.1",
54
- "utilitas": "^1999.1.60",
54
+ "utilitas": "^1999.1.61",
55
55
  "youtube-transcript": "^1.2.1"
56
56
  }
57
57
  }
@@ -1,13 +1,19 @@
1
- import { bot } from '../index.mjs';
1
+ import { bot, storage } from '../index.mjs';
2
2
 
3
3
  const GEMINI = 'GEMINI';
4
4
  const types = { image: 'photo', video: 'video' };
5
5
 
6
6
  const action = async (ctx, next) => {
7
- let [provider, func] = [GEMINI, 'image'];
7
+ let [provider, func, reference] = [GEMINI, 'image', null];
8
8
  switch (ctx.cmd.cmd) {
9
- case 'gptimage': provider = 'OPENAI'; break;
10
- case 'fantasy': func = 'video';
9
+ case 'fantasy': func = 'video'; break;
10
+ case 'gptimage':
11
+ provider = 'OPENAI';
12
+ reference = ctx.collected.filter(x => [
13
+ storage.MIME_JPEG, storage.MIME_PNG, storage.MIME_WEBP
14
+ ].includes(x?.content?.mime_type)).slice(0, 16).map(
15
+ x => x?.content?.data
16
+ );
11
17
  }
12
18
  if (!ctx.cmd.args) {
13
19
  return await ctx.ok('Please input your prompt.');
@@ -15,7 +21,8 @@ const action = async (ctx, next) => {
15
21
  let [objMsg, output] = [(await ctx.ok('💭'))[0], null]; //tts = null
16
22
  try {
17
23
  output = (await ctx._.gen[func](ctx.cmd.args, {
18
- provider, expected: 'FILE'
24
+ provider, expected: 'FILE',
25
+ ...reference?.length ? { reference, input: 'BASE64' } : {},
19
26
  })) || [];
20
27
  } catch (err) {
21
28
  return await ctx.er(err.message || `Error generating ${func}.`,