@promptbook/openai 0.72.0-8 → 0.72.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 +81 -74
- package/esm/index.es.js +122 -29
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/browser.index.d.ts +2 -0
- package/esm/typings/src/_packages/cli.index.d.ts +20 -0
- package/esm/typings/src/_packages/core.index.d.ts +42 -30
- package/esm/typings/src/_packages/documents.index.d.ts +8 -0
- package/esm/typings/src/_packages/legacy-documents.index.d.ts +8 -0
- package/esm/typings/src/_packages/markdown-utils.index.d.ts +6 -0
- package/esm/typings/src/_packages/node.index.d.ts +12 -4
- package/esm/typings/src/_packages/pdf.index.d.ts +8 -0
- package/esm/typings/src/_packages/types.index.d.ts +33 -17
- package/esm/typings/src/_packages/utils.index.d.ts +2 -2
- package/esm/typings/src/_packages/website-crawler.index.d.ts +8 -0
- package/esm/typings/src/collection/PipelineCollection.d.ts +1 -1
- package/esm/typings/src/collection/SimplePipelineCollection.d.ts +2 -2
- package/esm/typings/src/collection/collectionToJson.d.ts +1 -1
- package/esm/typings/src/collection/constructors/createCollectionFromDirectory.d.ts +5 -3
- package/esm/typings/src/collection/constructors/createCollectionFromJson.d.ts +1 -1
- package/esm/typings/src/collection/constructors/createCollectionFromPromise.d.ts +1 -1
- package/esm/typings/src/commands/_common/types/CommandParser.d.ts +5 -5
- package/esm/typings/src/config.d.ts +26 -13
- package/esm/typings/src/conversion/pipelineStringToJson.d.ts +3 -1
- package/esm/typings/src/dialogs/callback/CallbackInterfaceToolsOptions.d.ts +2 -2
- package/esm/typings/src/dialogs/simple-prompt/SimplePromptInterfaceTools.d.ts +3 -3
- package/esm/typings/src/executables/$provideExecutablesForNode.d.ts +12 -0
- package/esm/typings/src/executables/apps/locateLibreoffice.d.ts +11 -0
- package/esm/typings/src/executables/apps/locatePandoc.d.ts +11 -0
- package/esm/typings/src/executables/locateApp.d.ts +33 -0
- package/esm/typings/src/executables/platforms/locateAppOnLinux.d.ts +12 -0
- package/esm/typings/src/executables/platforms/locateAppOnMacOs.d.ts +12 -0
- package/esm/typings/src/executables/platforms/locateAppOnWindows.d.ts +12 -0
- package/esm/typings/src/execution/{CommonExecutionToolsOptions.d.ts → CommonToolsOptions.d.ts} +1 -1
- package/esm/typings/src/execution/EmbeddingVector.d.ts +1 -1
- package/esm/typings/src/execution/Executables.d.ts +18 -0
- package/esm/typings/src/execution/ExecutionTools.d.ts +32 -6
- package/esm/typings/src/execution/FilesystemTools.d.ts +9 -0
- package/esm/typings/src/execution/LlmExecutionTools.d.ts +2 -2
- package/esm/typings/src/execution/PipelineExecutorResult.d.ts +2 -2
- package/esm/typings/src/execution/assertsExecutionSuccessful.d.ts +3 -2
- package/esm/typings/src/execution/createPipelineExecutor/00-CreatePipelineExecutorOptions.d.ts +29 -6
- package/esm/typings/src/execution/createPipelineExecutor/10-executePipeline.d.ts +3 -12
- package/esm/typings/src/execution/createPipelineExecutor/20-executeTemplate.d.ts +4 -18
- package/esm/typings/src/execution/createPipelineExecutor/40-executeAttempts.d.ts +9 -19
- package/esm/typings/src/execution/translation/automatic-translate/automatic-translators/LindatAutomaticTranslator.d.ts +11 -3
- package/esm/typings/src/execution/translation/automatic-translate/translateMessages.d.ts +1 -0
- package/esm/typings/src/execution/utils/$provideExecutionToolsForNode.d.ts +13 -0
- package/esm/typings/src/execution/utils/addUsage.d.ts +1 -1
- package/esm/typings/src/execution/utils/forEachAsync.d.ts +1 -1
- package/esm/typings/src/formats/_common/FormatDefinition.d.ts +2 -2
- package/esm/typings/src/formats/_common/FormatSubvalueDefinition.d.ts +2 -2
- package/esm/typings/src/llm-providers/_common/{$llmToolsMetadataRegister.d.ts → register/$llmToolsMetadataRegister.d.ts} +4 -1
- package/esm/typings/src/llm-providers/_common/{$llmToolsRegister.d.ts → register/$llmToolsRegister.d.ts} +5 -2
- package/esm/typings/src/llm-providers/_common/{createLlmToolsFromConfigurationFromEnv.d.ts → register/$provideLlmToolsConfigurationFromEnv.d.ts} +3 -3
- package/esm/typings/src/llm-providers/_common/{getLlmToolsForCli.d.ts → register/$provideLlmToolsForCli.d.ts} +4 -11
- package/esm/typings/src/llm-providers/_common/{getLlmToolsForTestingAndScriptsAndPlayground.d.ts → register/$provideLlmToolsForTestingAndScriptsAndPlayground.d.ts} +4 -3
- package/esm/typings/src/llm-providers/_common/{createLlmToolsFromEnv.d.ts → register/$provideLlmToolsFromEnv.d.ts} +6 -5
- package/esm/typings/src/llm-providers/_common/{$registeredLlmToolsMessage.d.ts → register/$registeredLlmToolsMessage.d.ts} +5 -2
- package/esm/typings/src/llm-providers/_common/{LlmToolsConfiguration.d.ts → register/LlmToolsConfiguration.d.ts} +6 -5
- package/esm/typings/src/llm-providers/_common/{LlmToolsMetadata.d.ts → register/LlmToolsMetadata.d.ts} +5 -4
- package/esm/typings/src/llm-providers/_common/{LlmToolsOptions.d.ts → register/LlmToolsOptions.d.ts} +4 -1
- package/esm/typings/src/llm-providers/_common/{createLlmToolsFromConfiguration.d.ts → register/createLlmToolsFromConfiguration.d.ts} +12 -4
- package/esm/typings/src/llm-providers/_common/utils/cache/CacheLlmToolsOptions.d.ts +4 -1
- package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +1 -1
- package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionToolsOptions.d.ts +5 -5
- package/esm/typings/src/llm-providers/anthropic-claude/anthropic-claude-models.d.ts +1 -1
- package/esm/typings/src/llm-providers/anthropic-claude/register-configuration.d.ts +4 -3
- package/esm/typings/src/llm-providers/anthropic-claude/register-constructor.d.ts +4 -3
- package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.d.ts +1 -1
- package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionToolsOptions.d.ts +4 -3
- package/esm/typings/src/llm-providers/azure-openai/register-configuration.d.ts +4 -3
- package/esm/typings/src/llm-providers/azure-openai/register-constructor.d.ts +4 -3
- package/esm/typings/src/llm-providers/langtail/LangtailExecutionTools.d.ts +1 -1
- package/esm/typings/src/llm-providers/mocked/$fakeTextToExpectations.d.ts +1 -1
- package/esm/typings/src/llm-providers/mocked/MockedEchoLlmExecutionTools.d.ts +4 -4
- package/esm/typings/src/llm-providers/mocked/MockedFackedLlmExecutionTools.d.ts +4 -4
- package/esm/typings/src/llm-providers/multiple/MultipleLlmExecutionTools.d.ts +4 -4
- package/esm/typings/src/llm-providers/multiple/joinLlmExecutionTools.d.ts +1 -1
- package/esm/typings/src/llm-providers/openai/OpenAiAssistantExecutionTools.d.ts +0 -1
- package/esm/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +2 -2
- package/esm/typings/src/llm-providers/openai/OpenAiExecutionToolsOptions.d.ts +4 -4
- package/esm/typings/src/llm-providers/openai/openai-models.d.ts +1 -1
- package/esm/typings/src/llm-providers/openai/register-configuration.d.ts +5 -4
- package/esm/typings/src/llm-providers/openai/register-constructor.d.ts +5 -4
- package/esm/typings/src/llm-providers/remote/RemoteLlmExecutionTools.d.ts +4 -4
- package/esm/typings/src/llm-providers/remote/interfaces/PromptbookServer_ListModels_Request.d.ts +16 -7
- package/esm/typings/src/llm-providers/remote/interfaces/PromptbookServer_ListModels_Response.d.ts +4 -4
- package/esm/typings/src/llm-providers/remote/interfaces/PromptbookServer_Prompt_Request.d.ts +7 -13
- package/esm/typings/src/llm-providers/remote/interfaces/PromptbookServer_Prompt_Response.d.ts +3 -3
- package/esm/typings/src/llm-providers/remote/interfaces/RemoteLlmExecutionToolsOptions.d.ts +11 -16
- package/esm/typings/src/llm-providers/remote/interfaces/RemoteServerOptions.d.ts +24 -9
- package/esm/typings/src/llm-providers/remote/startRemoteServer.d.ts +1 -1
- package/esm/typings/src/personas/preparePersona.d.ts +2 -1
- package/esm/typings/src/prepare/PrepareAndScrapeOptions.d.ts +10 -28
- package/esm/typings/src/prepare/preparePipeline.d.ts +2 -1
- package/esm/typings/src/prepare/prepareTemplates.d.ts +3 -2
- package/esm/typings/src/scrapers/_common/Converter.d.ts +4 -10
- package/esm/typings/src/scrapers/_common/Scraper.d.ts +5 -17
- package/esm/typings/src/scrapers/_common/prepareKnowledgePieces.d.ts +2 -1
- package/esm/typings/src/scrapers/_common/register/$provideFilesystemForNode.d.ts +11 -0
- package/esm/typings/src/scrapers/_common/register/$provideScrapersForBrowser.d.ts +12 -0
- package/esm/typings/src/scrapers/_common/register/$provideScrapersForNode.d.ts +15 -0
- package/esm/typings/src/scrapers/_common/register/$registeredScrapersMessage.d.ts +12 -0
- package/esm/typings/src/scrapers/_common/register/$scrapersMetadataRegister.d.ts +13 -0
- package/esm/typings/src/scrapers/_common/register/$scrapersRegister.d.ts +13 -0
- package/esm/typings/src/scrapers/_common/register/ScraperAndConverterMetadata.d.ts +41 -0
- package/esm/typings/src/scrapers/_common/register/ScraperConstructor.d.ts +12 -0
- package/esm/typings/src/scrapers/_common/utils/getScraperIntermediateSource.d.ts +3 -2
- package/esm/typings/src/scrapers/_common/utils/makeKnowledgeSourceHandler.d.ts +3 -2
- package/esm/typings/src/scrapers/document/{documentScraper.d.ts → DocumentScraper.d.ts} +18 -12
- package/esm/typings/src/scrapers/document/createDocumentScraper.d.ts +20 -0
- package/esm/typings/src/scrapers/document/register-constructor.d.ts +13 -0
- package/esm/typings/src/scrapers/document/register-metadata.d.ts +24 -0
- package/esm/typings/src/scrapers/document-legacy/LegacyDocumentScraper.d.ts +43 -0
- package/esm/typings/src/scrapers/document-legacy/createLegacyDocumentScraper.d.ts +20 -0
- package/esm/typings/src/scrapers/document-legacy/register-constructor.d.ts +13 -0
- package/esm/typings/src/scrapers/document-legacy/register-metadata.d.ts +24 -0
- package/esm/typings/src/scrapers/markdown/MarkdownScraper.d.ts +29 -0
- package/esm/typings/src/scrapers/markdown/createMarkdownScraper.d.ts +20 -0
- package/esm/typings/src/scrapers/markdown/register-constructor.d.ts +13 -0
- package/esm/typings/src/scrapers/markdown/register-metadata.d.ts +24 -0
- package/esm/typings/src/scrapers/pdf/PdfScraper.d.ts +40 -0
- package/esm/typings/src/scrapers/pdf/createPdfScraper.d.ts +20 -0
- package/esm/typings/src/scrapers/pdf/register-constructor.d.ts +13 -0
- package/esm/typings/src/scrapers/pdf/register-metadata.d.ts +24 -0
- package/esm/typings/src/scrapers/website/WebsiteScraper.d.ts +50 -0
- package/esm/typings/src/scrapers/website/createWebsiteScraper.d.ts +20 -0
- package/esm/typings/src/scrapers/website/register-constructor.d.ts +13 -0
- package/esm/typings/src/scrapers/website/register-metadata.d.ts +24 -0
- package/esm/typings/src/scrapers/website/utils/createShowdownConverter.d.ts +7 -0
- package/esm/typings/src/scripting/javascript/JavascriptExecutionToolsOptions.d.ts +2 -2
- package/esm/typings/src/scripting/javascript/utils/preserve.d.ts +1 -1
- package/esm/typings/src/scripting/python/PythonExecutionTools.d.ts +3 -3
- package/esm/typings/src/scripting/typescript/TypescriptExecutionTools.d.ts +3 -3
- package/esm/typings/src/storage/file-cache-storage/FileCacheStorage.d.ts +5 -3
- package/esm/typings/src/storage/file-cache-storage/utils/nameToSubfolderPath.d.ts +1 -1
- package/esm/typings/src/storage/{utils → memory/utils}/PrefixStorage.d.ts +1 -1
- package/esm/typings/src/storage/{utils → memory/utils}/makePromptbookStorageFromWebStorage.d.ts +1 -1
- package/esm/typings/src/types/Arrayable.d.ts +1 -1
- package/esm/typings/src/types/IntermediateFilesStrategy.d.ts +7 -0
- package/esm/typings/src/types/PipelineJson/KnowledgePieceJson.d.ts +4 -4
- package/esm/typings/src/types/PipelineJson/KnowledgeSourceJson.d.ts +1 -1
- package/esm/typings/src/types/PipelineJson/PersonaJson.d.ts +1 -1
- package/esm/typings/src/types/PipelineJson/TemplateJsonCommon.d.ts +2 -2
- package/esm/typings/src/types/Prompt.d.ts +2 -1
- package/esm/typings/src/types/execution-report/ExecutionReportJson.d.ts +1 -1
- package/esm/typings/src/types/typeAliases.d.ts +18 -8
- package/esm/typings/src/utils/$Register.d.ts +20 -7
- package/esm/typings/src/utils/FromtoItems.d.ts +1 -1
- package/esm/typings/src/utils/arrayableToArray.d.ts +1 -1
- package/esm/typings/src/utils/emojis.d.ts +1 -1
- package/esm/typings/src/utils/execCommand/$execCommand.d.ts +5 -3
- package/esm/typings/src/utils/execCommand/$execCommandNormalizeOptions.d.ts +12 -0
- package/esm/typings/src/utils/execCommand/$execCommands.d.ts +2 -1
- package/esm/typings/src/utils/execCommand/ExecCommandOptions.d.ts +45 -0
- package/esm/typings/src/utils/expectation-counters/countSentences.d.ts +1 -1
- package/esm/typings/src/utils/files/isDirectoryExisting.d.ts +14 -0
- package/esm/typings/src/utils/files/isExecutable.d.ts +11 -0
- package/esm/typings/src/utils/files/isFileExisting.d.ts +13 -0
- package/esm/typings/src/utils/files/isFileExisting.test.d.ts +1 -0
- package/esm/typings/src/utils/files/{$listAllFiles.d.ts → listAllFiles.d.ts} +3 -4
- package/esm/typings/src/utils/files/listAllFiles.test.d.ts +1 -0
- package/esm/typings/src/utils/markdown/extractAllBlocksFromMarkdown.d.ts +1 -1
- package/esm/typings/src/utils/markdown/splitMarkdownIntoSections.d.ts +1 -1
- package/esm/typings/src/utils/normalization/IKeywords.d.ts +2 -2
- package/esm/typings/src/utils/normalization/parseKeywords.d.ts +2 -2
- package/esm/typings/src/utils/normalization/parseKeywordsFromString.d.ts +2 -2
- package/esm/typings/src/utils/normalization/searchKeywords.d.ts +2 -2
- package/esm/typings/src/utils/organization/TODO_USE.d.ts +1 -1
- package/esm/typings/src/utils/organization/keepUnused.d.ts +1 -1
- package/esm/typings/src/utils/random/$randomSeed.d.ts +1 -1
- package/esm/typings/src/utils/sets/intersection.d.ts +1 -1
- package/esm/typings/src/utils/sets/union.d.ts +1 -1
- package/esm/typings/src/utils/unwrapResult.d.ts +4 -4
- package/package.json +4 -3
- package/umd/index.umd.js +122 -29
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/execution/createPipelineExecutor/00-CreatePipelineExecutorSettings.d.ts +0 -29
- package/esm/typings/src/scrapers/document-legacy/legacyDocumentScraper.d.ts +0 -37
- package/esm/typings/src/scrapers/index.d.ts +0 -8
- package/esm/typings/src/scrapers/markdown/markdownScraper.d.ts +0 -29
- package/esm/typings/src/scrapers/pdf/pdfScraper.d.ts +0 -35
- package/esm/typings/src/scrapers/website/utils/markdownConverter.d.ts +0 -12
- package/esm/typings/src/scrapers/website/websiteScraper.d.ts +0 -43
- package/esm/typings/src/utils/execCommand/IExecCommandOptions.d.ts +0 -23
- package/esm/typings/src/utils/execCommand/execCommandNormalizeOptions.d.ts +0 -10
- package/esm/typings/src/utils/files/$isDirectoryExisting.d.ts +0 -15
- package/esm/typings/src/utils/files/$isFileExisting.d.ts +0 -14
- /package/esm/typings/src/{scrapers/website/utils/markdownConverter.test.d.ts → executables/apps/locateLibreoffice.test.d.ts} +0 -0
- /package/esm/typings/src/{scrapers/website/websiteScraper.test.d.ts → executables/apps/locatePandoc.test.d.ts} +0 -0
- /package/esm/typings/src/{utils/files/$isDirectoryExisting.test.d.ts → executables/locateApp.test.d.ts} +0 -0
- /package/esm/typings/src/scrapers/document/{documentScraper.test.d.ts → DocumentScraper.test.d.ts} +0 -0
- /package/esm/typings/src/scrapers/document-legacy/{legacyDocumentScraper.test.d.ts → LegacyDocumentScraper.test.d.ts} +0 -0
- /package/esm/typings/src/scrapers/markdown/{markdownScraper.test.d.ts → MarkdownScraper.test.d.ts} +0 -0
- /package/esm/typings/src/{utils/files/$isFileExisting.test.d.ts → scrapers/website/utils/createShowdownConverter.test.d.ts} +0 -0
- /package/esm/typings/src/utils/files/{$listAllFiles.test.d.ts → isDirectoryExisting.test.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
#  Promptbook
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Build responsible, controlled and transparent applications on top of LLM models!
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
@@ -20,10 +20,6 @@ Supercharge your use of large language models
|
|
|
20
20
|
|
|
21
21
|
- ✨ **Support of [OpenAI o1 model](https://openai.com/o1/)**
|
|
22
22
|
|
|
23
|
-
<blockquote style="color: #ff8811">
|
|
24
|
-
<b>⚠ Warning:</b> This is a pre-release version of the library. It is not yet ready for production use. Please look at <a href="https://www.npmjs.com/package/@promptbook/core?activeTab=versions">latest stable release</a>.
|
|
25
|
-
</blockquote>
|
|
26
|
-
|
|
27
23
|
|
|
28
24
|
|
|
29
25
|
## 📦 Package `@promptbook/openai`
|
|
@@ -47,31 +43,37 @@ npm install @promptbook/openai
|
|
|
47
43
|
|
|
48
44
|
```typescript
|
|
49
45
|
import { createPipelineExecutor, assertsExecutionSuccessful } from '@promptbook/core';
|
|
50
|
-
import {
|
|
46
|
+
import {
|
|
47
|
+
createCollectionFromDirectory,
|
|
48
|
+
$provideExecutionToolsForNode,
|
|
49
|
+
$provideFilesystemForNode,
|
|
50
|
+
} from '@promptbook/node';
|
|
51
51
|
import { JavascriptExecutionTools } from '@promptbook/execute-javascript';
|
|
52
52
|
import { OpenAiExecutionTools } from '@promptbook/openai';
|
|
53
53
|
|
|
54
|
+
// ▶ Prepare tools
|
|
55
|
+
const fs = $provideFilesystemForNode();
|
|
56
|
+
const llm = new OpenAiExecutionTools(
|
|
57
|
+
// <- TODO: [🧱] Implement in a functional (not new Class) way
|
|
58
|
+
{
|
|
59
|
+
isVerbose: true,
|
|
60
|
+
apiKey: process.env.OPENAI_API_KEY,
|
|
61
|
+
},
|
|
62
|
+
);
|
|
63
|
+
const executables = await $provideExecutablesForNode();
|
|
64
|
+
const tools = {
|
|
65
|
+
llm,
|
|
66
|
+
fs,
|
|
67
|
+
scrapers: await $provideScrapersForNode({ fs, llm, executables }),
|
|
68
|
+
script: [new JavascriptExecutionTools()],
|
|
69
|
+
};
|
|
70
|
+
|
|
54
71
|
// ▶ Create whole pipeline collection
|
|
55
|
-
const collection = await createCollectionFromDirectory('./promptbook-collection');
|
|
72
|
+
const collection = await createCollectionFromDirectory('./promptbook-collection', tools);
|
|
56
73
|
|
|
57
74
|
// ▶ Get single Pipeline
|
|
58
75
|
const pipeline = await collection.getPipelineByUrl(`https://promptbook.studio/my-collection/write-article.ptbk.md`);
|
|
59
76
|
|
|
60
|
-
// ▶ Prepare tools
|
|
61
|
-
const tools = {
|
|
62
|
-
llm: new OpenAiExecutionTools(
|
|
63
|
-
// <- TODO: [🧱] Implement in a functional (not new Class) way
|
|
64
|
-
{
|
|
65
|
-
isVerbose: true,
|
|
66
|
-
apiKey: process.env.OPENAI_API_KEY,
|
|
67
|
-
},
|
|
68
|
-
),
|
|
69
|
-
script: [
|
|
70
|
-
new JavascriptExecutionTools(),
|
|
71
|
-
// <- TODO: [🧱] Implement in a functional (not new Class) way
|
|
72
|
-
],
|
|
73
|
-
};
|
|
74
|
-
|
|
75
77
|
// ▶ Create executor - the function that will execute the Pipeline
|
|
76
78
|
const pipelineExecutor = createPipelineExecutor({ pipeline, tools });
|
|
77
79
|
|
|
@@ -91,34 +93,29 @@ console.info(outputParameters);
|
|
|
91
93
|
|
|
92
94
|
## 🤺 Usage with OpenAI`s Assistants (GPTs)
|
|
93
95
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
+
> TODO: Write a guide how to use OpenAI's Assistants with Promptbook
|
|
97
|
+
|
|
98
|
+
|
|
96
99
|
|
|
97
100
|
## 🧙♂️ Connect to LLM providers automatically
|
|
98
101
|
|
|
99
|
-
You can just use `
|
|
102
|
+
You can just use `$provideExecutionToolsForNode` function to create all required tools from environment variables like `OPENAI_API_KEY` and `ANTHROPIC_CLAUDE_API_KEY` automatically.
|
|
100
103
|
|
|
101
104
|
```typescript
|
|
102
105
|
import { createPipelineExecutor, createCollectionFromDirectory, assertsExecutionSuccessful } from '@promptbook/core';
|
|
103
106
|
import { JavascriptExecutionTools } from '@promptbook/execute-javascript';
|
|
104
|
-
import {
|
|
107
|
+
import { $provideExecutionToolsForNode } from '@promptbook/node';
|
|
108
|
+
import { $provideFilesystemForNode } from '@promptbook/node';
|
|
109
|
+
|
|
110
|
+
// ▶ Prepare tools
|
|
111
|
+
const tools = await $provideExecutionToolsForNode();
|
|
105
112
|
|
|
106
113
|
// ▶ Create whole pipeline collection
|
|
107
|
-
const collection = await createCollectionFromDirectory('./promptbook-collection');
|
|
114
|
+
const collection = await createCollectionFromDirectory('./promptbook-collection', tools);
|
|
108
115
|
|
|
109
116
|
// ▶ Get single Pipeline
|
|
110
117
|
const pipeline = await collection.getPipelineByUrl(`https://promptbook.studio/my-collection/write-article.ptbk.md`);
|
|
111
118
|
|
|
112
|
-
// ▶ Prepare multiple tools
|
|
113
|
-
const tools = {
|
|
114
|
-
// Note: 🧙♂️ Just call `createLlmToolsFromEnv` to automatically connect to all configured providers
|
|
115
|
-
llm: createLlmToolsFromEnv(),
|
|
116
|
-
script: [
|
|
117
|
-
new JavascriptExecutionTools(),
|
|
118
|
-
// <- TODO: [🧱] Implement in a functional (not new Class) way
|
|
119
|
-
],
|
|
120
|
-
};
|
|
121
|
-
|
|
122
119
|
// ▶ Create executor - the function that will execute the Pipeline
|
|
123
120
|
const pipelineExecutor = createPipelineExecutor({ pipeline, tools });
|
|
124
121
|
|
|
@@ -142,50 +139,56 @@ You can use multiple LLM providers in one Promptbook execution. The best model w
|
|
|
142
139
|
|
|
143
140
|
```typescript
|
|
144
141
|
import { createPipelineExecutor, assertsExecutionSuccessful } from '@promptbook/core';
|
|
145
|
-
import {
|
|
142
|
+
import {
|
|
143
|
+
createCollectionFromDirectory,
|
|
144
|
+
$provideExecutionToolsForNode,
|
|
145
|
+
$provideFilesystemForNode,
|
|
146
|
+
} from '@promptbook/node';
|
|
146
147
|
import { JavascriptExecutionTools } from '@promptbook/execute-javascript';
|
|
147
148
|
import { OpenAiExecutionTools } from '@promptbook/openai';
|
|
148
149
|
import { AnthropicClaudeExecutionTools } from '@promptbook/anthropic-claude';
|
|
149
150
|
import { AzureOpenAiExecutionTools } from '@promptbook/azure-openai';
|
|
150
151
|
|
|
152
|
+
// ▶ Prepare multiple tools
|
|
153
|
+
const fs = $provideFilesystemForNode();
|
|
154
|
+
const llm = [
|
|
155
|
+
// Note: You can use multiple LLM providers in one Promptbook execution.
|
|
156
|
+
// The best model will be chosen automatically according to the prompt and the model's capabilities.
|
|
157
|
+
new OpenAiExecutionTools(
|
|
158
|
+
// <- TODO: [🧱] Implement in a functional (not new Class) way
|
|
159
|
+
{
|
|
160
|
+
apiKey: process.env.OPENAI_API_KEY,
|
|
161
|
+
},
|
|
162
|
+
),
|
|
163
|
+
new AnthropicClaudeExecutionTools(
|
|
164
|
+
// <- TODO: [🧱] Implement in a functional (not new Class) way
|
|
165
|
+
{
|
|
166
|
+
apiKey: process.env.ANTHROPIC_CLAUDE_API_KEY,
|
|
167
|
+
},
|
|
168
|
+
),
|
|
169
|
+
new AzureOpenAiExecutionTools(
|
|
170
|
+
// <- TODO: [🧱] Implement in a functional (not new Class) way
|
|
171
|
+
{
|
|
172
|
+
resourceName: process.env.AZUREOPENAI_RESOURCE_NAME,
|
|
173
|
+
deploymentName: process.env.AZUREOPENAI_DEPLOYMENT_NAME,
|
|
174
|
+
apiKey: process.env.AZUREOPENAI_API_KEY,
|
|
175
|
+
},
|
|
176
|
+
),
|
|
177
|
+
];
|
|
178
|
+
const executables = await $provideExecutablesForNode();
|
|
179
|
+
const tools = {
|
|
180
|
+
llm,
|
|
181
|
+
fs,
|
|
182
|
+
scrapers: await $provideScrapersForNode({ fs, llm, executables }),
|
|
183
|
+
script: [new JavascriptExecutionTools()],
|
|
184
|
+
};
|
|
185
|
+
|
|
151
186
|
// ▶ Create whole pipeline collection
|
|
152
|
-
const collection = await createCollectionFromDirectory('./promptbook-collection');
|
|
187
|
+
const collection = await createCollectionFromDirectory('./promptbook-collection', tools);
|
|
153
188
|
|
|
154
189
|
// ▶ Get single Pipeline
|
|
155
190
|
const pipeline = await collection.getPipelineByUrl(`https://promptbook.studio/my-collection/write-article.ptbk.md`);
|
|
156
191
|
|
|
157
|
-
// ▶ Prepare multiple tools
|
|
158
|
-
const tools = {
|
|
159
|
-
llm: [
|
|
160
|
-
// Note: You can use multiple LLM providers in one Promptbook execution.
|
|
161
|
-
// The best model will be chosen automatically according to the prompt and the model's capabilities.
|
|
162
|
-
new OpenAiExecutionTools(
|
|
163
|
-
// <- TODO: [🧱] Implement in a functional (not new Class) way
|
|
164
|
-
{
|
|
165
|
-
apiKey: process.env.OPENAI_API_KEY,
|
|
166
|
-
},
|
|
167
|
-
),
|
|
168
|
-
new AnthropicClaudeExecutionTools(
|
|
169
|
-
// <- TODO: [🧱] Implement in a functional (not new Class) way
|
|
170
|
-
{
|
|
171
|
-
apiKey: process.env.ANTHROPIC_CLAUDE_API_KEY,
|
|
172
|
-
},
|
|
173
|
-
),
|
|
174
|
-
new AzureOpenAiExecutionTools(
|
|
175
|
-
// <- TODO: [🧱] Implement in a functional (not new Class) way
|
|
176
|
-
{
|
|
177
|
-
resourceName: process.env.AZUREOPENAI_RESOURCE_NAME,
|
|
178
|
-
deploymentName: process.env.AZUREOPENAI_DEPLOYMENT_NAME,
|
|
179
|
-
apiKey: process.env.AZUREOPENAI_API_KEY,
|
|
180
|
-
},
|
|
181
|
-
),
|
|
182
|
-
],
|
|
183
|
-
script: [
|
|
184
|
-
new JavascriptExecutionTools(),
|
|
185
|
-
// <- TODO: [🧱] Implement in a functional (not new Class) way
|
|
186
|
-
],
|
|
187
|
-
};
|
|
188
|
-
|
|
189
192
|
// ▶ Create executor - the function that will execute the Pipeline
|
|
190
193
|
const pipelineExecutor = createPipelineExecutor({ pipeline, tools });
|
|
191
194
|
|
|
@@ -221,15 +224,15 @@ Rest of the documentation is common for **entire promptbook ecosystem**:
|
|
|
221
224
|
|
|
222
225
|
|
|
223
226
|
|
|
224
|
-
If you have a simple, single prompt for ChatGPT, GPT-4, Anthropic Claude, Google Gemini, Llama
|
|
227
|
+
If you have a simple, single prompt for ChatGPT, GPT-4, Anthropic Claude, Google Gemini, Llama 3, or whatever, it doesn't matter how you integrate it. Whether it's calling a REST API directly, using the SDK, hardcoding the prompt into the source code, or importing a text file, the process remains the same.
|
|
225
228
|
|
|
226
|
-
But often you will struggle with the limitations of LLMs
|
|
229
|
+
But often you will struggle with the **limitations of LLMs**, such as **hallucinations, off-topic responses, poor quality output, language and prompt drift, word repetition repetition repetition repetition or misuse, lack of context, or just plain w𝒆𝐢rd responses**. When this happens, you generally have three options:
|
|
227
230
|
|
|
228
231
|
1. **Fine-tune** the model to your specifications or even train your own.
|
|
229
232
|
2. **Prompt-engineer** the prompt to the best shape you can achieve.
|
|
230
233
|
3. Orchestrate **multiple prompts** in a [pipeline](https://github.com/webgptorg/promptbook/discussions/64) to get the best result.
|
|
231
234
|
|
|
232
|
-
In all of these situations, but especially in 3., the Promptbook
|
|
235
|
+
In all of these situations, but especially in 3., the **✨ Promptbook can make your life waaaaaaaaaay easier**.
|
|
233
236
|
|
|
234
237
|
- [**Separates concerns**](https://github.com/webgptorg/promptbook/discussions/32) between prompt-engineer and programmer, between code files and prompt files, and between prompts and their execution logic.
|
|
235
238
|
- Establishes a [**common format `.ptbk.md`**](https://github.com/webgptorg/promptbook/discussions/85) that can be used to describe your prompt business logic without having to write code or deal with the technicalities of LLMs.
|
|
@@ -501,6 +504,10 @@ Or you can install them separately:
|
|
|
501
504
|
- **[@promptbook/fake-llm](https://www.npmjs.com/package/@promptbook/fake-llm)** - Mocked execution tools for testing the library and saving the tokens
|
|
502
505
|
- **[@promptbook/remote-client](https://www.npmjs.com/package/@promptbook/remote-client)** - Remote client for remote execution of promptbooks
|
|
503
506
|
- **[@promptbook/remote-server](https://www.npmjs.com/package/@promptbook/remote-server)** - Remote server for remote execution of promptbooks
|
|
507
|
+
- **[@promptbook/pdf](https://www.npmjs.com/package/@promptbook/pdf)** - Read knowledge from `.pdf` documents
|
|
508
|
+
- **[@promptbook/documents](https://www.npmjs.com/package/@promptbook/documents)** - Read knowledge from documents like `.docx`, `.odt`,…
|
|
509
|
+
- **[@promptbook/legacy-documents](https://www.npmjs.com/package/@promptbook/legacy-documents)** - Read knowledge from legacy documents like `.doc`, `.rtf`,…
|
|
510
|
+
- **[@promptbook/website-crawler](https://www.npmjs.com/package/@promptbook/website-crawler)** - Crawl knowledge from the web
|
|
504
511
|
- **[@promptbook/types](https://www.npmjs.com/package/@promptbook/types)** - Just typescript types used in the library
|
|
505
512
|
- **[@promptbook/cli](https://www.npmjs.com/package/@promptbook/cli)** - Command line interface utilities for promptbooks
|
|
506
513
|
|
package/esm/index.es.js
CHANGED
|
@@ -6,7 +6,7 @@ import OpenAI from 'openai';
|
|
|
6
6
|
/**
|
|
7
7
|
* The version of the Promptbook library
|
|
8
8
|
*/
|
|
9
|
-
var PROMPTBOOK_VERSION = '0.72.0-
|
|
9
|
+
var PROMPTBOOK_VERSION = '0.72.0-34';
|
|
10
10
|
// TODO: [main] !!!! List here all the versions and annotate + put into script
|
|
11
11
|
|
|
12
12
|
/*! *****************************************************************************
|
|
@@ -1413,7 +1413,6 @@ var OpenAiExecutionTools = /** @class */ (function () {
|
|
|
1413
1413
|
* @param options which are relevant are directly passed to the OpenAI client
|
|
1414
1414
|
*/
|
|
1415
1415
|
function OpenAiExecutionTools(options) {
|
|
1416
|
-
if (options === void 0) { options = {}; }
|
|
1417
1416
|
this.options = options;
|
|
1418
1417
|
/**
|
|
1419
1418
|
* OpenAI API client.
|
|
@@ -1441,8 +1440,8 @@ var OpenAiExecutionTools = /** @class */ (function () {
|
|
|
1441
1440
|
if (this.client === null) {
|
|
1442
1441
|
openAiOptions = __assign({}, this.options);
|
|
1443
1442
|
delete openAiOptions.isVerbose;
|
|
1444
|
-
delete openAiOptions.
|
|
1445
|
-
this.client = new OpenAI(
|
|
1443
|
+
delete openAiOptions.userId;
|
|
1444
|
+
this.client = new OpenAI(openAiOptions);
|
|
1446
1445
|
}
|
|
1447
1446
|
return [2 /*return*/, this.client];
|
|
1448
1447
|
});
|
|
@@ -1489,11 +1488,12 @@ var OpenAiExecutionTools = /** @class */ (function () {
|
|
|
1489
1488
|
* Calls OpenAI API to use a chat model.
|
|
1490
1489
|
*/
|
|
1491
1490
|
OpenAiExecutionTools.prototype.callChatModel = function (prompt) {
|
|
1491
|
+
var _a;
|
|
1492
1492
|
return __awaiter(this, void 0, void 0, function () {
|
|
1493
1493
|
var content, parameters, modelRequirements, format, client, modelName, modelSettings, rawPromptContent, rawRequest, start, complete, rawResponse, resultContent, usage;
|
|
1494
1494
|
var _this = this;
|
|
1495
|
-
return __generator(this, function (
|
|
1496
|
-
switch (
|
|
1495
|
+
return __generator(this, function (_b) {
|
|
1496
|
+
switch (_b.label) {
|
|
1497
1497
|
case 0:
|
|
1498
1498
|
if (this.options.isVerbose) {
|
|
1499
1499
|
console.info('💬 OpenAI callChatModel call', { prompt: prompt });
|
|
@@ -1501,7 +1501,7 @@ var OpenAiExecutionTools = /** @class */ (function () {
|
|
|
1501
1501
|
content = prompt.content, parameters = prompt.parameters, modelRequirements = prompt.modelRequirements, format = prompt.format;
|
|
1502
1502
|
return [4 /*yield*/, this.getClient()];
|
|
1503
1503
|
case 1:
|
|
1504
|
-
client =
|
|
1504
|
+
client = _b.sent();
|
|
1505
1505
|
// TODO: [☂] Use here more modelRequirements
|
|
1506
1506
|
if (modelRequirements.modelVariant !== 'CHAT') {
|
|
1507
1507
|
throw new PipelineExecutionError('Use callChatModel only for CHAT variant');
|
|
@@ -1533,7 +1533,7 @@ var OpenAiExecutionTools = /** @class */ (function () {
|
|
|
1533
1533
|
role: 'user',
|
|
1534
1534
|
content: rawPromptContent,
|
|
1535
1535
|
},
|
|
1536
|
-
], false), user: this.options.
|
|
1536
|
+
], false), user: (_a = this.options.userId) === null || _a === void 0 ? void 0 : _a.toString() });
|
|
1537
1537
|
start = getCurrentIsoDate();
|
|
1538
1538
|
if (this.options.isVerbose) {
|
|
1539
1539
|
console.info(colors.bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
|
|
@@ -1545,7 +1545,7 @@ var OpenAiExecutionTools = /** @class */ (function () {
|
|
|
1545
1545
|
throw error;
|
|
1546
1546
|
})];
|
|
1547
1547
|
case 2:
|
|
1548
|
-
rawResponse =
|
|
1548
|
+
rawResponse = _b.sent();
|
|
1549
1549
|
if (this.options.isVerbose) {
|
|
1550
1550
|
console.info(colors.bgWhite('rawResponse'), JSON.stringify(rawResponse, null, 4));
|
|
1551
1551
|
}
|
|
@@ -1584,11 +1584,12 @@ var OpenAiExecutionTools = /** @class */ (function () {
|
|
|
1584
1584
|
* Calls OpenAI API to use a complete model.
|
|
1585
1585
|
*/
|
|
1586
1586
|
OpenAiExecutionTools.prototype.callCompletionModel = function (prompt) {
|
|
1587
|
+
var _a;
|
|
1587
1588
|
return __awaiter(this, void 0, void 0, function () {
|
|
1588
1589
|
var content, parameters, modelRequirements, client, modelName, modelSettings, rawPromptContent, rawRequest, start, complete, rawResponse, resultContent, usage;
|
|
1589
1590
|
var _this = this;
|
|
1590
|
-
return __generator(this, function (
|
|
1591
|
-
switch (
|
|
1591
|
+
return __generator(this, function (_b) {
|
|
1592
|
+
switch (_b.label) {
|
|
1592
1593
|
case 0:
|
|
1593
1594
|
if (this.options.isVerbose) {
|
|
1594
1595
|
console.info('🖋 OpenAI callCompletionModel call', { prompt: prompt });
|
|
@@ -1596,7 +1597,7 @@ var OpenAiExecutionTools = /** @class */ (function () {
|
|
|
1596
1597
|
content = prompt.content, parameters = prompt.parameters, modelRequirements = prompt.modelRequirements;
|
|
1597
1598
|
return [4 /*yield*/, this.getClient()];
|
|
1598
1599
|
case 1:
|
|
1599
|
-
client =
|
|
1600
|
+
client = _b.sent();
|
|
1600
1601
|
// TODO: [☂] Use here more modelRequirements
|
|
1601
1602
|
if (modelRequirements.modelVariant !== 'COMPLETION') {
|
|
1602
1603
|
throw new PipelineExecutionError('Use callCompletionModel only for COMPLETION variant');
|
|
@@ -1611,7 +1612,7 @@ var OpenAiExecutionTools = /** @class */ (function () {
|
|
|
1611
1612
|
// <- Note: [🧆]
|
|
1612
1613
|
};
|
|
1613
1614
|
rawPromptContent = replaceParameters(content, __assign(__assign({}, parameters), { modelName: modelName }));
|
|
1614
|
-
rawRequest = __assign(__assign({}, modelSettings), { prompt: rawPromptContent, user: this.options.
|
|
1615
|
+
rawRequest = __assign(__assign({}, modelSettings), { prompt: rawPromptContent, user: (_a = this.options.userId) === null || _a === void 0 ? void 0 : _a.toString() });
|
|
1615
1616
|
start = getCurrentIsoDate();
|
|
1616
1617
|
if (this.options.isVerbose) {
|
|
1617
1618
|
console.info(colors.bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
|
|
@@ -1623,7 +1624,7 @@ var OpenAiExecutionTools = /** @class */ (function () {
|
|
|
1623
1624
|
throw error;
|
|
1624
1625
|
})];
|
|
1625
1626
|
case 2:
|
|
1626
|
-
rawResponse =
|
|
1627
|
+
rawResponse = _b.sent();
|
|
1627
1628
|
if (this.options.isVerbose) {
|
|
1628
1629
|
console.info(colors.bgWhite('rawResponse'), JSON.stringify(rawResponse, null, 4));
|
|
1629
1630
|
}
|
|
@@ -1849,17 +1850,16 @@ var OpenAiAssistantExecutionTools = /** @class */ (function (_super) {
|
|
|
1849
1850
|
assistant_id: this.assistantId,
|
|
1850
1851
|
thread: {
|
|
1851
1852
|
messages: [
|
|
1852
|
-
// TODO:
|
|
1853
|
+
// TODO: [🗯] !! Allow threads to be passed
|
|
1853
1854
|
{ role: 'user', content: rawPromptContent },
|
|
1854
1855
|
],
|
|
1855
1856
|
},
|
|
1856
|
-
//
|
|
1857
|
+
// <- TODO: Add user identification here> user: this.options.user,
|
|
1857
1858
|
};
|
|
1858
1859
|
start = getCurrentIsoDate();
|
|
1859
1860
|
if (this.options.isVerbose) {
|
|
1860
1861
|
console.info(colors.bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
|
|
1861
1862
|
}
|
|
1862
|
-
console.log('!!!!!! OpenAI client', client);
|
|
1863
1863
|
return [4 /*yield*/, client.beta.threads.createAndRunStream(rawRequest)];
|
|
1864
1864
|
case 2:
|
|
1865
1865
|
stream = _g.sent();
|
|
@@ -1877,7 +1877,7 @@ var OpenAiAssistantExecutionTools = /** @class */ (function (_super) {
|
|
|
1877
1877
|
messageDelta.content[0].type === 'text') {
|
|
1878
1878
|
console.info('messageDelta', (_a = messageDelta.content[0].text) === null || _a === void 0 ? void 0 : _a.value);
|
|
1879
1879
|
}
|
|
1880
|
-
// TODO:
|
|
1880
|
+
// <- TODO: [🐚] Make streaming and running tasks working
|
|
1881
1881
|
});
|
|
1882
1882
|
stream.on('messageCreated', function (message) {
|
|
1883
1883
|
if (_this.options.isVerbose) {
|
|
@@ -1905,18 +1905,20 @@ var OpenAiAssistantExecutionTools = /** @class */ (function (_super) {
|
|
|
1905
1905
|
throw new PipelineExecutionError("There is NOT 'text' BUT ".concat((_b = rawResponse[0].content[0]) === null || _b === void 0 ? void 0 : _b.type, " finalMessages content type from OpenAI"));
|
|
1906
1906
|
}
|
|
1907
1907
|
resultContent = (_c = rawResponse[0].content[0]) === null || _c === void 0 ? void 0 : _c.text.value;
|
|
1908
|
-
// <- TODO:
|
|
1908
|
+
// <- TODO: [🧠] There are also annotations, maybe use them
|
|
1909
1909
|
// eslint-disable-next-line prefer-const
|
|
1910
1910
|
complete = getCurrentIsoDate();
|
|
1911
1911
|
usage = UNCERTAIN_USAGE;
|
|
1912
|
-
// TODO:
|
|
1912
|
+
// <- TODO: [🥘] Compute real usage for assistant
|
|
1913
|
+
// ?> const usage = computeOpenAiUsage(content, resultContent || '', rawResponse);
|
|
1913
1914
|
if (resultContent === null) {
|
|
1914
1915
|
throw new PipelineExecutionError('No response message from OpenAI');
|
|
1915
1916
|
}
|
|
1916
1917
|
return [2 /*return*/, $asDeeplyFrozenSerializableJson('OpenAiAssistantExecutionTools ChatPromptResult', {
|
|
1917
1918
|
content: resultContent,
|
|
1918
1919
|
modelName: 'assistant',
|
|
1919
|
-
//
|
|
1920
|
+
// <- TODO: [🥘] Detect used model in assistant
|
|
1921
|
+
// ?> model: rawResponse.model || modelName,
|
|
1920
1922
|
timing: {
|
|
1921
1923
|
start: start,
|
|
1922
1924
|
complete: complete,
|
|
@@ -1934,7 +1936,6 @@ var OpenAiAssistantExecutionTools = /** @class */ (function (_super) {
|
|
|
1934
1936
|
return OpenAiAssistantExecutionTools;
|
|
1935
1937
|
}(OpenAiExecutionTools));
|
|
1936
1938
|
/**
|
|
1937
|
-
* TODO: !!!!!! DO not use colors - can be used in browser
|
|
1938
1939
|
* TODO: [🧠][🧙♂️] Maybe there can be some wizzard for thoose who want to use just OpenAI
|
|
1939
1940
|
* TODO: Maybe make custom OpenAiError
|
|
1940
1941
|
* TODO: [🧠][🈁] Maybe use `isDeterministic` from options
|
|
@@ -1992,6 +1993,85 @@ function $getGlobalScope() {
|
|
|
1992
1993
|
return Function('return this')();
|
|
1993
1994
|
}
|
|
1994
1995
|
|
|
1996
|
+
/**
|
|
1997
|
+
* @@@
|
|
1998
|
+
*
|
|
1999
|
+
* @param text @@@
|
|
2000
|
+
* @returns @@@
|
|
2001
|
+
* @example 'HELLO_WORLD'
|
|
2002
|
+
* @example 'I_LOVE_PROMPTBOOK'
|
|
2003
|
+
* @public exported from `@promptbook/utils`
|
|
2004
|
+
*/
|
|
2005
|
+
function normalizeTo_SCREAMING_CASE(text) {
|
|
2006
|
+
var e_1, _a;
|
|
2007
|
+
var charType;
|
|
2008
|
+
var lastCharType = 'OTHER';
|
|
2009
|
+
var normalizedName = '';
|
|
2010
|
+
try {
|
|
2011
|
+
for (var text_1 = __values(text), text_1_1 = text_1.next(); !text_1_1.done; text_1_1 = text_1.next()) {
|
|
2012
|
+
var char = text_1_1.value;
|
|
2013
|
+
var normalizedChar = void 0;
|
|
2014
|
+
if (/^[a-z]$/.test(char)) {
|
|
2015
|
+
charType = 'LOWERCASE';
|
|
2016
|
+
normalizedChar = char.toUpperCase();
|
|
2017
|
+
}
|
|
2018
|
+
else if (/^[A-Z]$/.test(char)) {
|
|
2019
|
+
charType = 'UPPERCASE';
|
|
2020
|
+
normalizedChar = char;
|
|
2021
|
+
}
|
|
2022
|
+
else if (/^[0-9]$/.test(char)) {
|
|
2023
|
+
charType = 'NUMBER';
|
|
2024
|
+
normalizedChar = char;
|
|
2025
|
+
}
|
|
2026
|
+
else {
|
|
2027
|
+
charType = 'OTHER';
|
|
2028
|
+
normalizedChar = '_';
|
|
2029
|
+
}
|
|
2030
|
+
if (charType !== lastCharType &&
|
|
2031
|
+
!(lastCharType === 'UPPERCASE' && charType === 'LOWERCASE') &&
|
|
2032
|
+
!(lastCharType === 'NUMBER') &&
|
|
2033
|
+
!(charType === 'NUMBER')) {
|
|
2034
|
+
normalizedName += '_';
|
|
2035
|
+
}
|
|
2036
|
+
normalizedName += normalizedChar;
|
|
2037
|
+
lastCharType = charType;
|
|
2038
|
+
}
|
|
2039
|
+
}
|
|
2040
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2041
|
+
finally {
|
|
2042
|
+
try {
|
|
2043
|
+
if (text_1_1 && !text_1_1.done && (_a = text_1.return)) _a.call(text_1);
|
|
2044
|
+
}
|
|
2045
|
+
finally { if (e_1) throw e_1.error; }
|
|
2046
|
+
}
|
|
2047
|
+
normalizedName = normalizedName.replace(/_+/g, '_');
|
|
2048
|
+
normalizedName = normalizedName.replace(/_?\/_?/g, '/');
|
|
2049
|
+
normalizedName = normalizedName.replace(/^_/, '');
|
|
2050
|
+
normalizedName = normalizedName.replace(/_$/, '');
|
|
2051
|
+
return normalizedName;
|
|
2052
|
+
}
|
|
2053
|
+
/**
|
|
2054
|
+
* TODO: Tests
|
|
2055
|
+
* > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'Moje tabule' })).toEqual('/VtG7sR9rRJqwNEdM2/Moje tabule');
|
|
2056
|
+
* > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'ěščřžžýáíúů' })).toEqual('/VtG7sR9rRJqwNEdM2/escrzyaieuu');
|
|
2057
|
+
* > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj');
|
|
2058
|
+
* > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj_ahojAhoj ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj-ahoj-ahoj-ahoj');
|
|
2059
|
+
* TODO: [🌺] Use some intermediate util splitWords
|
|
2060
|
+
*/
|
|
2061
|
+
|
|
2062
|
+
/**
|
|
2063
|
+
* @@@
|
|
2064
|
+
*
|
|
2065
|
+
* @param text @@@
|
|
2066
|
+
* @returns @@@
|
|
2067
|
+
* @example 'hello_world'
|
|
2068
|
+
* @example 'i_love_promptbook'
|
|
2069
|
+
* @public exported from `@promptbook/utils`
|
|
2070
|
+
*/
|
|
2071
|
+
function normalizeTo_snake_case(text) {
|
|
2072
|
+
return normalizeTo_SCREAMING_CASE(text).toLowerCase();
|
|
2073
|
+
}
|
|
2074
|
+
|
|
1995
2075
|
/**
|
|
1996
2076
|
* Register is @@@
|
|
1997
2077
|
*
|
|
@@ -2000,9 +2080,9 @@ function $getGlobalScope() {
|
|
|
2000
2080
|
* @private internal utility, exported are only signleton instances of this class
|
|
2001
2081
|
*/
|
|
2002
2082
|
var $Register = /** @class */ (function () {
|
|
2003
|
-
function $Register(
|
|
2004
|
-
this.
|
|
2005
|
-
storageName = "_promptbook_".concat(
|
|
2083
|
+
function $Register(registerName) {
|
|
2084
|
+
this.registerName = registerName;
|
|
2085
|
+
var storageName = "_promptbook_".concat(normalizeTo_snake_case(registerName));
|
|
2006
2086
|
var globalScope = $getGlobalScope();
|
|
2007
2087
|
if (globalScope[storageName] === undefined) {
|
|
2008
2088
|
globalScope[storageName] = [];
|
|
@@ -2013,11 +2093,10 @@ var $Register = /** @class */ (function () {
|
|
|
2013
2093
|
this.storage = globalScope[storageName];
|
|
2014
2094
|
}
|
|
2015
2095
|
$Register.prototype.list = function () {
|
|
2016
|
-
// <- TODO: ReadonlyDeep<
|
|
2096
|
+
// <- TODO: ReadonlyDeep<ReadonlyArray<TRegistered>>
|
|
2017
2097
|
return this.storage;
|
|
2018
2098
|
};
|
|
2019
2099
|
$Register.prototype.register = function (registered) {
|
|
2020
|
-
// <- TODO: What to return here
|
|
2021
2100
|
var packageName = registered.packageName, className = registered.className;
|
|
2022
2101
|
var existingRegistrationIndex = this.storage.findIndex(function (item) { return item.packageName === packageName && item.className === className; });
|
|
2023
2102
|
var existingRegistration = this.storage[existingRegistrationIndex];
|
|
@@ -2027,6 +2106,17 @@ var $Register = /** @class */ (function () {
|
|
|
2027
2106
|
else {
|
|
2028
2107
|
this.storage[existingRegistrationIndex] = registered;
|
|
2029
2108
|
}
|
|
2109
|
+
return {
|
|
2110
|
+
registerName: this.registerName,
|
|
2111
|
+
packageName: packageName,
|
|
2112
|
+
className: className,
|
|
2113
|
+
get isDestroyed() {
|
|
2114
|
+
return false;
|
|
2115
|
+
},
|
|
2116
|
+
destroy: function () {
|
|
2117
|
+
throw new NotYetImplementedError("Registration to ".concat(this.registerName, " is permanent in this version of Promptbook"));
|
|
2118
|
+
},
|
|
2119
|
+
};
|
|
2030
2120
|
};
|
|
2031
2121
|
return $Register;
|
|
2032
2122
|
}());
|
|
@@ -2039,11 +2129,14 @@ var $Register = /** @class */ (function () {
|
|
|
2039
2129
|
* @public exported from `@promptbook/core`
|
|
2040
2130
|
*/
|
|
2041
2131
|
var $llmToolsRegister = new $Register('llm_execution_tools_constructors');
|
|
2132
|
+
/**
|
|
2133
|
+
* TODO: [®] DRY Register logic
|
|
2134
|
+
*/
|
|
2042
2135
|
|
|
2043
2136
|
/**
|
|
2044
|
-
*
|
|
2137
|
+
* Registration of LLM provider
|
|
2045
2138
|
*
|
|
2046
|
-
*
|
|
2139
|
+
* Warning: This is not useful for the end user, it is just a side effect of the mechanism that handles all available LLM tools
|
|
2047
2140
|
*
|
|
2048
2141
|
* @public exported from `@promptbook/openai`
|
|
2049
2142
|
* @public exported from `@promptbook/cli`
|