compress-lightreach 0.1.4 → 0.1.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/README.md +4 -0
- package/dist/api-client.d.ts +2 -2
- package/dist/api-client.js +9 -3
- package/dist/core.d.ts +1 -0
- package/dist/core.js +2 -1
- package/package.json +2 -3
package/README.md
CHANGED
|
@@ -10,6 +10,10 @@ Compress Light Reach is a Node.js/TypeScript library that intelligently compress
|
|
|
10
10
|
|
|
11
11
|
## Features
|
|
12
12
|
|
|
13
|
+
- **Token-aware compression**: Only replaces substrings >1 token with 1-token placeholders
|
|
14
|
+
- **Dual algorithms**:
|
|
15
|
+
- Fast greedy (~99% optimal) for daily use
|
|
16
|
+
- Optimal DP (O(n²)) for critical prompts
|
|
13
17
|
- **Lossless**: Perfect decompression guaranteed
|
|
14
18
|
- **Output compression**: Optional model output compression support
|
|
15
19
|
- **Cloud API**: Uses Light Reach's cloud service for compression
|
package/dist/api-client.d.ts
CHANGED
|
@@ -58,8 +58,8 @@ export declare class PcompresslrAPIClient {
|
|
|
58
58
|
private session;
|
|
59
59
|
constructor(apiKey?: string, apiUrl?: string, timeout?: number);
|
|
60
60
|
private makeRequest;
|
|
61
|
-
compress(prompt: string, model?: string, algorithm?: "greedy" | "optimal"): Promise<CompressResponse>;
|
|
61
|
+
compress(prompt: string, model?: string, algorithm?: "greedy" | "optimal", tags?: Record<string, string>): Promise<CompressResponse>;
|
|
62
62
|
decompress(llmFormat: string): Promise<DecompressResponse>;
|
|
63
63
|
healthCheck(): Promise<HealthCheckResponse>;
|
|
64
|
-
complete(prompt: string, model: string, llmProvider: "openai" | "anthropic", llmApiKey: string, compress?: boolean, compressOutput?: boolean, algorithm?: "greedy" | "optimal", temperature?: number, maxTokens?: number): Promise<CompleteResponse>;
|
|
64
|
+
complete(prompt: string, model: string, llmProvider: "openai" | "anthropic", llmApiKey: string, compress?: boolean, compressOutput?: boolean, algorithm?: "greedy" | "optimal", temperature?: number, maxTokens?: number, tags?: Record<string, string>): Promise<CompleteResponse>;
|
|
65
65
|
}
|
package/dist/api-client.js
CHANGED
|
@@ -41,7 +41,7 @@ class APIRequestError extends PcompresslrAPIError {
|
|
|
41
41
|
}
|
|
42
42
|
exports.APIRequestError = APIRequestError;
|
|
43
43
|
class PcompresslrAPIClient {
|
|
44
|
-
constructor(apiKey, apiUrl, timeout =
|
|
44
|
+
constructor(apiKey, apiUrl, timeout = 120000 // 2 minutes - complete() calls LLM which can take 30+ seconds
|
|
45
45
|
) {
|
|
46
46
|
this.DEFAULT_API_URL = "https://api.compress.lightreach.io";
|
|
47
47
|
// Get API key from parameter or environment
|
|
@@ -136,12 +136,15 @@ class PcompresslrAPIClient {
|
|
|
136
136
|
throw new APIRequestError(`Request failed: ${errorMessage}`);
|
|
137
137
|
}
|
|
138
138
|
}
|
|
139
|
-
async compress(prompt, model = "gpt-4", algorithm = "greedy") {
|
|
139
|
+
async compress(prompt, model = "gpt-4", algorithm = "greedy", tags) {
|
|
140
140
|
const data = {
|
|
141
141
|
prompt,
|
|
142
142
|
model,
|
|
143
143
|
algorithm
|
|
144
144
|
};
|
|
145
|
+
if (tags) {
|
|
146
|
+
data.tags = tags;
|
|
147
|
+
}
|
|
145
148
|
return this.makeRequest("/api/v1/compress", data);
|
|
146
149
|
}
|
|
147
150
|
async decompress(llmFormat) {
|
|
@@ -166,7 +169,7 @@ class PcompresslrAPIClient {
|
|
|
166
169
|
throw new APIRequestError(`Health check failed: ${errorMessage}`);
|
|
167
170
|
}
|
|
168
171
|
}
|
|
169
|
-
async complete(prompt, model, llmProvider, llmApiKey, compress = true, compressOutput = false, algorithm = "greedy", temperature, maxTokens) {
|
|
172
|
+
async complete(prompt, model, llmProvider, llmApiKey, compress = true, compressOutput = false, algorithm = "greedy", temperature, maxTokens, tags) {
|
|
170
173
|
const data = {
|
|
171
174
|
prompt,
|
|
172
175
|
model,
|
|
@@ -182,6 +185,9 @@ class PcompresslrAPIClient {
|
|
|
182
185
|
if (maxTokens !== undefined) {
|
|
183
186
|
data.max_tokens = maxTokens;
|
|
184
187
|
}
|
|
188
|
+
if (tags !== undefined) {
|
|
189
|
+
data.tags = tags;
|
|
190
|
+
}
|
|
185
191
|
return this.makeRequest("/api/v1/complete", data);
|
|
186
192
|
}
|
|
187
193
|
}
|
package/dist/core.d.ts
CHANGED
package/dist/core.js
CHANGED
|
@@ -84,6 +84,7 @@ class Pcompresslr {
|
|
|
84
84
|
* @param options.useOptimal - Whether to use optimal algorithm. If undefined, uses constructor setting.
|
|
85
85
|
* @param options.temperature - LLM temperature setting (optional)
|
|
86
86
|
* @param options.maxTokens - Maximum tokens to generate (optional)
|
|
87
|
+
* @param options.tags - Optional dictionary of tags for cost attribution (e.g., {team: 'marketing'})
|
|
87
88
|
*
|
|
88
89
|
* @returns Dictionary containing:
|
|
89
90
|
* - decompressed_response: Final decompressed response
|
|
@@ -126,7 +127,7 @@ class Pcompresslr {
|
|
|
126
127
|
try {
|
|
127
128
|
const result = await this.apiClient.complete(prompt, modelToUse, providerToUse, keyToUse, options?.compress !== false, // default true
|
|
128
129
|
options?.compressOutput || false, // default false
|
|
129
|
-
algorithm, options?.temperature, options?.maxTokens);
|
|
130
|
+
algorithm, options?.temperature, options?.maxTokens, options?.tags);
|
|
130
131
|
return result;
|
|
131
132
|
}
|
|
132
133
|
catch (error) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "compress-lightreach",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "Intelligent compression algorithms for LLM prompts that reduce token usage",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -8,8 +8,7 @@
|
|
|
8
8
|
"pcompresslr": "./dist/cli.js"
|
|
9
9
|
},
|
|
10
10
|
"scripts": {
|
|
11
|
-
"
|
|
12
|
-
"build": "npm run increment-version && tsc",
|
|
11
|
+
"build": "tsc",
|
|
13
12
|
"prepublishOnly": "npm run build",
|
|
14
13
|
"test": "jest",
|
|
15
14
|
"test:watch": "jest --watch",
|