@rws-framework/ai-tools 3.2.4 → 3.2.6
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
|
@@ -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}`);
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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);
|
package/src/types/IPrompt.ts
CHANGED
|
@@ -128,15 +128,18 @@ interface IRWSPromptJSON {
|
|
|
128
128
|
|
|
129
129
|
type ChainStreamType = AsyncGenerator<IterableReadableStream<ChainValues>>;
|
|
130
130
|
|
|
131
|
-
interface
|
|
132
|
-
|
|
133
|
-
|
|
131
|
+
interface CompoundInputContent{
|
|
132
|
+
text?: string,
|
|
133
|
+
type: InputType,
|
|
134
|
+
source?: {
|
|
135
|
+
media_type: string,
|
|
136
|
+
data: string
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
interface CompoundInput {
|
|
134
141
|
role?: 'user' | 'assistant' | 'system',
|
|
135
|
-
|
|
136
|
-
type: string,
|
|
137
|
-
media_type: string,
|
|
138
|
-
data: string
|
|
139
|
-
}
|
|
142
|
+
content: CompoundInputContent | CompoundInputContent[],
|
|
140
143
|
}
|
|
141
144
|
|
|
142
145
|
export {
|
|
@@ -161,6 +164,7 @@ export {
|
|
|
161
164
|
IRWSHistoryMessage,
|
|
162
165
|
InputType,
|
|
163
166
|
CompoundInput,
|
|
167
|
+
CompoundInputContent,
|
|
164
168
|
IToolCall,
|
|
165
169
|
ToolHandler
|
|
166
170
|
};
|