utilitas 1999.1.21 → 1999.1.22

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
@@ -65,7 +65,7 @@ const [
65
65
  TOOL, silent, GEMINI_EMBEDDING_M, INVALID_FILE, tokenSafeRatio,
66
66
  GPT_QUERY_LIMIT, CONTENT_IS_REQUIRED, OPENAI_HI_RES_SIZE, k, kT, m, minute,
67
67
  hour, gb, trimTailing, EBD, GEMINI_20_FLASH_EXP, IMAGE, JINA,
68
- JINA_DEEPSEARCH, JINA_CLIP,
68
+ JINA_DEEPSEARCH, JINA_CLIP, VERTEX,
69
69
  ] = [
70
70
  'OpenAI', 'Gemini', 'OPENAI_TRAINING', 'Ollama', 'gpt-4o-mini',
71
71
  'gpt-4o', 'o1', 'o3-mini', 'gemini-2.0-flash',
@@ -84,7 +84,7 @@ const [
84
84
  x => 1024 * 1024 * x, x => 60 * x, x => 60 * 60 * x,
85
85
  x => 1024 * 1024 * 1024 * x, x => x.replace(/[\.\s]*$/, ''),
86
86
  { embedding: true }, 'gemini-2.0-flash-exp', 'image', 'Jina',
87
- 'jina-deepsearch-v1', 'jina-clip-v2',
87
+ 'jina-deepsearch-v1', 'jina-clip-v2', 'Vertex',
88
88
  ];
89
89
 
90
90
  const [tool, messages, text]
@@ -236,9 +236,9 @@ const DEFAULT_EMBEDDING = {
236
236
  };
237
237
 
238
238
  const PROVIDER_ICONS = {
239
- [OPENAI]: '⚛️', [AZURE_OPENAI]: '⚛️',
239
+ [OPENAI]: '⚛️', [AZURE_OPENAI]: '⚛️', [AZURE]: '☁️', [JINA]: '✴️',
240
+ [GEMINI]: '♊️', [VERTEX]: '📖', [OLLAMA]: '🦙',
240
241
  [ANTHROPIC]: '✳️', [VERTEX_ANTHROPIC]: '✳️',
241
- [GEMINI]: '♊️', [AZURE]: '☁️', [OLLAMA]: '🦙', [JINA]: '✴️',
242
242
  };
243
243
 
244
244
  const FEATURE_ICONS = {
@@ -261,7 +261,7 @@ let tokeniser;
261
261
 
262
262
  const unifyProvider = provider => {
263
263
  assert(provider = (provider || '').trim(), 'AI provider is required.');
264
- for (let type of [OPENAI, AZURE_OPENAI, AZURE, GEMINI, ANTHROPIC,
264
+ for (let type of [OPENAI, AZURE_OPENAI, AZURE, GEMINI, VERTEX, ANTHROPIC,
265
265
  VERTEX_ANTHROPIC, JINA, OLLAMA]) {
266
266
  if (insensitiveCompare(provider, type)) { return type; }
267
267
  }
@@ -347,18 +347,18 @@ const toolsClaude = async () => (await toolsOpenAI()).map(x => ({
347
347
  }
348
348
  }));
349
349
 
350
- const toolsGemini = async () => (await toolsOpenAI()).map(x => ({
350
+ const toolsGemini = async (options) => (await toolsOpenAI()).map(x => ({
351
351
  ...x, def: {
352
- name: x.def.function.name,
353
- description: x.def.function.description,
352
+ name: x.def.function.name, description: x.def.function.description,
354
353
  parameters: {
355
354
  type: 'object',
356
355
  properties: x.def.function.parameters.properties,
357
356
  required: x.def.function.parameters.required,
358
- },
359
- // Vertex API only: response: x.def.function?.response ?? {
360
- // type: 'string', description: 'It could be a string or JSON',
361
- // },
357
+ }, ...options?.provider === 'VERTEX' ? {
358
+ response: x.def.function?.response ?? {
359
+ type: 'string', description: 'It could be a string or JSON',
360
+ }
361
+ } : {},
362
362
  }
363
363
  }));
364
364
 
@@ -426,8 +426,8 @@ const init = async (options = {}) => {
426
426
  setupAi({ provider, model, client, prompt: promptOpenAI });
427
427
  break;
428
428
  case GEMINI:
429
- assertApiKey(provider, options);
430
- const { GoogleGenAI } = await need('@google/genai');
429
+ assert(options.apiKey, `${provider} api key is required.`);
430
+ var { GoogleGenAI } = await need('@google/genai');
431
431
  var client = new GoogleGenAI(options);
432
432
  for (let model of models) {
433
433
  setupAi({
@@ -436,6 +436,21 @@ const init = async (options = {}) => {
436
436
  });
437
437
  }
438
438
  break;
439
+ case VERTEX:
440
+ assert(options.credentials && options.project,
441
+ `${provider} credentials and project id are required.`);
442
+ process.env['GOOGLE_APPLICATION_CREDENTIALS'] = options.credentials;
443
+ var { GoogleGenAI } = await need('@google/genai');
444
+ var client = new GoogleGenAI({
445
+ vertexai: true, location: 'us-east5', ...options
446
+ });
447
+ for (let model of models) {
448
+ setupAi({
449
+ provider, model, client,
450
+ prompt: promptGemini, embedding: createGeminiEmbedding,
451
+ });
452
+ }
453
+ break;
439
454
  case ANTHROPIC:
440
455
  assertApiKey(provider, options);
441
456
  var client = new ((
@@ -447,7 +462,8 @@ const init = async (options = {}) => {
447
462
  break;
448
463
  case VERTEX_ANTHROPIC:
449
464
  // https://github.com/anthropics/anthropic-sdk-typescript/tree/main/packages/vertex-sdk
450
- assert(options?.credentials, `${provider} api credentials are required.`);
465
+ assert(options.credentials && options.projectId,
466
+ `${provider} credentials and project id are required.`);
451
467
  process.env['GOOGLE_APPLICATION_CREDENTIALS'] = options.credentials;
452
468
  process.env['ANTHROPIC_VERTEX_PROJECT_ID'] = options.projectId;
453
469
  var model = models[0];
@@ -1126,7 +1142,7 @@ const packGeminiReferences = (chunks, supports) => {
1126
1142
  };
1127
1143
 
1128
1144
  const promptGemini = async (aiId, content, options = {}) => {
1129
- let { client, model } = await getAi(aiId);
1145
+ let { provider, client, model } = await getAi(aiId);
1130
1146
  let [event, result, references, functionCalls, responded, images] =
1131
1147
  [null, options.result ?? '', null, [], false, []];
1132
1148
  options.model = options.model || model.name;
@@ -1153,7 +1169,7 @@ const promptGemini = async (aiId, content, options = {}) => {
1153
1169
  // { googleSearch: {} },
1154
1170
  {
1155
1171
  functionDeclarations: (
1156
- await toolsGemini()
1172
+ await toolsGemini({ provider })
1157
1173
  ).map(x => x.def)
1158
1174
  },
1159
1175
  ], toolConfig: { functionCallingConfig: { mode: 'AUTO' } },
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": "1999.1.21",
4
+ "version": "1999.1.22",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/Leask/utilitas",
7
7
  "main": "index.mjs",
@@ -33,7 +33,6 @@ const manifest = {
33
33
  "@google-cloud/text-to-speech": "^6.0.0",
34
34
  "@google-cloud/vision": "^5.0.0",
35
35
  "@google/genai": "^0.4.0",
36
- "@google/generative-ai": "^0.24.0",
37
36
  "@mozilla/readability": "github:mozilla/readability",
38
37
  "@sentry/node": "^9.6.0",
39
38
  "@sentry/profiling-node": "^9.6.0",
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": "1999.1.21",
4
+ "version": "1999.1.22",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/Leask/utilitas",
7
7
  "main": "index.mjs",
@@ -44,7 +44,6 @@
44
44
  "@google-cloud/text-to-speech": "^6.0.0",
45
45
  "@google-cloud/vision": "^5.0.0",
46
46
  "@google/genai": "^0.4.0",
47
- "@google/generative-ai": "^0.24.0",
48
47
  "@mozilla/readability": "github:mozilla/readability",
49
48
  "@sentry/node": "^9.6.0",
50
49
  "@sentry/profiling-node": "^9.6.0",