@razzium/piece-aimw-api 0.0.16 → 0.0.17

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@razzium/piece-aimw-api",
3
- "version": "0.0.16",
3
+ "version": "0.0.17",
4
4
  "dependencies": {
5
5
  "tiktoken": "1.0.11"
6
6
  }
@@ -1,4 +1,4 @@
1
- import { encoding_for_model } from 'tiktoken';
1
+ // tiktoken est importé dynamiquement dans calculateTokensFromString pour éviter crash à l'import
2
2
 
3
3
  export const baseUrl = 'https://rekto.dashboard.aimw.ai/api';
4
4
 
@@ -86,13 +86,16 @@ export const streamToBuffer = (stream: any) => {
86
86
 
87
87
  export const calculateTokensFromString = (string: string, model: string) => {
88
88
  try {
89
- const encoder = encoding_for_model(model as any);
89
+ // Import dynamique pour éviter crash à l'import du module
90
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
91
+ const tiktoken = require('tiktoken');
92
+ const encoder = tiktoken.encoding_for_model(model as any);
90
93
  const tokens = encoder.encode(string);
91
94
  encoder.free();
92
95
 
93
96
  return tokens.length;
94
97
  } catch (e) {
95
- // Model not supported by tiktoken, every 4 chars is a token
98
+ // Tiktoken non disponible ou model non supporté - fallback: ~4 chars par token
96
99
  return Math.round(string.length / 4);
97
100
  }
98
101
  };