@promptbook/openai 0.103.0-4 → 0.103.0-41
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 +64 -30
- package/esm/index.es.js +166 -8
- package/esm/index.es.js.map +1 -1
- package/esm/typings/books/index.d.ts +0 -81
- package/esm/typings/src/_packages/browser.index.d.ts +6 -0
- package/esm/typings/src/_packages/cli.index.d.ts +4 -0
- package/esm/typings/src/_packages/components.index.d.ts +12 -8
- package/esm/typings/src/_packages/core.index.d.ts +30 -10
- package/esm/typings/src/_packages/node.index.d.ts +4 -2
- package/esm/typings/src/_packages/remote-server.index.d.ts +2 -0
- package/esm/typings/src/_packages/types.index.d.ts +18 -2
- package/esm/typings/src/_packages/wizard.index.d.ts +4 -0
- package/esm/typings/src/book-2.0/agent-source/AgentBasicInformation.d.ts +1 -0
- package/esm/typings/src/book-2.0/agent-source/padBook.d.ts +16 -0
- package/esm/typings/src/book-components/BookEditor/BookEditor.d.ts +76 -15
- package/esm/typings/src/book-components/BookEditor/BookEditorActionbar.d.ts +14 -0
- package/esm/typings/src/book-components/BookEditor/BookEditorMonaco.d.ts +5 -0
- package/esm/typings/src/book-components/Chat/MarkdownContent/MarkdownContent.d.ts +15 -0
- package/esm/typings/src/book-components/Chat/MockedChat/MockedChat.d.ts +5 -0
- package/esm/typings/src/book-components/Chat/save/html/htmlSaveFormatDefinition.d.ts +1 -0
- package/esm/typings/src/book-components/Chat/save/pdf/pdfSaveFormatDefinition.d.ts +4 -0
- package/esm/typings/src/book-components/Qr/BrandedQrCode.d.ts +18 -0
- package/esm/typings/src/book-components/Qr/GenericQrCode.d.ts +10 -0
- package/esm/typings/src/book-components/Qr/PromptbookQrCode.d.ts +18 -0
- package/esm/typings/src/book-components/Qr/useQrCode.d.ts +15 -0
- package/esm/typings/src/book-components/_common/Dropdown/Dropdown.d.ts +15 -0
- package/esm/typings/src/book-components/_common/Modal/Modal.d.ts +2 -2
- package/esm/typings/src/book-components/_common/Tooltip/Tooltip.d.ts +47 -0
- package/esm/typings/src/book-components/_common/react-utils/classNames.d.ts +1 -1
- package/esm/typings/src/book-components/icons/AboutIcon.d.ts +9 -0
- package/esm/typings/src/book-components/icons/CloseIcon.d.ts +4 -8
- package/esm/typings/src/book-components/icons/DownloadIcon.d.ts +9 -0
- package/esm/typings/src/book-components/icons/ExitFullscreenIcon.d.ts +7 -0
- package/esm/typings/src/book-components/icons/FullscreenIcon.d.ts +7 -0
- package/esm/typings/src/book-components/icons/MenuIcon.d.ts +12 -0
- package/esm/typings/src/cli/cli-commands/_boilerplate.d.ts +2 -1
- package/esm/typings/src/cli/cli-commands/about.d.ts +3 -1
- package/esm/typings/src/cli/cli-commands/hello.d.ts +2 -1
- package/esm/typings/src/cli/cli-commands/list-models.d.ts +2 -1
- package/esm/typings/src/cli/cli-commands/list-scrapers.d.ts +2 -1
- package/esm/typings/src/cli/cli-commands/login.d.ts +2 -1
- package/esm/typings/src/cli/cli-commands/make.d.ts +2 -1
- package/esm/typings/src/cli/cli-commands/prettify.d.ts +2 -1
- package/esm/typings/src/cli/cli-commands/run.d.ts +2 -1
- package/esm/typings/src/cli/cli-commands/{start-server.d.ts → start-agents-server.d.ts} +3 -2
- package/esm/typings/src/cli/cli-commands/start-pipelines-server.d.ts +15 -0
- package/esm/typings/src/cli/cli-commands/test-command.d.ts +2 -1
- package/esm/typings/src/cli/common/$addGlobalOptionsToCommand.d.ts +2 -1
- package/esm/typings/src/collection/agent-collection/AgentCollection.d.ts +36 -0
- package/esm/typings/src/collection/agent-collection/constructors/AgentCollectionInDirectory.d.ts +88 -0
- package/esm/typings/src/collection/{PipelineCollection.d.ts → pipeline-collection/PipelineCollection.d.ts} +7 -3
- package/esm/typings/src/collection/{SimplePipelineCollection.d.ts → pipeline-collection/SimplePipelineCollection.d.ts} +5 -5
- package/esm/typings/src/collection/{constructors/createCollectionFromDirectory.d.ts → pipeline-collection/constructors/createPipelineCollectionFromDirectory.d.ts} +8 -11
- package/esm/typings/src/collection/pipeline-collection/constructors/createPipelineCollectionFromJson.d.ts +13 -0
- package/esm/typings/src/collection/{constructors/createCollectionFromPromise.d.ts → pipeline-collection/constructors/createPipelineCollectionFromPromise.d.ts} +6 -5
- package/esm/typings/src/collection/{constructors/createCollectionFromUrl.d.ts → pipeline-collection/constructors/createPipelineCollectionFromUrl.d.ts} +3 -3
- package/esm/typings/src/collection/{constructors/createSubcollection.d.ts → pipeline-collection/constructors/createPipelineSubcollection.d.ts} +3 -3
- package/esm/typings/src/collection/pipeline-collection/pipelineCollectionToJson.d.ts +13 -0
- package/esm/typings/src/commands/_common/types/CommandParser.d.ts +4 -5
- package/esm/typings/src/config.d.ts +22 -2
- package/esm/typings/src/errors/0-index.d.ts +3 -0
- package/esm/typings/src/errors/NotAllowed.d.ts +9 -0
- package/esm/typings/src/execution/AvailableModel.d.ts +1 -0
- package/esm/typings/src/execution/Executables.d.ts +3 -0
- package/esm/typings/src/execution/ExecutionTask.d.ts +12 -3
- package/esm/typings/src/execution/ExecutionTools.d.ts +5 -0
- package/esm/typings/src/execution/FilesystemTools.d.ts +1 -1
- package/esm/typings/src/execution/LlmExecutionTools.d.ts +7 -1
- package/esm/typings/src/execution/createPipelineExecutor/10-executePipeline.d.ts +5 -0
- package/esm/typings/src/execution/createPipelineExecutor/20-executeTask.d.ts +5 -0
- package/esm/typings/src/execution/createPipelineExecutor/30-executeFormatSubvalues.d.ts +5 -0
- package/esm/typings/src/execution/createPipelineExecutor/40-executeAttempts.d.ts +5 -0
- package/esm/typings/src/execution/utils/logLlmCall.d.ts +8 -0
- package/esm/typings/src/execution/utils/usage-constants.d.ts +4 -124
- package/esm/typings/src/high-level-abstractions/_common/HighLevelAbstraction.d.ts +2 -1
- package/esm/typings/src/llm-providers/_common/register/$registeredLlmToolsMessage.d.ts +2 -1
- package/esm/typings/src/llm-providers/agent/Agent.d.ts +49 -0
- package/esm/typings/src/llm-providers/agent/AgentLlmExecutionTools.d.ts +9 -4
- package/esm/typings/src/llm-providers/agent/AgentOptions.d.ts +17 -0
- package/esm/typings/src/llm-providers/agent/CreateAgentLlmExecutionToolsOptions.d.ts +16 -0
- package/esm/typings/src/llm-providers/agent/createAgentLlmExecutionTools.d.ts +1 -19
- package/esm/typings/src/llm-providers/openai/OpenAiAssistantExecutionTools.d.ts +28 -0
- package/esm/typings/src/llm-providers/openai/OpenAiAssistantExecutionToolsOptions.d.ts +7 -1
- package/esm/typings/src/other/templates/getTemplatesPipelineCollection.d.ts +1 -1
- package/esm/typings/src/playground/permanent/_boilerplate.d.ts +5 -0
- package/esm/typings/src/playground/permanent/agent-with-browser-playground.d.ts +5 -0
- package/esm/typings/src/playground/playground.d.ts +0 -3
- package/esm/typings/src/playground/playground1.d.ts +2 -0
- package/esm/typings/src/remote-server/startAgentServer.d.ts +23 -0
- package/esm/typings/src/remote-server/startRemoteServer.d.ts +4 -1
- package/esm/typings/src/remote-server/types/RemoteServerOptions.d.ts +22 -8
- package/esm/typings/src/scrapers/_boilerplate/createBoilerplateScraper.d.ts +1 -12
- package/esm/typings/src/scrapers/_boilerplate/register-metadata.d.ts +1 -9
- package/esm/typings/src/scrapers/document/createDocumentScraper.d.ts +1 -12
- package/esm/typings/src/scrapers/document/register-metadata.d.ts +1 -9
- package/esm/typings/src/scrapers/document-legacy/createLegacyDocumentScraper.d.ts +1 -12
- package/esm/typings/src/scrapers/document-legacy/register-metadata.d.ts +1 -9
- package/esm/typings/src/scrapers/markdown/createMarkdownScraper.d.ts +1 -12
- package/esm/typings/src/scrapers/markdown/register-metadata.d.ts +1 -9
- package/esm/typings/src/scrapers/markitdown/createMarkitdownScraper.d.ts +1 -12
- package/esm/typings/src/scrapers/markitdown/register-metadata.d.ts +1 -9
- package/esm/typings/src/scrapers/pdf/createPdfScraper.d.ts +1 -12
- package/esm/typings/src/scrapers/pdf/register-metadata.d.ts +1 -9
- package/esm/typings/src/scrapers/website/createWebsiteScraper.d.ts +1 -12
- package/esm/typings/src/scrapers/website/register-metadata.d.ts +1 -9
- package/esm/typings/src/storage/env-storage/$EnvStorage.d.ts +2 -1
- package/esm/typings/src/transpilers/_common/BookTranspiler.d.ts +29 -0
- package/esm/typings/src/transpilers/_common/BookTranspilerOptions.d.ts +18 -0
- package/esm/typings/src/transpilers/_common/register/$bookTranspilersRegister.d.ts +15 -0
- package/esm/typings/src/transpilers/formatted-book-in-markdown/FormattedBookInMarkdownTranspiler.d.ts +13 -0
- package/esm/typings/src/transpilers/formatted-book-in-markdown/register.d.ts +15 -0
- package/esm/typings/src/transpilers/openai-sdk/OpenAiSdkTranspiler.d.ts +13 -0
- package/esm/typings/src/transpilers/openai-sdk/OpenAiSdkTranspiler.test.d.ts +1 -0
- package/esm/typings/src/transpilers/openai-sdk/playground/playground.d.ts +5 -0
- package/esm/typings/src/transpilers/openai-sdk/register.d.ts +15 -0
- package/esm/typings/src/types/LlmCall.d.ts +20 -0
- package/esm/typings/src/types/Updatable.d.ts +19 -0
- package/esm/typings/src/types/typeAliases.d.ts +1 -1
- package/esm/typings/src/utils/execCommand/$execCommand.d.ts +2 -1
- package/esm/typings/src/utils/execCommand/$execCommands.d.ts +2 -1
- package/esm/typings/src/utils/files/$induceBookDownload.d.ts +13 -0
- package/esm/typings/src/utils/files/$induceFileDownload.d.ts +13 -0
- package/esm/typings/src/utils/files/ObjectUrl.d.ts +46 -0
- package/esm/typings/src/utils/files/listAllFiles.d.ts +2 -3
- package/esm/typings/src/utils/misc/aboutPromptbookInformation.d.ts +21 -0
- package/esm/typings/src/utils/misc/injectCssModuleIntoShadowRoot.d.ts +1 -0
- package/esm/typings/src/utils/misc/xAboutPromptbookInformation.d.ts +13 -0
- package/esm/typings/src/utils/organization/$side_effect.d.ts +7 -0
- package/esm/typings/src/utils/serialization/$deepFreeze.d.ts +2 -1
- package/esm/typings/src/version.d.ts +1 -1
- package/esm/typings/src/wizard/$getCompiledBook.d.ts +1 -2
- package/package.json +7 -6
- package/umd/index.umd.js +169 -12
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/book-components/BookEditor/BookEditorInner.d.ts +0 -5
- package/esm/typings/src/book-components/BookEditor/BookEditorWrapper.d.ts +0 -9
- package/esm/typings/src/book-components/BookEditor/config.d.ts +0 -10
- package/esm/typings/src/book-components/Chat/utils/renderMarkdown.d.ts +0 -21
- package/esm/typings/src/collection/collectionToJson.d.ts +0 -13
- package/esm/typings/src/collection/constructors/createCollectionFromJson.d.ts +0 -13
- /package/esm/typings/src/{book-components/Chat/utils/renderMarkdown.test.d.ts → collection/agent-collection/constructors/AgentCollectionInDirectory.test.d.ts} +0 -0
- /package/esm/typings/src/collection/{constructors/createCollectionFromDirectory.test.d.ts → pipeline-collection/constructors/createPipelineCollectionFromDirectory.test.d.ts} +0 -0
- /package/esm/typings/src/collection/{constructors/createCollectionFromJson.test.d.ts → pipeline-collection/constructors/createPipelineCollectionFromJson.test.d.ts} +0 -0
- /package/esm/typings/src/collection/{constructors/createCollectionFromPromise.test.d.ts → pipeline-collection/constructors/createPipelineCollectionFromPromise.test.d.ts} +0 -0
- /package/esm/typings/src/collection/{collectionToJson.test.d.ts → pipeline-collection/pipelineCollectionToJson.test.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -82,7 +82,7 @@ The package offers three main integration paths:
|
|
|
82
82
|
```typescript
|
|
83
83
|
import { createPipelineExecutor } from '@promptbook/core';
|
|
84
84
|
import {
|
|
85
|
-
|
|
85
|
+
createPipelineCollectionFromDirectory,
|
|
86
86
|
$provideExecutionToolsForNode,
|
|
87
87
|
$provideFilesystemForNode,
|
|
88
88
|
$provideScrapersForNode,
|
|
@@ -110,7 +110,7 @@ const tools = {
|
|
|
110
110
|
};
|
|
111
111
|
|
|
112
112
|
// ▶ Create whole pipeline collection
|
|
113
|
-
const collection = await
|
|
113
|
+
const collection = await createPipelineCollectionFromDirectory('./books', tools);
|
|
114
114
|
|
|
115
115
|
// ▶ Get single Pipeline
|
|
116
116
|
const pipeline = await collection.getPipelineByUrl(`https://promptbook.studio/my-collection/write-article.book`);
|
|
@@ -164,7 +164,7 @@ console.info(joke);
|
|
|
164
164
|
You can just use `$provideExecutionToolsForNode` function to create all required tools from environment variables like `ANTHROPIC_CLAUDE_API_KEY` and `OPENAI_API_KEY` automatically.
|
|
165
165
|
|
|
166
166
|
```typescript
|
|
167
|
-
import { createPipelineExecutor,
|
|
167
|
+
import { createPipelineExecutor, createPipelineCollectionFromDirectory } from '@promptbook/core';
|
|
168
168
|
import { JavascriptExecutionTools } from '@promptbook/javascript';
|
|
169
169
|
import { $provideExecutionToolsForNode } from '@promptbook/node';
|
|
170
170
|
import { $provideFilesystemForNode } from '@promptbook/node';
|
|
@@ -174,7 +174,7 @@ import { $provideFilesystemForNode } from '@promptbook/node';
|
|
|
174
174
|
const tools = await $provideExecutionToolsForNode();
|
|
175
175
|
|
|
176
176
|
// ▶ Create whole pipeline collection
|
|
177
|
-
const collection = await
|
|
177
|
+
const collection = await createPipelineCollectionFromDirectory('./books', tools);
|
|
178
178
|
|
|
179
179
|
// ▶ Get single Pipeline
|
|
180
180
|
const pipeline = await collection.getPipelineByUrl(`https://promptbook.studio/my-collection/write-article.book`);
|
|
@@ -202,7 +202,7 @@ You can use multiple LLM providers in one Promptbook execution. The best model w
|
|
|
202
202
|
```typescript
|
|
203
203
|
import { createPipelineExecutor } from '@promptbook/core';
|
|
204
204
|
import {
|
|
205
|
-
|
|
205
|
+
createPipelineCollectionFromDirectory,
|
|
206
206
|
$provideExecutionToolsForNode,
|
|
207
207
|
$provideFilesystemForNode,
|
|
208
208
|
} from '@promptbook/node';
|
|
@@ -246,7 +246,7 @@ const tools = {
|
|
|
246
246
|
};
|
|
247
247
|
|
|
248
248
|
// ▶ Create whole pipeline collection
|
|
249
|
-
const collection = await
|
|
249
|
+
const collection = await createPipelineCollectionFromDirectory('./books', tools);
|
|
250
250
|
|
|
251
251
|
// ▶ Get single Pipeline
|
|
252
252
|
const pipeline = await collection.getPipelineByUrl(`https://promptbook.studio/my-collection/write-article.book`);
|
|
@@ -292,7 +292,7 @@ import { startRemoteServer } from '@promptbook/remote-server';
|
|
|
292
292
|
// Start the server
|
|
293
293
|
await startRemoteServer({
|
|
294
294
|
port: 3000,
|
|
295
|
-
collection: await
|
|
295
|
+
collection: await createPipelineCollectionFromDirectory('./books'),
|
|
296
296
|
isAnonymousModeAllowed: true,
|
|
297
297
|
isApplicationModeAllowed: true,
|
|
298
298
|
});
|
|
@@ -329,8 +329,6 @@ This allows you to:
|
|
|
329
329
|
- Integrate Promptbook into existing OpenAI-based applications
|
|
330
330
|
- Use Promptbook books as models in other AI frameworks
|
|
331
331
|
|
|
332
|
-
|
|
333
|
-
|
|
334
332
|
## 📦 Exported Entities
|
|
335
333
|
|
|
336
334
|
### Version Information
|
|
@@ -386,11 +384,15 @@ The main challenge is to narrow it down, constrain it, set the proper **context,
|
|
|
386
384
|
|
|
387
385
|
Promptbook takes the best from both worlds. You are defining your AI behavior by simple **books**, which are very explicit. They are automatically enforced, but they are very easy to understand, very easy to write, and very reliable and portable.
|
|
388
386
|
|
|
387
|
+
<table style="border: 1px solid #777; border-radius: 10px;"><tr><td>
|
|
389
388
|
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
/>
|
|
389
|
+
**<ins>Paul Smith & Associés</ins>**<br/>
|
|
390
|
+
<br/>
|
|
391
|
+
**PERSONA** You are a company lawyer.<br/>
|
|
392
|
+
Your job is to provide legal advice and support to the company and its employees.<br/>
|
|
393
|
+
You are knowledgeable, professional, and detail-oriented.<br/>
|
|
394
|
+
|
|
395
|
+
</td></tr></table>
|
|
394
396
|
|
|
395
397
|
<div style="page-break-after: always;"></div>
|
|
396
398
|
|
|
@@ -404,11 +406,15 @@ You can look at it as prompting (or writing a system message), but decorated by
|
|
|
404
406
|
|
|
405
407
|
Personas define the character of your AI persona, its role, and how it should interact with users. It sets the tone and style of communication.
|
|
406
408
|
|
|
409
|
+
<table style="border: 1px solid #777; border-radius: 10px;"><tr><td>
|
|
410
|
+
|
|
411
|
+
**<ins>Paul Smith & Associés</ins>**<br/>
|
|
412
|
+
<br/>
|
|
413
|
+
**PERSONA** You are a company lawyer.<br/>
|
|
414
|
+
Your job is to provide legal advice and support to the company and its employees.<br/>
|
|
415
|
+
You are knowledgeable, professional, and detail-oriented.<br/>
|
|
407
416
|
|
|
408
|
-
|
|
409
|
-
alt="Paul Smith & Associés Book"
|
|
410
|
-
src="https://promptbook.studio/embed/book-preview.png?book=Paul%20Smith%20%26%20Associ%C3%A9s%0A%20%20%20%20%20%20%7C%20PERSONA%20You%20are%20a%20company%20lawyer.%0A%20%20%20%20%20%20%7C%20Your%20job%20is%20to%20provide%20legal%20advice%20and%20support%20to%20the%20company%20and%20its%20employees.%0A%20%20%20%20%20%20%7C%20You%20are%20knowledgeable%2C%20professional%2C%20and%20detail-oriented.&width=800&height=450&nonce=0"
|
|
411
|
-
/>
|
|
417
|
+
</td></tr></table>
|
|
412
418
|
|
|
413
419
|
#### `Knowledge` commitment
|
|
414
420
|
|
|
@@ -418,11 +424,18 @@ This can include domain-specific knowledge, company policies, or any other relev
|
|
|
418
424
|
|
|
419
425
|
Promptbook Engine will automatically enforce this knowledge during interactions. When the knowledge is short enough, it will be included in the prompt. When it is too long, it will be stored in vector databases and RAG retrieved when needed. But you don't need to care about it.
|
|
420
426
|
|
|
427
|
+
<table style="border: 1px solid #777; border-radius: 10px;"><tr><td>
|
|
421
428
|
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
/>
|
|
429
|
+
**<ins>Paul Smith & Associés</ins>**<br/>
|
|
430
|
+
<br/>
|
|
431
|
+
**PERSONA** You are a company lawyer.<br/>
|
|
432
|
+
Your job is to provide legal advice and support to the company and its employees.<br/>
|
|
433
|
+
You are knowledgeable, professional, and detail-oriented.<br/>
|
|
434
|
+
<br/>
|
|
435
|
+
**KNOWLEDGE** https://company.com/company-policies.pdf<br/>
|
|
436
|
+
**KNOWLEDGE** https://company.com/internal-documents/employee-handbook.docx<br/>
|
|
437
|
+
|
|
438
|
+
</td></tr></table>
|
|
426
439
|
|
|
427
440
|
#### `Rule` commitment
|
|
428
441
|
|
|
@@ -430,21 +443,42 @@ Rules will enforce specific behaviors or constraints on the AI's responses. This
|
|
|
430
443
|
|
|
431
444
|
Depending on rule strictness, Promptbook will either propagate it to the prompt or use other techniques, like adversary agent, to enforce it.
|
|
432
445
|
|
|
446
|
+
<table style="border: 1px solid #777; border-radius: 10px;"><tr><td>
|
|
447
|
+
|
|
448
|
+
**<ins>Paul Smith & Associés</ins>**<br/>
|
|
449
|
+
<br/>
|
|
450
|
+
**PERSONA** You are a company lawyer.<br/>
|
|
451
|
+
Your job is to provide legal advice and support to the company and its employees.<br/>
|
|
452
|
+
You are knowledgeable, professional, and detail-oriented.<br/>
|
|
453
|
+
<br/>
|
|
454
|
+
**RULE** Always ensure compliance with laws and regulations.<br/>
|
|
455
|
+
**RULE** Never provide legal advice outside your area of expertise.<br/>
|
|
456
|
+
**RULE** Never provide legal advice about criminal law.<br/>
|
|
457
|
+
**KNOWLEDGE** https://company.com/company-policies.pdf<br/>
|
|
458
|
+
**KNOWLEDGE** https://company.com/internal-documents/employee-handbook.docx<br/>
|
|
433
459
|
|
|
434
|
-
|
|
435
|
-
alt="Paul Smith & Associés Book"
|
|
436
|
-
src="https://promptbook.studio/embed/book-preview.png?book=Paul%20Smith%20%26%20Associ%C3%A9s%0A%20%20%20%20%20%20%7C%20PERSONA%20You%20are%20a%20company%20lawyer.%0A%20%20%20%20%20%20%7C%20Your%20job%20is%20to%20provide%20legal%20advice%20and%20support%20to%20the%20company%20and%20its%20employees.%0A%20%20%20%20%20%20%7C%20You%20are%20knowledgeable%2C%20professional%2C%20and%20detail-oriented.%0A%20%20%20%20%20%20%7C%20RULE%20Always%20ensure%20compliance%20with%20laws%20and%20regulations.%0A%20%20%20%20%20%20%7C%20RULE%20Never%20provide%20legal%20advice%20outside%20your%20area%20of%20expertise.%0A%20%20%20%20%20%20%7C%20RULE%20Never%20provide%20legal%20advice%20about%20criminal%20law.%0A%20%20%20%20%20%20%7C%20KNOWLEDGE%20%20https%3A%2F%2Fcompany.com%2Fcompany-policies.pdf%0A%20%20%20%20%20%20%7C%20KNOWLEDGE%20https%3A%2F%2Fcompany.com%2Finternal-documents%2Femployee-handbook.docx&width=800&height=450&nonce=0"
|
|
437
|
-
/>
|
|
460
|
+
</td></tr></table>
|
|
438
461
|
|
|
439
462
|
#### `Action` commitment
|
|
440
463
|
|
|
441
464
|
Action Commitment allows you to define specific actions that the AI can take during interactions. This can include things like posting on a social media platform, sending emails, creating calendar events, or interacting with your internal systems.
|
|
442
465
|
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
/>
|
|
466
|
+
<table style="border: 1px solid #777; border-radius: 10px;"><tr><td>
|
|
467
|
+
|
|
468
|
+
**<ins>Paul Smith & Associés</ins>**<br/>
|
|
469
|
+
<br/>
|
|
470
|
+
**PERSONA** You are a company lawyer.<br/>
|
|
471
|
+
Your job is to provide legal advice and support to the company and its employees.<br/>
|
|
472
|
+
You are knowledgeable, professional, and detail-oriented.<br/>
|
|
473
|
+
<br/>
|
|
474
|
+
**RULE** Always ensure compliance with laws and regulations.<br/>
|
|
475
|
+
**RULE** Never provide legal advice outside your area of expertise.<br/>
|
|
476
|
+
**RULE** Never provide legal advice about criminal law.<br/>
|
|
477
|
+
**KNOWLEDGE** https://company.com/company-policies.pdf<br/>
|
|
478
|
+
**KNOWLEDGE** https://company.com/internal-documents/employee-handbook.docx<br/>
|
|
479
|
+
**ACTION** When a user asks about an issue that could be treated as a crime, notify legal@company.com.<br/>
|
|
480
|
+
|
|
481
|
+
</td></tr></table>
|
|
448
482
|
|
|
449
483
|
[Read more about the language](./BLUEPRINT.md)
|
|
450
484
|
|
package/esm/index.es.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import colors from 'colors';
|
|
2
|
+
import { forEver } from 'waitasecond';
|
|
2
3
|
import spaceTrim$1, { spaceTrim } from 'spacetrim';
|
|
3
4
|
import { randomBytes } from 'crypto';
|
|
4
5
|
import Bottleneck from 'bottleneck';
|
|
@@ -19,7 +20,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
19
20
|
* @generated
|
|
20
21
|
* @see https://github.com/webgptorg/promptbook
|
|
21
22
|
*/
|
|
22
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.103.0-
|
|
23
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.103.0-41';
|
|
23
24
|
/**
|
|
24
25
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
25
26
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -65,6 +66,19 @@ const $isRunningInWebWorker = new Function(`
|
|
|
65
66
|
* TODO: [🎺]
|
|
66
67
|
*/
|
|
67
68
|
|
|
69
|
+
/**
|
|
70
|
+
* This error indicates that promptbook operation is not allowed
|
|
71
|
+
*
|
|
72
|
+
* @public exported from `@promptbook/core`
|
|
73
|
+
*/
|
|
74
|
+
class NotAllowed extends Error {
|
|
75
|
+
constructor(message) {
|
|
76
|
+
super(message);
|
|
77
|
+
this.name = 'NotAllowed';
|
|
78
|
+
Object.setPrototypeOf(this, NotAllowed.prototype);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
68
82
|
/**
|
|
69
83
|
* This error type indicates that some part of the code is not implemented yet
|
|
70
84
|
*
|
|
@@ -1147,15 +1161,30 @@ const ADMIN_GITHUB_NAME = 'hejny';
|
|
|
1147
1161
|
* @public exported from `@promptbook/core`
|
|
1148
1162
|
*/
|
|
1149
1163
|
const PROMPTBOOK_COLOR = Color.fromHex('#79EAFD');
|
|
1150
|
-
// <- TODO: [🧠] Using `Color` here increases the package size approx 3kb, maybe remove it
|
|
1164
|
+
// <- TODO: [🧠][🈵] Using `Color` here increases the package size approx 3kb, maybe remove it
|
|
1165
|
+
/**
|
|
1166
|
+
* Colors for syntax highlighting in the `<BookEditor/>`
|
|
1167
|
+
*
|
|
1168
|
+
* TODO: [🗽] Unite branding and make single place for it
|
|
1169
|
+
*
|
|
1170
|
+
* @public exported from `@promptbook/core`
|
|
1171
|
+
*/
|
|
1172
|
+
({
|
|
1173
|
+
TITLE: Color.fromHex('#244EA8'),
|
|
1174
|
+
LINE: Color.fromHex('#eeeeee'),
|
|
1175
|
+
COMMITMENT: Color.fromHex('#DA0F78'),
|
|
1176
|
+
PARAMETER: Color.fromHex('#8e44ad'),
|
|
1177
|
+
});
|
|
1178
|
+
// <- TODO: [🧠][🈵] Using `Color` here increases the package size approx 3kb, maybe remove it
|
|
1151
1179
|
/**
|
|
1152
|
-
*
|
|
1180
|
+
* Chat color of the Promptbook (in chat)
|
|
1153
1181
|
*
|
|
1154
1182
|
* TODO: [🗽] Unite branding and make single place for it
|
|
1155
1183
|
*
|
|
1156
1184
|
* @public exported from `@promptbook/core`
|
|
1157
1185
|
*/
|
|
1158
1186
|
PROMPTBOOK_COLOR.then(lighten(0.1)).then(saturate(0.9)).then(grayscale(0.9));
|
|
1187
|
+
// <- TODO: [🧠][🈵] Using `Color` and `lighten`, `saturate`,... here increases the package size approx 3kb, maybe remove it
|
|
1159
1188
|
/**
|
|
1160
1189
|
* Color of the user (in chat)
|
|
1161
1190
|
*
|
|
@@ -1825,10 +1854,13 @@ const LINES_PER_STANDARD_PAGE = 44;
|
|
|
1825
1854
|
* @public exported from `@promptbook/utils`
|
|
1826
1855
|
*/
|
|
1827
1856
|
function countLines(text) {
|
|
1857
|
+
if (text === '') {
|
|
1858
|
+
return 0;
|
|
1859
|
+
}
|
|
1828
1860
|
text = text.replace('\r\n', '\n');
|
|
1829
1861
|
text = text.replace('\r', '\n');
|
|
1830
1862
|
const lines = text.split('\n');
|
|
1831
|
-
return lines.reduce((count, line) => count + Math.ceil(line.length / CHARACTERS_PER_STANDARD_LINE), 0);
|
|
1863
|
+
return lines.reduce((count, line) => count + Math.max(Math.ceil(line.length / CHARACTERS_PER_STANDARD_LINE), 1), 0);
|
|
1832
1864
|
}
|
|
1833
1865
|
/**
|
|
1834
1866
|
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
@@ -3595,6 +3627,12 @@ class OpenAiExecutionTools extends OpenAiCompatibleExecutionTools {
|
|
|
3595
3627
|
*
|
|
3596
3628
|
* This is useful for calling OpenAI API with a single assistant, for more wide usage use `OpenAiExecutionTools`.
|
|
3597
3629
|
*
|
|
3630
|
+
* Note: [🦖] There are several different things in Promptbook:
|
|
3631
|
+
* - `Agent` - which represents an AI Agent with its source, memories, actions, etc. Agent is a higher-level abstraction which is internally using:
|
|
3632
|
+
* - `LlmExecutionTools` - which wraps one or more LLM models and provides an interface to execute them
|
|
3633
|
+
* - `AgentLlmExecutionTools` - which is a specific implementation of `LlmExecutionTools` that wraps another LlmExecutionTools and applies agent-specific system prompts and requirements
|
|
3634
|
+
* - `OpenAiAssistantExecutionTools` - which is a specific implementation of `LlmExecutionTools` for OpenAI models with assistant capabilities, recommended for usage in `Agent` or `AgentLlmExecutionTools`
|
|
3635
|
+
*
|
|
3598
3636
|
* @public exported from `@promptbook/openai`
|
|
3599
3637
|
*/
|
|
3600
3638
|
class OpenAiAssistantExecutionTools extends OpenAiExecutionTools {
|
|
@@ -3604,11 +3642,18 @@ class OpenAiAssistantExecutionTools extends OpenAiExecutionTools {
|
|
|
3604
3642
|
* @param options which are relevant are directly passed to the OpenAI client
|
|
3605
3643
|
*/
|
|
3606
3644
|
constructor(options) {
|
|
3645
|
+
var _a;
|
|
3607
3646
|
if (options.isProxied) {
|
|
3608
3647
|
throw new NotYetImplementedError(`Proxy mode is not yet implemented for OpenAI assistants`);
|
|
3609
3648
|
}
|
|
3610
3649
|
super(options);
|
|
3650
|
+
this.isCreatingNewAssistantsAllowed = false;
|
|
3611
3651
|
this.assistantId = options.assistantId;
|
|
3652
|
+
this.isCreatingNewAssistantsAllowed = (_a = options.isCreatingNewAssistantsAllowed) !== null && _a !== void 0 ? _a : false;
|
|
3653
|
+
if (this.assistantId === null && !this.isCreatingNewAssistantsAllowed) {
|
|
3654
|
+
throw new NotAllowed(`Assistant ID is null and creating new assistants is not allowed - this configuration does not make sense`);
|
|
3655
|
+
}
|
|
3656
|
+
// <- TODO: !!! `OpenAiAssistantExecutionToolsOptions` - Allow `assistantId: null` together with `isCreatingNewAssistantsAllowed: true`
|
|
3612
3657
|
// TODO: [👱] Make limiter same as in `OpenAiExecutionTools`
|
|
3613
3658
|
}
|
|
3614
3659
|
get title() {
|
|
@@ -3667,14 +3712,13 @@ class OpenAiAssistantExecutionTools extends OpenAiExecutionTools {
|
|
|
3667
3712
|
// TODO: [👨👨👧👧][🧠] What about system message for assistants, does it make sense - combination of OpenAI assistants with Promptbook Personas
|
|
3668
3713
|
assistant_id: this.assistantId,
|
|
3669
3714
|
thread: {
|
|
3670
|
-
messages: 'thread' in prompt &&
|
|
3715
|
+
messages: 'thread' in prompt &&
|
|
3716
|
+
Array.isArray(prompt.thread)
|
|
3671
3717
|
? prompt.thread.map((msg) => ({
|
|
3672
3718
|
role: msg.role === 'assistant' ? 'assistant' : 'user',
|
|
3673
3719
|
content: msg.content,
|
|
3674
3720
|
}))
|
|
3675
|
-
: [
|
|
3676
|
-
{ role: 'user', content: rawPromptContent },
|
|
3677
|
-
],
|
|
3721
|
+
: [{ role: 'user', content: rawPromptContent }],
|
|
3678
3722
|
},
|
|
3679
3723
|
// <- TODO: Add user identification here> user: this.options.user,
|
|
3680
3724
|
};
|
|
@@ -3754,7 +3798,120 @@ class OpenAiAssistantExecutionTools extends OpenAiExecutionTools {
|
|
|
3754
3798
|
},
|
|
3755
3799
|
});
|
|
3756
3800
|
}
|
|
3801
|
+
async playground() {
|
|
3802
|
+
const client = await this.getClient();
|
|
3803
|
+
// List all assistants
|
|
3804
|
+
const assistants = await client.beta.assistants.list();
|
|
3805
|
+
console.log('!!! Assistants:', assistants);
|
|
3806
|
+
// Get details of a specific assistant
|
|
3807
|
+
const assistantId = 'asst_MO8fhZf4dGloCfXSHeLcIik0';
|
|
3808
|
+
const assistant = await client.beta.assistants.retrieve(assistantId);
|
|
3809
|
+
console.log('!!! Assistant Details:', assistant);
|
|
3810
|
+
// Update an assistant
|
|
3811
|
+
const updatedAssistant = await client.beta.assistants.update(assistantId, {
|
|
3812
|
+
name: assistant.name + '(M)',
|
|
3813
|
+
description: 'Updated description via Promptbook',
|
|
3814
|
+
metadata: {
|
|
3815
|
+
[Math.random().toString(36).substring(2, 15)]: new Date().toISOString(),
|
|
3816
|
+
},
|
|
3817
|
+
});
|
|
3818
|
+
console.log('!!! Updated Assistant:', updatedAssistant);
|
|
3819
|
+
await forEver();
|
|
3820
|
+
}
|
|
3821
|
+
async createNewAssistant(options) {
|
|
3822
|
+
if (!this.isCreatingNewAssistantsAllowed) {
|
|
3823
|
+
throw new NotAllowed(`Creating new assistants is not allowed. Set \`isCreatingNewAssistantsAllowed: true\` in options to enable this feature.`);
|
|
3824
|
+
}
|
|
3825
|
+
await this.playground();
|
|
3826
|
+
const { name, instructions } = options;
|
|
3827
|
+
const client = await this.getClient();
|
|
3828
|
+
/*
|
|
3829
|
+
TODO: !!!
|
|
3830
|
+
async function downloadFile(url: string, folder = './tmp'): Promise<string> {
|
|
3831
|
+
const filename = path.basename(url.split('?')[0]);
|
|
3832
|
+
const filepath = path.join(folder, filename);
|
|
3833
|
+
|
|
3834
|
+
if (!fs.existsSync(folder)) fs.mkdirSync(folder);
|
|
3835
|
+
|
|
3836
|
+
const res = await fetch(url);
|
|
3837
|
+
if (!res.ok) throw new Error(`Download error: ${url}`);
|
|
3838
|
+
const buffer = await res.arrayBuffer();
|
|
3839
|
+
fs.writeFileSync(filepath, Buffer.from(buffer));
|
|
3840
|
+
console.log(`📥 File downloaded: ${filename}`);
|
|
3841
|
+
|
|
3842
|
+
return filepath;
|
|
3843
|
+
}
|
|
3844
|
+
|
|
3845
|
+
async function uploadFileToOpenAI(filepath: string) {
|
|
3846
|
+
const file = await client.files.create({
|
|
3847
|
+
file: fs.createReadStream(filepath),
|
|
3848
|
+
purpose: 'assistants',
|
|
3849
|
+
});
|
|
3850
|
+
console.log(`⬆️ File uploaded to OpenAI: ${file.filename} (${file.id})`);
|
|
3851
|
+
return file;
|
|
3852
|
+
}
|
|
3853
|
+
|
|
3854
|
+
// 🌐 URL addresses of files to upload
|
|
3855
|
+
const fileUrls = [
|
|
3856
|
+
'https://raw.githubusercontent.com/vercel/next.js/canary/packages/next/README.md',
|
|
3857
|
+
'https://raw.githubusercontent.com/openai/openai-cookbook/main/examples/How_to_call_the_Assistants_API_with_Node.js.ipynb',
|
|
3858
|
+
];
|
|
3859
|
+
|
|
3860
|
+
// 1️⃣ Download files from URL
|
|
3861
|
+
const localFiles = [];
|
|
3862
|
+
for (const url of fileUrls) {
|
|
3863
|
+
const filepath = await downloadFile(url);
|
|
3864
|
+
localFiles.push(filepath);
|
|
3865
|
+
}
|
|
3866
|
+
|
|
3867
|
+
// 2️⃣ Upload files to OpenAI
|
|
3868
|
+
const uploadedFiles = [];
|
|
3869
|
+
for (const filepath of localFiles) {
|
|
3870
|
+
const file = await uploadFileToOpenAI(filepath);
|
|
3871
|
+
uploadedFiles.push(file.id);
|
|
3872
|
+
}
|
|
3873
|
+
*/
|
|
3874
|
+
alert('!!!! Creating new OpenAI assistant');
|
|
3875
|
+
// 3️⃣ Create assistant with uploaded files
|
|
3876
|
+
const assistant = await client.beta.assistants.create({
|
|
3877
|
+
name,
|
|
3878
|
+
description: 'Assistant created via Promptbook',
|
|
3879
|
+
model: 'gpt-4o',
|
|
3880
|
+
instructions,
|
|
3881
|
+
tools: [/* TODO: [🧠] Maybe add { type: 'code_interpreter' }, */ { type: 'file_search' }],
|
|
3882
|
+
// !!!! file_ids: uploadedFiles,
|
|
3883
|
+
});
|
|
3884
|
+
console.log(`✅ Assistant created: ${assistant.id}`);
|
|
3885
|
+
// TODO: !!!! Try listing existing assistants
|
|
3886
|
+
// TODO: !!!! Try marking existing assistants by DISCRIMINANT
|
|
3887
|
+
// TODO: !!!! Allow to update and reconnect to existing assistants
|
|
3888
|
+
return new OpenAiAssistantExecutionTools({
|
|
3889
|
+
...this.options,
|
|
3890
|
+
isCreatingNewAssistantsAllowed: false,
|
|
3891
|
+
assistantId: assistant.id,
|
|
3892
|
+
});
|
|
3893
|
+
}
|
|
3894
|
+
/**
|
|
3895
|
+
* Discriminant for type guards
|
|
3896
|
+
*/
|
|
3897
|
+
get discriminant() {
|
|
3898
|
+
return DISCRIMINANT;
|
|
3899
|
+
}
|
|
3900
|
+
/**
|
|
3901
|
+
* Type guard to check if given `LlmExecutionTools` are instanceof `OpenAiAssistantExecutionTools`
|
|
3902
|
+
*
|
|
3903
|
+
* Note: This is useful when you can possibly have multiple versions of `@promptbook/openai` installed
|
|
3904
|
+
*/
|
|
3905
|
+
static isOpenAiAssistantExecutionTools(llmExecutionTools) {
|
|
3906
|
+
return llmExecutionTools.discriminant === DISCRIMINANT;
|
|
3907
|
+
}
|
|
3757
3908
|
}
|
|
3909
|
+
/**
|
|
3910
|
+
* Discriminant for type guards
|
|
3911
|
+
*
|
|
3912
|
+
* @private const of `OpenAiAssistantExecutionTools`
|
|
3913
|
+
*/
|
|
3914
|
+
const DISCRIMINANT = 'OPEN_AI_ASSISTANT_V1';
|
|
3758
3915
|
/**
|
|
3759
3916
|
* TODO: [🧠][🧙♂️] Maybe there can be some wizard for those who want to use just OpenAI
|
|
3760
3917
|
* TODO: Maybe make custom OpenAiError
|
|
@@ -3990,6 +4147,7 @@ const PROMPTBOOK_ERRORS = {
|
|
|
3990
4147
|
PromptbookFetchError,
|
|
3991
4148
|
UnexpectedError,
|
|
3992
4149
|
WrappedError,
|
|
4150
|
+
NotAllowed,
|
|
3993
4151
|
// TODO: [🪑]> VersionMismatchError,
|
|
3994
4152
|
};
|
|
3995
4153
|
/**
|