@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 +1 -1
- package/src/lib/common/common.ts +6 -3
package/package.json
CHANGED
package/src/lib/common/common.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
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
|
-
//
|
|
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
|
};
|