@smythos/sre 1.7.1 → 1.7.7

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.
Files changed (53) hide show
  1. package/dist/index.js +33 -31
  2. package/dist/index.js.map +1 -1
  3. package/dist/types/Core/ConnectorsService.d.ts +2 -1
  4. package/dist/types/Core/SmythRuntime.class.d.ts +1 -0
  5. package/dist/types/helpers/BinaryInput.helper.d.ts +1 -1
  6. package/dist/types/helpers/LocalCache.helper.d.ts +18 -0
  7. package/dist/types/helpers/TemplateString.helper.d.ts +2 -1
  8. package/dist/types/subsystems/IO/VectorDB.service/VectorDBConnector.d.ts +4 -4
  9. package/dist/types/subsystems/IO/VectorDB.service/connectors/MilvusVectorDB.class.d.ts +2 -2
  10. package/dist/types/subsystems/IO/VectorDB.service/connectors/PineconeVectorDB.class.d.ts +2 -2
  11. package/dist/types/subsystems/IO/VectorDB.service/connectors/RAMVecrtorDB.class.d.ts +2 -2
  12. package/dist/types/subsystems/IO/VectorDB.service/embed/BaseEmbedding.d.ts +16 -9
  13. package/dist/types/subsystems/IO/VectorDB.service/embed/index.d.ts +4 -1
  14. package/dist/types/subsystems/LLMManager/LLM.inference.d.ts +36 -2
  15. package/dist/types/types/LLM.types.d.ts +54 -31
  16. package/dist/types/types/VectorDB.types.d.ts +6 -3
  17. package/dist/types/utils/string.utils.d.ts +0 -4
  18. package/package.json +1 -1
  19. package/src/Components/Classifier.class.ts +8 -2
  20. package/src/Components/GenAILLM.class.ts +11 -7
  21. package/src/Components/LLMAssistant.class.ts +12 -3
  22. package/src/Components/ScrapflyWebScrape.class.ts +8 -1
  23. package/src/Components/TavilyWebSearch.class.ts +4 -1
  24. package/src/Core/ConnectorsService.ts +12 -2
  25. package/src/Core/SmythRuntime.class.ts +32 -17
  26. package/src/helpers/BinaryInput.helper.ts +8 -8
  27. package/src/helpers/Conversation.helper.ts +11 -1
  28. package/src/helpers/LocalCache.helper.ts +18 -0
  29. package/src/helpers/TemplateString.helper.ts +20 -9
  30. package/src/index.ts +208 -208
  31. package/src/index.ts.bak +208 -208
  32. package/src/subsystems/AgentManager/Agent.class.ts +2 -0
  33. package/src/subsystems/AgentManager/AgentData.service/AgentDataConnector.ts +6 -5
  34. package/src/subsystems/AgentManager/AgentLogger.class.ts +1 -1
  35. package/src/subsystems/IO/VectorDB.service/VectorDBConnector.ts +15 -4
  36. package/src/subsystems/IO/VectorDB.service/connectors/MilvusVectorDB.class.ts +31 -10
  37. package/src/subsystems/IO/VectorDB.service/connectors/PineconeVectorDB.class.ts +27 -10
  38. package/src/subsystems/IO/VectorDB.service/connectors/RAMVecrtorDB.class.ts +25 -9
  39. package/src/subsystems/IO/VectorDB.service/embed/BaseEmbedding.ts +182 -12
  40. package/src/subsystems/IO/VectorDB.service/embed/GoogleEmbedding.ts +1 -1
  41. package/src/subsystems/IO/VectorDB.service/embed/OpenAIEmbedding.ts +1 -1
  42. package/src/subsystems/IO/VectorDB.service/embed/index.ts +12 -2
  43. package/src/subsystems/LLMManager/LLM.inference.ts +76 -17
  44. package/src/subsystems/LLMManager/LLM.service/connectors/openai/apiInterfaces/ChatCompletionsApiInterface.ts +3 -2
  45. package/src/subsystems/LLMManager/LLM.service/connectors/openai/apiInterfaces/ResponsesApiInterface.ts +2 -2
  46. package/src/subsystems/LLMManager/ModelsProvider.service/ModelsProviderConnector.ts +2 -2
  47. package/src/subsystems/LLMManager/ModelsProvider.service/connectors/JSONModelsProvider.class.ts +4 -1
  48. package/src/subsystems/MemoryManager/Cache.service/connectors/RedisCache.class.ts +12 -0
  49. package/src/types/LLM.types.ts +66 -38
  50. package/src/types/VectorDB.types.ts +7 -3
  51. package/src/utils/string.utils.ts +193 -191
  52. package/dist/bundle-analysis-lazy.html +0 -4949
  53. package/dist/bundle-analysis.html +0 -4949
