the-token-company 0.2.2 → 0.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/dist/ai-sdk.js +1 -1
- package/dist/anthropic.js +1 -1
- package/dist/client.d.ts +1 -0
- package/dist/client.js +3 -1
- package/dist/openai.js +1 -1
- package/dist/types.d.ts +2 -0
- package/package.json +1 -1
package/dist/ai-sdk.js
CHANGED
|
@@ -17,7 +17,7 @@ import { CompressionStats } from "./types.js";
|
|
|
17
17
|
*/
|
|
18
18
|
export function compressionMiddleware(options) {
|
|
19
19
|
const stats = new CompressionStats();
|
|
20
|
-
const compressor = new StatsTTC(new TheTokenCompany({ apiKey: options.compressionApiKey, appId: options.appId }), stats);
|
|
20
|
+
const compressor = new StatsTTC(new TheTokenCompany({ apiKey: options.compressionApiKey, appId: options.appId, fetch: options.fetch }), stats);
|
|
21
21
|
const compressionModel = options.model ?? "bear-2";
|
|
22
22
|
const roleAggr = resolveAggressiveness(options.aggressiveness ?? 0.2);
|
|
23
23
|
const middleware = {
|
package/dist/anthropic.js
CHANGED
|
@@ -24,7 +24,7 @@ import { CompressionStats } from "./types.js";
|
|
|
24
24
|
*/
|
|
25
25
|
export function withCompression(client, options) {
|
|
26
26
|
const stats = new CompressionStats();
|
|
27
|
-
const compressor = new StatsTTC(new TheTokenCompany({ apiKey: options.compressionApiKey, appId: options.appId }), stats);
|
|
27
|
+
const compressor = new StatsTTC(new TheTokenCompany({ apiKey: options.compressionApiKey, appId: options.appId, fetch: options.fetch }), stats);
|
|
28
28
|
const model = options.model ?? "bear-2";
|
|
29
29
|
const roleAggr = resolveAggressiveness(options.aggressiveness ?? 0.2);
|
|
30
30
|
const systemAggr = roleAggr["system"];
|
package/dist/client.d.ts
CHANGED
package/dist/client.js
CHANGED
|
@@ -14,12 +14,14 @@ export class TheTokenCompany {
|
|
|
14
14
|
timeout;
|
|
15
15
|
gzip;
|
|
16
16
|
appId;
|
|
17
|
+
fetchFn;
|
|
17
18
|
constructor(options) {
|
|
18
19
|
this.apiKey = options.apiKey;
|
|
19
20
|
this.baseUrl = (options.baseUrl ?? BASE_URL).replace(/\/$/, "");
|
|
20
21
|
this.timeout = options.timeout ?? DEFAULT_TIMEOUT;
|
|
21
22
|
this.gzip = options.gzip ?? true;
|
|
22
23
|
this.appId = options.appId;
|
|
24
|
+
this.fetchFn = options.fetch ?? globalThis.fetch;
|
|
23
25
|
}
|
|
24
26
|
async compress(text, options = {}) {
|
|
25
27
|
const { model = "bear-2", aggressiveness = 0.2 } = options;
|
|
@@ -49,7 +51,7 @@ export class TheTokenCompany {
|
|
|
49
51
|
else {
|
|
50
52
|
body = jsonBody;
|
|
51
53
|
}
|
|
52
|
-
const response = await
|
|
54
|
+
const response = await this.fetchFn(`${this.baseUrl}/v1/compress`, {
|
|
53
55
|
method: "POST",
|
|
54
56
|
headers,
|
|
55
57
|
body: body,
|
package/dist/openai.js
CHANGED
|
@@ -22,7 +22,7 @@ import { CompressionStats } from "./types.js";
|
|
|
22
22
|
*/
|
|
23
23
|
export function withCompression(client, options) {
|
|
24
24
|
const stats = new CompressionStats();
|
|
25
|
-
const compressor = new StatsTTC(new TheTokenCompany({ apiKey: options.compressionApiKey, appId: options.appId }), stats);
|
|
25
|
+
const compressor = new StatsTTC(new TheTokenCompany({ apiKey: options.compressionApiKey, appId: options.appId, fetch: options.fetch }), stats);
|
|
26
26
|
const model = options.model ?? "bear-2";
|
|
27
27
|
const roleAggr = resolveAggressiveness(options.aggressiveness ?? 0.2);
|
|
28
28
|
const originalCreate = client.chat.completions.create.bind(client.chat.completions);
|
package/dist/types.d.ts
CHANGED
|
@@ -24,6 +24,7 @@ export interface TheTokenCompanyOptions {
|
|
|
24
24
|
timeout?: number;
|
|
25
25
|
gzip?: boolean;
|
|
26
26
|
appId?: string;
|
|
27
|
+
fetch?: typeof globalThis.fetch;
|
|
27
28
|
}
|
|
28
29
|
export type Aggressiveness = number | Record<string, number>;
|
|
29
30
|
export interface WithCompressionOptions {
|
|
@@ -31,6 +32,7 @@ export interface WithCompressionOptions {
|
|
|
31
32
|
model?: string;
|
|
32
33
|
aggressiveness?: Aggressiveness;
|
|
33
34
|
appId?: string;
|
|
35
|
+
fetch?: typeof globalThis.fetch;
|
|
34
36
|
}
|
|
35
37
|
export interface TurnStats {
|
|
36
38
|
inputTokens: number;
|