@promptbook/legacy-documents 0.105.0-1 → 0.105.0-4
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 +36 -77
- package/esm/index.es.js +90 -66
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/core.index.d.ts +2 -0
- package/esm/typings/src/_packages/types.index.d.ts +4 -0
- package/esm/typings/src/book-2.0/agent-source/AgentBasicInformation.d.ts +10 -3
- package/esm/typings/src/book-2.0/agent-source/AgentModelRequirements.d.ts +11 -1
- package/esm/typings/src/book-2.0/agent-source/communication-samples.test.d.ts +1 -0
- package/esm/typings/src/book-2.0/agent-source/createAgentModelRequirementsWithCommitments.blocks.test.d.ts +1 -0
- package/esm/typings/src/book-2.0/agent-source/createAgentModelRequirementsWithCommitments.import.test.d.ts +1 -0
- package/esm/typings/src/book-2.0/agent-source/parseAgentSource.import.test.d.ts +1 -0
- package/esm/typings/src/book-2.0/agent-source/parseAgentSourceWithCommitments.blocks.test.d.ts +1 -0
- package/esm/typings/src/commitments/USE_TIME/USE_TIME.d.ts +40 -0
- package/esm/typings/src/commitments/USE_TIME/USE_TIME.test.d.ts +1 -0
- package/esm/typings/src/commitments/_base/BaseCommitmentDefinition.d.ts +8 -0
- package/esm/typings/src/commitments/_base/CommitmentDefinition.d.ts +8 -0
- package/esm/typings/src/commitments/index.d.ts +11 -2
- package/esm/typings/src/config.d.ts +1 -0
- package/esm/typings/src/import-plugins/$fileImportPlugins.d.ts +7 -0
- package/esm/typings/src/import-plugins/AgentFileImportPlugin.d.ts +7 -0
- package/esm/typings/src/import-plugins/FileImportPlugin.d.ts +24 -0
- package/esm/typings/src/import-plugins/JsonFileImportPlugin.d.ts +7 -0
- package/esm/typings/src/import-plugins/TextFileImportPlugin.d.ts +7 -0
- package/esm/typings/src/llm-providers/_common/utils/cache/cacheLlmTools.d.ts +2 -1
- package/esm/typings/src/llm-providers/_common/utils/count-total-usage/countUsage.d.ts +2 -2
- package/esm/typings/src/llm-providers/agent/Agent.d.ts +9 -2
- package/esm/typings/src/llm-providers/agent/AgentLlmExecutionTools.d.ts +3 -1
- package/esm/typings/src/llm-providers/openai/OpenAiAssistantExecutionTools.d.ts +10 -0
- package/esm/typings/src/llm-providers/remote/RemoteLlmExecutionTools.d.ts +1 -1
- package/esm/typings/src/scripting/javascript/JavascriptExecutionToolsOptions.d.ts +6 -1
- package/esm/typings/src/types/ModelRequirements.d.ts +6 -12
- package/esm/typings/src/utils/execCommand/$execCommandNormalizeOptions.d.ts +2 -3
- package/esm/typings/src/utils/execCommand/ExecCommandOptions.d.ts +7 -1
- package/esm/typings/src/utils/organization/keepImported.d.ts +9 -0
- package/esm/typings/src/utils/organization/keepTypeImported.d.ts +0 -1
- package/esm/typings/src/version.d.ts +1 -1
- package/package.json +2 -2
- package/umd/index.umd.js +90 -66
- package/umd/index.umd.js.map +1 -1
package/README.md
CHANGED
|
@@ -60,19 +60,20 @@ Rest of the documentation is common for **entire promptbook ecosystem**:
|
|
|
60
60
|
|
|
61
61
|
## 📖 The Book Whitepaper
|
|
62
62
|
|
|
63
|
-
|
|
63
|
+
Nowadays, the biggest challenge for most business applications isn't the raw capabilities of AI models. Large language models such as GPT-5.2 and Claude-4.5 are incredibly capable.
|
|
64
64
|
|
|
65
|
-
The main challenge
|
|
65
|
+
The main challenge lies in **managing the context**, providing rules and knowledge, and narrowing the personality.
|
|
66
66
|
|
|
67
|
-
Promptbook
|
|
67
|
+
In Promptbook, you can define your context **using simple Books** that are very explicit, easy to understand and write, reliable, and highly portable.
|
|
68
68
|
|
|
69
69
|
<table style="border: 1px solid #777; border-radius: 10px;"><tr><td>
|
|
70
70
|
|
|
71
|
-
**<ins>Paul Smith
|
|
71
|
+
**<ins>Paul Smith</ins>**<br/>
|
|
72
72
|
<br/>
|
|
73
73
|
**PERSONA** You are a company lawyer.<br/>
|
|
74
74
|
Your job is to provide legal advice and support to the company and its employees.<br/>
|
|
75
|
-
You are knowledgeable, professional, and detail-oriented.<br/>
|
|
75
|
+
**RULE** You are knowledgeable, professional, and detail-oriented.<br/>
|
|
76
|
+
TEAM You are part of the legal team of Paul Smith & Associés, you discuss with {Emily White}, the head of the compliance department. {George Brown} is expert in corporate law and {Sophia Black} is expert in labor law.<br/>
|
|
76
77
|
|
|
77
78
|
</td></tr></table>
|
|
78
79
|
|
|
@@ -82,7 +83,9 @@ You are knowledgeable, professional, and detail-oriented.<br/>
|
|
|
82
83
|
|
|
83
84
|
We have created a language called **Book**, which allows you to write AI agents in their native language and create your own AI persona. Book provides a guide to define all the traits and commitments.
|
|
84
85
|
|
|
85
|
-
You can look at it as prompting (or writing a system message), but decorated by **commitments**.
|
|
86
|
+
You can look at it as "prompting" _(or writing a system message)_, but decorated by **commitments**.
|
|
87
|
+
|
|
88
|
+
**Commitments** are special syntax elements that define contracts between you and the AI agent. They are transformed by Promptbook Engine into low-level parameters like which model to use, its temperature, system message, RAG index, MCP servers, and many other parameters. For some commitments _(for example `RULE` commitment)_ Promptbook Engine can even create adversary agents and extra checks to enforce the rules.
|
|
86
89
|
|
|
87
90
|
#### `Persona` commitment
|
|
88
91
|
|
|
@@ -93,8 +96,6 @@ Personas define the character of your AI persona, its role, and how it should in
|
|
|
93
96
|
**<ins>Paul Smith & Associés</ins>**<br/>
|
|
94
97
|
<br/>
|
|
95
98
|
**PERSONA** You are a company lawyer.<br/>
|
|
96
|
-
Your job is to provide legal advice and support to the company and its employees.<br/>
|
|
97
|
-
You are knowledgeable, professional, and detail-oriented.<br/>
|
|
98
99
|
|
|
99
100
|
</td></tr></table>
|
|
100
101
|
|
|
@@ -114,7 +115,7 @@ Promptbook Engine will automatically enforce this knowledge during interactions.
|
|
|
114
115
|
Your job is to provide legal advice and support to the company and its employees.<br/>
|
|
115
116
|
You are knowledgeable, professional, and detail-oriented.<br/>
|
|
116
117
|
<br/>
|
|
117
|
-
**KNOWLEDGE**
|
|
118
|
+
**KNOWLEDGE** https://company.com/company-policies.pdf<br/>
|
|
118
119
|
**KNOWLEDGE** https://company.com/internal-documents/employee-handbook.docx<br/>
|
|
119
120
|
|
|
120
121
|
</td></tr></table>
|
|
@@ -136,14 +137,14 @@ You are knowledgeable, professional, and detail-oriented.<br/>
|
|
|
136
137
|
**RULE** Always ensure compliance with laws and regulations.<br/>
|
|
137
138
|
**RULE** Never provide legal advice outside your area of expertise.<br/>
|
|
138
139
|
**RULE** Never provide legal advice about criminal law.<br/>
|
|
139
|
-
**KNOWLEDGE**
|
|
140
|
+
**KNOWLEDGE** https://company.com/company-policies.pdf<br/>
|
|
140
141
|
**KNOWLEDGE** https://company.com/internal-documents/employee-handbook.docx<br/>
|
|
141
142
|
|
|
142
143
|
</td></tr></table>
|
|
143
144
|
|
|
144
|
-
#### `
|
|
145
|
+
#### `Team` commitment
|
|
145
146
|
|
|
146
|
-
|
|
147
|
+
Team commitment allows you to define the team structure and advisory fellow members the AI can consult with. This allows the AI to simulate collaboration and consultation with other experts, enhancing the quality of its responses.
|
|
147
148
|
|
|
148
149
|
<table style="border: 1px solid #777; border-radius: 10px;"><tr><td>
|
|
149
150
|
|
|
@@ -156,81 +157,36 @@ You are knowledgeable, professional, and detail-oriented.<br/>
|
|
|
156
157
|
**RULE** Always ensure compliance with laws and regulations.<br/>
|
|
157
158
|
**RULE** Never provide legal advice outside your area of expertise.<br/>
|
|
158
159
|
**RULE** Never provide legal advice about criminal law.<br/>
|
|
159
|
-
**KNOWLEDGE**
|
|
160
|
+
**KNOWLEDGE** https://company.com/company-policies.pdf<br/>
|
|
160
161
|
**KNOWLEDGE** https://company.com/internal-documents/employee-handbook.docx<br/>
|
|
161
|
-
|
|
162
|
+
TEAM You are part of the legal team of Paul Smith & Associés, you discuss with {Emily White}, the head of the compliance department. {George Brown} is expert in corporate law and {Sophia Black} is expert in labor law.<br/>
|
|
162
163
|
|
|
163
164
|
</td></tr></table>
|
|
164
165
|
|
|
165
|
-
[Read more about the language](./BLUEPRINT.md)
|
|
166
|
-
|
|
167
|
-
<div style="page-break-after: always;"></div>
|
|
168
|
-
|
|
169
|
-
### Where to use your AI agent in book
|
|
170
|
-
|
|
171
|
-
Books can be useful in various applications and scenarios. Here are some examples:
|
|
172
|
-
|
|
173
|
-
#### Chat apps:
|
|
174
166
|
|
|
175
|
-
Create your own chat shopping assistant and place it in your eShop.
|
|
176
|
-
You will be able to answer customer questions, help them find products, and provide personalized recommendations. Everything is tightly controlled by the book you have written.
|
|
177
167
|
|
|
178
|
-
|
|
168
|
+
### Promptbook Ecosystem
|
|
179
169
|
|
|
180
|
-
|
|
170
|
+
!!!@@@
|
|
181
171
|
|
|
182
|
-
####
|
|
183
|
-
|
|
184
|
-
Do you love Vibecoding, but the AI code is not always aligned with your coding style and architecture, rules, security, etc.? Create your own coding agent to help enforce your specific coding standards and practices.
|
|
185
|
-
|
|
186
|
-
This can be integrated to almost any Vibecoding platform, like GitHub Copilot, Amazon CodeWhisperer, Cursor, Cline, Kilocode, Roocode,...
|
|
187
|
-
|
|
188
|
-
They will work the same as you are used to, but with your specific rules written in book.
|
|
189
|
-
|
|
190
|
-
#### Internal Expertise
|
|
191
|
-
|
|
192
|
-
Do you have an app written in TypeScript, Python, C#, Java, or any other language, and you are integrating the AI.
|
|
193
|
-
|
|
194
|
-
You can avoid struggle with choosing the best model, its settings like temperature, max tokens, etc., by writing a book agent and using it as your AI expertise.
|
|
195
|
-
|
|
196
|
-
Doesn't matter if you do automations, data analysis, customer support, sentiment analysis, classification, or any other task. Your AI agent will be tailored to your specific needs and requirements.
|
|
197
|
-
|
|
198
|
-
Even works in no-code platforms!
|
|
199
|
-
|
|
200
|
-
<div style="page-break-after: always;"></div>
|
|
172
|
+
#### Promptbook Server
|
|
201
173
|
|
|
202
|
-
|
|
174
|
+
!!!@@@
|
|
203
175
|
|
|
204
|
-
|
|
176
|
+
#### Promptbook Engine
|
|
205
177
|
|
|
206
|
-
|
|
178
|
+
!!!@@@
|
|
207
179
|
|
|
208
|
-
We have written ai asistant in book who can help you with writing your first book.
|
|
209
180
|
|
|
210
|
-
#### Your AI twin
|
|
211
181
|
|
|
212
|
-
Copy your own behavior, personality, and knowledge into book and create your AI twin. It can help you with your work, personal life, or any other task.
|
|
213
182
|
|
|
214
|
-
#### AI persona workpool
|
|
215
183
|
|
|
216
|
-
Or you can pick from our library of pre-written books for various roles and tasks. You can find books for customer support, coding, marketing, sales, HR, legal, and many other roles.
|
|
217
184
|
|
|
218
185
|
|
|
219
186
|
|
|
220
187
|
|
|
221
188
|
|
|
222
189
|
|
|
223
|
-
## 🚀 Get started
|
|
224
|
-
|
|
225
|
-
Take a look at the simple starter kit with books integrated into the **Hello World** sample applications:
|
|
226
|
-
|
|
227
|
-
- [Hello Book](https://github.com/webgptorg/hello-world)
|
|
228
|
-
- [Hello Book in Node.js](https://github.com/webgptorg/hello-world-node-js)
|
|
229
|
-
- [Hello Book in Next.js](https://github.com/webgptorg/hello-world-next-js)
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
190
|
|
|
235
191
|
|
|
236
192
|
## 💜 The Promptbook Project
|
|
@@ -246,33 +202,32 @@ Promptbook project is ecosystem of multiple projects and tools, following is a l
|
|
|
246
202
|
</thead>
|
|
247
203
|
<tbody>
|
|
248
204
|
<tr>
|
|
249
|
-
<td><a href="https://
|
|
205
|
+
<td><a href="https://gallery.ptbk.io/">Agents Server</a></td>
|
|
250
206
|
<td>
|
|
251
|
-
|
|
252
|
-
<hr>
|
|
253
|
-
There is also <a href="https://github.com/webgptorg/book-extension">a plugin for VSCode</a> to support <code>.book</code> file extension
|
|
207
|
+
Place where you "AI agents live". It allows to create, manage, deploy, and interact with AI agents created in Book language.
|
|
254
208
|
</td>
|
|
255
209
|
</tr>
|
|
256
210
|
<tr>
|
|
257
|
-
<td><a href="https://github.com/webgptorg/
|
|
211
|
+
<td><a href="https://github.com/webgptorg/book">Book language</a></td>
|
|
258
212
|
<td>
|
|
259
|
-
|
|
213
|
+
Human-friendly, high-level language that abstracts away low-level details of AI. It allows to focus on personality, behavior, knowledge, and rules of AI agents rather than on models, parameters, and prompt engineering.
|
|
214
|
+
<hr>
|
|
215
|
+
There is also <a href="https://github.com/webgptorg/book-extension">a plugin for VSCode</a> to support <code>.book</code> file extension
|
|
260
216
|
</td>
|
|
261
217
|
</tr>
|
|
262
218
|
<tr>
|
|
263
|
-
<td><a href="https://promptbook
|
|
219
|
+
<td><a href="https://github.com/webgptorg/promptbook">Promptbook Engine</a></td>
|
|
264
220
|
<td>
|
|
265
|
-
Promptbook
|
|
221
|
+
Promptbook engine can run AI agents based on Book language.
|
|
222
|
+
It is released as <a href="https://www.npmjs.com/package/@promptbook/core#-packages-for-developers">multiple NPM packages</a> and <a href="https://hub.docker.com/r/hejny/promptbook">Promptbook Agent Server as Docker Package</a>
|
|
223
|
+
Agent Server is based on Promptbook Engine.
|
|
266
224
|
</td>
|
|
267
225
|
</tr>
|
|
226
|
+
|
|
268
227
|
</tbody>
|
|
269
228
|
</table>
|
|
270
229
|
|
|
271
|
-
Hello world examples:
|
|
272
230
|
|
|
273
|
-
- [Hello world](https://github.com/webgptorg/hello-world)
|
|
274
|
-
- [Hello world in Node.js](https://github.com/webgptorg/hello-world-node-js)
|
|
275
|
-
- [Hello world in Next.js](https://github.com/webgptorg/hello-world-next-js)
|
|
276
231
|
|
|
277
232
|
### 🌐 Community & Social Media
|
|
278
233
|
|
|
@@ -330,6 +285,8 @@ Join our growing community of developers and users:
|
|
|
330
285
|
|
|
331
286
|
|
|
332
287
|
|
|
288
|
+
|
|
289
|
+
|
|
333
290
|
## 📚 Documentation
|
|
334
291
|
|
|
335
292
|
See detailed guides and API reference in the [docs](https://github.com/webgptorg/promptbook/discussions/categories/concepts) or [online](https://discord.gg/x3QWNaa89N).
|
|
@@ -406,6 +363,8 @@ The following glossary is used to clarify certain concepts:
|
|
|
406
363
|
|
|
407
364
|
_Note: This section is not a complete dictionary, more list of general AI / LLM terms that has connection with Promptbook_
|
|
408
365
|
|
|
366
|
+
|
|
367
|
+
|
|
409
368
|
### 💯 Core concepts
|
|
410
369
|
|
|
411
370
|
- [📚 Collection of pipelines](https://github.com/webgptorg/promptbook/discussions/65)
|
package/esm/index.es.js
CHANGED
|
@@ -26,7 +26,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
|
|
|
26
26
|
* @generated
|
|
27
27
|
* @see https://github.com/webgptorg/promptbook
|
|
28
28
|
*/
|
|
29
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.105.0-
|
|
29
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.105.0-4';
|
|
30
30
|
/**
|
|
31
31
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
32
32
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -988,6 +988,7 @@ const PROMPTBOOK_COLOR = Color.fromString('promptbook');
|
|
|
988
988
|
SEPARATOR: Color.fromHex('#cccccc'),
|
|
989
989
|
COMMITMENT: Color.fromHex('#DA0F78'),
|
|
990
990
|
PARAMETER: Color.fromHex('#8e44ad'),
|
|
991
|
+
CODE_BLOCK: Color.fromHex('#7700ffff'),
|
|
991
992
|
});
|
|
992
993
|
// <- TODO: [🧠][🈵] Using `Color` here increases the package size approx 3kb, maybe remove it
|
|
993
994
|
/**
|
|
@@ -1309,6 +1310,7 @@ function $execCommandNormalizeOptions(options) {
|
|
|
1309
1310
|
let args = [];
|
|
1310
1311
|
let timeout;
|
|
1311
1312
|
let isVerbose;
|
|
1313
|
+
let env;
|
|
1312
1314
|
if (typeof options === 'string') {
|
|
1313
1315
|
// TODO: [1] DRY default values
|
|
1314
1316
|
command = options;
|
|
@@ -1316,6 +1318,7 @@ function $execCommandNormalizeOptions(options) {
|
|
|
1316
1318
|
crashOnError = true;
|
|
1317
1319
|
timeout = Infinity; // <- TODO: [⏳]
|
|
1318
1320
|
isVerbose = DEFAULT_IS_VERBOSE;
|
|
1321
|
+
env = undefined;
|
|
1319
1322
|
}
|
|
1320
1323
|
else {
|
|
1321
1324
|
/*
|
|
@@ -1332,6 +1335,7 @@ function $execCommandNormalizeOptions(options) {
|
|
|
1332
1335
|
crashOnError = (_b = options.crashOnError) !== null && _b !== void 0 ? _b : true;
|
|
1333
1336
|
timeout = (_c = options.timeout) !== null && _c !== void 0 ? _c : Infinity;
|
|
1334
1337
|
isVerbose = (_d = options.isVerbose) !== null && _d !== void 0 ? _d : DEFAULT_IS_VERBOSE;
|
|
1338
|
+
env = options.env;
|
|
1335
1339
|
}
|
|
1336
1340
|
// TODO: /(-[a-zA-Z0-9-]+\s+[^\s]*)|[^\s]*/g
|
|
1337
1341
|
const _ = Array.from(command.matchAll(/(".*")|([^\s]*)/g))
|
|
@@ -1350,7 +1354,7 @@ function $execCommandNormalizeOptions(options) {
|
|
|
1350
1354
|
if (/^win/.test(process.platform) && ['npm', 'npx'].includes(command)) {
|
|
1351
1355
|
command = `${command}.cmd`;
|
|
1352
1356
|
}
|
|
1353
|
-
return { command, humanReadableCommand, args, cwd, crashOnError, timeout, isVerbose };
|
|
1357
|
+
return { command, humanReadableCommand, args, cwd, crashOnError, timeout, isVerbose, env };
|
|
1354
1358
|
}
|
|
1355
1359
|
// TODO: This should show type error> execCommandNormalizeOptions({ command: '', commands: [''] });
|
|
1356
1360
|
|
|
@@ -1371,7 +1375,7 @@ function $execCommand(options) {
|
|
|
1371
1375
|
}
|
|
1372
1376
|
return new Promise((resolve, reject) => {
|
|
1373
1377
|
// eslint-disable-next-line prefer-const
|
|
1374
|
-
const { command, humanReadableCommand, args, cwd, crashOnError, timeout, isVerbose = DEFAULT_IS_VERBOSE, } = $execCommandNormalizeOptions(options);
|
|
1378
|
+
const { command, humanReadableCommand, args, cwd, crashOnError, timeout, isVerbose = DEFAULT_IS_VERBOSE, env, } = $execCommandNormalizeOptions(options);
|
|
1375
1379
|
if (timeout !== Infinity) {
|
|
1376
1380
|
// TODO: In waitasecond forTime(Infinity) should be equivalent to forEver()
|
|
1377
1381
|
forTime(timeout).then(() => {
|
|
@@ -1389,7 +1393,11 @@ function $execCommand(options) {
|
|
|
1389
1393
|
console.info(colors.yellow(cwd) + ' ' + colors.green(command) + ' ' + colors.blue(args.join(' ')));
|
|
1390
1394
|
}
|
|
1391
1395
|
try {
|
|
1392
|
-
const commandProcess = spawn(command, args, {
|
|
1396
|
+
const commandProcess = spawn(command, args, {
|
|
1397
|
+
cwd,
|
|
1398
|
+
shell: true,
|
|
1399
|
+
env: env ? { ...process.env, ...env } : process.env,
|
|
1400
|
+
});
|
|
1393
1401
|
if (isVerbose) {
|
|
1394
1402
|
commandProcess.on('message', (message) => {
|
|
1395
1403
|
console.info({ message });
|
|
@@ -3994,74 +4002,90 @@ function addUsage(...usageItems) {
|
|
|
3994
4002
|
* in real-time through an observable.
|
|
3995
4003
|
*
|
|
3996
4004
|
* @param llmTools - The LLM tools to be intercepted and tracked
|
|
3997
|
-
* @returns
|
|
4005
|
+
* @returns Full proxy of the tools with added usage tracking capabilities
|
|
3998
4006
|
* @public exported from `@promptbook/core`
|
|
3999
4007
|
*/
|
|
4000
4008
|
function countUsage(llmTools) {
|
|
4001
4009
|
let totalUsage = ZERO_USAGE;
|
|
4002
4010
|
const spending = new Subject();
|
|
4003
|
-
|
|
4004
|
-
|
|
4005
|
-
|
|
4006
|
-
//
|
|
4007
|
-
|
|
4008
|
-
|
|
4009
|
-
|
|
4010
|
-
|
|
4011
|
-
|
|
4012
|
-
//
|
|
4013
|
-
|
|
4014
|
-
|
|
4015
|
-
|
|
4016
|
-
|
|
4017
|
-
|
|
4018
|
-
|
|
4019
|
-
|
|
4020
|
-
|
|
4021
|
-
|
|
4022
|
-
|
|
4023
|
-
|
|
4024
|
-
//
|
|
4025
|
-
|
|
4011
|
+
// Create a Proxy to intercept all property access and ensure full proxying of all properties
|
|
4012
|
+
const proxyTools = new Proxy(llmTools, {
|
|
4013
|
+
get(target, prop, receiver) {
|
|
4014
|
+
// Handle title property
|
|
4015
|
+
if (prop === 'title') {
|
|
4016
|
+
return `${target.title} (+usage)`;
|
|
4017
|
+
// <- TODO: [🧈] Maybe standartize the suffix when wrapping `LlmExecutionTools` up
|
|
4018
|
+
// <- TODO: [🧈][🧠] Does it make sense to suffix "(+usage)"?
|
|
4019
|
+
}
|
|
4020
|
+
// Handle description property
|
|
4021
|
+
if (prop === 'description') {
|
|
4022
|
+
return `${target.description} (+usage)`;
|
|
4023
|
+
// <- TODO: [🧈] Maybe standartize the suffix when wrapping `LlmExecutionTools` up
|
|
4024
|
+
// <- TODO: [🧈][🧠] Does it make sense to suffix "(+usage)"?
|
|
4025
|
+
}
|
|
4026
|
+
// Handle spending method (new method added by this wrapper)
|
|
4027
|
+
if (prop === 'spending') {
|
|
4028
|
+
return () => {
|
|
4029
|
+
return spending.asObservable();
|
|
4030
|
+
};
|
|
4031
|
+
}
|
|
4032
|
+
// Handle getTotalUsage method (new method added by this wrapper)
|
|
4033
|
+
if (prop === 'getTotalUsage') {
|
|
4034
|
+
// <- Note: [🥫] Not using getter `get totalUsage` but `getTotalUsage` to allow this object to be proxied
|
|
4035
|
+
return () => {
|
|
4036
|
+
return totalUsage;
|
|
4037
|
+
};
|
|
4038
|
+
}
|
|
4039
|
+
// Handle callChatModel method with usage counting
|
|
4040
|
+
if (prop === 'callChatModel' && target.callChatModel !== undefined) {
|
|
4041
|
+
return async (prompt) => {
|
|
4042
|
+
// console.info('[🚕] callChatModel through countTotalUsage');
|
|
4043
|
+
const promptResult = await target.callChatModel(prompt);
|
|
4044
|
+
totalUsage = addUsage(totalUsage, promptResult.usage);
|
|
4045
|
+
spending.next(promptResult.usage);
|
|
4046
|
+
return promptResult;
|
|
4047
|
+
};
|
|
4048
|
+
}
|
|
4049
|
+
// Handle callCompletionModel method with usage counting
|
|
4050
|
+
if (prop === 'callCompletionModel' && target.callCompletionModel !== undefined) {
|
|
4051
|
+
return async (prompt) => {
|
|
4052
|
+
// console.info('[🚕] callCompletionModel through countTotalUsage');
|
|
4053
|
+
const promptResult = await target.callCompletionModel(prompt);
|
|
4054
|
+
totalUsage = addUsage(totalUsage, promptResult.usage);
|
|
4055
|
+
spending.next(promptResult.usage);
|
|
4056
|
+
return promptResult;
|
|
4057
|
+
};
|
|
4058
|
+
}
|
|
4059
|
+
// Handle callEmbeddingModel method with usage counting
|
|
4060
|
+
if (prop === 'callEmbeddingModel' && target.callEmbeddingModel !== undefined) {
|
|
4061
|
+
return async (prompt) => {
|
|
4062
|
+
// console.info('[🚕] callEmbeddingModel through countTotalUsage');
|
|
4063
|
+
const promptResult = await target.callEmbeddingModel(prompt);
|
|
4064
|
+
totalUsage = addUsage(totalUsage, promptResult.usage);
|
|
4065
|
+
spending.next(promptResult.usage);
|
|
4066
|
+
return promptResult;
|
|
4067
|
+
};
|
|
4068
|
+
}
|
|
4069
|
+
// Handle callImageGenerationModel method with usage counting
|
|
4070
|
+
if (prop === 'callImageGenerationModel' && target.callImageGenerationModel !== undefined) {
|
|
4071
|
+
return async (prompt) => {
|
|
4072
|
+
// console.info('[🚕] callImageGenerationModel through countTotalUsage');
|
|
4073
|
+
const promptResult = await target.callImageGenerationModel(prompt);
|
|
4074
|
+
totalUsage = addUsage(totalUsage, promptResult.usage);
|
|
4075
|
+
spending.next(promptResult.usage);
|
|
4076
|
+
return promptResult;
|
|
4077
|
+
};
|
|
4078
|
+
}
|
|
4079
|
+
// <- Note: [🤖]
|
|
4080
|
+
// For all other properties and methods, delegate to the original target
|
|
4081
|
+
const value = Reflect.get(target, prop, receiver);
|
|
4082
|
+
// If it's a function, bind it to the target to preserve context
|
|
4083
|
+
if (typeof value === 'function') {
|
|
4084
|
+
return value.bind(target);
|
|
4085
|
+
}
|
|
4086
|
+
return value;
|
|
4026
4087
|
},
|
|
4027
|
-
};
|
|
4028
|
-
if (llmTools.callChatModel !== undefined) {
|
|
4029
|
-
proxyTools.callChatModel = async (prompt) => {
|
|
4030
|
-
// console.info('[🚕] callChatModel through countTotalUsage');
|
|
4031
|
-
const promptResult = await llmTools.callChatModel(prompt);
|
|
4032
|
-
totalUsage = addUsage(totalUsage, promptResult.usage);
|
|
4033
|
-
spending.next(promptResult.usage);
|
|
4034
|
-
return promptResult;
|
|
4035
|
-
};
|
|
4036
|
-
}
|
|
4037
|
-
if (llmTools.callCompletionModel !== undefined) {
|
|
4038
|
-
proxyTools.callCompletionModel = async (prompt) => {
|
|
4039
|
-
// console.info('[🚕] callCompletionModel through countTotalUsage');
|
|
4040
|
-
const promptResult = await llmTools.callCompletionModel(prompt);
|
|
4041
|
-
totalUsage = addUsage(totalUsage, promptResult.usage);
|
|
4042
|
-
spending.next(promptResult.usage);
|
|
4043
|
-
return promptResult;
|
|
4044
|
-
};
|
|
4045
|
-
}
|
|
4046
|
-
if (llmTools.callEmbeddingModel !== undefined) {
|
|
4047
|
-
proxyTools.callEmbeddingModel = async (prompt) => {
|
|
4048
|
-
// console.info('[🚕] callEmbeddingModel through countTotalUsage');
|
|
4049
|
-
const promptResult = await llmTools.callEmbeddingModel(prompt);
|
|
4050
|
-
totalUsage = addUsage(totalUsage, promptResult.usage);
|
|
4051
|
-
spending.next(promptResult.usage);
|
|
4052
|
-
return promptResult;
|
|
4053
|
-
};
|
|
4054
|
-
}
|
|
4055
|
-
if (llmTools.callImageGenerationModel !== undefined) {
|
|
4056
|
-
proxyTools.callImageGenerationModel = async (prompt) => {
|
|
4057
|
-
// console.info('[🚕] callImageGenerationModel through countTotalUsage');
|
|
4058
|
-
const promptResult = await llmTools.callImageGenerationModel(prompt);
|
|
4059
|
-
totalUsage = addUsage(totalUsage, promptResult.usage);
|
|
4060
|
-
spending.next(promptResult.usage);
|
|
4061
|
-
return promptResult;
|
|
4062
|
-
};
|
|
4063
|
-
}
|
|
4064
|
-
// <- Note: [🤖]
|
|
4088
|
+
});
|
|
4065
4089
|
return proxyTools;
|
|
4066
4090
|
}
|
|
4067
4091
|
/**
|