utilitas 1998.2.19 → 1998.2.20

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
@@ -318,6 +318,7 @@ const MODELS = {
318
318
  tokenLimitsITPM: 40000,
319
319
  tokenLimitsOTPM: 8000,
320
320
  trainingData: 'Apr 2024', // ?
321
+ reasoning: true,
321
322
  supportedMimeTypes: [
322
323
  png, jpeg, gif, webp, pdf,
323
324
  ],
@@ -743,16 +744,27 @@ const promptOllama = async (content, options = {}) => {
743
744
  const promptClaude = async (content, options = {}) => {
744
745
  const { client } = await getClaudeClient(options);
745
746
  options.model = options?.model || DEFAULT_MODELS[CLAUDE];
747
+ const reasoning = options?.reasoning ?? MODELS[options.model]?.reasoning;
746
748
  const resp = await client.messages.create({
747
749
  model: options.model, max_tokens: MODELS[options.model].maxOutputTokens,
748
750
  messages: [
749
751
  ...options?.messages || [], buildClaudeMessage(content, options)
750
- ], stream: !!options?.stream,
752
+ ], stream: !!options?.stream, ...reasoning ? {
753
+ thinking: options?.thinking || { type: 'enabled', budget_tokens: 1024 },
754
+ } : {} // https://docs.anthropic.com/en/docs/build-with-claude/extended-thinking
751
755
  });
752
- let [event, result] = [null, ''];
756
+ let [event, result, thinkEnd] = [null, '', ''];
753
757
  if (options?.stream) {
754
758
  for await (event of resp) {
755
- const delta = event?.content_block?.text || event?.delta?.text || '';
759
+ let [thkDelta, txtDelta] = [
760
+ event?.content_block?.thinking || event?.delta?.thinking || '',
761
+ event?.content_block?.text || event?.delta?.text || '',
762
+ ];
763
+ if (reasoning) {
764
+ !result && thkDelta && (thkDelta = `${THINK_STR}\n${thkDelta}`);
765
+ result && txtDelta && !thinkEnd && (thinkEnd = thkDelta = `${thkDelta}\n${THINK_END}\n\n`);
766
+ }
767
+ const delta = thkDelta + txtDelta;
756
768
  if (delta === '') { continue; }
757
769
  result += delta;
758
770
  event.content = { text: options?.delta ? delta : result };
@@ -852,7 +864,7 @@ const promptGemini = async (content, options) => {
852
864
  // Google's bug: history is not allowed while using inline_data?
853
865
  assert(!(
854
866
  options?.jsonMode && MODELS[genModel]?.json == false
855
- ), `This model does not support JSON output: ${genModel}`);
867
+ ), `This model does not support JSON output: ${genModel} `);
856
868
  const chat = generative.startChat({
857
869
  history: options?.messages && !options?.attachments?.length
858
870
  ? options.messages : [],
@@ -948,7 +960,7 @@ const listGptFineTuningEvents = async (job_id, options) => {
948
960
 
949
961
  const tailGptFineTuningEvents = async (job_id, options) => {
950
962
  assert(job_id, 'Job ID is required.');
951
- const [loopName, listOpts] = [`GPT-${job_id}`, {
963
+ const [loopName, listOpts] = [`GPT - ${job_id} `, {
952
964
  ...options, params: { ...options?.params, order: 'ascending' }
953
965
  }];
954
966
  let lastEvent;
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.19",
4
+ "version": "1998.2.20",
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.19",
4
+ "version": "1998.2.20",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/Leask/utilitas",
7
7
  "main": "index.mjs",