@rws-framework/ai-tools 3.2.3 → 3.2.5

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,7 +1,7 @@
1
1
  {
2
2
  "name": "@rws-framework/ai-tools",
3
3
  "private": false,
4
- "version": "3.2.3",
4
+ "version": "3.2.5",
5
5
  "description": "",
6
6
  "main": "src/index.ts",
7
7
  "scripts": {},
@@ -63,10 +63,7 @@ export class LangChainEmbeddingService {
63
63
  const rateLimitingCfg = {...OpenAIRateLimitingService.DEFAULT_CONFIG, ...this.config.rateLimiting};
64
64
 
65
65
  this.rateLimitingService.initialize(this.config.model || 'text-embedding-3-large', rateLimitingCfg);
66
- console.log('Inintialized rate limiting with config:', rateLimitingCfg);
67
66
  }
68
-
69
- console.log(`Initialized ${this.config.provider} embeddings with model ${this.config.model}`, this.config.apiKey);
70
67
  }
71
68
 
72
69
  private initializeTextSplitter(chunkConfig?: IChunkConfig): void {
@@ -126,8 +123,6 @@ export class LangChainEmbeddingService {
126
123
  const maxTokens = this.chunkConfig?.chunkSize || 450; // Safe token limit for embedding models
127
124
  const overlap = this.chunkConfig?.chunkOverlap || 50; // Character overlap, not token
128
125
 
129
- console.log('[LCEmbeddingService] Chunking with:', this.chunkConfig);
130
-
131
126
  return TextChunker.chunkText(text, maxTokens, overlap);
132
127
  }
133
128
 
@@ -2,6 +2,7 @@ import { Injectable } from '@nestjs/common';
2
2
  import PQueue from 'p-queue';
3
3
  import { IBatchMetadata, IRateLimitConfig } from '../types/rag.types';
4
4
  import tiktoken from 'tiktoken';
5
+ import { BlackLogger } from '@rws-framework/server/nest';
5
6
 
6
7
  let encoding_for_model: any = null;
7
8
  encoding_for_model = tiktoken.encoding_for_model
@@ -21,6 +22,8 @@ export class OpenAIRateLimitingService {
21
22
  private queue: PQueue;
22
23
  private config: Required<IRateLimitConfig>;
23
24
 
25
+ private logger = new BlackLogger(OpenAIRateLimitingService.name);
26
+
24
27
  constructor() {
25
28
  this.config = { ...OpenAIRateLimitingService.DEFAULT_CONFIG };
26
29
  this.queue = new PQueue({ concurrency: this.config.concurrency });
@@ -42,7 +45,7 @@ export class OpenAIRateLimitingService {
42
45
  this.tokenizer = null;
43
46
  }
44
47
  } catch (e) {
45
- console.warn(`Could not load tokenizer for model ${model}, using character-based estimation`);
48
+ this.logger.warn(`Could not load tokenizer for model ${model}, using character-based estimation`);
46
49
  this.tokenizer = null;
47
50
  }
48
51
 
@@ -96,7 +99,7 @@ export class OpenAIRateLimitingService {
96
99
  // Shrink batch if >1 and retry quickly (binary shrink)
97
100
  if (attemptBatch.length <= 1) throw err;
98
101
  attemptBatch = attemptBatch.slice(0, Math.ceil(attemptBatch.length / 2));
99
- console.log(`Rate limit hit, shrinking batch to ${attemptBatch.length} items`);
102
+ this.logger.debug(`Rate limit hit, shrinking batch to ${attemptBatch.length} items`);
100
103
  // Small sleep to avoid immediate retry stampede
101
104
  await this.sleep(200 + Math.random() * 200);
102
105
  continue;
@@ -179,7 +182,7 @@ export class OpenAIRateLimitingService {
179
182
  const delay = Math.min(60_000, this.config.baseBackoffMs * (2 ** attempt));
180
183
  const jitter = Math.random() * 300;
181
184
 
182
- console.log(`Retrying request in ${delay + jitter}ms (attempt ${attempt + 1}/${this.config.maxRetries})`);
185
+ this.logger.warn(`Retrying request in ${delay + jitter}ms (attempt ${attempt + 1}/${this.config.maxRetries})`);
183
186
  await this.sleep(delay + jitter);
184
187
 
185
188
  return this.callWithRetry(fn, attempt + 1);