halbot 1990.1.117 → 1990.1.119

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/README.md CHANGED
@@ -67,21 +67,41 @@ All supported configuration fields:
67
67
  // REQUIRED, string.
68
68
  "telegramToken": "[[Telegram Bot API Token]]",
69
69
 
70
+ // Set some of these fields if you need ChatGPT features.
70
71
  // OPTIONAL, string.
71
- // Set this field if you need ChatGPT features.
72
72
  "openaiApiKey": "[[OpenAI API Key]]",
73
+ // OPTIONAL, string.
73
74
  "openaiEndpoint": "[[Custom OpenAI API endpoint]]",
75
+ // OPTIONAL, string, default: "gpt-3.5-turbo".
74
76
  "chatGptModel": "[[Custom ChatGPT Model ID]]",
77
+ // OPTIONAL, integer, default: 0.
78
+ "chatGptPriority": "[[Custom ChatGPT Priority]]",
75
79
 
80
+ // Set some of these fields if you need to use custom ChatGPT API.
81
+ // OPTIONAL, string.
82
+ "chatGptApiKey": "[[Custom ChatGPT API Key]]",
76
83
  // OPTIONAL, string.
84
+ "chatGptEndpoint": "[[Custom ChatGPT API endpoint]]",
85
+
77
86
  // Set this field if you need Gemini features.
87
+ // OPTIONAL, string.
78
88
  "googleCredentials": "[[Google Cloud Credentials]]",
89
+ // OPTIONAL, string.
79
90
  "googleProject": "[[Google Cloud Project ID]]",
91
+ // OPTIONAL, string, default: "gemini-pro-vision".
92
+ "geminiModel": "[[Custom Gemini Model ID]]",
93
+ // OPTIONAL, integer, default: 1.
94
+ "geminiPriority": "[[Custom Gemini Priority]]",
80
95
 
81
- // OPTIONAL, boolean.
82
96
  // Set this field if you need Mistral features.
97
+ // OPTIONAL, boolean.
83
98
  "mistralEnabled": "[[Enable Mistral hosted by Ollama]]",
99
+ // OPTIONAL, string.
84
100
  "mistralEndpoint": "[[Custom Mistral API endpoint]]",
101
+ // OPTIONAL, string, default: "Mistral" (Mistral 7B).
102
+ "mistralModel": "[[Custom Mistral Model ID]]",
103
+ // OPTIONAL, integer, default: 2.
104
+ "mistralPriority": "[[Custom Mistral Priority]]",
85
105
 
86
106
  // OPTIONAL, string.
87
107
  // Set this field if you need TTS/STT/OCR/OBJECT_DETECT features.
package/index.mjs CHANGED
@@ -1,6 +1,5 @@
1
1
  import { alan, bot, image, shot, speech, utilitas, vision } from 'utilitas';
2
2
  import { parse } from 'csv-parse/sync';
3
- import { end } from 'utilitas/lib/event.mjs';
4
3
 
5
4
  await utilitas.locate(utilitas.__(import.meta.url, 'package.json'));
6
5
  const log = content => utilitas.log(content, 'halbot');
@@ -35,15 +34,24 @@ const init = async (options) => {
35
34
  const info = bot.lines([
36
35
  `[${bot.EMOJI_BOT} ${pkg.title}](${pkg.homepage})`, pkg.description
37
36
  ]);
38
- if (options?.openaiApiKey) {
39
- const apiKey = { apiKey: options.openaiApiKey };
37
+ if (options?.openaiApiKey || options?.chatGptApiKey) {
38
+ const apiKey = { apiKey: options?.chatGptApiKey || options?.openaiApiKey };
40
39
  await alan.init({
41
- provider: 'openai', ...apiKey, baseURL: options?.openaiEndpoint,
40
+ provider: 'openai', ...apiKey,
41
+ baseURL: options?.chatGptEndpoint || options?.openaiEndpoint,
42
42
  });
43
+ ai['ChatGPT'] = {
44
+ engine: 'CHATGPT', priority: options?.chatGptPriority || 0,
45
+ };
46
+ engines['CHATGPT'] = {
47
+ // only support custom model while prompting
48
+ model: options?.chatGptModel,
49
+ };
50
+ }
51
+ if (options?.openaiApiKey) {
52
+ const apiKey = { apiKey: options.openaiApiKey };
43
53
  await speech.init({ ...apiKey, provider: 'OPENAI', ...speechOptions });
44
54
  await image.init(apiKey);
45
- ai['ChatGPT'] = { engine: 'CHATGPT' };
46
- engines['CHATGPT'] = { model: options?.chatGptModel };
47
55
  }
48
56
  if (options?.googleApiKey) {
49
57
  const apiKey = { apiKey: options.googleApiKey };
@@ -57,18 +65,28 @@ const init = async (options) => {
57
65
  provider: 'VERTEX',
58
66
  credentials: options.googleCredentials,
59
67
  project: options.googleProject,
68
+ // only support custom model while initiating
69
+ model: options?.geminiModel,
60
70
  });
61
- ai['Gemini'] = { engine: 'VERTEX' };
62
- engines['VERTEX'] = {};
71
+ ai['Gemini'] = {
72
+ engine: 'VERTEX', priority: options?.geminiPriority || 1,
73
+ };
74
+ engines['VERTEX'] = {
75
+ // save for reference not for prompting
76
+ model: options?.geminiModel,
77
+ };
63
78
  }
64
79
  if (options?.mistralEnabled || options?.mistralEndpoint) {
65
80
  await alan.init({
66
- provider: 'OLLAMA',
67
- endpoint: options?.mistralEndpoint,
68
- model: options?.mistralModel,
81
+ provider: 'OLLAMA', endpoint: options?.mistralEndpoint,
69
82
  });
70
- ai['Mistral'] = { engine: 'OLLAMA' };
71
- engines['OLLAMA'] = {};
83
+ ai['Mistral'] = {
84
+ engine: 'OLLAMA', priority: options?.mistralPriority || 2,
85
+ };
86
+ engines['OLLAMA'] = {
87
+ // only support custom model while prompting
88
+ model: options?.mistralModel,
89
+ };
72
90
  }
73
91
  await alan.initChat({ engines, sessions: options?.storage });
74
92
  assert(utilitas.countKeys(ai), 'No AI provider is configured.');
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.117",
4
+ "version": "1990.1.119",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/Leask/halbot",
7
7
  "type": "module",
@@ -46,7 +46,7 @@
46
46
  "openai": "^4.24.1",
47
47
  "telegraf": "^4.15.3",
48
48
  "tesseract.js": "^5.0.4",
49
- "utilitas": "^1995.2.46",
49
+ "utilitas": "^1995.2.47",
50
50
  "youtube-transcript": "^1.0.6"
51
51
  }
52
52
  }
@@ -4,7 +4,10 @@ let configuredAi;
4
4
 
5
5
  const action = async (ctx, next) => {
6
6
  ctx.isDefaultAi = name => name === ctx.firstAi;
7
- ctx.firstAi = (configuredAi = Object.keys(ctx._.ai))[0];
7
+ const arrSort = (configuredAi = Object.keys(ctx._.ai)).map(
8
+ k => [k, ctx._.ai[k].priority]
9
+ ).sort((x, y) => x[1] - y[1]);
10
+ ctx.firstAi = arrSort[0][0];
8
11
  switch (ctx.session.config?.ai) {
9
12
  case '': ctx.selectedAi = [ctx.firstAi]; break;
10
13
  case '@': ctx.selectedAi = configuredAi; break;