utilitas 1995.2.72 → 1995.2.74

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
@@ -4,24 +4,26 @@ import { loop, end } from './event.mjs';
4
4
 
5
5
  import {
6
6
  ensureString, ignoreErrFunc, log as _log, need, renderText as _renderText,
7
- throwError, trim,
7
+ throwError,
8
8
  } from './utilitas.mjs';
9
9
 
10
10
  const _NEED = [
11
11
  '@google-cloud/aiplatform', '@google-cloud/vertexai',
12
- '@google/generative-ai', 'js-tiktoken', 'OpenAI',
12
+ '@google/generative-ai', 'js-tiktoken', 'ollama', 'OpenAI',
13
13
  ];
14
14
 
15
15
  const [
16
- GPT_35_TURBO, GPT_35_TURBO_1106, GPT_4, GPT_4_1106, GPT_4_VISION,
17
- GEMINI_PRO, GEMINI_PRO_VISION, TEXT_EMBEDDING_ADA_002, EMBEDDING_001,
18
- EMBEDDING_GECKO_001, EMBEDDING_GECKO_002, EMBEDDING_GECKO_ML001, MISTRAL,
16
+ GPT_35_TURBO, GPT_35_TURBO_16K, GPT_4, GPT_4_VISION, GEMINI_PRO,
17
+ GEMINI_PRO_VISION, EMBEDDING_001, EMBEDDING_GECKO_001, EMBEDDING_GECKO_002,
18
+ EMBEDDING_GECKO_ML001, MISTRAL, TEXT_EMBEDDING_3_SMALL,
19
+ TEXT_EMBEDDING_3_LARGE, GPT_4_TURBO
19
20
  ] = [
20
- 'gpt-3.5-turbo', 'gpt-3.5-turbo-1106', 'gpt-4', 'gpt-4-1106',
21
- 'gpt-4-vision-preview', 'gemini-pro', 'gemini-pro-vision',
22
- 'text-embedding-ada-002', 'embedding-001', 'textembedding-gecko@001',
23
- 'textembedding-gecko@002', 'textembedding-gecko-multilingual@001',
24
- 'mistral',
21
+ 'gpt-3.5-turbo', 'gpt-3.5-turbo-1106', 'gpt-4', 'gpt-4-vision-preview',
22
+ 'gemini-pro', 'gemini-pro-vision', 'embedding-001',
23
+ 'textembedding-gecko@001', 'textembedding-gecko@002',
24
+ 'textembedding-gecko-multilingual@001', 'mistral',
25
+ 'text-embedding-3-small', 'text-embedding-3-large',
26
+ 'gpt-4-turbo-preview',
25
27
  ];
26
28
 
