utilitas 1998.2.42 → 1998.2.44

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
@@ -54,7 +54,7 @@ const [
54
54
  CLAUDE_35_HAIKU, CLOUD_37_SONNET, AUDIO, WAV, CHATGPT_MINI, ATTACHMENTS,
55
55
  CHAT, OPENAI_VOICE, MEDIUM, LOW, HIGH, GPT_REASONING_EFFORT, THINK,
56
56
  THINK_STR, THINK_END, AZURE, TOOLS_STR, TOOLS_END, TOOLS, TEXT, THINKING,
57
- OK, FUNC,
57
+ OK, FUNC, GPT_45,
58
58
  ] = [
59
59
  'OPENAI', 'GEMINI', 'CHATGPT', 'OPENAI_EMBEDDING', 'GEMINI_EMEDDING',
60
60
  'OPENAI_TRAINING', 'OLLAMA', 'CLAUDE', 'gpt-4o-mini', 'gpt-4o', 'o1',
@@ -67,6 +67,7 @@ const [
67
67
  '[ATTACHMENTS]', 'CHAT', 'OPENAI_VOICE', 'medium', 'low', 'high',
68
68
  'medium', 'think', '<think>', '</think>', 'AZURE', '<tools>',
69
69
  '</tools>', 'tools', 'text', 'thinking', 'OK', 'function',
70
+ 'gpt-4.5-preview',
70
71
  ];
71
72
 
72
73
  const [
@@ -147,9 +148,9 @@ const MODELS = {
147
148
  contextWindow: 128000,
148
149
  imageCostTokens: 1105,
149
150
  maxOutputTokens: 16384,
150
- requestLimitsRPM: 5000,
151
- tokenLimitsTPD: 40000000,
152
- tokenLimitsTPM: 4000000,
151
+ requestLimitsRPM: 10000,
152
+ tokenLimitsTPD: 1000000000,
153
+ tokenLimitsTPM: 10000000,
153
154
  trainingData: 'Oct 2023',
154
155
  json: true,
155
156
  vision: true,
@@ -166,9 +167,9 @@ const MODELS = {
166
167
  contextWindow: 128000,
167
168
  imageCostTokens: 1105,
168
169
  maxOutputTokens: 16384,
169
- requestLimitsRPM: 5000,
170
- tokenLimitsTPD: 100000000,
171
- tokenLimitsTPM: 800000,
170
+ requestLimitsRPM: 10000,
171
+ tokenLimitsTPD: 20000000,
172
+ tokenLimitsTPM: 2000000,
172
173
  trainingData: 'Oct 2023',
173
174
  json: true,
174
175
  vision: true,
@@ -185,9 +186,9 @@ const MODELS = {
185
186
  contextWindow: 200000,
186
187
  imageCostTokens: 1105,
187
188
  maxOutputTokens: 100000,
188
- requestLimitsRPM: 500,
189
- tokenLimitsTPD: 100000000,
190
- tokenLimitsTPM: 800000,
189
+ requestLimitsRPM: 10000,
190
+ tokenLimitsTPD: 200000000,
191
+ tokenLimitsTPM: 2000000,
191
192
  trainingData: 'Oct 2023',
192
193
  json: true,
193
194
  reasoning: true,
@@ -205,9 +206,9 @@ const MODELS = {
205
206
  contextWindow: 200000,
206
207
  imageCostTokens: 1105,
207
208
  maxOutputTokens: 100000,
208
- requestLimitsRPM: 5000,
209
- tokenLimitsTPD: 40000000,
210
- tokenLimitsTPM: 4000000,
209
+ requestLimitsRPM: 10000,
210
+ tokenLimitsTPD: 1000000000,
211
+ tokenLimitsTPM: 10000000,
211
212
  trainingData: 'Oct 2023',
212
213
  json: true,
213
214
  reasoning: true,
@@ -221,6 +222,21 @@ const MODELS = {
221
222
  // wav,
222
223
  // ],
223
224
  },
225
+ [GPT_45]: {
226
+ contextWindow: 128000,
227
+ imageCostTokens: 1105,
228
+ maxOutputTokens: 16384,
229
+ requestLimitsRPM: 10000,
230
+ tokenLimitsTPD: 100000000,
231
+ tokenLimitsTPM: 1000000,
232
+ json: true,
233
+ vision: true,
234
+ tools: true,
235
+ supportedMimeTypes: [
236
+ png, jpeg, gif, webp,
237
+ ],
238
+ trainingData: 'Oct 2023',
239
+ },
224
240
  [GEMINI_20_FLASH]: {
225
241
  // https://ai.google.dev/gemini-api/docs/models/gemini
226
242
  // https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/send-multimodal-prompts?hl=en#gemini-send-multimodal-samples-pdf-nodejs
@@ -628,8 +644,10 @@ const buildClaudeMessage = (text, options) => {
628
644
  }
629
645
  });
630
646
  return String.isString(text) ? {
631
- role: options?.role || user,
632
- content: [...attachments, { type: TEXT, text }],
647
+ role: options?.role || user, content: [...attachments, {
648
+ type: TEXT, text,
649
+ cache_control: options?.cache_control ?? { type: 'ephemeral' }
650
+ }],
633
651
  } : text;
634
652
  };
635
653
 
@@ -655,10 +673,11 @@ const streamResp = async (resp, options) => {
655
673
  };
656
674
 
657
675
  const getInfoEnd = text => Math.max(...[THINK_END, TOOLS_END].map(x => {
658
- const keyEnd = text.indexOf(`${x}\n`);
676
+ const keyEnd = text.indexOf(text.endsWith(x) ? x : `${x}\n`);
659
677
  return keyEnd >= 0 ? (keyEnd + x.length) : 0;
660
678
  }));
661
679
 
680
+ // @todo: escape ``` in think and tools
662
681
  const packResp = async (resp, options) => {
663
682
  if (options?.raw) { return resp; }
664
683
  let [txt, audio, references, simpleText, referencesMarkdown, end, json] = [
@@ -1018,18 +1037,25 @@ const promptOllama = async (content, options = {}) => {
1018
1037
 
1019
1038
  const promptClaude = async (content, options = {}) => {
1020
1039
  options.model = options.model || DEFAULT_MODELS[CLAUDE];
1021
- let [_MODEL, event, text, thinking, signature, result, thinkEnd, tool_use]
1022
- = [MODELS[options.model], null, '', '', '', options.result ?? '', '', []];
1040
+ let [
1041
+ _MODEL, event, text, thinking, signature, result, thinkEnd, tool_use,
1042
+ responded
1043
+ ] = [
1044
+ MODELS[options.model], null, '', '', '', options.result ?? '', '',
1045
+ [], false
1046
+ ];
1023
1047
  const { client } = await getClaudeClient(options);
1024
1048
  const { history }
1025
1049
  = await buildPrompts(_MODEL, content, { ...options, flavor: CLAUDE });
1026
- const resp = await client.messages.create({
1050
+ const resp = await client.beta.messages.create({
1027
1051
  model: options.model, max_tokens: _MODEL.maxOutputTokens, ...history,
1028
1052
  stream: true, ...options.reasoning ?? _MODEL?.reasoning ? {
1029
1053
  thinking: options.thinking || { type: 'enabled', budget_tokens: 1024 },
1030
1054
  } : {}, ..._MODEL?.tools ? { // https://docs.anthropic.com/en/docs/build-with-claude/extended-thinking
1031
1055
  tools: options.tools ?? toolsClaude.map(x => x.def),
1032
1056
  tool_choice: { type: 'auto' },
1057
+ betas: ['token-efficient-tools-2025-02-19'],
1058
+ // @todo: https://docs.anthropic.com/en/docs/build-with-claude/tool-use/token-efficient-tool-use
1033
1059
  } : {},
1034
1060
  });
1035
1061
  for await (const chunk of resp) {
@@ -1048,6 +1074,8 @@ const promptClaude = async (content, options = {}) => {
1048
1074
  tool_use[tool_use.length - 1].input += event.partial_json;
1049
1075
  }
1050
1076
  deltaText = deltaThink + deltaText;
1077
+ options.result && deltaText
1078
+ && (responded = responded || (deltaText = `\n\n${deltaText}`));
1051
1079
  result += deltaText;
1052
1080
  deltaText && await streamResp({
1053
1081
  text: options.delta ? deltaText : result,
@@ -1143,7 +1171,6 @@ const promptGemini = async (content, options = {}) => {
1143
1171
  ) : {},
1144
1172
  });
1145
1173
  // https://github.com/google/generative-ai-js/blob/main/samples/node/advanced-chat.js
1146
- // @todo: check this issue similar to Vertex AI:
1147
1174
  // Google's bug: history is not allowed while using inline_data?
1148
1175
  const chat = client.startChat({ history, ...generationConfig(options) });
1149
1176
  const resp = await chat.sendMessageStream(prompt);
@@ -1508,9 +1535,8 @@ export {
1508
1535
  ATTACHMENT_TOKEN_COST, CLOUD_37_SONNET, CODE_INTERPRETER, DEEPSEEK_R1,
1509
1536
  DEEPSEEK_R1_32B, DEEPSEEK_R1_70B, DEFAULT_MODELS,
1510
1537
  EMBEDDING_001,
1511
- FUNCTION, GEMINI_20_FLASH, GEMINI_20_FLASH_THINKING, GPT_4O, GPT_4O_MINI, GPT_O1, GPT_O3_MINI, INSTRUCTIONS, MODELS,
1512
- OPENAI_VOICE,
1513
- RETRIEVAL,
1538
+ FUNCTION, GEMINI_20_FLASH, GEMINI_20_FLASH_THINKING, GPT_45, GPT_4O, GPT_4O_MINI, GPT_O1, GPT_O3_MINI, INSTRUCTIONS, MODELS,
1539
+ OPENAI_VOICE, RETRIEVAL,
1514
1540
  TEXT_EMBEDDING_3_SMALL, _NEED, analyzeSessions,
1515
1541
  buildGptTrainingCase,
1516
1542
  buildGptTrainingCases,
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": "1998.2.42",
4
+ "version": "1998.2.44",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/Leask/utilitas",
7
7
  "main": "index.mjs",
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": "1998.2.42",
4
+ "version": "1998.2.44",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/Leask/utilitas",
7
7
  "main": "index.mjs",