@@ -19,7 +19,7 @@ export async function asyncReplace(str, regex, asyncFn) {
19
19
  matches.map(async (match) => {
20
20
  // Call the async function with all match groups
21
21
  return asyncFn(...match);
22
- }),
22
+ })
23
23
  );
24
24
 
25
25
  // Reassemble the string with replacements
@@ -222,193 +222,195 @@ export const identifyMimetypeFromString = (input: string) => {
222
222
  return 'text/plain';
223
223
  };
224
224
 
225
- export function chunkText(
226
- text: string,
227
- {
228
- chunkSize = 4000,
229
- chunkOverlap = 500,
230
- }: {
231
- chunkSize?: number;
232
- chunkOverlap?: number;
233
- } = {},
234
- ): string[] {
235
- const textSplitter = new RecursiveTextSplitter({
236
- chunkSize,
237
- chunkOverlap,
238
- });
239
- let output = textSplitter.splitText(text);
240
-
241
- return output;
242
- }
243
- class TextSplitter {
244
- private chunkSize: number;
245
- private chunkOverlap: number;
246
- private separators: string[] = ['\n\n', '\n', ' ', ''];
247
- private keepSeparator: boolean = true;
248
-
249
- constructor({
250
- chunkSize = 1000,
251
- chunkOverlap = 200,
252
- separators,
253
- keepSeparator,
254
- }: {
255
- chunkSize?: number;
256
- chunkOverlap?: number;
257
- separators?: string[];
258
- keepSeparator?: boolean;
259
- } = {}) {
260
- this.chunkSize = chunkSize;
261
- this.chunkOverlap = chunkOverlap;
262
-
263
- if (separators) {
264
- this.separators = separators;
265
- }
266
-
267
- if (keepSeparator !== undefined) {
268
- this.keepSeparator = keepSeparator;
269
- }
270
-
271
- if (this.chunkOverlap >= this.chunkSize) {
272
- throw new Error('Cannot have chunkOverlap >= chunkSize');
273
- }
274
- }
275
-
276
- public splitText(text: string): string[] {
277
- return this._splitText(text, this.separators);
278
- }
279
-
280
- private _splitText(text: string, separators: string[]): string[] {
281
- const finalChunks: string[] = [];
282
-
283
- // Get appropriate separator to use
284
- let separator: string = separators[separators.length - 1];
285
- let newSeparators: string[] | undefined;
286
-
287
- for (let i = 0; i < separators.length; i += 1) {
288
- const s = separators[i];
289
- if (s === '') {
290
- separator = s;
291
- break;
292
- }
293
- if (text.includes(s)) {
294
- separator = s;
295
- newSeparators = separators.slice(i + 1);
296
- break;
297
- }
298
- }
299
-
300
- // Split the text using the identified separator
301
- const splits = this.splitOnSeparator(text, separator);
302
-
303
- // Process splits, recursively splitting longer texts
304
- let goodSplits: string[] = [];
305
- const _separator = this.keepSeparator ? '' : separator;
306
-
307
- for (const s of splits) {
308
- if (this.lengthFunction(s) < this.chunkSize) {
309
- goodSplits.push(s);
310
- } else {
311
- if (goodSplits.length) {
312
- const mergedText = this.mergeSplits(goodSplits, _separator);
313
- finalChunks.push(...mergedText);
314
- goodSplits = [];
315
- }
316
-
317
- if (!newSeparators) {
318
- finalChunks.push(s);
319
- } else {
320
- const otherInfo = this._splitText(s, newSeparators);
321
- finalChunks.push(...otherInfo);
322
- }
323
- }
324
- }
325
-
326
- if (goodSplits.length) {
327
- const mergedText = this.mergeSplits(goodSplits, _separator);
328
- finalChunks.push(...mergedText);
329
- }
330
-
331
- return finalChunks;
332
- }
333
-
334
- private splitOnSeparator(text: string, separator: string): string[] {
335
- let splits: string[];
336
-
337
- if (separator) {
338
- if (this.keepSeparator) {
339
- const regexEscapedSeparator = separator.replace(/[/\-\\^$*+?.()|[\]{}]/g, '\\$&');
340
- splits = text.split(new RegExp(`(?=${regexEscapedSeparator})`));
341
- } else {
342
- splits = text.split(separator);
343
- }
344
- } else {
345
- splits = text.split('');
346
- }
347
-
348
- return splits.filter((s) => s !== '');
349
- }
350
-
351
- private lengthFunction(text: string): number {
352
- return text.length;
353
- }
354
-
355
- private joinDocs(docs: string[], separator: string): string | null {
356
- const text = docs.join(separator).trim();
357
- return text === '' ? null : text;
358
- }
359
-
360
- private mergeSplits(splits: string[], separator: string): string[] {
361
- const docs: string[] = [];
362
- const currentDoc: string[] = [];
363
- let total = 0;
364
-
365
- for (const d of splits) {
366
- const _len = this.lengthFunction(d);
367
-
368
- if (total + _len + currentDoc.length * separator.length > this.chunkSize) {
369
- if (total > this.chunkSize) {
370
- console.warn(`Created a chunk of size ${total}, which is longer than the specified ${this.chunkSize}`);
371
- }
372
-
373
- if (currentDoc.length > 0) {
374
- const doc = this.joinDocs(currentDoc, separator);
375
- if (doc !== null) {
376
- docs.push(doc);
377
- }
378
-
379
- // Keep popping if conditions are met
380
- while (total > this.chunkOverlap || (total + _len + currentDoc.length * separator.length > this.chunkSize && total > 0)) {
381
- total -= this.lengthFunction(currentDoc[0]);
382
- currentDoc.shift();
383
- }
384
- }
385
- }
386
-
387
- currentDoc.push(d);
388
- total += _len;
389
- }
390
-
391
- const doc = this.joinDocs(currentDoc, separator);
392
- if (doc !== null) {
393
- docs.push(doc);
394
- }
395
-
396
- return docs;
397
- }
398
- }
399
-
400
- class RecursiveTextSplitter extends TextSplitter {
401
- constructor({
402
- chunkSize = 1000,
403
- chunkOverlap = 200,
404
- separators = ['\n\n', '\n', ' ', ''],
405
- keepSeparator = true,
406
- }: {
407
- chunkSize?: number;
408
- chunkOverlap?: number;
409
- separators?: string[];
410
- keepSeparator?: boolean;
411
- } = {}) {
412
- super({ chunkSize, chunkOverlap, separators, keepSeparator });
413
- }
414
- }
225
+ // export function chunkText(
226
+ // text: string,
227
+ // {
228
+ // chunkSize,
229
+ // chunkOverlap,
230
+ // }: {
231
+ // chunkSize: number;
232
+ // chunkOverlap: number;
233
+ // }
234
+ // ): string[] {
235
+ // const textSplitter = new TextSplitter({
236
+ // chunkSize,
237
+ // chunkOverlap,
238
+ // separators: ['\n\n', '\n', ' ', ''],
239
+ // keepSeparator: true,
240
+ // });
241
+ // let output = textSplitter.splitText(text);
242
+
243
+ // return output;
244
+ // }
245
+ // class TextSplitter {
246
+ // private chunkSize: number;
247
+ // private chunkOverlap: number;
248
+ // private separators: string[] = ['\n\n', '\n', ' ', ''];
249
+ // private keepSeparator: boolean = true;
250
+
251
+ // constructor({
252
+ // chunkSize = 1000,
253
+ // chunkOverlap = 200,
254
+ // separators,
255
+ // keepSeparator,
256
+ // }: {
257
+ // chunkSize?: number;
258
+ // chunkOverlap?: number;
259
+ // separators?: string[];
260
+ // keepSeparator?: boolean;
261
+ // } = {}) {
262
+ // this.chunkSize = chunkSize;
263
+ // this.chunkOverlap = chunkOverlap;
264
+
265
+ // if (separators) {
266
+ // this.separators = separators;
267
+ // }
268
+
269
+ // if (keepSeparator !== undefined) {
270
+ // this.keepSeparator = keepSeparator;
271
+ // }
272
+
273
+ // if (this.chunkOverlap >= this.chunkSize) {
274
+ // throw new Error('Cannot have chunkOverlap >= chunkSize');
275
+ // }
276
+ // }
277
+
278
+ // public splitText(text: string): string[] {
279
+ // return this._splitText(text, this.separators);
280
+ // }
281
+
282
+ // private _splitText(text: string, separators: string[]): string[] {
283
+ // const finalChunks: string[] = [];
284
+
285
+ // // Get appropriate separator to use
286
+ // let separator: string = separators[separators.length - 1];
287
+ // let newSeparators: string[] | undefined;
288
+
289
+ // for (let i = 0; i < separators.length; i += 1) {
290
+ // const s = separators[i];
291
+ // if (s === '') {
292
+ // separator = s;
293
+ // break;
294
+ // }
295
+ // if (text.includes(s)) {
296
+ // separator = s;
297
+ // newSeparators = separators.slice(i + 1);
298
+ // break;
299
+ // }
300
+ // }
301
+
302
+ // // Split the text using the identified separator
303
+ // const splits = this.splitOnSeparator(text, separator);
304
+
305
+ // // Process splits, recursively splitting longer texts
306
+ // let goodSplits: string[] = [];
307
+ // const _separator = this.keepSeparator ? '' : separator;
308
+
309
+ // for (const s of splits) {
310
+ // if (this.lengthFunction(s) < this.chunkSize) {
311
+ // goodSplits.push(s);
312
+ // } else {
313
+ // if (goodSplits.length) {
314
+ // const mergedText = this.mergeSplits(goodSplits, _separator);
315
+ // finalChunks.push(...mergedText);
316
+ // goodSplits = [];
317
+ // }
318
+
319
+ // if (!newSeparators) {
320
+ // finalChunks.push(s);
321
+ // } else {
322
+ // const otherInfo = this._splitText(s, newSeparators);
323
+ // finalChunks.push(...otherInfo);
324
+ // }
325
+ // }
326
+ // }
327
+
328
+ // if (goodSplits.length) {
329
+ // const mergedText = this.mergeSplits(goodSplits, _separator);
330
+ // finalChunks.push(...mergedText);
331
+ // }
332
+
333
+ // return finalChunks;
334
+ // }
335
+
336
+ // private splitOnSeparator(text: string, separator: string): string[] {
337
+ // let splits: string[];
338
+
339
+ // if (separator) {
340
+ // if (this.keepSeparator) {
341
+ // const regexEscapedSeparator = separator.replace(/[/\-\\^$*+?.()|[\]{}]/g, '\\$&');
342
+ // splits = text.split(new RegExp(`(?=${regexEscapedSeparator})`));
343
+ // } else {
344
+ // splits = text.split(separator);
345
+ // }
346
+ // } else {
347
+ // splits = text.split('');
348
+ // }
349
+
350
+ // return splits.filter((s) => s !== '');
351
+ // }
352
+
353
+ // private lengthFunction(text: string): number {
354
+ // return text.length;
355
+ // }
356
+
357
+ // private joinDocs(docs: string[], separator: string): string | null {
358
+ // const text = docs.join(separator).trim();
359
+ // return text === '' ? null : text;
360
+ // }
361
+
362
+ // private mergeSplits(splits: string[], separator: string): string[] {
363
+ // const docs: string[] = [];
364
+ // const currentDoc: string[] = [];
365
+ // let total = 0;
366
+
367
+ // for (const d of splits) {
368
+ // const _len = this.lengthFunction(d);
369
+
370
+ // if (total + _len + currentDoc.length * separator.length > this.chunkSize) {
371
+ // if (total > this.chunkSize) {
372
+ // console.warn(`Created a chunk of size ${total}, which is longer than the specified ${this.chunkSize}`);
373
+ // }
374
+
375
+ // if (currentDoc.length > 0) {
376
+ // const doc = this.joinDocs(currentDoc, separator);
377
+ // if (doc !== null) {
378
+ // docs.push(doc);
379
+ // }
380
+
381
+ // // Keep popping if conditions are met
382
+ // while (total > this.chunkOverlap || (total + _len + currentDoc.length * separator.length > this.chunkSize && total > 0)) {
383
+ // total -= this.lengthFunction(currentDoc[0]);
384
+ // currentDoc.shift();
385
+ // }
386
+ // }
387
+ // }
388
+
389
+ // currentDoc.push(d);
390
+ // total += _len;
391
+ // }
392
+
393
+ // const doc = this.joinDocs(currentDoc, separator);
394
+ // if (doc !== null) {
395
+ // docs.push(doc);
396
+ // }
397
+
398
+ // return docs;
399
+ // }
400
+ // }
401
+
402
+ // class RecursiveTextSplitter extends TextSplitter {
403
+ // constructor({
404
+ // chunkSize = 1000,
405
+ // chunkOverlap = 200,
406
+ // separators = ['\n\n', '\n', ' ', ''],
407
+ // keepSeparator = true,
408
+ // }: {
409
+ // chunkSize?: number;
410
+ // chunkOverlap?: number;
411
+ // separators?: string[];
412
+ // keepSeparator?: boolean;
413
+ // } = {}) {
414
+ // super({ chunkSize, chunkOverlap, separators, keepSeparator });
415
+ // }
416
+ // }