@promptbook/node 0.61.0-10 → 0.61.0-12
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/esm/index.es.js +368 -224
- package/esm/index.es.js.map +1 -1
- package/esm/typings/promptbook-collection/index.d.ts +83 -2
- package/esm/typings/src/_packages/core.index.d.ts +2 -2
- package/esm/typings/src/_packages/types.index.d.ts +2 -2
- package/esm/typings/src/_packages/utils.index.d.ts +3 -1
- package/esm/typings/src/cli/cli-commands/hello.d.ts +3 -0
- package/esm/typings/src/cli/cli-commands/make.d.ts +3 -0
- package/esm/typings/src/cli/cli-commands/prettify.d.ts +3 -0
- package/esm/typings/src/cli/promptbookCli.d.ts +1 -0
- package/esm/typings/src/collection/PipelineCollection.d.ts +1 -1
- package/esm/typings/src/collection/SimplePipelineCollection.d.ts +1 -1
- package/esm/typings/src/collection/constructors/createCollectionFromDirectory.d.ts +1 -0
- package/esm/typings/src/commands/_BOILERPLATE/boilerplateCommandParser.d.ts +1 -0
- package/esm/typings/src/commands/_common/types/CommandParser.d.ts +4 -1
- package/esm/typings/src/config.d.ts +4 -0
- package/esm/typings/src/conversion/pipelineJsonToString.d.ts +1 -1
- package/esm/typings/src/conversion/pipelineStringToJson.d.ts +1 -0
- package/esm/typings/src/conversion/pipelineStringToJsonSync.d.ts +2 -0
- package/esm/typings/src/conversion/validation/validatePipeline.d.ts +6 -0
- package/esm/typings/src/errors/EnvironmentMismatchError.d.ts +7 -0
- package/{umd/typings/src/errors/VersionMismatch.d.ts → esm/typings/src/errors/VersionMismatchError.d.ts} +1 -1
- package/esm/typings/src/execution/CommonExecutionToolsOptions.d.ts +1 -0
- package/esm/typings/src/execution/LlmExecutionTools.d.ts +3 -1
- package/esm/typings/src/execution/PipelineExecutor.d.ts +4 -3
- package/esm/typings/src/execution/PromptResult.d.ts +12 -0
- package/esm/typings/src/execution/ScriptExecutionTools.d.ts +4 -2
- package/esm/typings/src/execution/createPipelineExecutor.d.ts +2 -0
- package/esm/typings/src/formats/csv/ListFormatDefinition.d.ts +1 -0
- package/esm/typings/src/formats/json/JsonFormatDefinition.d.ts +1 -0
- package/esm/typings/src/formats/list/ListFormatDefinition.d.ts +1 -0
- package/esm/typings/src/formats/xml/XmlFormatDefinition.d.ts +1 -0
- package/esm/typings/src/knowledge/dialogs/simple-prompt/SimplePromptInterfaceTools.d.ts +3 -0
- package/esm/typings/src/knowledge/prepare-knowledge/_common/prepareKnowledgePieces.d.ts +1 -1
- package/esm/typings/src/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.d.ts +1 -0
- package/esm/typings/src/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.test.d.ts +3 -0
- package/esm/typings/src/knowledge/prepare-knowledge/pdf/prepareKnowledgeFromPdf.d.ts +1 -0
- package/esm/typings/src/llm-providers/_common/createLlmToolsFromEnv.d.ts +22 -0
- package/esm/typings/src/llm-providers/_common/getLlmToolsForCli.d.ts +10 -0
- package/esm/typings/src/llm-providers/_common/getLlmToolsForTestingAndScriptsAndPlayground.d.ts +10 -0
- package/esm/typings/src/llm-providers/_common/utils/cache/CacheItem.d.ts +29 -0
- package/esm/typings/src/llm-providers/_common/utils/cache/CacheLlmToolsOptions.d.ts +10 -0
- package/esm/typings/src/llm-providers/_common/utils/cache/cacheLlmTools.d.ts +16 -0
- package/esm/typings/src/llm-providers/_common/utils/count-total-cost/LlmExecutionToolsWithTotalCost.d.ts +11 -0
- package/esm/typings/src/llm-providers/_common/utils/count-total-cost/countTotalCost.d.ts +14 -0
- package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +1 -0
- package/esm/typings/src/llm-providers/anthropic-claude/anthropic-claude-models.d.ts +1 -1
- package/esm/typings/src/llm-providers/anthropic-claude/playground/playground.d.ts +3 -0
- package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.d.ts +1 -0
- package/esm/typings/src/llm-providers/azure-openai/playground/playground.d.ts +3 -0
- package/esm/typings/src/llm-providers/langtail/LangtailExecutionTools.d.ts +3 -0
- package/esm/typings/src/llm-providers/langtail/LangtailExecutionToolsOptions.d.ts +1 -1
- package/esm/typings/src/llm-providers/mocked/MockedEchoLlmExecutionTools.d.ts +1 -1
- package/esm/typings/src/llm-providers/mocked/MockedFackedLlmExecutionTools.d.ts +1 -1
- package/esm/typings/src/llm-providers/multiple/MultipleLlmExecutionTools.d.ts +3 -1
- package/esm/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +1 -0
- package/esm/typings/src/llm-providers/openai/computeUsage.d.ts +2 -2
- package/esm/typings/src/llm-providers/openai/openai-models.d.ts +1 -0
- package/esm/typings/src/llm-providers/openai/playground/playground.d.ts +3 -0
- package/esm/typings/src/personas/preparePersona.d.ts +4 -2
- package/esm/typings/src/prepare/preparePipeline.d.ts +3 -1
- package/esm/typings/src/prepare/unpreparePipeline.d.ts +1 -0
- package/esm/typings/src/storage/_common/PromptbookStorage.d.ts +25 -0
- package/esm/typings/src/storage/_common/PromptbookStorage.test-type.d.ts +5 -0
- package/esm/typings/src/storage/files-storage/FilesStorage.d.ts +30 -0
- package/esm/typings/src/storage/files-storage/FilesStorageOptions.d.ts +13 -0
- package/esm/typings/src/storage/files-storage/utils/nameToSubfolderPath.d.ts +7 -0
- package/esm/typings/src/storage/files-storage/utils/nameToSubfolderPath.test.d.ts +1 -0
- package/esm/typings/src/storage/local-storage/getLocalStorage.d.ts +9 -0
- package/esm/typings/src/storage/local-storage/getSessionStorage.d.ts +9 -0
- package/esm/typings/src/storage/memory/MemoryStorage.d.ts +34 -0
- package/esm/typings/src/storage/utils/PrefixStorage.d.ts +26 -0
- package/esm/typings/src/storage/utils/makePromptbookStorageFromWebStorage.d.ts +11 -0
- package/esm/typings/src/types/ModelRequirements.d.ts +21 -1
- package/esm/typings/src/types/Parameters.d.ts +0 -1
- package/esm/typings/src/types/PipelineJson/PipelineJson.d.ts +1 -2
- package/esm/typings/src/types/PipelineJson/PreparationJson.d.ts +1 -5
- package/esm/typings/src/types/PipelineJson/PromptTemplateJsonCommon.d.ts +1 -0
- package/esm/typings/src/types/PipelineJson/PromptTemplateParameterJson.d.ts +11 -2
- package/esm/typings/src/types/PipelineString.d.ts +1 -1
- package/esm/typings/src/types/Prompt.d.ts +5 -2
- package/esm/typings/src/types/execution-report/countWorkingDuration.d.ts +1 -1
- package/esm/typings/src/types/typeAliases.d.ts +35 -1
- package/esm/typings/src/utils/emojis.d.ts +2 -2
- package/esm/typings/src/utils/formatNumber.d.ts +1 -1
- package/esm/typings/src/utils/isRunningInWhatever.d.ts +3 -0
- package/esm/typings/src/utils/markdown/addAutoGeneratedSection.d.ts +1 -1
- package/esm/typings/src/utils/markdown/createMarkdownChart.d.ts +1 -1
- package/esm/typings/src/utils/markdown/createMarkdownTable.d.ts +1 -1
- package/esm/typings/src/utils/markdown/extractAllBlocksFromMarkdown-real.test.d.ts +1 -0
- package/esm/typings/src/utils/markdown/extractAllBlocksFromMarkdown.d.ts +7 -0
- package/esm/typings/src/utils/markdown/extractOneBlockFromMarkdown.d.ts +1 -1
- package/esm/typings/src/utils/organization/TODO.d.ts +2 -0
- package/esm/typings/src/utils/organization/TODO_USE.d.ts +1 -0
- package/esm/typings/src/utils/organization/___.d.ts +2 -0
- package/esm/typings/src/utils/organization/just.d.ts +1 -0
- package/esm/typings/src/utils/organization/keepImported.d.ts +12 -0
- package/esm/typings/src/utils/organization/notUsing.d.ts +12 -0
- package/esm/typings/src/utils/organization/really_any.d.ts +2 -0
- package/esm/typings/src/utils/random/randomSeed.d.ts +7 -0
- package/esm/typings/src/version.d.ts +3 -0
- package/package.json +2 -2
- package/umd/index.umd.js +368 -224
- package/umd/index.umd.js.map +1 -1
- package/umd/typings/promptbook-collection/index.d.ts +83 -2
- package/umd/typings/src/_packages/core.index.d.ts +2 -2
- package/umd/typings/src/_packages/types.index.d.ts +2 -2
- package/umd/typings/src/_packages/utils.index.d.ts +3 -1
- package/umd/typings/src/cli/cli-commands/hello.d.ts +3 -0
- package/umd/typings/src/cli/cli-commands/make.d.ts +3 -0
- package/umd/typings/src/cli/cli-commands/prettify.d.ts +3 -0
- package/umd/typings/src/cli/promptbookCli.d.ts +1 -0
- package/umd/typings/src/collection/PipelineCollection.d.ts +1 -1
- package/umd/typings/src/collection/SimplePipelineCollection.d.ts +1 -1
- package/umd/typings/src/collection/constructors/createCollectionFromDirectory.d.ts +1 -0
- package/umd/typings/src/commands/_BOILERPLATE/boilerplateCommandParser.d.ts +1 -0
- package/umd/typings/src/commands/_common/types/CommandParser.d.ts +4 -1
- package/umd/typings/src/config.d.ts +4 -0
- package/umd/typings/src/conversion/pipelineJsonToString.d.ts +1 -1
- package/umd/typings/src/conversion/pipelineStringToJson.d.ts +1 -0
- package/umd/typings/src/conversion/pipelineStringToJsonSync.d.ts +2 -0
- package/umd/typings/src/conversion/validation/validatePipeline.d.ts +6 -0
- package/umd/typings/src/errors/EnvironmentMismatchError.d.ts +7 -0
- package/{esm/typings/src/errors/VersionMismatch.d.ts → umd/typings/src/errors/VersionMismatchError.d.ts} +1 -1
- package/umd/typings/src/execution/CommonExecutionToolsOptions.d.ts +1 -0
- package/umd/typings/src/execution/LlmExecutionTools.d.ts +3 -1
- package/umd/typings/src/execution/PipelineExecutor.d.ts +4 -3
- package/umd/typings/src/execution/PromptResult.d.ts +12 -0
- package/umd/typings/src/execution/ScriptExecutionTools.d.ts +4 -2
- package/umd/typings/src/execution/createPipelineExecutor.d.ts +2 -0
- package/umd/typings/src/formats/csv/ListFormatDefinition.d.ts +1 -0
- package/umd/typings/src/formats/json/JsonFormatDefinition.d.ts +1 -0
- package/umd/typings/src/formats/list/ListFormatDefinition.d.ts +1 -0
- package/umd/typings/src/formats/xml/XmlFormatDefinition.d.ts +1 -0
- package/umd/typings/src/knowledge/dialogs/simple-prompt/SimplePromptInterfaceTools.d.ts +3 -0
- package/umd/typings/src/knowledge/prepare-knowledge/_common/prepareKnowledgePieces.d.ts +1 -1
- package/umd/typings/src/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.d.ts +1 -0
- package/umd/typings/src/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.test.d.ts +3 -0
- package/umd/typings/src/knowledge/prepare-knowledge/pdf/prepareKnowledgeFromPdf.d.ts +1 -0
- package/umd/typings/src/llm-providers/_common/createLlmToolsFromEnv.d.ts +22 -0
- package/umd/typings/src/llm-providers/_common/getLlmToolsForCli.d.ts +10 -0
- package/umd/typings/src/llm-providers/_common/getLlmToolsForTestingAndScriptsAndPlayground.d.ts +10 -0
- package/umd/typings/src/llm-providers/_common/utils/cache/CacheItem.d.ts +29 -0
- package/umd/typings/src/llm-providers/_common/utils/cache/CacheLlmToolsOptions.d.ts +10 -0
- package/umd/typings/src/llm-providers/_common/utils/cache/cacheLlmTools.d.ts +16 -0
- package/umd/typings/src/llm-providers/_common/utils/count-total-cost/LlmExecutionToolsWithTotalCost.d.ts +11 -0
- package/umd/typings/src/llm-providers/_common/utils/count-total-cost/countTotalCost.d.ts +14 -0
- package/umd/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +1 -0
- package/umd/typings/src/llm-providers/anthropic-claude/anthropic-claude-models.d.ts +1 -1
- package/umd/typings/src/llm-providers/anthropic-claude/playground/playground.d.ts +3 -0
- package/umd/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.d.ts +1 -0
- package/umd/typings/src/llm-providers/azure-openai/playground/playground.d.ts +3 -0
- package/umd/typings/src/llm-providers/langtail/LangtailExecutionTools.d.ts +3 -0
- package/umd/typings/src/llm-providers/langtail/LangtailExecutionToolsOptions.d.ts +1 -1
- package/umd/typings/src/llm-providers/mocked/MockedEchoLlmExecutionTools.d.ts +1 -1
- package/umd/typings/src/llm-providers/mocked/MockedFackedLlmExecutionTools.d.ts +1 -1
- package/umd/typings/src/llm-providers/multiple/MultipleLlmExecutionTools.d.ts +3 -1
- package/umd/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +1 -0
- package/umd/typings/src/llm-providers/openai/computeUsage.d.ts +2 -2
- package/umd/typings/src/llm-providers/openai/openai-models.d.ts +1 -0
- package/umd/typings/src/llm-providers/openai/playground/playground.d.ts +3 -0
- package/umd/typings/src/personas/preparePersona.d.ts +4 -2
- package/umd/typings/src/prepare/preparePipeline.d.ts +3 -1
- package/umd/typings/src/prepare/unpreparePipeline.d.ts +1 -0
- package/umd/typings/src/storage/_common/PromptbookStorage.d.ts +25 -0
- package/umd/typings/src/storage/_common/PromptbookStorage.test-type.d.ts +5 -0
- package/umd/typings/src/storage/files-storage/FilesStorage.d.ts +30 -0
- package/umd/typings/src/storage/files-storage/FilesStorageOptions.d.ts +13 -0
- package/umd/typings/src/storage/files-storage/utils/nameToSubfolderPath.d.ts +7 -0
- package/umd/typings/src/storage/files-storage/utils/nameToSubfolderPath.test.d.ts +1 -0
- package/umd/typings/src/storage/local-storage/getLocalStorage.d.ts +9 -0
- package/umd/typings/src/storage/local-storage/getSessionStorage.d.ts +9 -0
- package/umd/typings/src/storage/memory/MemoryStorage.d.ts +34 -0
- package/umd/typings/src/storage/utils/PrefixStorage.d.ts +26 -0
- package/umd/typings/src/storage/utils/makePromptbookStorageFromWebStorage.d.ts +11 -0
- package/umd/typings/src/types/ModelRequirements.d.ts +21 -1
- package/umd/typings/src/types/Parameters.d.ts +0 -1
- package/umd/typings/src/types/PipelineJson/PipelineJson.d.ts +1 -2
- package/umd/typings/src/types/PipelineJson/PreparationJson.d.ts +1 -5
- package/umd/typings/src/types/PipelineJson/PromptTemplateJsonCommon.d.ts +1 -0
- package/umd/typings/src/types/PipelineJson/PromptTemplateParameterJson.d.ts +11 -2
- package/umd/typings/src/types/PipelineString.d.ts +1 -1
- package/umd/typings/src/types/Prompt.d.ts +5 -2
- package/umd/typings/src/types/execution-report/countWorkingDuration.d.ts +1 -1
- package/umd/typings/src/types/typeAliases.d.ts +35 -1
- package/umd/typings/src/utils/emojis.d.ts +2 -2
- package/umd/typings/src/utils/formatNumber.d.ts +1 -1
- package/umd/typings/src/utils/isRunningInWhatever.d.ts +3 -0
- package/umd/typings/src/utils/markdown/addAutoGeneratedSection.d.ts +1 -1
- package/umd/typings/src/utils/markdown/createMarkdownChart.d.ts +1 -1
- package/umd/typings/src/utils/markdown/createMarkdownTable.d.ts +1 -1
- package/umd/typings/src/utils/markdown/extractAllBlocksFromMarkdown-real.test.d.ts +1 -0
- package/umd/typings/src/utils/markdown/extractAllBlocksFromMarkdown.d.ts +7 -0
- package/umd/typings/src/utils/markdown/extractOneBlockFromMarkdown.d.ts +1 -1
- package/umd/typings/src/utils/organization/TODO.d.ts +2 -0
- package/umd/typings/src/utils/organization/TODO_USE.d.ts +1 -0
- package/umd/typings/src/utils/organization/___.d.ts +2 -0
- package/umd/typings/src/utils/organization/just.d.ts +1 -0
- package/umd/typings/src/utils/organization/keepImported.d.ts +12 -0
- package/umd/typings/src/utils/organization/notUsing.d.ts +12 -0
- package/umd/typings/src/utils/organization/really_any.d.ts +2 -0
- package/umd/typings/src/utils/random/randomSeed.d.ts +7 -0
- package/umd/typings/src/version.d.ts +3 -0
- package/esm/typings/src/collection/constructors/justTestFsImport.d.ts +0 -7
- package/esm/typings/src/knowledge/prepare-knowledge/_common/utils/getLlmToolsForTests.d.ts +0 -7
- package/umd/typings/src/collection/constructors/justTestFsImport.d.ts +0 -7
- package/umd/typings/src/knowledge/prepare-knowledge/_common/utils/getLlmToolsForTests.d.ts +0 -7
package/esm/index.es.js
CHANGED
|
@@ -144,6 +144,10 @@ var RESERVED_PARAMETER_NAMES = [
|
|
|
144
144
|
// <- TODO: Add more like 'date', 'modelName',...
|
|
145
145
|
// <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
|
|
146
146
|
];
|
|
147
|
+
/*
|
|
148
|
+
TODO: !!! Just testing false-negative detection of [🟡][🟢][🔵][⚪] leak
|
|
149
|
+
*/
|
|
150
|
+
// [🟡][🟢][🔵][⚪]
|
|
147
151
|
|
|
148
152
|
/**
|
|
149
153
|
* Function `addUsage` will add multiple usages into one
|
|
@@ -310,7 +314,7 @@ function forEachAsync(array, options, callbackfunction) {
|
|
|
310
314
|
});
|
|
311
315
|
}
|
|
312
316
|
|
|
313
|
-
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.61.0-
|
|
317
|
+
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.61.0-11",parameters:[{name:"content",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledge",description:"The knowledge JSON object",isInput:false,isOutput:true}],promptTemplates:[{name:"knowledge",title:"Knowledge",dependentParameterNames:["content"],blockType:"PROMPT_TEMPLATE",personaName:null,modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},content:"You are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {content}",resultingParameterName:"knowledge"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-11",modelUsage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-knowledge-from-markdown.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.ptbk.md",promptbookVersion:"0.61.0-11",parameters:[{name:"content",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],promptTemplates:[{name:"knowledge",title:"Knowledge",dependentParameterNames:["content"],blockType:"PROMPT_TEMPLATE",personaName:null,modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},content:"You are experienced data researcher, detect the important keywords in the document.\n\n# Rules\n\n- Write just keywords separated by comma\n\n# The document\n\nTake information from this document:\n\n> {content}",resultingParameterName:"keywords"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-11",modelUsage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-knowledge-keywords.ptbk.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.ptbk.md",promptbookVersion:"0.61.0-11",parameters:[{name:"content",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],promptTemplates:[{name:"knowledge",title:"Knowledge",dependentParameterNames:["content"],blockType:"PROMPT_TEMPLATE",expectations:{words:{min:1,max:8}},personaName:null,modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},content:"You are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Title should be concise and clear\n- Write maximum 5 words for the title\n\n# The document\n\n> {content}",resultingParameterName:"title"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-11",modelUsage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-knowledge-title.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.ptbk.md",promptbookVersion:"0.61.0-11",parameters:[{name:"availableModelNames",description:"List of available model names separated by comma (,)",isInput:true,isOutput:false},{name:"personaDescription",description:"Description of the persona",isInput:true,isOutput:false},{name:"modelRequirements",description:"Specific requirements for the model",isInput:false,isOutput:true}],promptTemplates:[{name:"make-model-requirements",title:"Make modelRequirements",dependentParameterNames:["availableModelNames","personaDescription"],blockType:"PROMPT_TEMPLATE",expectFormat:"JSON",personaName:null,modelRequirements:{modelVariant:"CHAT",modelName:"gpt-4-turbo"},content:"You are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Sample\n\n```json\n{\n\"modelName\": \"gpt-4o\",\n\"systemMessage\": \"You are experienced AI engineer and helpfull assistant.\",\n\"temperature\": 0.7\n}\n```\n\n## Instructions\n\n### Option `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Option `systemMessage`\n\nThe system message is used to communicate instructions or provide context to the model at the beginning of a conversation. It is displayed in a different format compared to user messages, helping the model understand its role in the conversation. The system message typically guides the model's behavior, sets the tone, or specifies desired output from the model. By utilizing the system message effectively, users can steer the model towards generating more accurate and relevant responses.\n\nFor example:\n\n> You are an experienced AI engineer and helpful assistant.\n\n> You are a friendly and knowledgeable chatbot.\n\n### Option `temperature`\n\nThe sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit.\n\nYou can pick a value between 0 and 2. For example:\n\n- `0.1`: Low temperature, extremely conservative and deterministic\n- `0.5`: Medium temperature, balanced between conservative and creative\n- `1.0`: High temperature, creative and bit random\n- `1.5`: Very high temperature, extremely creative and often chaotic and unpredictable\n- `2.0`: Maximum temperature, completely random and unpredictable, for some extreme creative use cases\n\n# The assistant\n\nTake this description of the persona:\n\n> {personaDescription}",resultingParameterName:"modelRequirements"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-11",modelUsage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-persona.ptbk.md"}];
|
|
314
318
|
|
|
315
319
|
/**
|
|
316
320
|
* Prettify the html code
|
|
@@ -550,7 +554,7 @@ function promptTemplateParameterJsonToString(promptTemplateParameterJson) {
|
|
|
550
554
|
return parameterString;
|
|
551
555
|
}
|
|
552
556
|
/**
|
|
553
|
-
* TODO:
|
|
557
|
+
* TODO: !!!! Implement new features and commands into `promptTemplateParameterJsonToString`
|
|
554
558
|
* TODO: [🧠] Is there a way to auto-detect missing features in pipelineJsonToString
|
|
555
559
|
* TODO: Escape all
|
|
556
560
|
*/
|
|
@@ -927,6 +931,12 @@ function validatePipeline(pipeline) {
|
|
|
927
931
|
* > * - ...
|
|
928
932
|
* > ex port function validatePipeline(promptbook: unknown): asserts promptbook is PipelineJson {
|
|
929
933
|
*/
|
|
934
|
+
/**
|
|
935
|
+
* TODO: [🧠][🐣] !!!! Validate that all samples match expectations
|
|
936
|
+
* TODO: [🧠][🐣] !!!! Validate that knowledge is valid (non-void)
|
|
937
|
+
* TODO: [🧠] !!! Validationg not only logic itself but imports around - files and websites and rerefenced pipelines exists
|
|
938
|
+
* TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
939
|
+
*/
|
|
930
940
|
|
|
931
941
|
/**
|
|
932
942
|
* This error indicates that promptbook not found in the collection
|
|
@@ -967,7 +977,7 @@ var SimplePipelineCollection = /** @class */ (function () {
|
|
|
967
977
|
/**
|
|
968
978
|
* Constructs a pipeline collection from promptbooks
|
|
969
979
|
*
|
|
970
|
-
* @param promptbooks
|
|
980
|
+
* @param promptbooks @@@
|
|
971
981
|
*
|
|
972
982
|
* @private Use instead `createCollectionFromJson`
|
|
973
983
|
* Note: During the construction logic of all promptbooks are validated
|
|
@@ -1608,7 +1618,7 @@ var MultipleLlmExecutionTools = /** @class */ (function () {
|
|
|
1608
1618
|
};
|
|
1609
1619
|
/**
|
|
1610
1620
|
* List all available models that can be used
|
|
1611
|
-
* This
|
|
1621
|
+
* This lists is a combination of all available models from all execution tools
|
|
1612
1622
|
*/
|
|
1613
1623
|
MultipleLlmExecutionTools.prototype.listModels = function () {
|
|
1614
1624
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -1654,6 +1664,8 @@ var MultipleLlmExecutionTools = /** @class */ (function () {
|
|
|
1654
1664
|
}());
|
|
1655
1665
|
/**
|
|
1656
1666
|
* TODO: [🧠][🎛] Aggregating multiple models - have result not only from one first aviable model BUT all of them
|
|
1667
|
+
* TODO: [🏖] If no llmTools have for example not defined `callCompletionModel` this will still return object with defined `callCompletionModel` which just throws `PipelineExecutionError`, make it undefined instead
|
|
1668
|
+
* Look how `countTotalUsage` (and `cacheLlmTools`) implements it
|
|
1657
1669
|
*/
|
|
1658
1670
|
|
|
1659
1671
|
/**
|
|
@@ -1724,8 +1736,11 @@ function arrayableToArray(input) {
|
|
|
1724
1736
|
/**
|
|
1725
1737
|
* The version of the Promptbook library
|
|
1726
1738
|
*/
|
|
1727
|
-
var PROMPTBOOK_VERSION = '0.61.0-
|
|
1739
|
+
var PROMPTBOOK_VERSION = '0.61.0-11';
|
|
1728
1740
|
// TODO: !!!! List here all the versions and annotate + put into script
|
|
1741
|
+
/**
|
|
1742
|
+
* TODO: [🔼] !!! Export via `@promptbook/code`
|
|
1743
|
+
*/
|
|
1729
1744
|
|
|
1730
1745
|
/**
|
|
1731
1746
|
* Counts number of characters in the text
|
|
@@ -1907,7 +1922,6 @@ function createPipelineExecutor(options) {
|
|
|
1907
1922
|
var _this = this;
|
|
1908
1923
|
var pipeline = options.pipeline, tools = options.tools, _a = options.settings, settings = _a === void 0 ? {} : _a;
|
|
1909
1924
|
var _b = settings.maxExecutionAttempts, maxExecutionAttempts = _b === void 0 ? 3 : _b;
|
|
1910
|
-
// TODO: !!!!! Implement new commands
|
|
1911
1925
|
validatePipeline(pipeline);
|
|
1912
1926
|
var llmTools = joinLlmExecutionTools.apply(void 0, __spreadArray([], __read(arrayableToArray(tools.llm)), false));
|
|
1913
1927
|
var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
|
|
@@ -1983,7 +1997,10 @@ function createPipelineExecutor(options) {
|
|
|
1983
1997
|
: 'anonymous' /* <- TODO: [🧠] How to deal with anonymous pipelines, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(currentTemplate.name),
|
|
1984
1998
|
parameters: parametersToPass,
|
|
1985
1999
|
content: replaceParameters(currentTemplate.content, parametersToPass) /* <- [2] */,
|
|
2000
|
+
// <- TODO: !!!!! Apply {context} and knowledges
|
|
2001
|
+
// <- TODO: !!!!! Apply samples
|
|
1986
2002
|
modelRequirements: currentTemplate.modelRequirements,
|
|
2003
|
+
// <- TODO: !!!!! Apply persona
|
|
1987
2004
|
expectations: currentTemplate.expectations,
|
|
1988
2005
|
expectFormat: currentTemplate.expectFormat,
|
|
1989
2006
|
postprocessing: (currentTemplate.postprocessing || []).map(function (functionName) { return function (result) { return __awaiter(_this, void 0, void 0, function () {
|
|
@@ -2430,10 +2447,12 @@ function createPipelineExecutor(options) {
|
|
|
2430
2447
|
}
|
|
2431
2448
|
/**
|
|
2432
2449
|
* TODO: [🪂] Pass maxParallelCount here
|
|
2450
|
+
* TODO: [♈] Probbably move expectations from templates to parameters
|
|
2433
2451
|
* TODO: [🧠] When not meet expectations in PROMPT_DIALOG, make some way to tell the user
|
|
2434
2452
|
* TODO: [👧] Strongly type the executors to avoid need of remove nullables whtn noUncheckedIndexedAccess in tsconfig.json
|
|
2435
2453
|
* Note: CreatePipelineExecutorOptions are just connected to PipelineExecutor so do not extract to types folder
|
|
2436
2454
|
* TODO: [🧠][3] transparent = (report intermediate parameters) / opaque execution = (report only output parameters) progress reporting mode
|
|
2455
|
+
* TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
2437
2456
|
*/
|
|
2438
2457
|
|
|
2439
2458
|
/**
|
|
@@ -2444,6 +2463,7 @@ function createPipelineExecutor(options) {
|
|
|
2444
2463
|
*
|
|
2445
2464
|
* @param value any values
|
|
2446
2465
|
* @returns void
|
|
2466
|
+
* @private within the repository
|
|
2447
2467
|
*/
|
|
2448
2468
|
function TODO_USE() {
|
|
2449
2469
|
var value = [];
|
|
@@ -2451,7 +2471,6 @@ function TODO_USE() {
|
|
|
2451
2471
|
value[_i] = arguments[_i];
|
|
2452
2472
|
}
|
|
2453
2473
|
}
|
|
2454
|
-
// TODO: !!!! Find ACRY all just(...) and replace with TODO_USE
|
|
2455
2474
|
|
|
2456
2475
|
/**
|
|
2457
2476
|
* @@@
|
|
@@ -2580,6 +2599,7 @@ function prepareKnowledgeFromMarkdown(content /* <- TODO: [🖖] (?maybe not) Al
|
|
|
2580
2599
|
});
|
|
2581
2600
|
}
|
|
2582
2601
|
/**
|
|
2602
|
+
* TODO: [🔼] !!! Export via `@promptbook/markdown`
|
|
2583
2603
|
* TODO: [🪂] Do it in parallel 11:11
|
|
2584
2604
|
* Note: No need to aggregate usage here, it is done by intercepting the llmTools
|
|
2585
2605
|
*/
|
|
@@ -2588,7 +2608,6 @@ function prepareKnowledgeFromMarkdown(content /* <- TODO: [🖖] (?maybe not) Al
|
|
|
2588
2608
|
* Prepares the knowle
|
|
2589
2609
|
*
|
|
2590
2610
|
* @see https://github.com/webgptorg/promptbook/discussions/41
|
|
2591
|
-
* @private within the package
|
|
2592
2611
|
*/
|
|
2593
2612
|
function prepareKnowledgePieces(knowledgeSources, options) {
|
|
2594
2613
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -2603,7 +2622,7 @@ function prepareKnowledgePieces(knowledgeSources, options) {
|
|
|
2603
2622
|
var partialPieces, pieces;
|
|
2604
2623
|
return __generator(this, function (_a) {
|
|
2605
2624
|
switch (_a.label) {
|
|
2606
|
-
case 0: return [4 /*yield*/, prepareKnowledgeFromMarkdown(knowledgeSource.source, // <- TODO: !!!!! Unhardcode markdown, detect which type it is
|
|
2625
|
+
case 0: return [4 /*yield*/, prepareKnowledgeFromMarkdown(knowledgeSource.source, // <- TODO: [🐝] !!!!! Unhardcode markdown, detect which type it is
|
|
2607
2626
|
options)];
|
|
2608
2627
|
case 1:
|
|
2609
2628
|
partialPieces = _a.sent();
|
|
@@ -2641,6 +2660,7 @@ TODO: [🧊] This is how it can look in future
|
|
|
2641
2660
|
> ):
|
|
2642
2661
|
*/
|
|
2643
2662
|
/**
|
|
2663
|
+
* TODO: [🔼] !!! Export via `@promptbook/core`
|
|
2644
2664
|
* TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
|
|
2645
2665
|
* Put `knowledgePieces` into `PrepareKnowledgeOptions`
|
|
2646
2666
|
* TODO: [🪂] More than max things can run in parallel by acident [1,[2a,2b,_],[3a,3b,_]]
|
|
@@ -2653,37 +2673,66 @@ TODO: [🧊] This is how it can look in future
|
|
|
2653
2673
|
* Prepares the persona for the pipeline
|
|
2654
2674
|
*
|
|
2655
2675
|
* @see https://github.com/webgptorg/promptbook/discussions/22
|
|
2656
|
-
* @private within the package
|
|
2657
2676
|
*/
|
|
2658
2677
|
function preparePersona(personaDescription, options) {
|
|
2659
2678
|
return __awaiter(this, void 0, void 0, function () {
|
|
2660
|
-
var llmTools, _a,
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
|
|
2679
|
+
var llmTools, _a, isVerbose, collection, preparePersonaExecutor, _b, availableModels, availableModelNames, result, outputParameters, modelRequirementsRaw, modelRequirements, modelName, systemMessage, temperature;
|
|
2680
|
+
var _c;
|
|
2681
|
+
return __generator(this, function (_d) {
|
|
2682
|
+
switch (_d.label) {
|
|
2683
|
+
case 0:
|
|
2684
|
+
llmTools = options.llmTools, _a = options.isVerbose, isVerbose = _a === void 0 ? false : _a;
|
|
2685
|
+
collection = createCollectionFromJson.apply(void 0, __spreadArray([], __read(PipelineCollection), false));
|
|
2686
|
+
_b = createPipelineExecutor;
|
|
2687
|
+
_c = {};
|
|
2688
|
+
return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-persona.ptbk.md')];
|
|
2689
|
+
case 1:
|
|
2690
|
+
preparePersonaExecutor = _b.apply(void 0, [(_c.pipeline = _d.sent(),
|
|
2691
|
+
_c.tools = {
|
|
2692
|
+
llm: llmTools,
|
|
2693
|
+
},
|
|
2694
|
+
_c)]);
|
|
2695
|
+
return [4 /*yield*/, llmTools.listModels()];
|
|
2696
|
+
case 2:
|
|
2697
|
+
availableModels = _d.sent();
|
|
2698
|
+
availableModelNames = availableModels
|
|
2699
|
+
.filter(function (_a) {
|
|
2700
|
+
var modelVariant = _a.modelVariant;
|
|
2701
|
+
return modelVariant === 'CHAT';
|
|
2702
|
+
})
|
|
2703
|
+
.map(function (_a) {
|
|
2704
|
+
var modelName = _a.modelName;
|
|
2705
|
+
return modelName;
|
|
2706
|
+
})
|
|
2707
|
+
.join(',');
|
|
2708
|
+
return [4 /*yield*/, preparePersonaExecutor({ availableModelNames: availableModelNames, personaDescription: personaDescription })];
|
|
2709
|
+
case 3:
|
|
2710
|
+
result = _d.sent();
|
|
2711
|
+
assertsExecutionSuccessful(result);
|
|
2712
|
+
outputParameters = result.outputParameters;
|
|
2713
|
+
modelRequirementsRaw = outputParameters.modelRequirements;
|
|
2714
|
+
modelRequirements = JSON.parse(modelRequirementsRaw);
|
|
2715
|
+
if (isVerbose) {
|
|
2716
|
+
console.info("PERSONA ".concat(personaDescription), modelRequirements);
|
|
2717
|
+
}
|
|
2718
|
+
modelName = modelRequirements.modelName, systemMessage = modelRequirements.systemMessage, temperature = modelRequirements.temperature;
|
|
2719
|
+
return [2 /*return*/, {
|
|
2720
|
+
modelVariant: 'CHAT',
|
|
2721
|
+
modelName: modelName,
|
|
2722
|
+
systemMessage: systemMessage,
|
|
2723
|
+
temperature: temperature,
|
|
2724
|
+
}];
|
|
2725
|
+
}
|
|
2671
2726
|
});
|
|
2672
2727
|
});
|
|
2673
2728
|
}
|
|
2674
2729
|
/**
|
|
2675
|
-
* TODO: [
|
|
2730
|
+
* TODO: [🔼] !!! Export via `@promptbook/core`
|
|
2731
|
+
* TODO: [🏢] !! Check validity of `modelName` in pipeline
|
|
2732
|
+
* TODO: [🏢] !! Check validity of `systemMessage` in pipeline
|
|
2733
|
+
* TODO: [🏢] !! Check validity of `temperature` in pipeline
|
|
2676
2734
|
*/
|
|
2677
2735
|
|
|
2678
|
-
/**
|
|
2679
|
-
* Simple wrapper `new Date().toISOString()`
|
|
2680
|
-
*
|
|
2681
|
-
* @returns string_date branded type
|
|
2682
|
-
*/
|
|
2683
|
-
function $currentDate() {
|
|
2684
|
-
return new Date().toISOString();
|
|
2685
|
-
}
|
|
2686
|
-
|
|
2687
2736
|
/**
|
|
2688
2737
|
* Prepare pipeline from string (markdown) format to JSON format
|
|
2689
2738
|
*
|
|
@@ -2706,7 +2755,7 @@ function preparePipeline(pipeline, options) {
|
|
|
2706
2755
|
knowledgeSources = pipeline.knowledgeSources, personas = pipeline.personas;
|
|
2707
2756
|
currentPreparation = {
|
|
2708
2757
|
id: 1,
|
|
2709
|
-
date: $currentDate(),
|
|
2758
|
+
// TODO: [🍥]> date: $currentDate(),
|
|
2710
2759
|
promptbookVersion: PROMPTBOOK_VERSION,
|
|
2711
2760
|
modelUsage: addUsage(),
|
|
2712
2761
|
};
|
|
@@ -2715,8 +2764,8 @@ function preparePipeline(pipeline, options) {
|
|
|
2715
2764
|
// <- TODO: [🧊]
|
|
2716
2765
|
currentPreparation,
|
|
2717
2766
|
];
|
|
2718
|
-
preparedPersonas =
|
|
2719
|
-
return [4 /*yield*/, forEachAsync(personas, { maxParallelCount: maxParallelCount /* <- TODO: [🪂] When there are subtasks, this maximul limit can be broken */ }, function (persona) { return __awaiter(_this, void 0, void 0, function () {
|
|
2767
|
+
preparedPersonas = new Array(personas.length);
|
|
2768
|
+
return [4 /*yield*/, forEachAsync(personas, { maxParallelCount: maxParallelCount /* <- TODO: [🪂] When there are subtasks, this maximul limit can be broken */ }, function (persona, index) { return __awaiter(_this, void 0, void 0, function () {
|
|
2720
2769
|
var modelRequirements, preparedPersona;
|
|
2721
2770
|
return __generator(this, function (_a) {
|
|
2722
2771
|
switch (_a.label) {
|
|
@@ -2724,7 +2773,7 @@ function preparePipeline(pipeline, options) {
|
|
|
2724
2773
|
case 1:
|
|
2725
2774
|
modelRequirements = _a.sent();
|
|
2726
2775
|
preparedPersona = __assign(__assign({}, persona), { modelRequirements: modelRequirements, preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] });
|
|
2727
|
-
preparedPersonas
|
|
2776
|
+
preparedPersonas[index] = preparedPersona;
|
|
2728
2777
|
return [2 /*return*/];
|
|
2729
2778
|
}
|
|
2730
2779
|
});
|
|
@@ -2743,12 +2792,187 @@ function preparePipeline(pipeline, options) {
|
|
|
2743
2792
|
});
|
|
2744
2793
|
}
|
|
2745
2794
|
/**
|
|
2795
|
+
* TODO: [🔼] !!! Export via `@promptbook/core`
|
|
2746
2796
|
* TODO: Write tests for `preparePipeline`
|
|
2747
2797
|
* TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
|
|
2748
2798
|
* TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
|
|
2749
|
-
* TODO: [
|
|
2799
|
+
* TODO: [🎐] !!!! Use here countTotalUsage
|
|
2800
|
+
* TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
2750
2801
|
*/
|
|
2751
2802
|
|
|
2803
|
+
/**
|
|
2804
|
+
* Tests if given string is valid URL.
|
|
2805
|
+
*
|
|
2806
|
+
* Note: This does not check if the file exists only if the path is valid
|
|
2807
|
+
*/
|
|
2808
|
+
function isValidFilePath(filePath) {
|
|
2809
|
+
if (typeof filePath !== 'string') {
|
|
2810
|
+
return false;
|
|
2811
|
+
}
|
|
2812
|
+
var filePathSlashes = filePath.split('\\').join('/');
|
|
2813
|
+
// Absolute Unix path: /hello.txt
|
|
2814
|
+
if (/^(\/)/i.test(filePathSlashes)) {
|
|
2815
|
+
return true;
|
|
2816
|
+
}
|
|
2817
|
+
// Absolute Windows path: /hello.txt
|
|
2818
|
+
if (/^([A-Z]{1,2}:\/?)\//i.test(filePathSlashes)) {
|
|
2819
|
+
return true;
|
|
2820
|
+
}
|
|
2821
|
+
// Relative path: ./hello.txt
|
|
2822
|
+
if (/^(\.\.?\/)+/i.test(filePathSlashes)) {
|
|
2823
|
+
return true;
|
|
2824
|
+
}
|
|
2825
|
+
return false;
|
|
2826
|
+
}
|
|
2827
|
+
|
|
2828
|
+
/**
|
|
2829
|
+
* Parses the knowledge command
|
|
2830
|
+
*
|
|
2831
|
+
* @see ./KNOWLEDGE-README.md for more details
|
|
2832
|
+
* @private within the commands folder
|
|
2833
|
+
*/
|
|
2834
|
+
var knowledgeCommandParser = {
|
|
2835
|
+
/**
|
|
2836
|
+
* Name of the command
|
|
2837
|
+
*/
|
|
2838
|
+
name: 'KNOWLEDGE',
|
|
2839
|
+
/**
|
|
2840
|
+
* BOILERPLATE command can be used in:
|
|
2841
|
+
*/
|
|
2842
|
+
usagePlaces: ['PIPELINE_HEAD'],
|
|
2843
|
+
/**
|
|
2844
|
+
* Description of the KNOWLEDGE command
|
|
2845
|
+
*/
|
|
2846
|
+
description: "Tells promptbook which external knowledge to use",
|
|
2847
|
+
/**
|
|
2848
|
+
* Link to discussion
|
|
2849
|
+
*/
|
|
2850
|
+
discussionUrl: 'https://github.com/webgptorg/promptbook/discussions/41',
|
|
2851
|
+
/**
|
|
2852
|
+
* Example usages of the KNOWLEDGE command
|
|
2853
|
+
*/
|
|
2854
|
+
examples: [
|
|
2855
|
+
'KNOWLEDGE https://www.pavolhejny.com/',
|
|
2856
|
+
'KNOWLEDGE ./hejny-cv.txt',
|
|
2857
|
+
'KNOWLEDGE ./hejny-cv.md',
|
|
2858
|
+
'KNOWLEDGE ./hejny-cv.pdf',
|
|
2859
|
+
'KNOWLEDGE ./hejny-cv.docx',
|
|
2860
|
+
],
|
|
2861
|
+
/**
|
|
2862
|
+
* Parses the KNOWLEDGE command
|
|
2863
|
+
*/
|
|
2864
|
+
parse: function (input) {
|
|
2865
|
+
var args = input.args;
|
|
2866
|
+
var source = args[0];
|
|
2867
|
+
if (source === undefined) {
|
|
2868
|
+
throw new ParsingError("Source is not defined");
|
|
2869
|
+
}
|
|
2870
|
+
if (source.startsWith('http://')) {
|
|
2871
|
+
throw new ParsingError("Source is not secure");
|
|
2872
|
+
}
|
|
2873
|
+
if (!(isValidFilePath(source) || isValidUrl(source))) {
|
|
2874
|
+
throw new ParsingError("Source not valid");
|
|
2875
|
+
}
|
|
2876
|
+
if (source.startsWith('../') || source.startsWith('/') || /^[A-Z]:[\\/]+/i.test(source)) {
|
|
2877
|
+
throw new ParsingError("Source cannot be outside of the .ptbk.md folder");
|
|
2878
|
+
}
|
|
2879
|
+
return {
|
|
2880
|
+
type: 'KNOWLEDGE',
|
|
2881
|
+
source: source,
|
|
2882
|
+
};
|
|
2883
|
+
},
|
|
2884
|
+
/**
|
|
2885
|
+
* Note: Prototype of [🍧] (remove this comment after full implementation)
|
|
2886
|
+
*/
|
|
2887
|
+
applyToPipelineJson: function (pipelineJson, personaCommand) {
|
|
2888
|
+
var source = personaCommand.source;
|
|
2889
|
+
var name = titleToName(source);
|
|
2890
|
+
pipelineJson.knowledgeSources.push({
|
|
2891
|
+
name: name,
|
|
2892
|
+
source: source,
|
|
2893
|
+
});
|
|
2894
|
+
},
|
|
2895
|
+
};
|
|
2896
|
+
|
|
2897
|
+
/**
|
|
2898
|
+
* Parses the persona command
|
|
2899
|
+
*
|
|
2900
|
+
* @see ./PERSONA-README.md for more details
|
|
2901
|
+
* @private within the commands folder
|
|
2902
|
+
*/
|
|
2903
|
+
var personaCommandParser = {
|
|
2904
|
+
/**
|
|
2905
|
+
* Name of the command
|
|
2906
|
+
*/
|
|
2907
|
+
name: 'PERSONA',
|
|
2908
|
+
/**
|
|
2909
|
+
* Aliases for the PERSONA command
|
|
2910
|
+
*/
|
|
2911
|
+
aliasNames: ['PERSON'],
|
|
2912
|
+
/**
|
|
2913
|
+
* PERSONA command can be used in:
|
|
2914
|
+
*/
|
|
2915
|
+
usagePlaces: ['PIPELINE_HEAD', 'PIPELINE_TEMPLATE'],
|
|
2916
|
+
/**
|
|
2917
|
+
* Description of the PERSONA command
|
|
2918
|
+
*/
|
|
2919
|
+
description: "Persona command is used to specify who the system is, it will be transformed into system message, top_t,...",
|
|
2920
|
+
/**
|
|
2921
|
+
* Link to discussion
|
|
2922
|
+
*/
|
|
2923
|
+
discussionUrl: 'https://github.com/webgptorg/promptbook/discussions/22',
|
|
2924
|
+
/**
|
|
2925
|
+
* Example usages of the PERSONA command
|
|
2926
|
+
*/
|
|
2927
|
+
examples: ['PERSONA Jane, skilled copywriter', 'PERSONA Joe, male 28 years old, programmer'],
|
|
2928
|
+
/**
|
|
2929
|
+
* Parses the PERSONA command
|
|
2930
|
+
*/
|
|
2931
|
+
parse: function (input) {
|
|
2932
|
+
var rawArgs = input.rawArgs;
|
|
2933
|
+
var _a = __read(rawArgs.split(/[,;:]/, 2), 2), personaNameRaw = _a[0], personaDescriptionRaw = _a[1];
|
|
2934
|
+
var personaName = (personaNameRaw || '').trim();
|
|
2935
|
+
if (personaName === '') {
|
|
2936
|
+
throw new ParsingError("You must set name for the persona");
|
|
2937
|
+
}
|
|
2938
|
+
var personaDescription = (personaDescriptionRaw || '').trim();
|
|
2939
|
+
if (personaDescription === '') {
|
|
2940
|
+
personaDescription = null;
|
|
2941
|
+
}
|
|
2942
|
+
return {
|
|
2943
|
+
type: 'PERSONA',
|
|
2944
|
+
personaName: personaName,
|
|
2945
|
+
personaDescription: personaDescription,
|
|
2946
|
+
};
|
|
2947
|
+
},
|
|
2948
|
+
/**
|
|
2949
|
+
* Note: Prototype of [🍧] (remove this comment after full implementation)
|
|
2950
|
+
*/
|
|
2951
|
+
applyToPipelineJson: function (pipelineJson, personaCommand) {
|
|
2952
|
+
var personaName = personaCommand.personaName, personaDescription = personaCommand.personaDescription;
|
|
2953
|
+
var persona = pipelineJson.personas.find(function (persona) { return persona.name === personaName; });
|
|
2954
|
+
if (persona === undefined) {
|
|
2955
|
+
pipelineJson.personas.push({
|
|
2956
|
+
name: personaName,
|
|
2957
|
+
description: personaDescription || '',
|
|
2958
|
+
});
|
|
2959
|
+
return;
|
|
2960
|
+
}
|
|
2961
|
+
if (persona.description === personaDescription) {
|
|
2962
|
+
return;
|
|
2963
|
+
}
|
|
2964
|
+
if (personaDescription === null) {
|
|
2965
|
+
return;
|
|
2966
|
+
}
|
|
2967
|
+
if (persona.description === '') {
|
|
2968
|
+
persona.description = personaDescription;
|
|
2969
|
+
return;
|
|
2970
|
+
}
|
|
2971
|
+
console.warn(spaceTrim("\n\n Persona \"".concat(personaName, "\" is defined multiple times with different description:\n\n First definition:\n ").concat(persona.description, "\n\n Second definition:\n ").concat(personaDescription, "\n\n ")));
|
|
2972
|
+
persona.description += spaceTrim('\n\n' + personaDescription);
|
|
2973
|
+
},
|
|
2974
|
+
};
|
|
2975
|
+
|
|
2752
2976
|
/**
|
|
2753
2977
|
* Removes Markdown formatting tags from a string.
|
|
2754
2978
|
*
|
|
@@ -2904,7 +3128,7 @@ var blockCommandParser = {
|
|
|
2904
3128
|
'Knowledge BLOCK',
|
|
2905
3129
|
// 'Knowledge', // <- Note: [⛱] For execution blocks which are also separate commands shortcut does not work
|
|
2906
3130
|
//---
|
|
2907
|
-
/*
|
|
3131
|
+
/* Note: Not implemented block types will be in examples in future -> */
|
|
2908
3132
|
'Instrument BLOCK',
|
|
2909
3133
|
// 'Instrument', // <- Note: [⛱]
|
|
2910
3134
|
'Action BLOCK',
|
|
@@ -2920,13 +3144,12 @@ var blockCommandParser = {
|
|
|
2920
3144
|
normalized = normalized.split('EXAMPLE').join('SAMPLE');
|
|
2921
3145
|
var blockTypes = BlockTypes.filter(function (blockType) { return normalized.includes(blockType); });
|
|
2922
3146
|
if (blockTypes.length !== 1) {
|
|
2923
|
-
// console.log('!!!', { blockType });
|
|
2924
3147
|
throw new ParsingError(spaceTrim(function (block) { return "\n Unknown block type in BLOCK command\n\n Supported block types are:\n ".concat(block(BlockTypes.join(', ')), "\n "); }));
|
|
2925
3148
|
}
|
|
2926
|
-
|
|
3149
|
+
var blockType = blockTypes[0];
|
|
2927
3150
|
return {
|
|
2928
3151
|
type: 'BLOCK',
|
|
2929
|
-
blockType:
|
|
3152
|
+
blockType: blockType,
|
|
2930
3153
|
};
|
|
2931
3154
|
},
|
|
2932
3155
|
};
|
|
@@ -3169,92 +3392,12 @@ var jokerCommandParser = {
|
|
|
3169
3392
|
},
|
|
3170
3393
|
};
|
|
3171
3394
|
|
|
3172
|
-
/**
|
|
3173
|
-
* Tests if given string is valid URL.
|
|
3174
|
-
*
|
|
3175
|
-
* Note: This does not check if the file exists only if the path is valid
|
|
3176
|
-
*/
|
|
3177
|
-
function isValidFilePath(filePath) {
|
|
3178
|
-
if (typeof filePath !== 'string') {
|
|
3179
|
-
return false;
|
|
3180
|
-
}
|
|
3181
|
-
var filePathSlashes = filePath.split('\\').join('/');
|
|
3182
|
-
// Absolute Unix path: /hello.txt
|
|
3183
|
-
if (/^(\/)/i.test(filePathSlashes)) {
|
|
3184
|
-
return true;
|
|
3185
|
-
}
|
|
3186
|
-
// Absolute Windows path: /hello.txt
|
|
3187
|
-
if (/^([A-Z]{1,2}:\/?)\//i.test(filePathSlashes)) {
|
|
3188
|
-
return true;
|
|
3189
|
-
}
|
|
3190
|
-
// Relative path: ./hello.txt
|
|
3191
|
-
if (/^(\.\.?\/)+/i.test(filePathSlashes)) {
|
|
3192
|
-
return true;
|
|
3193
|
-
}
|
|
3194
|
-
return false;
|
|
3195
|
-
}
|
|
3196
|
-
|
|
3197
|
-
/**
|
|
3198
|
-
* Parses the knowledge command
|
|
3199
|
-
*
|
|
3200
|
-
* @see ./KNOWLEDGE-README.md for more details
|
|
3201
|
-
* @private within the commands folder
|
|
3202
|
-
*/
|
|
3203
|
-
var knowledgeCommandParser = {
|
|
3204
|
-
/**
|
|
3205
|
-
* Name of the command
|
|
3206
|
-
*/
|
|
3207
|
-
name: 'KNOWLEDGE',
|
|
3208
|
-
/**
|
|
3209
|
-
* BOILERPLATE command can be used in:
|
|
3210
|
-
*/
|
|
3211
|
-
usagePlaces: ['PIPELINE_HEAD'],
|
|
3212
|
-
/**
|
|
3213
|
-
* Description of the KNOWLEDGE command
|
|
3214
|
-
*/
|
|
3215
|
-
description: "Tells promptbook which external knowledge to use",
|
|
3216
|
-
/**
|
|
3217
|
-
* Link to discussion
|
|
3218
|
-
*/
|
|
3219
|
-
discussionUrl: 'https://github.com/webgptorg/promptbook/discussions/41',
|
|
3220
|
-
/**
|
|
3221
|
-
* Example usages of the KNOWLEDGE command
|
|
3222
|
-
*/
|
|
3223
|
-
examples: [
|
|
3224
|
-
'KNOWLEDGE https://www.pavolhejny.com/',
|
|
3225
|
-
'KNOWLEDGE ./hejny-cv.txt',
|
|
3226
|
-
'KNOWLEDGE ./hejny-cv.md',
|
|
3227
|
-
'KNOWLEDGE ./hejny-cv.pdf',
|
|
3228
|
-
'KNOWLEDGE ./hejny-cv.docx',
|
|
3229
|
-
],
|
|
3230
|
-
/**
|
|
3231
|
-
* Parses the KNOWLEDGE command
|
|
3232
|
-
*/
|
|
3233
|
-
parse: function (input) {
|
|
3234
|
-
var args = input.args;
|
|
3235
|
-
var source = args[0];
|
|
3236
|
-
if (source === undefined) {
|
|
3237
|
-
throw new ParsingError("Source is not defined");
|
|
3238
|
-
}
|
|
3239
|
-
if (source.startsWith('http://')) {
|
|
3240
|
-
throw new ParsingError("Source is not secure");
|
|
3241
|
-
}
|
|
3242
|
-
if (!(isValidFilePath(source) || isValidUrl(source))) {
|
|
3243
|
-
throw new ParsingError("Source not valid");
|
|
3244
|
-
}
|
|
3245
|
-
if (source.startsWith('../') || source.startsWith('/') || /^[A-Z]:[\\/]+/i.test(source)) {
|
|
3246
|
-
throw new ParsingError("Source cannot be outside of the .ptbk.md folder");
|
|
3247
|
-
}
|
|
3248
|
-
return {
|
|
3249
|
-
type: 'KNOWLEDGE',
|
|
3250
|
-
source: source,
|
|
3251
|
-
};
|
|
3252
|
-
},
|
|
3253
|
-
};
|
|
3254
|
-
|
|
3255
3395
|
var MODEL_VARIANTS = ['COMPLETION', 'CHAT', 'EMBEDDING' /* <- TODO [🏳] */ /* <- [🤖] */];
|
|
3256
3396
|
/**
|
|
3257
|
-
* TODO:
|
|
3397
|
+
* TODO: [🧠][🈁] `seed` should maybe be somewhere else (not in `ModelRequirements`) (simmilar that `user` identification is not here)
|
|
3398
|
+
* TODO: [🧠][💱] Add more model options: `stop_token`, `logit_bias`, `logprobs` (`top_logprobs`), `top_k`, `top_p`, `presence_penalty`, `frequency_penalty`, `bestOf`, `logitBias`, `logitBiasType`,...
|
|
3399
|
+
* [💱] Probbably keep using just `temperature` in Promptbook (not `top_k` and `top_p`)
|
|
3400
|
+
* TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
3258
3401
|
* TODO: Maybe figure out better word than "variant"
|
|
3259
3402
|
* TODO: Add here more requirement options like max context size, max tokens, etc.
|
|
3260
3403
|
* TODO: [💕][🧠] Just selecting gpt3 or gpt4 level of model
|
|
@@ -3396,59 +3539,6 @@ var parameterCommandParser = {
|
|
|
3396
3539
|
},
|
|
3397
3540
|
};
|
|
3398
3541
|
|
|
3399
|
-
/**
|
|
3400
|
-
* Parses the persona command
|
|
3401
|
-
*
|
|
3402
|
-
* @see ./PERSONA-README.md for more details
|
|
3403
|
-
* @private within the commands folder
|
|
3404
|
-
*/
|
|
3405
|
-
var personaCommandParser = {
|
|
3406
|
-
/**
|
|
3407
|
-
* Name of the command
|
|
3408
|
-
*/
|
|
3409
|
-
name: 'PERSONA',
|
|
3410
|
-
/**
|
|
3411
|
-
* Aliases for the PERSONA command
|
|
3412
|
-
*/
|
|
3413
|
-
aliasNames: ['PERSON'],
|
|
3414
|
-
/**
|
|
3415
|
-
* PERSONA command can be used in:
|
|
3416
|
-
*/
|
|
3417
|
-
usagePlaces: ['PIPELINE_HEAD', 'PIPELINE_TEMPLATE'],
|
|
3418
|
-
/**
|
|
3419
|
-
* Description of the PERSONA command
|
|
3420
|
-
*/
|
|
3421
|
-
description: "Persona command is used to specify who the system is, it will be transformed into system message, top_t,...",
|
|
3422
|
-
/**
|
|
3423
|
-
* Link to discussion
|
|
3424
|
-
*/
|
|
3425
|
-
discussionUrl: 'https://github.com/webgptorg/promptbook/discussions/22',
|
|
3426
|
-
/**
|
|
3427
|
-
* Example usages of the PERSONA command
|
|
3428
|
-
*/
|
|
3429
|
-
examples: ['PERSONA Jane, skilled copywriter', 'PERSONA Joe, male 28 years old, programmer'],
|
|
3430
|
-
/**
|
|
3431
|
-
* Parses the PERSONA command
|
|
3432
|
-
*/
|
|
3433
|
-
parse: function (input) {
|
|
3434
|
-
var rawArgs = input.rawArgs;
|
|
3435
|
-
var _a = __read(rawArgs.split(/[,;:]/, 2), 2), personaNameRaw = _a[0], personaDescriptionRaw = _a[1];
|
|
3436
|
-
var personaName = (personaNameRaw || '').trim();
|
|
3437
|
-
if (personaName === '') {
|
|
3438
|
-
throw new ParsingError("You must set name for the persona");
|
|
3439
|
-
}
|
|
3440
|
-
var personaDescription = (personaDescriptionRaw || '').trim();
|
|
3441
|
-
if (personaDescription === '') {
|
|
3442
|
-
personaDescription = null;
|
|
3443
|
-
}
|
|
3444
|
-
return {
|
|
3445
|
-
type: 'PERSONA',
|
|
3446
|
-
personaName: personaName,
|
|
3447
|
-
personaDescription: personaDescription,
|
|
3448
|
-
};
|
|
3449
|
-
},
|
|
3450
|
-
};
|
|
3451
|
-
|
|
3452
3542
|
function isValidJavascriptName(javascriptName) {
|
|
3453
3543
|
if (typeof javascriptName !== 'string') {
|
|
3454
3544
|
return false;
|
|
@@ -3666,7 +3756,8 @@ var actionCommandParser = {
|
|
|
3666
3756
|
* Parses the ACTION command
|
|
3667
3757
|
*/
|
|
3668
3758
|
parse: function (input) {
|
|
3669
|
-
input.args;
|
|
3759
|
+
var args = input.args;
|
|
3760
|
+
TODO_USE(args);
|
|
3670
3761
|
return {
|
|
3671
3762
|
type: 'ACTION',
|
|
3672
3763
|
};
|
|
@@ -3704,7 +3795,8 @@ var instrumentCommandParser = {
|
|
|
3704
3795
|
* Parses the INSTRUMENT command
|
|
3705
3796
|
*/
|
|
3706
3797
|
parse: function (input) {
|
|
3707
|
-
input.args;
|
|
3798
|
+
var args = input.args;
|
|
3799
|
+
TODO_USE(args);
|
|
3708
3800
|
return {
|
|
3709
3801
|
type: 'INSTRUMENT',
|
|
3710
3802
|
};
|
|
@@ -3762,6 +3854,7 @@ var boilerplateCommandParser = {
|
|
|
3762
3854
|
};
|
|
3763
3855
|
/**
|
|
3764
3856
|
* TODO: [💐] Implement BOILERPLATE command into `pipelineStringToJsonSync` function
|
|
3857
|
+
* Note: [⚪] This should never be in any released package
|
|
3765
3858
|
*/
|
|
3766
3859
|
|
|
3767
3860
|
/**
|
|
@@ -3780,7 +3873,7 @@ var COMMANDS = [
|
|
|
3780
3873
|
actionCommandParser,
|
|
3781
3874
|
instrumentCommandParser,
|
|
3782
3875
|
personaCommandParser,
|
|
3783
|
-
boilerplateCommandParser, // <- TODO:
|
|
3876
|
+
boilerplateCommandParser, // <- TODO: !! Only in development, remove in production
|
|
3784
3877
|
];
|
|
3785
3878
|
|
|
3786
3879
|
/**
|
|
@@ -3866,7 +3959,7 @@ function parseCommand(raw, usagePlace) {
|
|
|
3866
3959
|
}));
|
|
3867
3960
|
}
|
|
3868
3961
|
/**
|
|
3869
|
-
*
|
|
3962
|
+
* @@@
|
|
3870
3963
|
*/
|
|
3871
3964
|
function getSupportedCommandsMessage() {
|
|
3872
3965
|
return COMMANDS.flatMap(function (_a) {
|
|
@@ -3877,7 +3970,7 @@ function getSupportedCommandsMessage() {
|
|
|
3877
3970
|
}).join('\n');
|
|
3878
3971
|
}
|
|
3879
3972
|
/**
|
|
3880
|
-
*
|
|
3973
|
+
* @@@
|
|
3881
3974
|
*/
|
|
3882
3975
|
function parseCommandVariant(input) {
|
|
3883
3976
|
var e_1, _a;
|
|
@@ -3886,7 +3979,6 @@ function parseCommandVariant(input) {
|
|
|
3886
3979
|
var _loop_1 = function (commandParser) {
|
|
3887
3980
|
var name_1 = commandParser.name, aliasNames = commandParser.aliasNames, deprecatedNames = commandParser.deprecatedNames, parse = commandParser.parse;
|
|
3888
3981
|
var names = __spreadArray(__spreadArray([name_1], __read((aliasNames || [])), false), __read((deprecatedNames || [])), false);
|
|
3889
|
-
// console.log('!!!', { commandName, names });
|
|
3890
3982
|
if (names.includes(commandName)) {
|
|
3891
3983
|
try {
|
|
3892
3984
|
return { value: parse({ usagePlace: usagePlace, raw: raw, rawArgs: rawArgs, normalized: normalized, args: args }) };
|
|
@@ -3996,25 +4088,42 @@ function extractAllBlocksFromMarkdown(markdown) {
|
|
|
3996
4088
|
var e_1, _a;
|
|
3997
4089
|
var codeBlocks = [];
|
|
3998
4090
|
var lines = markdown.split('\n');
|
|
4091
|
+
// Note: [0] Ensure that the last block notated by gt > will be closed
|
|
4092
|
+
lines.push('');
|
|
3999
4093
|
var currentCodeBlock = null;
|
|
4000
4094
|
try {
|
|
4001
4095
|
for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
|
|
4002
4096
|
var line = lines_1_1.value;
|
|
4097
|
+
if (line.startsWith('> ') || line === '>') {
|
|
4098
|
+
if (currentCodeBlock === null) {
|
|
4099
|
+
currentCodeBlock = { blockNotation: '>', language: null, content: '' };
|
|
4100
|
+
} /* not else */
|
|
4101
|
+
if (currentCodeBlock.blockNotation === '>') {
|
|
4102
|
+
if (currentCodeBlock.content !== '') {
|
|
4103
|
+
currentCodeBlock.content += '\n';
|
|
4104
|
+
}
|
|
4105
|
+
currentCodeBlock.content += line.slice(2);
|
|
4106
|
+
}
|
|
4107
|
+
}
|
|
4108
|
+
else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '>' /* <- Note: [0] */) {
|
|
4109
|
+
codeBlocks.push(currentCodeBlock);
|
|
4110
|
+
currentCodeBlock = null;
|
|
4111
|
+
}
|
|
4112
|
+
/* not else */
|
|
4003
4113
|
if (line.startsWith('```')) {
|
|
4004
4114
|
var language = line.slice(3).trim() || null;
|
|
4005
4115
|
if (currentCodeBlock === null) {
|
|
4006
|
-
currentCodeBlock = { language: language, content: '' };
|
|
4116
|
+
currentCodeBlock = { blockNotation: '```', language: language, content: '' };
|
|
4007
4117
|
}
|
|
4008
4118
|
else {
|
|
4009
4119
|
if (language !== null) {
|
|
4010
|
-
|
|
4011
|
-
throw new Error("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed and already opening new ").concat(language, " code block"));
|
|
4120
|
+
throw new ParsingError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed and already opening new ").concat(language, " code block"));
|
|
4012
4121
|
}
|
|
4013
4122
|
codeBlocks.push(currentCodeBlock);
|
|
4014
4123
|
currentCodeBlock = null;
|
|
4015
4124
|
}
|
|
4016
4125
|
}
|
|
4017
|
-
else if (currentCodeBlock !== null) {
|
|
4126
|
+
else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '```') {
|
|
4018
4127
|
if (currentCodeBlock.content !== '') {
|
|
4019
4128
|
currentCodeBlock.content += '\n';
|
|
4020
4129
|
}
|
|
@@ -4030,11 +4139,13 @@ function extractAllBlocksFromMarkdown(markdown) {
|
|
|
4030
4139
|
finally { if (e_1) throw e_1.error; }
|
|
4031
4140
|
}
|
|
4032
4141
|
if (currentCodeBlock !== null) {
|
|
4033
|
-
|
|
4034
|
-
throw new Error("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed at the end of the markdown"));
|
|
4142
|
+
throw new ParsingError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed at the end of the markdown"));
|
|
4035
4143
|
}
|
|
4036
4144
|
return codeBlocks;
|
|
4037
4145
|
}
|
|
4146
|
+
/**
|
|
4147
|
+
* TODO: Maybe name for `blockNotation` instead of '```' and '>'
|
|
4148
|
+
*/
|
|
4038
4149
|
|
|
4039
4150
|
/**
|
|
4040
4151
|
* Extracts exactly ONE code block from markdown.
|
|
@@ -4052,13 +4163,12 @@ function extractAllBlocksFromMarkdown(markdown) {
|
|
|
4052
4163
|
function extractOneBlockFromMarkdown(markdown) {
|
|
4053
4164
|
var codeBlocks = extractAllBlocksFromMarkdown(markdown);
|
|
4054
4165
|
if (codeBlocks.length !== 1) {
|
|
4055
|
-
|
|
4056
|
-
throw new Error(/* <- [🌻] */ 'There should be exactly one code block in the markdown');
|
|
4166
|
+
throw new ParsingError(spaceTrim(function (block) { return "\n There should be exactly 1 code block, found ".concat(codeBlocks.length, " code blocks\n\n ").concat(block(codeBlocks.map(function (block, i) { return "Block ".concat(i + 1, ":\n").concat(block.content); }).join('\n\n\n')), "\n "); }));
|
|
4057
4167
|
}
|
|
4058
4168
|
return codeBlocks[0];
|
|
4059
4169
|
}
|
|
4060
4170
|
/***
|
|
4061
|
-
* TODO: [🍓][🌻]
|
|
4171
|
+
* TODO: [🍓][🌻] Decide of this is internal util, external util OR validator/postprocessor
|
|
4062
4172
|
*/
|
|
4063
4173
|
|
|
4064
4174
|
/**
|
|
@@ -4068,13 +4178,13 @@ function parseMarkdownSection(value) {
|
|
|
4068
4178
|
var _a, _b;
|
|
4069
4179
|
var lines = value.split('\n');
|
|
4070
4180
|
if (!lines[0].startsWith('#')) {
|
|
4071
|
-
throw new
|
|
4181
|
+
throw new ParsingError('Markdown section must start with heading');
|
|
4072
4182
|
}
|
|
4073
4183
|
var title = lines[0].replace(/^#+\s*/, '');
|
|
4074
4184
|
var level = (_b = (_a = lines[0].match(/^#+/)) === null || _a === void 0 ? void 0 : _a[0].length) !== null && _b !== void 0 ? _b : 0;
|
|
4075
4185
|
var content = spaceTrim(lines.slice(1).join('\n'));
|
|
4076
4186
|
if (level < 1 || level > 6) {
|
|
4077
|
-
throw new
|
|
4187
|
+
throw new ParsingError('Markdown section must have heading level between 1 and 6');
|
|
4078
4188
|
}
|
|
4079
4189
|
return { title: title, level: level, content: content };
|
|
4080
4190
|
}
|
|
@@ -4456,7 +4566,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4456
4566
|
existingParameter.description &&
|
|
4457
4567
|
existingParameter.description !== parameterDescription &&
|
|
4458
4568
|
parameterDescription) {
|
|
4459
|
-
throw new ParsingError(spaceTrim$1(function (block) { return "\n Parameter {".concat(parameterName, "} is defined multiple times with different description
|
|
4569
|
+
throw new ParsingError(spaceTrim$1(function (block) { return "\n Parameter {".concat(parameterName, "} is defined multiple times with different description:\n\n First definition:\n ").concat(block(existingParameter.description || '[undefined]'), "\n\n Second definition:\n ").concat(block(parameterDescription || '[undefined]'), "\n "); }));
|
|
4460
4570
|
}
|
|
4461
4571
|
if (existingParameter) {
|
|
4462
4572
|
if (parameterDescription) {
|
|
@@ -4475,11 +4585,12 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4475
4585
|
// =============================================================
|
|
4476
4586
|
// Note: 3️⃣ Process pipeline head
|
|
4477
4587
|
pipelineJson.title = pipelineHead.title;
|
|
4478
|
-
// TODO: [1] DRY description
|
|
4588
|
+
// TODO: [🎾][1] DRY description
|
|
4479
4589
|
var description = pipelineHead.content;
|
|
4480
|
-
// Note: Remove codeblocks - TODO:
|
|
4590
|
+
// Note: Remove codeblocks - TODO: [🎾] Make util removeAllBlocksFromMarkdown (exported from `@promptbool/utils`)
|
|
4481
4591
|
description = description.split(/^```.*^```/gms).join('');
|
|
4482
|
-
|
|
4592
|
+
description = description.split(/^>.*$/gm).join('');
|
|
4593
|
+
//Note: Remove lists and return statement - TODO: [🎾] Make util (exported from `@promptbool/utils`)
|
|
4483
4594
|
description = description.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
4484
4595
|
description = spaceTrim$1(description);
|
|
4485
4596
|
if (description === '') {
|
|
@@ -4507,7 +4618,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4507
4618
|
pipelineJson.pipelineUrl = command.pipelineUrl.href;
|
|
4508
4619
|
break;
|
|
4509
4620
|
case 'KNOWLEDGE':
|
|
4510
|
-
|
|
4621
|
+
knowledgeCommandParser.applyToPipelineJson(pipelineJson, command);
|
|
4511
4622
|
break;
|
|
4512
4623
|
case 'ACTION':
|
|
4513
4624
|
console.error(new NotYetImplementedError('Actions are not implemented yet'));
|
|
@@ -4516,7 +4627,8 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4516
4627
|
console.error(new NotYetImplementedError('Instruments are not implemented yet'));
|
|
4517
4628
|
break;
|
|
4518
4629
|
case 'PERSONA':
|
|
4519
|
-
|
|
4630
|
+
personaCommandParser.applyToPipelineJson(pipelineJson, command);
|
|
4631
|
+
// <- Note: Prototype of [🍧] (remove this comment after full implementation)
|
|
4520
4632
|
break;
|
|
4521
4633
|
case 'BOILERPLATE':
|
|
4522
4634
|
throw new ParsingError('BOILERPLATE command is only for testing purposes and should not be used in the .ptbk.md file'); // <- TODO: [🚞]
|
|
@@ -4545,7 +4657,27 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4545
4657
|
var postprocessing = [];
|
|
4546
4658
|
var expectAmount = {};
|
|
4547
4659
|
var expectFormat = undefined;
|
|
4548
|
-
var
|
|
4660
|
+
var isBlockTypeSet = false;
|
|
4661
|
+
var lastLine = section.content.split('\n').pop();
|
|
4662
|
+
var resultingParameterNameMatch = /^->\s*\{(?<resultingParamName>[a-z0-9_]+)\}/im.exec(lastLine);
|
|
4663
|
+
var resultingParameterName = null;
|
|
4664
|
+
if (resultingParameterNameMatch &&
|
|
4665
|
+
resultingParameterNameMatch.groups !== undefined &&
|
|
4666
|
+
resultingParameterNameMatch.groups.resultingParamName !== undefined) {
|
|
4667
|
+
resultingParameterName = resultingParameterNameMatch.groups.resultingParamName;
|
|
4668
|
+
}
|
|
4669
|
+
var expectResultingParameterName = function () {
|
|
4670
|
+
if (resultingParameterName !== null) {
|
|
4671
|
+
return resultingParameterName;
|
|
4672
|
+
}
|
|
4673
|
+
throw new ParsingError(spaceTrim$1(function (block) { return "\n Template section must end with -> {parameterName}\n\n Invalid section:\n ".concat(block(
|
|
4674
|
+
// TODO: Show code of invalid sections each time + DRY
|
|
4675
|
+
section.content
|
|
4676
|
+
.split('\n')
|
|
4677
|
+
.map(function (line) { return " | ".concat(line); } /* <- TODO: [🚞] */)
|
|
4678
|
+
.join('\n')), "\n "); }));
|
|
4679
|
+
};
|
|
4680
|
+
var _e = extractOneBlockFromMarkdown(section.content), language = _e.language, content = _e.content;
|
|
4549
4681
|
try {
|
|
4550
4682
|
for (var listItems_2 = (e_3 = void 0, __values(listItems_3)), listItems_2_1 = listItems_2.next(); !listItems_2_1.done; listItems_2_1 = listItems_2.next()) {
|
|
4551
4683
|
var listItem = listItems_2_1.value;
|
|
@@ -4553,15 +4685,24 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4553
4685
|
switch (command.type) {
|
|
4554
4686
|
// TODO: [🍧] Use here applyToPipelineJson and remove switch statement
|
|
4555
4687
|
case 'BLOCK':
|
|
4556
|
-
if (
|
|
4688
|
+
if (isBlockTypeSet) {
|
|
4557
4689
|
throw new ParsingError('Block type is already defined in the prompt template. It can be defined only once.');
|
|
4558
4690
|
}
|
|
4559
4691
|
if (command.blockType === 'SAMPLE') {
|
|
4560
|
-
|
|
4692
|
+
expectResultingParameterName();
|
|
4693
|
+
var parameter = pipelineJson.parameters.find(function (param) { return param.name === resultingParameterName; });
|
|
4694
|
+
if (parameter === undefined) {
|
|
4695
|
+
throw new UnexpectedError("Can not find parameter {".concat(resultingParameterName, "} to assign sample value"));
|
|
4696
|
+
}
|
|
4697
|
+
parameter.sampleValues = parameter.sampleValues || [];
|
|
4698
|
+
parameter.sampleValues.push(content);
|
|
4561
4699
|
return "continue-templates";
|
|
4562
4700
|
}
|
|
4563
4701
|
if (command.blockType === 'KNOWLEDGE') {
|
|
4564
|
-
|
|
4702
|
+
knowledgeCommandParser.applyToPipelineJson(pipelineJson, {
|
|
4703
|
+
type: 'KNOWLEDGE',
|
|
4704
|
+
source: content, // <- TODO: [🐝] !!!! Work with KNOWLEDGE which not referring to the source file/wweb, but its content itself
|
|
4705
|
+
});
|
|
4565
4706
|
return "continue-templates";
|
|
4566
4707
|
}
|
|
4567
4708
|
if (command.blockType === 'ACTION') {
|
|
@@ -4572,8 +4713,9 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4572
4713
|
console.error(new NotYetImplementedError('Instruments are not implemented yet'));
|
|
4573
4714
|
return "continue-templates";
|
|
4574
4715
|
}
|
|
4716
|
+
expectResultingParameterName();
|
|
4575
4717
|
blockType = command.blockType;
|
|
4576
|
-
|
|
4718
|
+
isBlockTypeSet = true;
|
|
4577
4719
|
break;
|
|
4578
4720
|
case 'EXPECT_AMOUNT':
|
|
4579
4721
|
// eslint-disable-next-line no-case-declarations
|
|
@@ -4613,16 +4755,20 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4613
4755
|
postprocessing.push(command.functionName);
|
|
4614
4756
|
break;
|
|
4615
4757
|
case 'KNOWLEDGE':
|
|
4616
|
-
|
|
4758
|
+
// TODO: [👙] The knowledge is maybe relevant for just this template
|
|
4759
|
+
knowledgeCommandParser.applyToPipelineJson(pipelineJson, command);
|
|
4617
4760
|
break;
|
|
4618
4761
|
case 'ACTION':
|
|
4762
|
+
// TODO: [👙] The action is maybe relevant for just this template
|
|
4619
4763
|
console.error(new NotYetImplementedError('Actions are not implemented yet'));
|
|
4620
4764
|
break;
|
|
4621
4765
|
case 'INSTRUMENT':
|
|
4766
|
+
// TODO: [👙] The instrument is maybe relevant for just this template
|
|
4622
4767
|
console.error(new NotYetImplementedError('Instruments are not implemented yet'));
|
|
4623
4768
|
break;
|
|
4624
4769
|
case 'PERSONA':
|
|
4625
|
-
|
|
4770
|
+
personaCommandParser.applyToPipelineJson(pipelineJson, command);
|
|
4771
|
+
// <- Note: Prototype of [🍧] (remove this comment after full implementation)
|
|
4626
4772
|
break;
|
|
4627
4773
|
case 'BOILERPLATE':
|
|
4628
4774
|
console.error(new ParsingError('BOILERPLATE command is only for testing purposes and should not be used in the .ptbk.md file'));
|
|
@@ -4640,7 +4786,6 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4640
4786
|
}
|
|
4641
4787
|
finally { if (e_3) throw e_3.error; }
|
|
4642
4788
|
}
|
|
4643
|
-
var _e = extractOneBlockFromMarkdown(section.content), language = _e.language, content = _e.content;
|
|
4644
4789
|
if (blockType === 'SCRIPT') {
|
|
4645
4790
|
if (!language) {
|
|
4646
4791
|
throw new ParsingError('You must specify the language of the script in the prompt template');
|
|
@@ -4649,22 +4794,12 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4649
4794
|
throw new ParsingError(spaceTrim$1(function (block) { return "\n Script language ".concat(language, " is not supported.\n\n Supported languages are:\n ").concat(block(SUPPORTED_SCRIPT_LANGUAGES.join(', ')), "\n\n "); }));
|
|
4650
4795
|
}
|
|
4651
4796
|
}
|
|
4652
|
-
|
|
4653
|
-
var match = /^->\s*\{(?<resultingParamName>[a-z0-9_]+)\}/im.exec(lastLine);
|
|
4654
|
-
if (!match || match.groups === undefined || match.groups.resultingParamName === undefined) {
|
|
4655
|
-
throw new ParsingError(spaceTrim$1(function (block) { return "\n Each section must end with -> {parameterName}\n\n Invalid section:\n ".concat(block(
|
|
4656
|
-
// TODO: Show code of invalid sections each time + DRY
|
|
4657
|
-
section.content
|
|
4658
|
-
.split('\n')
|
|
4659
|
-
.map(function (line) { return " | ".concat(line); } /* <- TODO: [🚞] */)
|
|
4660
|
-
.join('\n')), "\n "); }));
|
|
4661
|
-
}
|
|
4662
|
-
var resultingParameterName = match.groups.resultingParamName;
|
|
4663
|
-
// TODO: [1] DRY description
|
|
4797
|
+
// TODO: [🎾][1] DRY description
|
|
4664
4798
|
var description_1 = section.content;
|
|
4665
|
-
// Note: Remove codeblocks
|
|
4799
|
+
// Note: Remove codeblocks - TODO: [🎾]
|
|
4666
4800
|
description_1 = description_1.split(/^```.*^```/gms).join('');
|
|
4667
|
-
|
|
4801
|
+
description_1 = description_1.split(/^>.*$/gm).join('');
|
|
4802
|
+
//Note: Remove lists and return statement - TODO: [🎾]
|
|
4668
4803
|
description_1 = description_1.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
4669
4804
|
description_1 = spaceTrim$1(description_1);
|
|
4670
4805
|
if (description_1 === '') {
|
|
@@ -4698,13 +4833,13 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4698
4833
|
modelRequirements: templateModelRequirements,
|
|
4699
4834
|
contentLanguage: blockType === 'SCRIPT' ? language : undefined,
|
|
4700
4835
|
content: content,
|
|
4701
|
-
resultingParameterName:
|
|
4836
|
+
resultingParameterName: expectResultingParameterName( /* <- Note: This is once more redundant */),
|
|
4702
4837
|
};
|
|
4703
4838
|
if (blockType !== 'PROMPT_TEMPLATE') {
|
|
4704
4839
|
delete template.modelRequirements;
|
|
4705
4840
|
}
|
|
4706
4841
|
// TODO: [🍧] What actually about preparation and pushing the block into `promptTemplates`
|
|
4707
|
-
pipelineJson.promptTemplates.push(template
|
|
4842
|
+
pipelineJson.promptTemplates.push(template);
|
|
4708
4843
|
};
|
|
4709
4844
|
try {
|
|
4710
4845
|
// =============================================================
|
|
@@ -4771,6 +4906,8 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
4771
4906
|
* TODO: Use spaceTrim more effectively
|
|
4772
4907
|
* TODO: [🧠] Parameter flags - isInput, isOutput, isInternal
|
|
4773
4908
|
* TODO: [🥞] Not optimal parsing because `splitMarkdownIntoSections` is executed twice with same string, once through `flattenMarkdown` and second directly here
|
|
4909
|
+
* TODO: [♈] Probbably move expectations from templates to parameters
|
|
4910
|
+
* TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
4774
4911
|
*/
|
|
4775
4912
|
|
|
4776
4913
|
/**
|
|
@@ -4810,6 +4947,7 @@ function pipelineStringToJson(pipelineString, options) {
|
|
|
4810
4947
|
}
|
|
4811
4948
|
/**
|
|
4812
4949
|
* TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
|
|
4950
|
+
* TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
4813
4951
|
*/
|
|
4814
4952
|
|
|
4815
4953
|
/**
|
|
@@ -4838,6 +4976,9 @@ var isRunningInNode = new Function("\n try {\n return this === global;
|
|
|
4838
4976
|
* Detects if the code is running in a web worker
|
|
4839
4977
|
*/
|
|
4840
4978
|
new Function("\n try {\n if (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope) {\n return true;\n } else {\n return false;\n }\n } catch (e) {\n return false;\n }\n");
|
|
4979
|
+
/**
|
|
4980
|
+
* TODO: [🔼] !!! Export via `@promptbook/utils`
|
|
4981
|
+
*/
|
|
4841
4982
|
|
|
4842
4983
|
/**
|
|
4843
4984
|
* Constructs Promptbook from async sources
|
|
@@ -4956,6 +5097,7 @@ function createCollectionFromDirectory(path, options) {
|
|
|
4956
5097
|
else {
|
|
4957
5098
|
colors.green("(In future, not implemented yet) Using your prebuild pipeline collection ".concat(makedLibraryFilePath));
|
|
4958
5099
|
// TODO: !! Implement;
|
|
5100
|
+
// TODO: [🌗]
|
|
4959
5101
|
}
|
|
4960
5102
|
_a = options || {}, _b = _a.isRecursive, isRecursive = _b === void 0 ? true : _b, _c = _a.isVerbose, isVerbose = _c === void 0 ? false : _c, _d = _a.isLazyLoaded, isLazyLoaded = _d === void 0 ? false : _d, _e = _a.isCrashedOnError, isCrashedOnError = _e === void 0 ? true : _e;
|
|
4961
5103
|
collection = createCollectionFromPromise(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
@@ -5000,6 +5142,7 @@ function createCollectionFromDirectory(path, options) {
|
|
|
5000
5142
|
case 5:
|
|
5001
5143
|
// TODO: Handle non-valid JSON files
|
|
5002
5144
|
promptbook = _d.apply(_c, [_e.sent()]);
|
|
5145
|
+
// TODO: [🌗]
|
|
5003
5146
|
promptbook = __assign(__assign({}, promptbook), { sourceFile: sourceFile });
|
|
5004
5147
|
return [3 /*break*/, 7];
|
|
5005
5148
|
case 6:
|
|
@@ -5146,6 +5289,7 @@ function listAllFiles(path, isRecursive) {
|
|
|
5146
5289
|
}
|
|
5147
5290
|
/**
|
|
5148
5291
|
* TODO: !!!! [🧠] Library precompilation and do not mix markdown and json promptbooks
|
|
5292
|
+
* Note: [🟢] This code should never be published outside of `@promptbook/node`
|
|
5149
5293
|
*/
|
|
5150
5294
|
|
|
5151
5295
|
export { PROMPTBOOK_VERSION, createCollectionFromDirectory };
|