utilitas 1998.2.5 → 1998.2.7

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/alan.mjs CHANGED
@@ -1043,7 +1043,7 @@ const talk = async (input, options) => {
1043
1043
  (options?.attachments || []).filter(x => [
1044
1044
  ..._MODEL?.supportedMimeTypes || [], ..._MODEL.supportedAudioTypes || []
1045
1045
  ].includes(x.mime_type)).map(x => attachments.push(x));
1046
- log(`Prompt: ${JSON.stringify(input)}`);
1046
+ log(`Prompt (${engine}): ${JSON.stringify(input)}`);
1047
1047
  switch (engine) {
1048
1048
  case CHATGPT:
1049
1049
  resp = await promptChatGPT(input, {
package/lib/bot.mjs CHANGED
@@ -646,20 +646,21 @@ const subconscious = [{
646
646
  try {
647
647
  const url = await getFileUrl(ctx.m.voice.file_id);
648
648
  const file = await getFile(ctx.m.voice.file_id, BUFFER_ENCODE);
649
+ const analyze = async () => {
650
+ const resp = await ignoreErrFunc(
651
+ async () => await ctx._.speech?.stt(file), logOptions
652
+ ) || ' ';
653
+ log(`STT: '${resp}'`);
654
+ ctx.collect(resp);
655
+ };
649
656
  if (bot._.supportedMimeTypes.has(wav)) {
650
657
  ctx.collect({
651
- mime_type: wav, url,
658
+ mime_type: wav, url, analyze,
652
659
  data: await convertAudioTo16kNanoPcmWave(file, {
653
660
  input: BUFFER, expected: BASE64,
654
661
  }),
655
662
  }, 'PROMPT');
656
- } else {
657
- const resp = await ignoreErrFunc(
658
- async () => await ctx._.speech?.stt(file), logOptions
659
- ) || ' ';
660
- log(`STT: '${resp}'`);
661
- ctx.collect(resp);
662
- }
663
+ } else { await analyze(); }
663
664
  } catch (err) { return await ctx.er(err); }
664
665
  }
665
666
  await next();
@@ -699,7 +700,7 @@ const subconscious = [{
699
700
  if (member) {
700
701
  if (member?.id === ctx.botInfo.id) { return ctx.end(); }
701
702
  ctx.collect(lines([
702
- `Say ${ctx.m.new_chat_member ? 'hello' : 'good bye'} to:`,
703
+ `Say ${ctx.m.new_chat_member ? 'hello' : 'goodbye'} to:`,
703
704
  uList([
704
705
  // `id: ${member.id}`,
705
706
  // `is_bot: ${member.is_bot}`,
@@ -807,12 +808,7 @@ const subconscious = [{
807
808
  try {
808
809
  const url = await getFileUrl(f.fileId);
809
810
  const file = (await get(url, BUFFER_ENCODE)).content;
810
- if (f.asPrompt) {
811
- ctx.collect({
812
- mime_type: f.mime_type, url,
813
- data: base64Encode(file, true),
814
- }, 'PROMPT');
815
- } else if (f.ocrFunc) {
811
+ const analyze = async () => {
816
812
  const content = trim(ensureArray(
817
813
  await ignoreErrFunc(async () => await f.ocrFunc(
818
814
  file, BUFFER_ENCODE
@@ -826,7 +822,13 @@ const subconscious = [{
826
822
  content
827
823
  ]), 'VISION');
828
824
  }
829
- }
825
+ };
826
+ if (f.asPrompt) {
827
+ ctx.collect({
828
+ mime_type: f.mime_type, url, analyze,
829
+ data: base64Encode(file, true),
830
+ }, 'PROMPT');
831
+ } else if (f.ocrFunc) { await analyze(); }
830
832
  } catch (err) { return await ctx.er(err); }
831
833
  }
832
834
  }
package/lib/manifest.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  const manifest = {
2
2
  "name": "utilitas",
3
3
  "description": "Just another common utility for JavaScript.",
4
- "version": "1998.2.5",
4
+ "version": "1998.2.7",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/Leask/utilitas",
7
7
  "main": "index.mjs",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "utilitas",
3
3
  "description": "Just another common utility for JavaScript.",
4
- "version": "1998.2.5",
4
+ "version": "1998.2.7",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/Leask/utilitas",
7
7
  "main": "index.mjs",