@sprucelabs/sprucebot-llm 16.0.1 → 18.0.0
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 +59 -0
- package/build/.spruce/settings.json +1 -1
- package/build/bots/adapters/AnthropicAdapter.d.ts +3 -1
- package/build/bots/adapters/AnthropicAdapter.js +21 -0
- package/build/bots/adapters/OllamaAdapter.d.ts +2 -1
- package/build/bots/adapters/OllamaAdapter.js +7 -0
- package/build/bots/adapters/OpenAiAdapter.d.ts +2 -1
- package/build/bots/adapters/OpenAiAdapter.js +7 -0
- package/build/esm/bots/adapters/AnthropicAdapter.d.ts +3 -1
- package/build/esm/bots/adapters/AnthropicAdapter.js +24 -3
- package/build/esm/bots/adapters/OllamaAdapter.d.ts +2 -1
- package/build/esm/bots/adapters/OllamaAdapter.js +7 -0
- package/build/esm/bots/adapters/OpenAiAdapter.d.ts +2 -1
- package/build/esm/bots/adapters/OpenAiAdapter.js +7 -0
- package/build/esm/index.d.ts +1 -1
- package/build/esm/index.js +1 -1
- package/build/esm/llm.types.d.ts +8 -0
- package/build/esm/tests/SpyAdapter.d.ts +2 -1
- package/build/esm/tests/SpyAdapter.js +7 -0
- package/build/index.d.ts +1 -1
- package/build/index.js +2 -2
- package/build/llm.types.d.ts +8 -0
- package/build/tests/SpyAdapter.d.ts +2 -1
- package/build/tests/SpyAdapter.js +7 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -22,6 +22,9 @@ A TypeScript library for leveraging large language models to do... anything!
|
|
|
22
22
|
* [Anthropic](#anthropic-adapter) - Claude models with prompt caching support
|
|
23
23
|
* [Ollama](#ollama-adapter) - Run local models like Llama, Mistral, etc.
|
|
24
24
|
* [Custom adapters](#custom-adapters) - Implement your own
|
|
25
|
+
* [Track token usage](#tracking-token-usage)
|
|
26
|
+
* Read cumulative input/output/total tokens from any adapter
|
|
27
|
+
* Includes Anthropic prompt-cache token counts
|
|
25
28
|
* Fully typed
|
|
26
29
|
* Built in modern TypeScript
|
|
27
30
|
* Fully typed schema-based state management (powered by `@sprucelabs/schema`)
|
|
@@ -192,6 +195,7 @@ adapter.setReasoningEffort('low')
|
|
|
192
195
|
- `adapter.setModel(model)`: set a default model for all requests unless a Skill overrides it.
|
|
193
196
|
- `adapter.setMessageMemoryLimit(limit)`: limit how many tracked messages are sent to OpenAI.
|
|
194
197
|
- `adapter.setReasoningEffort(effort)`: set `reasoning_effort` for models that support it.
|
|
198
|
+
- `adapter.getTokenUsage()`: returns cumulative [token usage](#tracking-token-usage) for this adapter. The OpenAI adapter currently returns zeros (not yet implemented).
|
|
195
199
|
- `OpenAiAdapter.OpenAI`: assign a custom OpenAI client class (useful for tests).
|
|
196
200
|
|
|
197
201
|
Requests are sent via `openai.chat.completions.create(...)` with messages built by the adapter from the Bot state and history.
|
|
@@ -234,6 +238,8 @@ Token usage (including cache creation and cache read tokens) is logged at the `i
|
|
|
234
238
|
[TOKEN USAGE] input=1234 cache_create=800 cache_read=400 output=256
|
|
235
239
|
```
|
|
236
240
|
|
|
241
|
+
The same numbers are also available programmatically via [`adapter.getTokenUsage()`](#tracking-token-usage).
|
|
242
|
+
|
|
237
243
|
No configuration is required — caching is applied automatically.
|
|
238
244
|
|
|
239
245
|
### Ollama adapter
|
|
@@ -270,6 +276,48 @@ await bot.sendMessage('Hello!')
|
|
|
270
276
|
|
|
271
277
|
The Ollama adapter connects to `http://localhost:11434/v1` by default (Ollama's OpenAI-compatible endpoint).
|
|
272
278
|
|
|
279
|
+
### Tracking token usage
|
|
280
|
+
|
|
281
|
+
Every adapter implements `getTokenUsage()`, which returns the **cumulative** token usage for that adapter instance since it was created:
|
|
282
|
+
|
|
283
|
+
```ts
|
|
284
|
+
import { LmmTokenUsage } from '@sprucelabs/sprucebot-llm'
|
|
285
|
+
|
|
286
|
+
await bot.sendMessage('Hello!')
|
|
287
|
+
|
|
288
|
+
const usage: LmmTokenUsage = adapter.getTokenUsage()
|
|
289
|
+
// {
|
|
290
|
+
// inputTokens: 1234,
|
|
291
|
+
// outputTokens: 256,
|
|
292
|
+
// totalTokens: 1490,
|
|
293
|
+
// cacheCreationTokens: 800, // Anthropic only
|
|
294
|
+
// cacheReadTokens: 400, // Anthropic only
|
|
295
|
+
// }
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
The `LmmTokenUsage` shape:
|
|
299
|
+
|
|
300
|
+
| Field | Type | Notes |
|
|
301
|
+
|-------|------|-------|
|
|
302
|
+
| `inputTokens` | `number` | Prompt / input tokens |
|
|
303
|
+
| `outputTokens` | `number` | Completion / output tokens |
|
|
304
|
+
| `totalTokens` | `number` | `inputTokens + outputTokens` |
|
|
305
|
+
| `cacheCreationTokens` | `number` (optional) | Anthropic only — tokens written to the prompt cache |
|
|
306
|
+
| `cacheReadTokens` | `number` (optional) | Anthropic only — tokens served from the prompt cache |
|
|
307
|
+
|
|
308
|
+
**Adapter support:**
|
|
309
|
+
|
|
310
|
+
| Adapter | `getTokenUsage()` |
|
|
311
|
+
|---------|-------------------|
|
|
312
|
+
| Anthropic | ✅ Fully tracked, including cache tokens |
|
|
313
|
+
| OpenAI | ⚠️ Returns zeros — not yet implemented |
|
|
314
|
+
| Ollama | ⚠️ Returns zeros — not yet implemented |
|
|
315
|
+
|
|
316
|
+
**Things to know:**
|
|
317
|
+
|
|
318
|
+
- **Cumulative, not per-call.** Totals accumulate across every `sendMessage` call on the adapter, and there is no reset method. To measure a single call, read `getTokenUsage()` before and after and diff the values.
|
|
319
|
+
- **Per adapter, not per bot.** Usage lives on the adapter instance. If you share one adapter across multiple bots (e.g. through a single `SprucebotLlmFactory`), the totals aggregate across all of them.
|
|
320
|
+
|
|
273
321
|
### Custom adapters
|
|
274
322
|
|
|
275
323
|
You can bring your own adapter by implementing the `LlmAdapter` interface and passing it to `SprucebotLlmFactory.Factory(...)`:
|
|
@@ -277,6 +325,8 @@ You can bring your own adapter by implementing the `LlmAdapter` interface and pa
|
|
|
277
325
|
```ts
|
|
278
326
|
import {
|
|
279
327
|
LlmAdapter,
|
|
328
|
+
LllmReasoningEffort,
|
|
329
|
+
LmmTokenUsage,
|
|
280
330
|
SprucebotLlmBot,
|
|
281
331
|
SprucebotLlmFactory,
|
|
282
332
|
} from '@sprucelabs/sprucebot-llm'
|
|
@@ -288,6 +338,15 @@ class MyAdapter implements LlmAdapter {
|
|
|
288
338
|
// Send to your model and return the model response as a string
|
|
289
339
|
return `echo: ${messages[messages.length - 1]?.message ?? ''}`
|
|
290
340
|
}
|
|
341
|
+
|
|
342
|
+
setModel(_model: string) {}
|
|
343
|
+
setReasoningEffort(_effort: LllmReasoningEffort) {}
|
|
344
|
+
setMemoryLimit(_limit: number) {}
|
|
345
|
+
|
|
346
|
+
// Return cumulative token usage for this adapter (zeros if you don't track it)
|
|
347
|
+
getTokenUsage(): LmmTokenUsage {
|
|
348
|
+
return { inputTokens: 0, outputTokens: 0, totalTokens: 0 }
|
|
349
|
+
}
|
|
291
350
|
}
|
|
292
351
|
|
|
293
352
|
const bots = SprucebotLlmFactory.Factory(new MyAdapter())
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Schema } from '@sprucelabs/schema';
|
|
2
2
|
import { Log } from '@sprucelabs/spruce-skill-utils';
|
|
3
3
|
import Anthropic from '@anthropic-ai/sdk';
|
|
4
|
-
import { LlmAdapter, SprucebotLlmBot, SendMessageOptions, LllmReasoningEffort } from '../../llm.types';
|
|
4
|
+
import { LlmAdapter, SprucebotLlmBot, SendMessageOptions, LllmReasoningEffort, LmmTokenUsage } from '../../llm.types';
|
|
5
5
|
export default class AnthropicAdapter implements LlmAdapter {
|
|
6
6
|
static Class?: new (apiKey: string, options?: AnthropicAdapterOptions) => LlmAdapter;
|
|
7
7
|
static Anthropic: typeof Anthropic;
|
|
@@ -12,6 +12,7 @@ export default class AnthropicAdapter implements LlmAdapter {
|
|
|
12
12
|
private memoryLimit?;
|
|
13
13
|
private isThinkingEnabled;
|
|
14
14
|
private log?;
|
|
15
|
+
private usage;
|
|
15
16
|
private constructor();
|
|
16
17
|
static Adapter(apiKey: string, options: AnthropicAdapterOptions): LlmAdapter;
|
|
17
18
|
sendMessage(bot: SprucebotLlmBot<Schema>, options?: SendMessageOptions): Promise<string>;
|
|
@@ -19,6 +20,7 @@ export default class AnthropicAdapter implements LlmAdapter {
|
|
|
19
20
|
setModel(model: string): void;
|
|
20
21
|
setReasoningEffort(effort: LllmReasoningEffort): void;
|
|
21
22
|
setMemoryLimit(limit: number): void;
|
|
23
|
+
getTokenUsage(): LmmTokenUsage;
|
|
22
24
|
}
|
|
23
25
|
export interface AnthropicAdapterOptions {
|
|
24
26
|
log?: Log;
|
|
@@ -10,6 +10,13 @@ class AnthropicAdapter {
|
|
|
10
10
|
constructor(apiKey, options) {
|
|
11
11
|
this.model = 'claude-sonnet-4-5';
|
|
12
12
|
this.isThinkingEnabled = false;
|
|
13
|
+
this.usage = {
|
|
14
|
+
inputTokens: 0,
|
|
15
|
+
outputTokens: 0,
|
|
16
|
+
totalTokens: 0,
|
|
17
|
+
cacheCreationTokens: 0,
|
|
18
|
+
cacheReadTokens: 0,
|
|
19
|
+
};
|
|
13
20
|
(0, schema_1.assertOptions)({ apiKey, maxTokens: options?.maxTokens }, [
|
|
14
21
|
'apiKey',
|
|
15
22
|
'maxTokens',
|
|
@@ -68,6 +75,17 @@ class AnthropicAdapter {
|
|
|
68
75
|
}, sendOptions);
|
|
69
76
|
const { usage } = response;
|
|
70
77
|
this.log?.info(`[TOKEN USAGE] input=${usage.input_tokens} cache_create=${usage.cache_creation_input_tokens ?? 0} cache_read=${usage.cache_read_input_tokens ?? 0} output=${usage.output_tokens}`);
|
|
78
|
+
this.usage = {
|
|
79
|
+
inputTokens: this.usage.inputTokens + usage.input_tokens,
|
|
80
|
+
outputTokens: this.usage.outputTokens + usage.output_tokens,
|
|
81
|
+
totalTokens: this.usage.totalTokens +
|
|
82
|
+
usage.input_tokens +
|
|
83
|
+
usage.output_tokens,
|
|
84
|
+
cacheCreationTokens: (this.usage.cacheCreationTokens ?? 0) +
|
|
85
|
+
(usage.cache_creation_input_tokens ?? 0),
|
|
86
|
+
cacheReadTokens: (this.usage.cacheReadTokens ?? 0) +
|
|
87
|
+
(usage.cache_read_input_tokens ?? 0),
|
|
88
|
+
};
|
|
71
89
|
const text = response.content
|
|
72
90
|
.filter((block) => block.type === 'text')
|
|
73
91
|
?.map((block) => block.text)
|
|
@@ -84,6 +102,9 @@ class AnthropicAdapter {
|
|
|
84
102
|
setMemoryLimit(limit) {
|
|
85
103
|
this.memoryLimit = limit;
|
|
86
104
|
}
|
|
105
|
+
getTokenUsage() {
|
|
106
|
+
return this.usage;
|
|
107
|
+
}
|
|
87
108
|
}
|
|
88
109
|
AnthropicAdapter.Anthropic = sdk_1.default;
|
|
89
110
|
exports.default = AnthropicAdapter;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Schema } from '@sprucelabs/schema';
|
|
2
2
|
import { Log } from '@sprucelabs/spruce-skill-utils';
|
|
3
|
-
import { LlmAdapter, SprucebotLlmBot, SendMessageOptions, LllmReasoningEffort } from '../../llm.types';
|
|
3
|
+
import { LlmAdapter, SprucebotLlmBot, SendMessageOptions, LllmReasoningEffort, LmmTokenUsage } from '../../llm.types';
|
|
4
4
|
export default class OllamaAdapter implements LlmAdapter {
|
|
5
5
|
static Class?: new (apiKey: string, options?: OllamaAdapterOptions) => LlmAdapter;
|
|
6
6
|
private openai;
|
|
@@ -11,6 +11,7 @@ export default class OllamaAdapter implements LlmAdapter {
|
|
|
11
11
|
setModel(model: string): void;
|
|
12
12
|
setReasoningEffort(effort: LllmReasoningEffort): void;
|
|
13
13
|
setMemoryLimit(_limit: number): void;
|
|
14
|
+
getTokenUsage(): LmmTokenUsage;
|
|
14
15
|
}
|
|
15
16
|
export interface OllamaAdapterOptions {
|
|
16
17
|
log?: Log;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Log } from '@sprucelabs/spruce-skill-utils';
|
|
2
2
|
import OpenAI from 'openai';
|
|
3
3
|
import { ReasoningEffort } from 'openai/resources';
|
|
4
|
-
import { LlmAdapter, SendMessageOptions, SprucebotLlmBot } from '../../llm.types';
|
|
4
|
+
import { LlmAdapter, LmmTokenUsage, SendMessageOptions, SprucebotLlmBot } from '../../llm.types';
|
|
5
5
|
export default class OpenAiAdapter implements LlmAdapter {
|
|
6
6
|
static Class?: new (apiKey: string, options?: OpenAiAdapterOptions) => LlmAdapter;
|
|
7
7
|
static OpenAI: typeof OpenAI;
|
|
@@ -18,6 +18,7 @@ export default class OpenAiAdapter implements LlmAdapter {
|
|
|
18
18
|
setModel(model: string): void;
|
|
19
19
|
setMemoryLimit(limit: number): void;
|
|
20
20
|
setReasoningEffort(effort: ReasoningEffort): void;
|
|
21
|
+
getTokenUsage(): LmmTokenUsage;
|
|
21
22
|
}
|
|
22
23
|
export declare const MESSAGE_RESPONSE_ERROR_MESSAGE = "Oh no! Something went wrong and I can't talk right now!";
|
|
23
24
|
export interface OpenAiAdapterOptions {
|
|
@@ -48,6 +48,13 @@ class OpenAiAdapter {
|
|
|
48
48
|
setReasoningEffort(effort) {
|
|
49
49
|
this.reasoningEffort = effort;
|
|
50
50
|
}
|
|
51
|
+
getTokenUsage() {
|
|
52
|
+
return {
|
|
53
|
+
inputTokens: 0,
|
|
54
|
+
outputTokens: 0,
|
|
55
|
+
totalTokens: 0,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
51
58
|
}
|
|
52
59
|
OpenAiAdapter.OpenAI = openai_1.default;
|
|
53
60
|
exports.default = OpenAiAdapter;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Schema } from '@sprucelabs/schema';
|
|
2
2
|
import { Log } from '@sprucelabs/spruce-skill-utils';
|
|
3
3
|
import Anthropic from '@anthropic-ai/sdk';
|
|
4
|
-
import { LlmAdapter, SprucebotLlmBot, SendMessageOptions, LllmReasoningEffort } from '../../llm.types';
|
|
4
|
+
import { LlmAdapter, SprucebotLlmBot, SendMessageOptions, LllmReasoningEffort, LmmTokenUsage } from '../../llm.types';
|
|
5
5
|
export default class AnthropicAdapter implements LlmAdapter {
|
|
6
6
|
static Class?: new (apiKey: string, options?: AnthropicAdapterOptions) => LlmAdapter;
|
|
7
7
|
static Anthropic: typeof Anthropic;
|
|
@@ -12,6 +12,7 @@ export default class AnthropicAdapter implements LlmAdapter {
|
|
|
12
12
|
private memoryLimit?;
|
|
13
13
|
private isThinkingEnabled;
|
|
14
14
|
private log?;
|
|
15
|
+
private usage;
|
|
15
16
|
private constructor();
|
|
16
17
|
static Adapter(apiKey: string, options: AnthropicAdapterOptions): LlmAdapter;
|
|
17
18
|
sendMessage(bot: SprucebotLlmBot<Schema>, options?: SendMessageOptions): Promise<string>;
|
|
@@ -19,6 +20,7 @@ export default class AnthropicAdapter implements LlmAdapter {
|
|
|
19
20
|
setModel(model: string): void;
|
|
20
21
|
setReasoningEffort(effort: LllmReasoningEffort): void;
|
|
21
22
|
setMemoryLimit(limit: number): void;
|
|
23
|
+
getTokenUsage(): LmmTokenUsage;
|
|
22
24
|
}
|
|
23
25
|
export interface AnthropicAdapterOptions {
|
|
24
26
|
log?: Log;
|
|
@@ -14,6 +14,13 @@ class AnthropicAdapter {
|
|
|
14
14
|
constructor(apiKey, options) {
|
|
15
15
|
this.model = 'claude-sonnet-4-5';
|
|
16
16
|
this.isThinkingEnabled = false;
|
|
17
|
+
this.usage = {
|
|
18
|
+
inputTokens: 0,
|
|
19
|
+
outputTokens: 0,
|
|
20
|
+
totalTokens: 0,
|
|
21
|
+
cacheCreationTokens: 0,
|
|
22
|
+
cacheReadTokens: 0,
|
|
23
|
+
};
|
|
17
24
|
assertOptions({ apiKey, maxTokens: options === null || options === void 0 ? void 0 : options.maxTokens }, [
|
|
18
25
|
'apiKey',
|
|
19
26
|
'maxTokens',
|
|
@@ -39,7 +46,7 @@ class AnthropicAdapter {
|
|
|
39
46
|
}
|
|
40
47
|
sendHandler(params, sendOptions) {
|
|
41
48
|
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
-
var _a, _b, _c, _d;
|
|
49
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
43
50
|
const { messages: openAiMessages, model } = params;
|
|
44
51
|
const messages = [];
|
|
45
52
|
const cacheMarkerIdx = openAiMessages.findIndex((msg) => msg.cache_marker);
|
|
@@ -73,8 +80,19 @@ class AnthropicAdapter {
|
|
|
73
80
|
}, sendOptions);
|
|
74
81
|
const { usage } = response;
|
|
75
82
|
(_a = this.log) === null || _a === void 0 ? void 0 : _a.info(`[TOKEN USAGE] input=${usage.input_tokens} cache_create=${(_b = usage.cache_creation_input_tokens) !== null && _b !== void 0 ? _b : 0} cache_read=${(_c = usage.cache_read_input_tokens) !== null && _c !== void 0 ? _c : 0} output=${usage.output_tokens}`);
|
|
76
|
-
|
|
77
|
-
|
|
83
|
+
this.usage = {
|
|
84
|
+
inputTokens: this.usage.inputTokens + usage.input_tokens,
|
|
85
|
+
outputTokens: this.usage.outputTokens + usage.output_tokens,
|
|
86
|
+
totalTokens: this.usage.totalTokens +
|
|
87
|
+
usage.input_tokens +
|
|
88
|
+
usage.output_tokens,
|
|
89
|
+
cacheCreationTokens: ((_d = this.usage.cacheCreationTokens) !== null && _d !== void 0 ? _d : 0) +
|
|
90
|
+
((_e = usage.cache_creation_input_tokens) !== null && _e !== void 0 ? _e : 0),
|
|
91
|
+
cacheReadTokens: ((_f = this.usage.cacheReadTokens) !== null && _f !== void 0 ? _f : 0) +
|
|
92
|
+
((_g = usage.cache_read_input_tokens) !== null && _g !== void 0 ? _g : 0),
|
|
93
|
+
};
|
|
94
|
+
const text = (_h = response.content
|
|
95
|
+
.filter((block) => block.type === 'text')) === null || _h === void 0 ? void 0 : _h.map((block) => block.text).join('').trim();
|
|
78
96
|
return text;
|
|
79
97
|
});
|
|
80
98
|
}
|
|
@@ -87,6 +105,9 @@ class AnthropicAdapter {
|
|
|
87
105
|
setMemoryLimit(limit) {
|
|
88
106
|
this.memoryLimit = limit;
|
|
89
107
|
}
|
|
108
|
+
getTokenUsage() {
|
|
109
|
+
return this.usage;
|
|
110
|
+
}
|
|
90
111
|
}
|
|
91
112
|
AnthropicAdapter.Anthropic = Anthropic;
|
|
92
113
|
export default AnthropicAdapter;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Schema } from '@sprucelabs/schema';
|
|
2
2
|
import { Log } from '@sprucelabs/spruce-skill-utils';
|
|
3
|
-
import { LlmAdapter, SprucebotLlmBot, SendMessageOptions, LllmReasoningEffort } from '../../llm.types';
|
|
3
|
+
import { LlmAdapter, SprucebotLlmBot, SendMessageOptions, LllmReasoningEffort, LmmTokenUsage } from '../../llm.types';
|
|
4
4
|
export default class OllamaAdapter implements LlmAdapter {
|
|
5
5
|
static Class?: new (apiKey: string, options?: OllamaAdapterOptions) => LlmAdapter;
|
|
6
6
|
private openai;
|
|
@@ -11,6 +11,7 @@ export default class OllamaAdapter implements LlmAdapter {
|
|
|
11
11
|
setModel(model: string): void;
|
|
12
12
|
setReasoningEffort(effort: LllmReasoningEffort): void;
|
|
13
13
|
setMemoryLimit(_limit: number): void;
|
|
14
|
+
getTokenUsage(): LmmTokenUsage;
|
|
14
15
|
}
|
|
15
16
|
export interface OllamaAdapterOptions {
|
|
16
17
|
log?: Log;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Log } from '@sprucelabs/spruce-skill-utils';
|
|
2
2
|
import OpenAI from 'openai';
|
|
3
3
|
import { ReasoningEffort } from 'openai/resources';
|
|
4
|
-
import { LlmAdapter, SendMessageOptions, SprucebotLlmBot } from '../../llm.types';
|
|
4
|
+
import { LlmAdapter, LmmTokenUsage, SendMessageOptions, SprucebotLlmBot } from '../../llm.types';
|
|
5
5
|
export default class OpenAiAdapter implements LlmAdapter {
|
|
6
6
|
static Class?: new (apiKey: string, options?: OpenAiAdapterOptions) => LlmAdapter;
|
|
7
7
|
static OpenAI: typeof OpenAI;
|
|
@@ -18,6 +18,7 @@ export default class OpenAiAdapter implements LlmAdapter {
|
|
|
18
18
|
setModel(model: string): void;
|
|
19
19
|
setMemoryLimit(limit: number): void;
|
|
20
20
|
setReasoningEffort(effort: ReasoningEffort): void;
|
|
21
|
+
getTokenUsage(): LmmTokenUsage;
|
|
21
22
|
}
|
|
22
23
|
export declare const MESSAGE_RESPONSE_ERROR_MESSAGE = "Oh no! Something went wrong and I can't talk right now!";
|
|
23
24
|
export interface OpenAiAdapterOptions {
|
|
@@ -53,6 +53,13 @@ class OpenAiAdapter {
|
|
|
53
53
|
setReasoningEffort(effort) {
|
|
54
54
|
this.reasoningEffort = effort;
|
|
55
55
|
}
|
|
56
|
+
getTokenUsage() {
|
|
57
|
+
return {
|
|
58
|
+
inputTokens: 0,
|
|
59
|
+
outputTokens: 0,
|
|
60
|
+
totalTokens: 0,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
56
63
|
}
|
|
57
64
|
OpenAiAdapter.OpenAI = OpenAI;
|
|
58
65
|
export default OpenAiAdapter;
|
package/build/esm/index.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export { default as SpyLlmAdapter } from './tests/SpyAdapter';
|
|
|
10
10
|
export { default as SpyOpenAiApi } from './bots/adapters/SpyOpenAiModule';
|
|
11
11
|
export { default as OllamaAdapter } from './bots/adapters/OllamaAdapter';
|
|
12
12
|
export * from './bots/adapters/OllamaAdapter';
|
|
13
|
-
export { default as
|
|
13
|
+
export { default as AnthropicAdapter } from './bots/adapters/AnthropicAdapter';
|
|
14
14
|
export * from './bots/adapters/AnthropicAdapter';
|
|
15
15
|
export { default as LlmAdapterLoader } from './bots/adapters/LlmAdapterLoader';
|
|
16
16
|
export * from './bots/adapters/LlmAdapterLoader';
|
package/build/esm/index.js
CHANGED
|
@@ -10,7 +10,7 @@ export { default as SpyLlmAdapter } from './tests/SpyAdapter.js';
|
|
|
10
10
|
export { default as SpyOpenAiApi } from './bots/adapters/SpyOpenAiModule.js';
|
|
11
11
|
export { default as OllamaAdapter } from './bots/adapters/OllamaAdapter.js';
|
|
12
12
|
export * from './bots/adapters/OllamaAdapter.js';
|
|
13
|
-
export { default as
|
|
13
|
+
export { default as AnthropicAdapter } from './bots/adapters/AnthropicAdapter.js';
|
|
14
14
|
export * from './bots/adapters/AnthropicAdapter.js';
|
|
15
15
|
export { default as LlmAdapterLoader } from './bots/adapters/LlmAdapterLoader.js';
|
|
16
16
|
export * from './bots/adapters/LlmAdapterLoader.js';
|
package/build/esm/llm.types.d.ts
CHANGED
|
@@ -21,6 +21,14 @@ export interface LlmAdapter {
|
|
|
21
21
|
setModel(model: string): void;
|
|
22
22
|
setReasoningEffort(effort: LllmReasoningEffort): void;
|
|
23
23
|
setMemoryLimit(limit: number): void;
|
|
24
|
+
getTokenUsage(): LmmTokenUsage;
|
|
25
|
+
}
|
|
26
|
+
export interface LmmTokenUsage {
|
|
27
|
+
inputTokens: number;
|
|
28
|
+
outputTokens: number;
|
|
29
|
+
totalTokens: number;
|
|
30
|
+
cacheCreationTokens?: number;
|
|
31
|
+
cacheReadTokens?: number;
|
|
24
32
|
}
|
|
25
33
|
export interface PromptOptions<StateSchema extends Schema, State extends SchemaValues<StateSchema> = SchemaValues<StateSchema>> {
|
|
26
34
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { OpenAiAdapterOptions } from '../bots/adapters/OpenAiAdapter';
|
|
2
|
-
import { LllmReasoningEffort, LlmAdapter, SendMessageOptions, SprucebotLlmBot } from '../llm.types';
|
|
2
|
+
import { LllmReasoningEffort, LlmAdapter, LmmTokenUsage, SendMessageOptions, SprucebotLlmBot } from '../llm.types';
|
|
3
3
|
export default class SpyLlmAdapter implements LlmAdapter {
|
|
4
4
|
static instance: SpyLlmAdapter;
|
|
5
5
|
lastSendMessageBot?: SprucebotLlmBot;
|
|
@@ -16,4 +16,5 @@ export default class SpyLlmAdapter implements LlmAdapter {
|
|
|
16
16
|
setModel(model: string): void;
|
|
17
17
|
setReasoningEffort(_effort: LllmReasoningEffort): void;
|
|
18
18
|
setMemoryLimit(_limit: number): void;
|
|
19
|
+
getTokenUsage(): LmmTokenUsage;
|
|
19
20
|
}
|
package/build/index.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export { default as SpyLlmAdapter } from './tests/SpyAdapter';
|
|
|
10
10
|
export { default as SpyOpenAiApi } from './bots/adapters/SpyOpenAiModule';
|
|
11
11
|
export { default as OllamaAdapter } from './bots/adapters/OllamaAdapter';
|
|
12
12
|
export * from './bots/adapters/OllamaAdapter';
|
|
13
|
-
export { default as
|
|
13
|
+
export { default as AnthropicAdapter } from './bots/adapters/AnthropicAdapter';
|
|
14
14
|
export * from './bots/adapters/AnthropicAdapter';
|
|
15
15
|
export { default as LlmAdapterLoader } from './bots/adapters/LlmAdapterLoader';
|
|
16
16
|
export * from './bots/adapters/LlmAdapterLoader';
|
package/build/index.js
CHANGED
|
@@ -17,7 +17,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
17
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.MockAdapterLoader = exports.LlmAdapterLoader = exports.
|
|
20
|
+
exports.MockAdapterLoader = exports.LlmAdapterLoader = exports.AnthropicAdapter = exports.OllamaAdapter = exports.SpyOpenAiApi = exports.SpyLlmAdapter = exports.SpyLllmBot = exports.MockLlmSkill = exports.SprucebotLlmError = exports.OpenAiAdapter = exports.SprucebotLlmSkillImpl = exports.SprucebotLlmBotImpl = exports.SprucebotLlmFactory = void 0;
|
|
21
21
|
var SprucebotLlmFactory_1 = require("./bots/SprucebotLlmFactory");
|
|
22
22
|
Object.defineProperty(exports, "SprucebotLlmFactory", { enumerable: true, get: function () { return __importDefault(SprucebotLlmFactory_1).default; } });
|
|
23
23
|
var SprucebotLlmBotImpl_1 = require("./bots/SprucebotLlmBotImpl");
|
|
@@ -41,7 +41,7 @@ var OllamaAdapter_1 = require("./bots/adapters/OllamaAdapter");
|
|
|
41
41
|
Object.defineProperty(exports, "OllamaAdapter", { enumerable: true, get: function () { return __importDefault(OllamaAdapter_1).default; } });
|
|
42
42
|
__exportStar(require("./bots/adapters/OllamaAdapter"), exports);
|
|
43
43
|
var AnthropicAdapter_1 = require("./bots/adapters/AnthropicAdapter");
|
|
44
|
-
Object.defineProperty(exports, "
|
|
44
|
+
Object.defineProperty(exports, "AnthropicAdapter", { enumerable: true, get: function () { return __importDefault(AnthropicAdapter_1).default; } });
|
|
45
45
|
__exportStar(require("./bots/adapters/AnthropicAdapter"), exports);
|
|
46
46
|
var LlmAdapterLoader_1 = require("./bots/adapters/LlmAdapterLoader");
|
|
47
47
|
Object.defineProperty(exports, "LlmAdapterLoader", { enumerable: true, get: function () { return __importDefault(LlmAdapterLoader_1).default; } });
|
package/build/llm.types.d.ts
CHANGED
|
@@ -21,6 +21,14 @@ export interface LlmAdapter {
|
|
|
21
21
|
setModel(model: string): void;
|
|
22
22
|
setReasoningEffort(effort: LllmReasoningEffort): void;
|
|
23
23
|
setMemoryLimit(limit: number): void;
|
|
24
|
+
getTokenUsage(): LmmTokenUsage;
|
|
25
|
+
}
|
|
26
|
+
export interface LmmTokenUsage {
|
|
27
|
+
inputTokens: number;
|
|
28
|
+
outputTokens: number;
|
|
29
|
+
totalTokens: number;
|
|
30
|
+
cacheCreationTokens?: number;
|
|
31
|
+
cacheReadTokens?: number;
|
|
24
32
|
}
|
|
25
33
|
export interface PromptOptions<StateSchema extends Schema, State extends SchemaValues<StateSchema> = SchemaValues<StateSchema>> {
|
|
26
34
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { OpenAiAdapterOptions } from '../bots/adapters/OpenAiAdapter';
|
|
2
|
-
import { LllmReasoningEffort, LlmAdapter, SendMessageOptions, SprucebotLlmBot } from '../llm.types';
|
|
2
|
+
import { LllmReasoningEffort, LlmAdapter, LmmTokenUsage, SendMessageOptions, SprucebotLlmBot } from '../llm.types';
|
|
3
3
|
export default class SpyLlmAdapter implements LlmAdapter {
|
|
4
4
|
static instance: SpyLlmAdapter;
|
|
5
5
|
lastSendMessageBot?: SprucebotLlmBot;
|
|
@@ -16,4 +16,5 @@ export default class SpyLlmAdapter implements LlmAdapter {
|
|
|
16
16
|
setModel(model: string): void;
|
|
17
17
|
setReasoningEffort(_effort: LllmReasoningEffort): void;
|
|
18
18
|
setMemoryLimit(_limit: number): void;
|
|
19
|
+
getTokenUsage(): LmmTokenUsage;
|
|
19
20
|
}
|