utilitas 1998.2.57 → 1998.2.59

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, GPT_45,
57
+ OK, FUNC, GPT_45, REDACTED_THINKING, GEMMA_3_27B,
58
58
  ] = [
59
59
  'OPENAI', 'GEMINI', 'CHATGPT', 'OPENAI_EMBEDDING', 'GEMINI_EMEDDING',
60
60
  'OPENAI_TRAINING', 'OLLAMA', 'CLAUDE', 'gpt-4o-mini', 'gpt-4o', 'o1',
@@ -67,7 +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
+ 'gpt-4.5-preview', 'redacted_thinking', 'gemma-3-27b-it',
71
71
  ];
72
72
 
73
73
  const [
@@ -305,6 +305,15 @@ const MODELS = {
305
305
  flac, mp3, m4a, mpga, opus, pcm, wav, webm, tgpp,
306
306
  ],
307
307
  },
308
+ [GEMMA_3_27B]: {
309
+ contextWindow: 128 * 1000,
310
+ imageCostTokens: 256,
311
+ maxImageSize: 896 * 896,
312
+ maxOutputTokens: 1024 * 8,
313
+ vision: true,
314
+ json: true,
315
+ supportedMimeTypes: [png, jpeg],
316
+ },
308
317
  [DEEPSEEK_R1]: {
309
318
  contextWindow: 128 * 1000,
310
319
  maxOutputTokens: 32768,
@@ -806,7 +815,8 @@ const buildPrompts = async (model, input, options = {}) => {
806
815
  prompt = buildOllamaMessage(content, options);
807
816
  break;
808
817
  case GEMINI:
809
- systemPrompt = buildGeminiHistory(options.systemPrompt, _system);
818
+ const _role = { role: options.model === GEMMA_3_27B ? user : system };
819
+ systemPrompt = buildGeminiHistory(options.systemPrompt, _role);
810
820
  prompt = options.toolsResult?.[options.toolsResult?.length - 1]?.parts
811
821
  || buildGeminiMessage(content, options)
812
822
  break;
@@ -844,6 +854,7 @@ const buildPrompts = async (model, input, options = {}) => {
844
854
  break;
845
855
  case GEMINI:
846
856
  history.push(
857
+ ...options.model === GEMMA_3_27B ? [systemPrompt] : [],
847
858
  ...options.toolsResult?.length ? [
848
859
  buildGeminiHistory(content, { ...options, role: user }),
849
860
  ...options.toolsResult.slice(0, options.toolsResult.length - 1)
@@ -861,6 +872,10 @@ const buildPrompts = async (model, input, options = {}) => {
861
872
  content = trimTailing(trimTailing(content).slice(0, -1)) + '...';
862
873
  }
863
874
  }, model.maxInputTokens - options.attachments?.length * ATTACHMENT_TOKEN_COST);
875
+ if ([CHATGPT, OLLAMA].includes(options.flavor)
876
+ || options.model === GEMMA_3_27B) {
877
+ systemPrompt = null;
878
+ }
864
879
  return { systemPrompt, history, prompt };
865
880
  };
866
881
 
@@ -1054,23 +1069,36 @@ const promptClaude = async (content, options = {}) => {
1054
1069
  options.model = options.model || DEFAULT_MODELS[CLAUDE];
1055
1070
  let [
1056
1071
  _MODEL, event, text, thinking, signature, result, thinkEnd, tool_use,
1057
- responded
1072
+ responded, redacted_thinking,
1058
1073
  ] = [
1059
1074
  MODELS[options.model], null, '', '', '', options.result ?? '', '',
1060
- [], false
1075
+ [], false, [],
1061
1076
  ];
1077
+ // https://docs.anthropic.com/en/docs/build-with-claude/extended-thinking
1078
+ options?.test_redacted_thinking && !options?.result && (
1079
+ content += '\n\nANTHROPIC_MAGIC_STRING_TRIGGER_REDACTED_THINKING_'
1080
+ + '46C9A13E193C177646C7398A98432ECCCE4C1253D5E2D82641AC0E52CC2876CB'
1081
+ );
1062
1082
  const { client } = await getClaudeClient(options);
1063
1083
  const { systemPrompt: system, history }
1064
1084
  = await buildPrompts(_MODEL, content, { ...options, flavor: CLAUDE });
1065
1085
  const resp = await client.beta.messages.create({
1066
- model: options.model, max_tokens: _MODEL.maxOutputTokens, ...history,
1067
- system, stream: true, ...options.reasoning ?? _MODEL?.reasoning ? {
1068
- thinking: options.thinking || { type: 'enabled', budget_tokens: 1024 },
1069
- } : {}, ..._MODEL?.tools ? { // https://docs.anthropic.com/en/docs/build-with-claude/extended-thinking
1086
+ model: options.model,
1087
+ max_tokens: options?.extendedThinking ? 128000 : _MODEL.maxOutputTokens,
1088
+ ...history, system, stream: true,
1089
+ ...options.reasoning ?? _MODEL?.reasoning ? {
1090
+ thinking: options.thinking || {
1091
+ type: 'enabled',
1092
+ budget_tokens: options?.extendedThinking ? 16000 : 1024,
1093
+ },
1094
+ } : {}, ..._MODEL?.tools ? {
1070
1095
  tools: options.tools ?? (await toolsClaude()).map(x => x.def),
1071
- tool_choice: { type: 'auto' },
1072
- betas: ['token-efficient-tools-2025-02-19'],
1073
- // @todo: https://docs.anthropic.com/en/docs/build-with-claude/tool-use/token-efficient-tool-use
1096
+ tool_choice: { type: 'auto' }, betas: [
1097
+ // https://docs.anthropic.com/en/docs/build-with-claude/tool-use/token-efficient-tool-use
1098
+ 'token-efficient-tools-2025-02-19',
1099
+ // https://docs.anthropic.com/en/docs/build-with-claude/extended-thinking
1100
+ ...options?.extendedThinking ? ['output-128k-2025-02-19'] : [],
1101
+ ],
1074
1102
  } : {},
1075
1103
  });
1076
1104
  for await (const chunk of resp) {
@@ -1083,6 +1111,7 @@ const promptClaude = async (content, options = {}) => {
1083
1111
  && (deltaThink = `${THINK_STR}\n${deltaThink}`);
1084
1112
  thinking && deltaText && !thinkEnd
1085
1113
  && (thinkEnd = deltaThink = `${deltaThink}\n${THINK_END}\n\n`);
1114
+ event?.type === REDACTED_THINKING && redacted_thinking.push(event);
1086
1115
  if (event?.type === 'tool_use') {
1087
1116
  tool_use.push({ ...event, input: '' });
1088
1117
  } else if (event.partial_json) {
@@ -1099,6 +1128,7 @@ const promptClaude = async (content, options = {}) => {
1099
1128
  event = {
1100
1129
  role: assistant, content: [
1101
1130
  ...thinking ? [{ type: THINKING, thinking, signature }] : [],
1131
+ ...redacted_thinking,
1102
1132
  ...text ? [{ type: TEXT, text }] : [], ...tool_use,
1103
1133
  ]
1104
1134
  };
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.57",
4
+ "version": "1998.2.59",
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.57",
4
+ "version": "1998.2.59",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/Leask/utilitas",
7
7
  "main": "index.mjs",