utilitas 1999.1.36 → 1999.1.38
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/dist/utilitas.lite.mjs +1 -1
- package/dist/utilitas.lite.mjs.map +1 -1
- package/lib/bot.mjs +56 -52
- package/lib/image.mjs +11 -6
- package/lib/manifest.mjs +1 -1
- package/package.json +1 -1
package/lib/bot.mjs
CHANGED
|
@@ -753,59 +753,63 @@ const subconscious = [{
|
|
|
753
753
|
run: true, priority: -8860, name: 'vision', func: async (ctx, next) => {
|
|
754
754
|
ctx.collect(ctx.m?.caption || '');
|
|
755
755
|
const files = [];
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
756
|
+
for (const m of [
|
|
757
|
+
ctx.m, ...ctx.m.reply_to_message ? [ctx.m.reply_to_message] : []
|
|
758
|
+
]) {
|
|
759
|
+
if (m.document) {
|
|
760
|
+
let file = {
|
|
761
|
+
asPrompt: bot._.supportedMimeTypes.has(m.document.mime_type),
|
|
762
|
+
file_name: m.document.file_name, fileId: m.document.file_id,
|
|
763
|
+
mime_type: m.document.mime_type, type: FILE,
|
|
764
|
+
ocrFunc: async f => (await isTextFile(f)) && f.toString(),
|
|
765
|
+
};
|
|
766
|
+
if ('application/pdf' === m.document?.mime_type) {
|
|
767
|
+
file = { ...file, ocrFunc: ctx._.vision?.read, type: 'DOCUMENT' };
|
|
768
|
+
} else if (/^image\/.*$/ig.test(m.document?.mime_type)) {
|
|
769
|
+
file = { ...file, ocrFunc: ctx._.vision?.see, type: 'IMAGE' };
|
|
770
|
+
} else if (/^.*\.(docx|xlsx|pptx)$/.test(m.document?.file_name)) {
|
|
771
|
+
file = { ...file, ocrFunc: officeParser, type: 'DOCUMENT' };
|
|
772
|
+
}
|
|
773
|
+
files.push(file);
|
|
774
|
+
}
|
|
775
|
+
if (m.sticker) {
|
|
776
|
+
const s = m.sticker;
|
|
777
|
+
const url = await getFileUrl(s.file_id);
|
|
778
|
+
const file_name = basename(url);
|
|
779
|
+
const mime_type = mime.getType(file_name) || 'image';
|
|
780
|
+
files.push({
|
|
781
|
+
asPrompt: bot._.supportedMimeTypes.has(mime_type), file_name,
|
|
782
|
+
fileId: s.file_id, mime_type, type: 'PHOTO',
|
|
783
|
+
ocrFunc: ctx._.vision?.see,
|
|
784
|
+
});
|
|
785
|
+
}
|
|
786
|
+
if (m.photo?.[m.photo?.length - 1]) {
|
|
787
|
+
const p = m.photo[m.photo.length - 1];
|
|
788
|
+
files.push({
|
|
789
|
+
asPrompt: bot._.supportedMimeTypes.has(jpeg),
|
|
790
|
+
file_name: `${p.file_id}.jpg`, fileId: p.file_id,
|
|
791
|
+
mime_type: jpeg, type: 'PHOTO', ocrFunc: ctx._.vision?.see,
|
|
792
|
+
});
|
|
793
|
+
}
|
|
794
|
+
if (m.video_note) {
|
|
795
|
+
const vn = m.video_note;
|
|
796
|
+
const url = await getFileUrl(vn.file_id);
|
|
797
|
+
const file_name = basename(url);
|
|
798
|
+
const mime_type = mime.getType(file_name) || 'video';
|
|
799
|
+
files.push({
|
|
800
|
+
asPrompt: bot._.supportedMimeTypes.has(mime_type), file_name,
|
|
801
|
+
fileId: vn.file_id, mime_type, type: 'VIDEO',
|
|
802
|
+
});
|
|
803
|
+
}
|
|
804
|
+
if (m.video) {
|
|
805
|
+
const v = m.video;
|
|
806
|
+
const url = await getFileUrl(v.file_id);
|
|
807
|
+
const file_name = basename(url);
|
|
808
|
+
files.push({
|
|
809
|
+
asPrompt: bot._.supportedMimeTypes.has(v.mime_type), file_name,
|
|
810
|
+
fileId: v.file_id, mime_type: v.mime_type, type: 'VIDEO',
|
|
811
|
+
});
|
|
769
812
|
}
|
|
770
|
-
files.push(file);
|
|
771
|
-
}
|
|
772
|
-
if (ctx.m.sticker) {
|
|
773
|
-
const s = ctx.m.sticker;
|
|
774
|
-
const url = await getFileUrl(s.file_id);
|
|
775
|
-
const file_name = basename(url);
|
|
776
|
-
const mime_type = mime.getType(file_name) || 'image';
|
|
777
|
-
files.push({
|
|
778
|
-
asPrompt: bot._.supportedMimeTypes.has(mime_type), file_name,
|
|
779
|
-
fileId: s.file_id, mime_type, type: 'PHOTO',
|
|
780
|
-
ocrFunc: ctx._.vision?.see,
|
|
781
|
-
});
|
|
782
|
-
}
|
|
783
|
-
if (ctx.m.photo?.[ctx.m.photo?.length - 1]) {
|
|
784
|
-
const p = ctx.m.photo[ctx.m.photo.length - 1];
|
|
785
|
-
files.push({
|
|
786
|
-
asPrompt: bot._.supportedMimeTypes.has(jpeg),
|
|
787
|
-
file_name: `${p.file_id}.jpg`, fileId: p.file_id,
|
|
788
|
-
mime_type: jpeg, type: 'PHOTO', ocrFunc: ctx._.vision?.see,
|
|
789
|
-
});
|
|
790
|
-
}
|
|
791
|
-
if (ctx.m.video_note) {
|
|
792
|
-
const vn = ctx.m.video_note;
|
|
793
|
-
const url = await getFileUrl(vn.file_id);
|
|
794
|
-
const file_name = basename(url);
|
|
795
|
-
const mime_type = mime.getType(file_name) || 'video';
|
|
796
|
-
files.push({
|
|
797
|
-
asPrompt: bot._.supportedMimeTypes.has(mime_type), file_name,
|
|
798
|
-
fileId: vn.file_id, mime_type, type: 'VIDEO',
|
|
799
|
-
});
|
|
800
|
-
}
|
|
801
|
-
if (ctx.m.video) {
|
|
802
|
-
const v = ctx.m.video;
|
|
803
|
-
const url = await getFileUrl(v.file_id);
|
|
804
|
-
const file_name = basename(url);
|
|
805
|
-
files.push({
|
|
806
|
-
asPrompt: bot._.supportedMimeTypes.has(v.mime_type), file_name,
|
|
807
|
-
fileId: v.file_id, mime_type: v.mime_type, type: 'VIDEO',
|
|
808
|
-
});
|
|
809
813
|
}
|
|
810
814
|
if (files.length) {
|
|
811
815
|
await ctx.ok(EMOJI_LOOK);
|
package/lib/image.mjs
CHANGED
|
@@ -2,9 +2,12 @@ import { ensureString, need, throwError } from './utilitas.mjs';
|
|
|
2
2
|
import { MIME_PNG, convert } from './storage.mjs';
|
|
3
3
|
|
|
4
4
|
const _NEED = ['OpenAI'];
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
|
|
6
|
+
const [clients, OPENAI, GEMINI, BASE64, BUFFER, ERROR_GENERATING, IMAGEN_MODEL]
|
|
7
|
+
= [
|
|
8
|
+
{}, 'OPENAI', 'GEMINI', 'BASE64', 'BUFFER', 'Error generating image.',
|
|
9
|
+
'imagen-3.0-generate-002',
|
|
10
|
+
];
|
|
8
11
|
|
|
9
12
|
const init = async (options) => {
|
|
10
13
|
assert(options?.apiKey, 'API key is required.');
|
|
@@ -56,8 +59,9 @@ const generate = async (prompt, options) => {
|
|
|
56
59
|
} catch (err) { throwError(err?.message || ERROR_GENERATING); }
|
|
57
60
|
if (!options?.raw && !asUrl) {
|
|
58
61
|
resp.data = await Promise.all(resp.data.map(async x => ({
|
|
59
|
-
|
|
62
|
+
caption: x.revised_prompt, tts: x.revised_prompt,
|
|
60
63
|
data: await extractImage(x.b64_json, options),
|
|
64
|
+
mimeType: MIME_PNG,
|
|
61
65
|
})));
|
|
62
66
|
}
|
|
63
67
|
return resp?.data;
|
|
@@ -65,7 +69,7 @@ const generate = async (prompt, options) => {
|
|
|
65
69
|
options.expected === 'URL' && (options.expected = 'FILE');
|
|
66
70
|
var resp = await (await fetch(
|
|
67
71
|
'https://generativelanguage.googleapis.com/v1beta/models/'
|
|
68
|
-
+
|
|
72
|
+
+ `${IMAGEN_MODEL}:predict?key=${client.apiKey}`, {
|
|
69
73
|
method: 'POST', headers: { 'Content-Type': 'application/json' },
|
|
70
74
|
body: JSON.stringify({
|
|
71
75
|
instances: [{ prompt }], parameters: {
|
|
@@ -78,8 +82,9 @@ const generate = async (prompt, options) => {
|
|
|
78
82
|
if (!options?.raw) {
|
|
79
83
|
resp = await Promise.all((resp?.predictions || []).map(
|
|
80
84
|
async x => ({
|
|
81
|
-
|
|
85
|
+
caption: `🎨 by ${IMAGEN_MODEL}`, tts: null,
|
|
82
86
|
data: await extractImage(x.bytesBase64Encoded, options),
|
|
87
|
+
mimeType: x.mimeType,
|
|
83
88
|
})
|
|
84
89
|
));
|
|
85
90
|
}
|
package/lib/manifest.mjs
CHANGED