compress-lightreach 1.0.9 → 1.0.10
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/README.md +10 -86
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,8 +12,7 @@ Compress Light Reach is a Node.js/TypeScript SDK that provides intelligent model
|
|
|
12
12
|
|
|
13
13
|
- **Intelligent Model Routing**: Automatically selects the optimal model based on admin-configured quality settings and available provider keys
|
|
14
14
|
- **Token-aware Compression**: Replaces repeated substrings with shorter placeholders using a fast greedy algorithm
|
|
15
|
-
- **Lossless**:
|
|
16
|
-
- **Output Compression**: Optional model output compression support
|
|
15
|
+
- **Lossless Input Compression**: Prompt reconstruction is deterministic
|
|
17
16
|
- **Cloud API**: Uses Light Reach's cloud service for compression and routing
|
|
18
17
|
- **Multi-provider Support**: OpenAI, Anthropic, Google, DeepSeek, Moonshot
|
|
19
18
|
- **TypeScript**: Full TypeScript support with type definitions
|
|
@@ -154,17 +153,6 @@ const result = await client.complete({
|
|
|
154
153
|
});
|
|
155
154
|
```
|
|
156
155
|
|
|
157
|
-
### With Output Compression
|
|
158
|
-
|
|
159
|
-
```typescript
|
|
160
|
-
const result = await client.complete({
|
|
161
|
-
messages: [{ role: 'user', content: 'Generate a long report...' }],
|
|
162
|
-
compress_output: true,
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
console.log(result.choices[0].message.content);
|
|
166
|
-
```
|
|
167
|
-
|
|
168
156
|
### With Compression Config
|
|
169
157
|
|
|
170
158
|
Control which message roles get compressed:
|
|
@@ -193,35 +181,6 @@ console.log(result.choices[0].message.content);
|
|
|
193
181
|
console.log(`Model used: ${result.routing_info?.selected_model}`);
|
|
194
182
|
```
|
|
195
183
|
|
|
196
|
-
### Compression Only (No LLM Call)
|
|
197
|
-
|
|
198
|
-
```typescript
|
|
199
|
-
import { PcompresslrAPIClient } from 'compress-lightreach';
|
|
200
|
-
|
|
201
|
-
const client = new PcompresslrAPIClient("your-lightreach-api-key");
|
|
202
|
-
|
|
203
|
-
const compressed = await client.compress(
|
|
204
|
-
"Your text with repeated content here...",
|
|
205
|
-
"gpt-4",
|
|
206
|
-
{ team: 'backend' },
|
|
207
|
-
);
|
|
208
|
-
|
|
209
|
-
console.log(compressed.llm_format);
|
|
210
|
-
console.log(`Compression ratio: ${compressed.compression_ratio}`);
|
|
211
|
-
|
|
212
|
-
// Decompress later
|
|
213
|
-
const decompressed = await client.decompress(compressed.llm_format);
|
|
214
|
-
console.log(decompressed.decompressed);
|
|
215
|
-
```
|
|
216
|
-
|
|
217
|
-
### Command Line Interface
|
|
218
|
-
|
|
219
|
-
```bash
|
|
220
|
-
export PCOMPRESLR_API_KEY=your-api-key
|
|
221
|
-
|
|
222
|
-
npx pcompresslr "Your prompt with repeated text here..."
|
|
223
|
-
```
|
|
224
|
-
|
|
225
184
|
## API Reference
|
|
226
185
|
|
|
227
186
|
### `PcompresslrAPIClient`
|
|
@@ -254,7 +213,7 @@ For direct synchronous calls, use `completeSync()` instead.
|
|
|
254
213
|
| `messages` | `Message[]` | required | Conversation history with `role` and `content` |
|
|
255
214
|
| `llm_provider` | `'openai' \| 'anthropic' \| 'google' \| 'deepseek' \| 'moonshot'` | — | Optional provider constraint. Omit for cross-provider optimization |
|
|
256
215
|
| `compress` | `boolean` | `true` | Whether to compress messages |
|
|
257
|
-
| `compress_output` | `boolean` | `false` |
|
|
216
|
+
| `compress_output` | `boolean` | `false` | Advanced server hint. `complete()` still returns normal OpenAI-style text in `choices[0].message.content` |
|
|
258
217
|
| `compression_config` | `object` | — | Per-role compression settings (see below) |
|
|
259
218
|
| `temperature` | `number` | — | LLM temperature parameter |
|
|
260
219
|
| `max_tokens` | `number` | — | Maximum tokens to generate |
|
|
@@ -349,46 +308,6 @@ Explicit async job flow with configurable polling. Called internally by `complet
|
|
|
349
308
|
- `maxWaitMs` (number, default: timeout): Maximum wait time
|
|
350
309
|
- `idempotencyKey` (string, optional): Idempotency key for job creation
|
|
351
310
|
|
|
352
|
-
##### `compress(prompt, model?, tags?): Promise<CompressResponse>`
|
|
353
|
-
|
|
354
|
-
Compression-only (POST `/api/v1/compress`).
|
|
355
|
-
|
|
356
|
-
**Parameters:**
|
|
357
|
-
- `prompt` (string, required): Text to compress
|
|
358
|
-
- `model` (string, optional): Model for tokenization. Default: `'gpt-4'`
|
|
359
|
-
- `tags` (`Record<string, string>`, optional): Tags for attribution
|
|
360
|
-
|
|
361
|
-
**Response (`CompressResponse`):**
|
|
362
|
-
|
|
363
|
-
```typescript
|
|
364
|
-
{
|
|
365
|
-
compressed: string;
|
|
366
|
-
dictionary: Record<string, string>;
|
|
367
|
-
llm_format: string;
|
|
368
|
-
compression_ratio: number;
|
|
369
|
-
original_size: number;
|
|
370
|
-
compressed_size: number;
|
|
371
|
-
processing_time_ms: number;
|
|
372
|
-
algorithm: string;
|
|
373
|
-
}
|
|
374
|
-
```
|
|
375
|
-
|
|
376
|
-
##### `decompress(llmFormat): Promise<DecompressResponse>`
|
|
377
|
-
|
|
378
|
-
Decompress an LLM-formatted compressed prompt (POST `/api/v1/decompress`).
|
|
379
|
-
|
|
380
|
-
**Parameters:**
|
|
381
|
-
- `llmFormat` (string, required): The `llm_format` string from a compress response
|
|
382
|
-
|
|
383
|
-
**Response (`DecompressResponse`):**
|
|
384
|
-
|
|
385
|
-
```typescript
|
|
386
|
-
{
|
|
387
|
-
decompressed: string;
|
|
388
|
-
processing_time_ms: number;
|
|
389
|
-
}
|
|
390
|
-
```
|
|
391
|
-
|
|
392
311
|
##### `healthCheck(): Promise<HealthCheckResponse>`
|
|
393
312
|
|
|
394
313
|
Check API health status (GET `/health`).
|
|
@@ -451,7 +370,7 @@ try {
|
|
|
451
370
|
1. **Compression**: Identifies repeated substrings using efficient algorithms and replaces them with shorter placeholders, reducing token count
|
|
452
371
|
2. **Routing**: Selects the cheapest model that meets the admin-configured quality ceiling (global, tag-level, or integration-level)
|
|
453
372
|
3. **LLM Call**: Sends the compressed prompt to the selected model via your BYOK provider keys
|
|
454
|
-
4. **
|
|
373
|
+
4. **Response Shaping**: Returns standard OpenAI-style completion fields plus LightReach metadata extensions
|
|
455
374
|
|
|
456
375
|
## Examples
|
|
457
376
|
|
|
@@ -479,7 +398,7 @@ console.log(`Token savings: ${result.compression_stats.token_savings} tokens`);
|
|
|
479
398
|
console.log(`Compression ratio: ${(result.compression_stats.compression_ratio * 100).toFixed(2)}%`);
|
|
480
399
|
```
|
|
481
400
|
|
|
482
|
-
### Example 2:
|
|
401
|
+
### Example 2: Compression Config
|
|
483
402
|
|
|
484
403
|
```typescript
|
|
485
404
|
import { PcompresslrAPIClient } from 'compress-lightreach';
|
|
@@ -488,7 +407,12 @@ const client = new PcompresslrAPIClient("your-lightreach-api-key");
|
|
|
488
407
|
|
|
489
408
|
const result = await client.complete({
|
|
490
409
|
messages: [{ role: "user", content: "Generate a long report with repeated sections..." }],
|
|
491
|
-
|
|
410
|
+
compression_config: {
|
|
411
|
+
compress_system: false,
|
|
412
|
+
compress_user: true,
|
|
413
|
+
compress_assistant: false,
|
|
414
|
+
compress_only_last_n_user: 1,
|
|
415
|
+
},
|
|
492
416
|
});
|
|
493
417
|
|
|
494
418
|
console.log(result.choices[0].message.content);
|
package/package.json
CHANGED