halbot 1990.1.91 → 1990.1.93

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
@@ -1,4 +1,4 @@
1
- import { bot, hal, shot, speech, utilitas, vision } from 'utilitas';
1
+ import { bot, hal, image, shot, speech, utilitas, vision } from 'utilitas';
2
2
  import { parse } from 'csv-parse/sync';
3
3
 
4
4
  await utilitas.locate(utilitas.__(import.meta.url, 'package.json'));
@@ -7,7 +7,7 @@ const skillPath = utilitas.__(import.meta.url, 'skills');
7
7
 
8
8
  const promptSource = new Set([
9
9
  // 'https://raw.githubusercontent.com/f/awesome-chatgpt-prompts/main/prompts.csv',
10
- 'https://raw.githubusercontent.com/f/awesome-chatgpt-prompts/4fa40ad4067dce08a007f1c07562fac9dcbfcd1d/prompts.csv',
10
+ 'https://raw.githubusercontent.com/f/awesome-chatgpt-prompts/82f15563c9284c01ca54f0b915ae1aeda5a0fc3a/prompts.csv'
11
11
  ]);
12
12
 
13
13
  const fetchPrompts = async () => {
@@ -29,20 +29,25 @@ const fetchPrompts = async () => {
29
29
 
30
30
  const init = async (options) => {
31
31
  assert(options?.telegramToken, 'Telegram Bot API Token is required.');
32
- const [pkg, ai, _speech] = [await utilitas.which(), {}, {}];
33
- const info = bot.lines([`[${bot.EMOJI_BOT} ${pkg.title}](${pkg.homepage})`, pkg.description]);
32
+ const [pkg, ai, _speech, speechOptions]
33
+ = [await utilitas.which(), {}, {}, { tts: true, stt: true }];
34
+ const info = bot.lines([
35
+ `[${bot.EMOJI_BOT} ${pkg.title}](${pkg.homepage})`, pkg.description
36
+ ]);
34
37
  const cacheOptions = options?.storage ? { store: options.storage } : null;
35
- if (options?.googleApiKey) {
36
- const apiKey = { apiKey: options?.googleApiKey };
37
- await Promise.all([
38
- speech.init({ ...apiKey, tts: true, stt: true }),
39
- vision.init(apiKey),
40
- ]);
41
- }
42
- if (options?.chatGptKey) {
38
+ if (options?.openaiApiKey) {
39
+ const apiKey = { apiKey: options.openaiApiKey };
43
40
  ai['ChatGPT'] = await hal.init({
44
- provider: 'CHATGPT', clientOptions: { apiKey: options.chatGptKey },
45
- cacheOptions,
41
+ provider: 'CHATGPT', clientOptions: apiKey, cacheOptions,
42
+ });
43
+ await speech.init({ ...apiKey, provider: 'OPENAI', ...speechOptions });
44
+ await image.init(apiKey);
45
+ }
46
+ if (options?.googleApiKey) {
47
+ const apiKey = { apiKey: options.googleApiKey };
48
+ await vision.init(apiKey);
49
+ options?.openaiApiKey || await speech.init({
50
+ ...apiKey, provider: 'GOOGLE', ...speechOptions,
46
51
  });
47
52
  }
48
53
  if (options?.bingToken) {
@@ -67,11 +72,12 @@ const init = async (options) => {
67
72
  provider: 'telegram',
68
73
  session: options?.storage,
69
74
  skillPath: options?.skillPath || skillPath,
70
- speech: options?.googleApiKey && speech,
75
+ speech: (options?.openaiApiKey || options?.googleApiKey) && speech,
71
76
  vision: options?.googleApiKey && vision,
72
77
  });
73
78
  _bot._.ai = ai; // Should be an array of a map of AIs.
74
79
  _bot._.lang = options?.lang || 'English';
80
+ _bot._.image = options?.openaiApiKey && image;
75
81
  _bot._.prompts = await fetchPrompts();
76
82
  return _bot;
77
83
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "halbot",
3
3
  "description": "Just another ChatGPT/Bing Chat Telegram bob, which is simple design, easy to use, extendable and fun.",
4
- "version": "1990.1.91",
4
+ "version": "1990.1.93",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/Leask/halbot",
7
7
  "type": "module",
@@ -30,21 +30,22 @@
30
30
  },
31
31
  "dependencies": {
32
32
  "@ffmpeg-installer/ffmpeg": "^1.1.0",
33
- "@ffprobe-installer/ffprobe": "^2.1.1",
34
- "@google-cloud/speech": "^5.6.0",
35
- "@google-cloud/text-to-speech": "^4.2.3",
36
- "@google-cloud/vision": "^3.1.4",
33
+ "@ffprobe-installer/ffprobe": "^2.1.2",
34
+ "@google-cloud/speech": "^6.1.0",
35
+ "@google-cloud/text-to-speech": "^5.0.1",
36
+ "@google-cloud/vision": "^4.0.2",
37
37
  "@mozilla/readability": "^0.4.4",
38
- "@waylaidwanderer/chatgpt-api": "^1.37.2",
39
- "csv-parse": "^5.4.0",
38
+ "@waylaidwanderer/chatgpt-api": "^1.37.3",
39
+ "csv-parse": "^5.5.2",
40
40
  "fluent-ffmpeg": "^2.1.2",
41
41
  "ioredis": "^5.3.2",
42
42
  "jsdom": "^22.1.0",
43
- "mysql2": "^3.5.2",
44
- "office-text-extractor": "^3.0.1",
45
- "telegraf": "^4.12.2",
46
- "tesseract.js": "^4.1.1",
47
- "utilitas": "^1995.0.46",
43
+ "mysql2": "^3.6.3",
44
+ "office-text-extractor": "^3.0.2",
45
+ "openai": "^4.17.3",
46
+ "telegraf": "^4.15.0",
47
+ "tesseract.js": "^5.0.3",
48
+ "utilitas": "^1995.1.14",
48
49
  "youtube-transcript": "^1.0.6"
49
50
  }
50
51
  }
@@ -40,7 +40,8 @@ const validateTone = val => {
40
40
  return val;
41
41
  };
42
42
 
43
- export const { run, priority, func, help, args } = {
43
+ export const { name, run, priority, func, help, args } = {
44
+ name: 'Engine',
44
45
  run: true,
45
46
  priority: 10,
46
47
  func: action,
@@ -22,7 +22,8 @@ const action = async (ctx, next) => {
22
22
  await next();
23
23
  };
24
24
 
25
- export const { run, priority, func, help, cmds } = {
25
+ export const { name, run, priority, func, help, cmds } = {
26
+ name: 'Instant',
26
27
  run: true,
27
28
  priority: 20,
28
29
  func: action,
@@ -14,7 +14,7 @@ const promptTranslate = (ctx, lang) => execPrompt(ctx, [
14
14
  // Inspired by:
15
15
  // https://github.com/yetone/bob-plugin-openai-polisher/blob/main/src/main.js
16
16
  const promptPolish = ctx => execPrompt(ctx, [
17
- 'Revise all the following text I send to you to make them more clear, concise, and coherent.',
17
+ 'Revise the following sentences to make them more clear, concise, and coherent.',
18
18
  'Please note that you need to list the changes and briefly explain why.',
19
19
  ]);
20
20
 
@@ -47,7 +47,8 @@ const action = async (ctx, next) => {
47
47
  await next();
48
48
  };
49
49
 
50
- export const { run, priority, func, cmds, help } = {
50
+ export const { name, run, priority, func, cmds, help } = {
51
+ name: 'Wording',
51
52
  run: true,
52
53
  priority: 30,
53
54
  func: action,
@@ -0,0 +1,28 @@
1
+ import { bot } from 'utilitas';
2
+
3
+ const action = async (ctx, next) => {
4
+ if (!ctx.cmd.args) {
5
+ return await ctx.ok('Please input your prompt.');
6
+ }
7
+ const objMsg = (await ctx.ok('✍️'))[0];
8
+ const images = await ctx._.image.generate(ctx.cmd.args, { expected: 'URL' });
9
+ await ctx.deleteMessage(objMsg.message_id);
10
+ for (let image of images) {
11
+ await ctx.image(image.url, { caption: image.revised_prompt });
12
+ await ctx.speech(image.revised_prompt);
13
+ }
14
+ };
15
+
16
+ export const { name, run, priority, func, cmds, help } = {
17
+ name: 'Image',
18
+ run: true,
19
+ priority: 40,
20
+ func: action,
21
+ help: bot.lines([
22
+ '¶ Use DALL-E to generate images.',
23
+ 'Example 1: /image a cat',
24
+ ]),
25
+ cmds: {
26
+ image: 'Use DALL-E to generate images: /image `PROMPT`',
27
+ },
28
+ };
@@ -59,9 +59,10 @@ const action = async (ctx, next) => {
59
59
  await next();
60
60
  };
61
61
 
62
- export const { run, priority, func, help, cmds, cmdx } = {
62
+ export const { name, run, priority, func, help, cmds, cmdx } = {
63
+ name: 'Prompt',
63
64
  run: true,
64
- priority: 40,
65
+ priority: 50,
65
66
  func: action,
66
67
  help: bot.lines([
67
68
  '¶ Maintain custom prompts.',
@@ -34,7 +34,8 @@ const action = async (ctx, next) => {
34
34
  await next();
35
35
  };
36
36
 
37
- export const { run, priority, func } = {
37
+ export const { name, run, priority, func } = {
38
+ name: 'Prepare',
38
39
  run: true,
39
40
  priority: 60,
40
41
  func: action,
@@ -66,7 +66,8 @@ const action = async (ctx, next) => {
66
66
  await next();
67
67
  };
68
68
 
69
- export const { run, priority, func } = {
69
+ export const { name, run, priority, func } = {
70
+ name: 'Chat',
70
71
  run: true,
71
72
  priority: 70,
72
73
  func: action,