27
29
  const [tool, provider, messages, text] = [
@@ -75,8 +77,8 @@ const DEFAULT_MODELS = {
75
77
  [GEMINI_EMEDDING]: EMBEDDING_001,
76
78
  [GEMINI]: GEMINI_PRO,
77
79
  [OLLAMA]: MISTRAL,
78
- [OPENAI_EMBEDDING]: TEXT_EMBEDDING_ADA_002,
79
- [OPENAI_TRAINING]: GPT_35_TURBO_1106,
80
+ [OPENAI_EMBEDDING]: TEXT_EMBEDDING_3_SMALL,
81
+ [OPENAI_TRAINING]: GPT_35_TURBO_16K,
80
82
  [VERTEX_EMEDDING]: EMBEDDING_GECKO_ML001,
81
83
  [VERTEX]: GEMINI_PRO_VISION,
82
84
  };
@@ -88,7 +90,7 @@ const chatConfig = {
88
90
  let tokeniser;
89
91
 
90
92
  // https://platform.openai.com/docs/models/continuous-model-upgrades
91
- // https://platform.openai.com/account/limits // Tier 2
93
+ // https://platform.openai.com/account/limits // Tier 3
92
94
  // https://cloud.google.com/vertex-ai/docs/generative-ai/model-reference/gemini
93
95
  // https://cloud.google.com/vertex-ai/docs/generative-ai/learn/models
94
96
  const MODELS = {
@@ -98,7 +100,7 @@ const MODELS = {
98
100
  requestLimitsRPM: 5000,
99
101
  trainingData: 'Sep 2021',
100
102
  },
101
- [GPT_35_TURBO_1106]: {
103
+ [GPT_35_TURBO_16K]: {
102
104
  contextWindow: 16385,
103
105
  maxOutputTokens: 4096,
104
106
  tokenLimitsTPM: 160000,
@@ -111,7 +113,7 @@ const MODELS = {
111
113
  requestLimitsRPM: 5000,
112
114
  trainingData: 'Sep 2021',
113
115
  },
114
- [GPT_4_1106]: {
116
+ [GPT_4_TURBO]: {
115
117
  contextWindow: 128000,
116
118
  maxOutputTokens: 4096,
117
119
  tokenLimitsTPM: 300000,
@@ -154,11 +156,20 @@ const MODELS = {
154
156
  tokenLimitsTPM: Infinity,
155
157
  requestLimitsRPM: Infinity,
156
158
  },
157
- [TEXT_EMBEDDING_ADA_002]: {
158
- contextWindow: 8192,
159
+ [TEXT_EMBEDDING_3_SMALL]: {
160
+ contextWindow: 8191,
161
+ outputDimension: 1536,
162
+ tokenLimitsTPM: 1000000,
163
+ requestLimitsRPM: 500,
164
+ trainingData: 'Sep 2021',
165
+ embedding: true,
166
+ },
167
+ [TEXT_EMBEDDING_3_LARGE]: {
168
+ contextWindow: 8191,
169
+ outputDimension: 3072, // ERROR: column cannot have more than 2000 dimensions for hnsw index
159
170
  tokenLimitsTPM: 1000000,
160
171
  requestLimitsRPM: 500,
161
- trainingData: 'Oct 2019',
172
+ trainingData: 'Sep 2021',
162
173
  embedding: true,
163
174
  },
164
175
  [GEMINI_EMEDDING]: {
@@ -260,8 +271,11 @@ const init = async (options) => {
260
271
  }
261
272
  break;
262
273
  case OLLAMA:
274
+ const Ollama = await need('ollama');
263
275
  clients[provider] = {
264
- endpoint: options?.endpoint || 'http://localhost:11434',
276
+ // @todo: this feature does not work yet.
277
+ // client: new Ollama({ host: options?.endpoint })
278
+ client: Ollama,
265
279
  };
266
280
  break;
267
281
  default:
@@ -363,32 +377,21 @@ const promptChatGPT = async (content, options) => {
363
377
  };
364
378
 
365
379
  const promptOllama = async (content, options) => {
366
- // @todo: Is it cool to use Ollama official API instead this implementation:
380
+ const { client } = await getOllamaClient(options);
367
381
  // https://github.com/ollama/ollama-js
368
- const { endpoint } = await getOllamaClient(options);
369
382
  // https://github.com/jmorganca/ollama/blob/main/examples/typescript-simplechat/client.ts
370
- const resp = await fetch(`${endpoint}/api/chat`, {
371
- method: 'POST', body: JSON.stringify({
372
- ...messages([...options?.messages || [], buildGptMessage(content)]),
373
- model: options?.model || DEFAULT_MODELS[OLLAMA],
374
- }),
375
- });
376
- const reader = resp.body?.getReader();
377
- reader || throwError('Failed to request Ollama API.');
383
+ const resp = await client.chat({
384
+ model: options?.model || DEFAULT_MODELS[OLLAMA], stream: true,
385
+ ...messages([...options?.messages || [], buildGptMessage(content)]),
386
+ })
378
387
  let [chunk, result] = [null, ''];
379
- while (true) {
380
- const { done, value } = await reader.read();
381
- if (done) { break; }
382
- const jsonl = trim(new TextDecoder().decode(value)).split('\n');
383
- for (const line of jsonl) {
384
- chunk = await ignoreErrFunc(() => JSON.parse(line));
385
- result += chunk.message?.content || '';
386
- chunk.done || await ignoreErrFunc(async () =>
387
- await options?.stream?.(
388
- options?.raw ? chunk : packResp(result)
389
- ), LOG
390
- );
391
- }
388
+ for await (chunk of resp) {
389
+ result += chunk.message?.content || '';
390
+ chunk.done || await ignoreErrFunc(async () =>
391
+ await options?.stream?.(
392
+ options?.raw ? chunk : packResp(result)
393
+ ), LOG
394
+ );
392
395
  }
393
396
  return { response: options?.raw ? chunk : packResp(result) };
394
397
  };
@@ -957,15 +960,15 @@ export {
957
960
  FUNCTION,
958
961
  GEMINI_PRO_VISION,
959
962
  GEMINI_PRO,
960
- GPT_35_TURBO_1106,
963
+ GPT_35_TURBO_16K,
961
964
  GPT_35_TURBO,
962
- GPT_4_1106,
965
+ GPT_4_TURBO,
963
966
  GPT_4_VISION,
964
967
  GPT_4,
965
968
  MISTRAL,
966
969
  MODELS,
967
970
  RETRIEVAL,
968
- TEXT_EMBEDDING_ADA_002,
971
+ TEXT_EMBEDDING_3_SMALL,
969
972
  buildGptTrainingCase,
970
973
  buildGptTrainingCases,
971
974
  cancelGptFineTuningJob,
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": "1995.2.72",
4
+ "version": "1995.2.74",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/Leask/utilitas",
7
7
  "main": "index.mjs",
@@ -26,16 +26,16 @@ const manifest = {
26
26
  "devDependencies": {
27
27
  "@ffmpeg-installer/ffmpeg": "^1.1.0",
28
28
  "@ffprobe-installer/ffprobe": "^2.1.2",
29
- "@google-cloud/aiplatform": "^3.10.0",
30
- "@google-cloud/speech": "^6.1.0",
29
+ "@google-cloud/aiplatform": "^3.10.1",
30
+ "@google-cloud/speech": "^6.1.1",
31
31
  "@google-cloud/storage": "^7.7.0",
32
32
  "@google-cloud/text-to-speech": "^5.0.2",
33
33
  "@google-cloud/vertexai": "^0.2.1",
34
- "@google-cloud/vision": "^4.0.2",
34
+ "@google-cloud/vision": "^4.0.3",
35
35
  "@google/generative-ai": "^0.1.3",
36
36
  "@mozilla/readability": "^0.5.0",
37
37
  "@ngrok/ngrok": "^0.9.1",
38
- "@sentry/node": "^7.95.0",
38
+ "@sentry/node": "^7.98.0",
39
39
  "acme-client": "^5.2.0",
40
40
  "browserify-fs": "^1.0.0",
41
41
  "buffer": "^6.0.3",
@@ -49,11 +49,12 @@ const manifest = {
49
49
  "mailgun.js": "^10.0.0",
50
50
  "mailparser": "^3.6.6",
51
51
  "mime-types": "^2.1.35",
52
- "mysql2": "^3.8.0",
52
+ "mysql2": "^3.9.0",
53
53
  "node-mailjet": "^6.0.5",
54
54
  "node-polyfill-webpack-plugin": "^3.0.0",
55
55
  "office-text-extractor": "^3.0.2",
56
- "openai": "^4.25.0",
56
+ "ollama": "^0.4.3",
57
+ "openai": "^4.26.0",
57
58
  "pdfjs-dist": "^4.0.379",
58
59
  "pg": "^8.11.3",
59
60
  "pgvector": "^0.1.7",
@@ -62,7 +63,7 @@ const manifest = {
62
63
  "telegraf": "^4.15.3",
63
64
  "telesignsdk": "^2.2.3",
64
65
  "tesseract.js": "^5.0.4",
65
- "twilio": "^4.20.1",
66
+ "twilio": "^4.21.0",
66
67
  "url": "github:Leask/node-url",
67
68
  "webpack-cli": "^5.1.4",
68
69
  "whisper-node": "^1.1.1",
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": "1995.2.72",
4
+ "version": "1995.2.74",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/Leask/utilitas",
7
7
  "main": "index.mjs",
@@ -37,16 +37,16 @@
37
37
  "devDependencies": {
38
38
  "@ffmpeg-installer/ffmpeg": "^1.1.0",
39
39
  "@ffprobe-installer/ffprobe": "^2.1.2",
40
- "@google-cloud/aiplatform": "^3.10.0",
41
- "@google-cloud/speech": "^6.1.0",
40
+ "@google-cloud/aiplatform": "^3.10.1",
41
+ "@google-cloud/speech": "^6.1.1",
42
42
  "@google-cloud/storage": "^7.7.0",
43
43
  "@google-cloud/text-to-speech": "^5.0.2",
44
44
  "@google-cloud/vertexai": "^0.2.1",
45
- "@google-cloud/vision": "^4.0.2",
45
+ "@google-cloud/vision": "^4.0.3",
46
46
  "@google/generative-ai": "^0.1.3",
47
47
  "@mozilla/readability": "^0.5.0",
48
48
  "@ngrok/ngrok": "^0.9.1",
49
- "@sentry/node": "^7.95.0",
49
+ "@sentry/node": "^7.98.0",
50
50
  "acme-client": "^5.2.0",
51
51
  "browserify-fs": "^1.0.0",
52
52
  "buffer": "^6.0.3",
@@ -60,11 +60,12 @@
60
60
  "mailgun.js": "^10.0.0",
61
61
  "mailparser": "^3.6.6",
62
62
  "mime-types": "^2.1.35",
63
- "mysql2": "^3.8.0",
63
+ "mysql2": "^3.9.0",
64
64
  "node-mailjet": "^6.0.5",
65
65
  "node-polyfill-webpack-plugin": "^3.0.0",
66
66
  "office-text-extractor": "^3.0.2",
67
- "openai": "^4.25.0",
67
+ "ollama": "^0.4.3",
68
+ "openai": "^4.26.0",
68
69
  "pdfjs-dist": "^4.0.379",
69
70
  "pg": "^8.11.3",
70
71
  "pgvector": "^0.1.7",
@@ -73,7 +74,7 @@
73
74
  "telegraf": "^4.15.3",
74
75
  "telesignsdk": "^2.2.3",
75
76
  "tesseract.js": "^5.0.4",
76
- "twilio": "^4.20.1",
77
+ "twilio": "^4.21.0",
77
78
  "url": "github:Leask/node-url",
78
79
  "webpack-cli": "^5.1.4",
79
80
  "whisper-node": "^1.1.1",