@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/umd/index.umd.js
CHANGED
|
@@ -149,6 +149,10 @@
|
|
|
149
149
|
// <- TODO: Add more like 'date', 'modelName',...
|
|
150
150
|
// <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
|
|
151
151
|
];
|
|
152
|
+
/*
|
|
153
|
+
TODO: !!! Just testing false-negative detection of [🟡][🟢][🔵][⚪] leak
|
|
154
|
+
*/
|
|
155
|
+
// [🟡][🟢][🔵][⚪]
|
|
152
156
|
|
|
153
157
|
/**
|
|
154
158
|
* Function `addUsage` will add multiple usages into one
|
|
@@ -315,7 +319,7 @@
|
|
|
315
319
|
});
|
|
316
320
|
}
|
|
317
321
|
|
|
318
|
-
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.61.0-
|
|
322
|
+
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"}];
|
|
319
323
|
|
|
320
324
|
/**
|
|
321
325
|
* Prettify the html code
|
|
@@ -555,7 +559,7 @@
|
|
|
555
559
|
return parameterString;
|
|
556
560
|
}
|
|
557
561
|
/**
|
|
558
|
-
* TODO:
|
|
562
|
+
* TODO: !!!! Implement new features and commands into `promptTemplateParameterJsonToString`
|
|
559
563
|
* TODO: [🧠] Is there a way to auto-detect missing features in pipelineJsonToString
|
|
560
564
|
* TODO: Escape all
|
|
561
565
|
*/
|
|
@@ -932,6 +936,12 @@
|
|
|
932
936
|
* > * - ...
|
|
933
937
|
* > ex port function validatePipeline(promptbook: unknown): asserts promptbook is PipelineJson {
|
|
934
938
|
*/
|
|
939
|
+
/**
|
|
940
|
+
* TODO: [🧠][🐣] !!!! Validate that all samples match expectations
|
|
941
|
+
* TODO: [🧠][🐣] !!!! Validate that knowledge is valid (non-void)
|
|
942
|
+
* TODO: [🧠] !!! Validationg not only logic itself but imports around - files and websites and rerefenced pipelines exists
|
|
943
|
+
* TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
944
|
+
*/
|
|
935
945
|
|
|
936
946
|
/**
|
|
937
947
|
* This error indicates that promptbook not found in the collection
|
|
@@ -972,7 +982,7 @@
|
|
|
972
982
|
/**
|
|
973
983
|
* Constructs a pipeline collection from promptbooks
|
|
974
984
|
*
|
|
975
|
-
* @param promptbooks
|
|
985
|
+
* @param promptbooks @@@
|
|
976
986
|
*
|
|
977
987
|
* @private Use instead `createCollectionFromJson`
|
|
978
988
|
* Note: During the construction logic of all promptbooks are validated
|
|
@@ -1613,7 +1623,7 @@
|
|
|
1613
1623
|
};
|
|
1614
1624
|
/**
|
|
1615
1625
|
* List all available models that can be used
|
|
1616
|
-
* This
|
|
1626
|
+
* This lists is a combination of all available models from all execution tools
|
|
1617
1627
|
*/
|
|
1618
1628
|
MultipleLlmExecutionTools.prototype.listModels = function () {
|
|
1619
1629
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -1659,6 +1669,8 @@
|
|
|
1659
1669
|
}());
|
|
1660
1670
|
/**
|
|
1661
1671
|
* TODO: [🧠][🎛] Aggregating multiple models - have result not only from one first aviable model BUT all of them
|
|
1672
|
+
* 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
|
|
1673
|
+
* Look how `countTotalUsage` (and `cacheLlmTools`) implements it
|
|
1662
1674
|
*/
|
|
1663
1675
|
|
|
1664
1676
|
/**
|
|
@@ -1729,8 +1741,11 @@
|
|
|
1729
1741
|
/**
|
|
1730
1742
|
* The version of the Promptbook library
|
|
1731
1743
|
*/
|
|
1732
|
-
var PROMPTBOOK_VERSION = '0.61.0-
|
|
1744
|
+
var PROMPTBOOK_VERSION = '0.61.0-11';
|
|
1733
1745
|
// TODO: !!!! List here all the versions and annotate + put into script
|
|
1746
|
+
/**
|
|
1747
|
+
* TODO: [🔼] !!! Export via `@promptbook/code`
|
|
1748
|
+
*/
|
|
1734
1749
|
|
|
1735
1750
|
/**
|
|
1736
1751
|
* Counts number of characters in the text
|
|
@@ -1912,7 +1927,6 @@
|
|
|
1912
1927
|
var _this = this;
|
|
1913
1928
|
var pipeline = options.pipeline, tools = options.tools, _a = options.settings, settings = _a === void 0 ? {} : _a;
|
|
1914
1929
|
var _b = settings.maxExecutionAttempts, maxExecutionAttempts = _b === void 0 ? 3 : _b;
|
|
1915
|
-
// TODO: !!!!! Implement new commands
|
|
1916
1930
|
validatePipeline(pipeline);
|
|
1917
1931
|
var llmTools = joinLlmExecutionTools.apply(void 0, __spreadArray([], __read(arrayableToArray(tools.llm)), false));
|
|
1918
1932
|
var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
|
|
@@ -1988,7 +2002,10 @@
|
|
|
1988
2002
|
: 'anonymous' /* <- TODO: [🧠] How to deal with anonymous pipelines, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(currentTemplate.name),
|
|
1989
2003
|
parameters: parametersToPass,
|
|
1990
2004
|
content: replaceParameters(currentTemplate.content, parametersToPass) /* <- [2] */,
|
|
2005
|
+
// <- TODO: !!!!! Apply {context} and knowledges
|
|
2006
|
+
// <- TODO: !!!!! Apply samples
|
|
1991
2007
|
modelRequirements: currentTemplate.modelRequirements,
|
|
2008
|
+
// <- TODO: !!!!! Apply persona
|
|
1992
2009
|
expectations: currentTemplate.expectations,
|
|
1993
2010
|
expectFormat: currentTemplate.expectFormat,
|
|
1994
2011
|
postprocessing: (currentTemplate.postprocessing || []).map(function (functionName) { return function (result) { return __awaiter(_this, void 0, void 0, function () {
|
|
@@ -2435,10 +2452,12 @@
|
|
|
2435
2452
|
}
|
|
2436
2453
|
/**
|
|
2437
2454
|
* TODO: [🪂] Pass maxParallelCount here
|
|
2455
|
+
* TODO: [♈] Probbably move expectations from templates to parameters
|
|
2438
2456
|
* TODO: [🧠] When not meet expectations in PROMPT_DIALOG, make some way to tell the user
|
|
2439
2457
|
* TODO: [👧] Strongly type the executors to avoid need of remove nullables whtn noUncheckedIndexedAccess in tsconfig.json
|
|
2440
2458
|
* Note: CreatePipelineExecutorOptions are just connected to PipelineExecutor so do not extract to types folder
|
|
2441
2459
|
* TODO: [🧠][3] transparent = (report intermediate parameters) / opaque execution = (report only output parameters) progress reporting mode
|
|
2460
|
+
* TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
2442
2461
|
*/
|
|
2443
2462
|
|
|
2444
2463
|
/**
|
|
@@ -2449,6 +2468,7 @@
|
|
|
2449
2468
|
*
|
|
2450
2469
|
* @param value any values
|
|
2451
2470
|
* @returns void
|
|
2471
|
+
* @private within the repository
|
|
2452
2472
|
*/
|
|
2453
2473
|
function TODO_USE() {
|
|
2454
2474
|
var value = [];
|
|
@@ -2456,7 +2476,6 @@
|
|
|
2456
2476
|
value[_i] = arguments[_i];
|
|
2457
2477
|
}
|
|
2458
2478
|
}
|
|
2459
|
-
// TODO: !!!! Find ACRY all just(...) and replace with TODO_USE
|
|
2460
2479
|
|
|
2461
2480
|
/**
|
|
2462
2481
|
* @@@
|
|
@@ -2585,6 +2604,7 @@
|
|
|
2585
2604
|
});
|
|
2586
2605
|
}
|
|
2587
2606
|
/**
|
|
2607
|
+
* TODO: [🔼] !!! Export via `@promptbook/markdown`
|
|
2588
2608
|
* TODO: [🪂] Do it in parallel 11:11
|
|
2589
2609
|
* Note: No need to aggregate usage here, it is done by intercepting the llmTools
|
|
2590
2610
|
*/
|
|
@@ -2593,7 +2613,6 @@
|
|
|
2593
2613
|
* Prepares the knowle
|
|
2594
2614
|
*
|
|
2595
2615
|
* @see https://github.com/webgptorg/promptbook/discussions/41
|
|
2596
|
-
* @private within the package
|
|
2597
2616
|
*/
|
|
2598
2617
|
function prepareKnowledgePieces(knowledgeSources, options) {
|
|
2599
2618
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -2608,7 +2627,7 @@
|
|
|
2608
2627
|
var partialPieces, pieces;
|
|
2609
2628
|
return __generator(this, function (_a) {
|
|
2610
2629
|
switch (_a.label) {
|
|
2611
|
-
case 0: return [4 /*yield*/, prepareKnowledgeFromMarkdown(knowledgeSource.source, // <- TODO: !!!!! Unhardcode markdown, detect which type it is
|
|
2630
|
+
case 0: return [4 /*yield*/, prepareKnowledgeFromMarkdown(knowledgeSource.source, // <- TODO: [🐝] !!!!! Unhardcode markdown, detect which type it is
|
|
2612
2631
|
options)];
|
|
2613
2632
|
case 1:
|
|
2614
2633
|
partialPieces = _a.sent();
|
|
@@ -2646,6 +2665,7 @@
|
|
|
2646
2665
|
> ):
|
|
2647
2666
|
*/
|
|
2648
2667
|
/**
|
|
2668
|
+
* TODO: [🔼] !!! Export via `@promptbook/core`
|
|
2649
2669
|
* TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
|
|
2650
2670
|
* Put `knowledgePieces` into `PrepareKnowledgeOptions`
|
|
2651
2671
|
* TODO: [🪂] More than max things can run in parallel by acident [1,[2a,2b,_],[3a,3b,_]]
|
|
@@ -2658,37 +2678,66 @@
|
|
|
2658
2678
|
* Prepares the persona for the pipeline
|
|
2659
2679
|
*
|
|
2660
2680
|
* @see https://github.com/webgptorg/promptbook/discussions/22
|
|
2661
|
-
* @private within the package
|
|
2662
2681
|
*/
|
|
2663
2682
|
function preparePersona(personaDescription, options) {
|
|
2664
2683
|
return __awaiter(this, void 0, void 0, function () {
|
|
2665
|
-
var llmTools, _a,
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
|
|
2684
|
+
var llmTools, _a, isVerbose, collection, preparePersonaExecutor, _b, availableModels, availableModelNames, result, outputParameters, modelRequirementsRaw, modelRequirements, modelName, systemMessage, temperature;
|
|
2685
|
+
var _c;
|
|
2686
|
+
return __generator(this, function (_d) {
|
|
2687
|
+
switch (_d.label) {
|
|
2688
|
+
case 0:
|
|
2689
|
+
llmTools = options.llmTools, _a = options.isVerbose, isVerbose = _a === void 0 ? false : _a;
|
|
2690
|
+
collection = createCollectionFromJson.apply(void 0, __spreadArray([], __read(PipelineCollection), false));
|
|
2691
|
+
_b = createPipelineExecutor;
|
|
2692
|
+
_c = {};
|
|
2693
|
+
return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-persona.ptbk.md')];
|
|
2694
|
+
case 1:
|
|
2695
|
+
preparePersonaExecutor = _b.apply(void 0, [(_c.pipeline = _d.sent(),
|
|
2696
|
+
_c.tools = {
|
|
2697
|
+
llm: llmTools,
|
|
2698
|
+
},
|
|
2699
|
+
_c)]);
|
|
2700
|
+
return [4 /*yield*/, llmTools.listModels()];
|
|
2701
|
+
case 2:
|
|
2702
|
+
availableModels = _d.sent();
|
|
2703
|
+
availableModelNames = availableModels
|
|
2704
|
+
.filter(function (_a) {
|
|
2705
|
+
var modelVariant = _a.modelVariant;
|
|
2706
|
+
return modelVariant === 'CHAT';
|
|
2707
|
+
})
|
|
2708
|
+
.map(function (_a) {
|
|
2709
|
+
var modelName = _a.modelName;
|
|
2710
|
+
return modelName;
|
|
2711
|
+
})
|
|
2712
|
+
.join(',');
|
|
2713
|
+
return [4 /*yield*/, preparePersonaExecutor({ availableModelNames: availableModelNames, personaDescription: personaDescription })];
|
|
2714
|
+
case 3:
|
|
2715
|
+
result = _d.sent();
|
|
2716
|
+
assertsExecutionSuccessful(result);
|
|
2717
|
+
outputParameters = result.outputParameters;
|
|
2718
|
+
modelRequirementsRaw = outputParameters.modelRequirements;
|
|
2719
|
+
modelRequirements = JSON.parse(modelRequirementsRaw);
|
|
2720
|
+
if (isVerbose) {
|
|
2721
|
+
console.info("PERSONA ".concat(personaDescription), modelRequirements);
|
|
2722
|
+
}
|
|
2723
|
+
modelName = modelRequirements.modelName, systemMessage = modelRequirements.systemMessage, temperature = modelRequirements.temperature;
|
|
2724
|
+
return [2 /*return*/, {
|
|
2725
|
+
modelVariant: 'CHAT',
|
|
2726
|
+
modelName: modelName,
|
|
2727
|
+
systemMessage: systemMessage,
|
|
2728
|
+
temperature: temperature,
|
|
2729
|
+
}];
|
|
2730
|
+
}
|
|
2676
2731
|
});
|
|
2677
2732
|
});
|
|
2678
2733
|
}
|
|
2679
2734
|
/**
|
|
2680
|
-
* TODO: [
|
|
2735
|
+
* TODO: [🔼] !!! Export via `@promptbook/core`
|
|
2736
|
+
* TODO: [🏢] !! Check validity of `modelName` in pipeline
|
|
2737
|
+
* TODO: [🏢] !! Check validity of `systemMessage` in pipeline
|
|
2738
|
+
* TODO: [🏢] !! Check validity of `temperature` in pipeline
|
|
2681
2739
|
*/
|
|
2682
2740
|
|
|
2683
|
-
/**
|
|
2684
|
-
* Simple wrapper `new Date().toISOString()`
|
|
2685
|
-
*
|
|
2686
|
-
* @returns string_date branded type
|
|
2687
|
-
*/
|
|
2688
|
-
function $currentDate() {
|
|
2689
|
-
return new Date().toISOString();
|
|
2690
|
-
}
|
|
2691
|
-
|
|
2692
2741
|
/**
|
|
2693
2742
|
* Prepare pipeline from string (markdown) format to JSON format
|
|
2694
2743
|
*
|
|
@@ -2711,7 +2760,7 @@
|
|
|
2711
2760
|
knowledgeSources = pipeline.knowledgeSources, personas = pipeline.personas;
|
|
2712
2761
|
currentPreparation = {
|
|
2713
2762
|
id: 1,
|
|
2714
|
-
date: $currentDate(),
|
|
2763
|
+
// TODO: [🍥]> date: $currentDate(),
|
|
2715
2764
|
promptbookVersion: PROMPTBOOK_VERSION,
|
|
2716
2765
|
modelUsage: addUsage(),
|
|
2717
2766
|
};
|
|
@@ -2720,8 +2769,8 @@
|
|
|
2720
2769
|
// <- TODO: [🧊]
|
|
2721
2770
|
currentPreparation,
|
|
2722
2771
|
];
|
|
2723
|
-
preparedPersonas =
|
|
2724
|
-
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 () {
|
|
2772
|
+
preparedPersonas = new Array(personas.length);
|
|
2773
|
+
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 () {
|
|
2725
2774
|
var modelRequirements, preparedPersona;
|
|
2726
2775
|
return __generator(this, function (_a) {
|
|
2727
2776
|
switch (_a.label) {
|
|
@@ -2729,7 +2778,7 @@
|
|
|
2729
2778
|
case 1:
|
|
2730
2779
|
modelRequirements = _a.sent();
|
|
2731
2780
|
preparedPersona = __assign(__assign({}, persona), { modelRequirements: modelRequirements, preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] });
|
|
2732
|
-
preparedPersonas
|
|
2781
|
+
preparedPersonas[index] = preparedPersona;
|
|
2733
2782
|
return [2 /*return*/];
|
|
2734
2783
|
}
|
|
2735
2784
|
});
|
|
@@ -2748,12 +2797,187 @@
|
|
|
2748
2797
|
});
|
|
2749
2798
|
}
|
|
2750
2799
|
/**
|
|
2800
|
+
* TODO: [🔼] !!! Export via `@promptbook/core`
|
|
2751
2801
|
* TODO: Write tests for `preparePipeline`
|
|
2752
2802
|
* TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
|
|
2753
2803
|
* TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
|
|
2754
|
-
* TODO: [
|
|
2804
|
+
* TODO: [🎐] !!!! Use here countTotalUsage
|
|
2805
|
+
* TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
2755
2806
|
*/
|
|
2756
2807
|
|
|
2808
|
+
/**
|
|
2809
|
+
* Tests if given string is valid URL.
|
|
2810
|
+
*
|
|
2811
|
+
* Note: This does not check if the file exists only if the path is valid
|
|
2812
|
+
*/
|
|
2813
|
+
function isValidFilePath(filePath) {
|
|
2814
|
+
if (typeof filePath !== 'string') {
|
|
2815
|
+
return false;
|
|
2816
|
+
}
|
|
2817
|
+
var filePathSlashes = filePath.split('\\').join('/');
|
|
2818
|
+
// Absolute Unix path: /hello.txt
|
|
2819
|
+
if (/^(\/)/i.test(filePathSlashes)) {
|
|
2820
|
+
return true;
|
|
2821
|
+
}
|
|
2822
|
+
// Absolute Windows path: /hello.txt
|
|
2823
|
+
if (/^([A-Z]{1,2}:\/?)\//i.test(filePathSlashes)) {
|
|
2824
|
+
return true;
|
|
2825
|
+
}
|
|
2826
|
+
// Relative path: ./hello.txt
|
|
2827
|
+
if (/^(\.\.?\/)+/i.test(filePathSlashes)) {
|
|
2828
|
+
return true;
|
|
2829
|
+
}
|
|
2830
|
+
return false;
|
|
2831
|
+
}
|
|
2832
|
+
|
|
2833
|
+
/**
|
|
2834
|
+
* Parses the knowledge command
|
|
2835
|
+
*
|
|
2836
|
+
* @see ./KNOWLEDGE-README.md for more details
|
|
2837
|
+
* @private within the commands folder
|
|
2838
|
+
*/
|
|
2839
|
+
var knowledgeCommandParser = {
|
|
2840
|
+
/**
|
|
2841
|
+
* Name of the command
|
|
2842
|
+
*/
|
|
2843
|
+
name: 'KNOWLEDGE',
|
|
2844
|
+
/**
|
|
2845
|
+
* BOILERPLATE command can be used in:
|
|
2846
|
+
*/
|
|
2847
|
+
usagePlaces: ['PIPELINE_HEAD'],
|
|
2848
|
+
/**
|
|
2849
|
+
* Description of the KNOWLEDGE command
|
|
2850
|
+
*/
|
|
2851
|
+
description: "Tells promptbook which external knowledge to use",
|
|
2852
|
+
/**
|
|
2853
|
+
* Link to discussion
|
|
2854
|
+
*/
|
|
2855
|
+
discussionUrl: 'https://github.com/webgptorg/promptbook/discussions/41',
|
|
2856
|
+
/**
|
|
2857
|
+
* Example usages of the KNOWLEDGE command
|
|
2858
|
+
*/
|
|
2859
|
+
examples: [
|
|
2860
|
+
'KNOWLEDGE https://www.pavolhejny.com/',
|
|
2861
|
+
'KNOWLEDGE ./hejny-cv.txt',
|
|
2862
|
+
'KNOWLEDGE ./hejny-cv.md',
|
|
2863
|
+
'KNOWLEDGE ./hejny-cv.pdf',
|
|
2864
|
+
'KNOWLEDGE ./hejny-cv.docx',
|
|
2865
|
+
],
|
|
2866
|
+
/**
|
|
2867
|
+
* Parses the KNOWLEDGE command
|
|
2868
|
+
*/
|
|
2869
|
+
parse: function (input) {
|
|
2870
|
+
var args = input.args;
|
|
2871
|
+
var source = args[0];
|
|
2872
|
+
if (source === undefined) {
|
|
2873
|
+
throw new ParsingError("Source is not defined");
|
|
2874
|
+
}
|
|
2875
|
+
if (source.startsWith('http://')) {
|
|
2876
|
+
throw new ParsingError("Source is not secure");
|
|
2877
|
+
}
|
|
2878
|
+
if (!(isValidFilePath(source) || isValidUrl(source))) {
|
|
2879
|
+
throw new ParsingError("Source not valid");
|
|
2880
|
+
}
|
|
2881
|
+
if (source.startsWith('../') || source.startsWith('/') || /^[A-Z]:[\\/]+/i.test(source)) {
|
|
2882
|
+
throw new ParsingError("Source cannot be outside of the .ptbk.md folder");
|
|
2883
|
+
}
|
|
2884
|
+
return {
|
|
2885
|
+
type: 'KNOWLEDGE',
|
|
2886
|
+
source: source,
|
|
2887
|
+
};
|
|
2888
|
+
},
|
|
2889
|
+
/**
|
|
2890
|
+
* Note: Prototype of [🍧] (remove this comment after full implementation)
|
|
2891
|
+
*/
|
|
2892
|
+
applyToPipelineJson: function (pipelineJson, personaCommand) {
|
|
2893
|
+
var source = personaCommand.source;
|
|
2894
|
+
var name = titleToName(source);
|
|
2895
|
+
pipelineJson.knowledgeSources.push({
|
|
2896
|
+
name: name,
|
|
2897
|
+
source: source,
|
|
2898
|
+
});
|
|
2899
|
+
},
|
|
2900
|
+
};
|
|
2901
|
+
|
|
2902
|
+
/**
|
|
2903
|
+
* Parses the persona command
|
|
2904
|
+
*
|
|
2905
|
+
* @see ./PERSONA-README.md for more details
|
|
2906
|
+
* @private within the commands folder
|
|
2907
|
+
*/
|
|
2908
|
+
var personaCommandParser = {
|
|
2909
|
+
/**
|
|
2910
|
+
* Name of the command
|
|
2911
|
+
*/
|
|
2912
|
+
name: 'PERSONA',
|
|
2913
|
+
/**
|
|
2914
|
+
* Aliases for the PERSONA command
|
|
2915
|
+
*/
|
|
2916
|
+
aliasNames: ['PERSON'],
|
|
2917
|
+
/**
|
|
2918
|
+
* PERSONA command can be used in:
|
|
2919
|
+
*/
|
|
2920
|
+
usagePlaces: ['PIPELINE_HEAD', 'PIPELINE_TEMPLATE'],
|
|
2921
|
+
/**
|
|
2922
|
+
* Description of the PERSONA command
|
|
2923
|
+
*/
|
|
2924
|
+
description: "Persona command is used to specify who the system is, it will be transformed into system message, top_t,...",
|
|
2925
|
+
/**
|
|
2926
|
+
* Link to discussion
|
|
2927
|
+
*/
|
|
2928
|
+
discussionUrl: 'https://github.com/webgptorg/promptbook/discussions/22',
|
|
2929
|
+
/**
|
|
2930
|
+
* Example usages of the PERSONA command
|
|
2931
|
+
*/
|
|
2932
|
+
examples: ['PERSONA Jane, skilled copywriter', 'PERSONA Joe, male 28 years old, programmer'],
|
|
2933
|
+
/**
|
|
2934
|
+
* Parses the PERSONA command
|
|
2935
|
+
*/
|
|
2936
|
+
parse: function (input) {
|
|
2937
|
+
var rawArgs = input.rawArgs;
|
|
2938
|
+
var _a = __read(rawArgs.split(/[,;:]/, 2), 2), personaNameRaw = _a[0], personaDescriptionRaw = _a[1];
|
|
2939
|
+
var personaName = (personaNameRaw || '').trim();
|
|
2940
|
+
if (personaName === '') {
|
|
2941
|
+
throw new ParsingError("You must set name for the persona");
|
|
2942
|
+
}
|
|
2943
|
+
var personaDescription = (personaDescriptionRaw || '').trim();
|
|
2944
|
+
if (personaDescription === '') {
|
|
2945
|
+
personaDescription = null;
|
|
2946
|
+
}
|
|
2947
|
+
return {
|
|
2948
|
+
type: 'PERSONA',
|
|
2949
|
+
personaName: personaName,
|
|
2950
|
+
personaDescription: personaDescription,
|
|
2951
|
+
};
|
|
2952
|
+
},
|
|
2953
|
+
/**
|
|
2954
|
+
* Note: Prototype of [🍧] (remove this comment after full implementation)
|
|
2955
|
+
*/
|
|
2956
|
+
applyToPipelineJson: function (pipelineJson, personaCommand) {
|
|
2957
|
+
var personaName = personaCommand.personaName, personaDescription = personaCommand.personaDescription;
|
|
2958
|
+
var persona = pipelineJson.personas.find(function (persona) { return persona.name === personaName; });
|
|
2959
|
+
if (persona === undefined) {
|
|
2960
|
+
pipelineJson.personas.push({
|
|
2961
|
+
name: personaName,
|
|
2962
|
+
description: personaDescription || '',
|
|
2963
|
+
});
|
|
2964
|
+
return;
|
|
2965
|
+
}
|
|
2966
|
+
if (persona.description === personaDescription) {
|
|
2967
|
+
return;
|
|
2968
|
+
}
|
|
2969
|
+
if (personaDescription === null) {
|
|
2970
|
+
return;
|
|
2971
|
+
}
|
|
2972
|
+
if (persona.description === '') {
|
|
2973
|
+
persona.description = personaDescription;
|
|
2974
|
+
return;
|
|
2975
|
+
}
|
|
2976
|
+
console.warn(spaceTrim__default["default"]("\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 ")));
|
|
2977
|
+
persona.description += spaceTrim__default["default"]('\n\n' + personaDescription);
|
|
2978
|
+
},
|
|
2979
|
+
};
|
|
2980
|
+
|
|
2757
2981
|
/**
|
|
2758
2982
|
* Removes Markdown formatting tags from a string.
|
|
2759
2983
|
*
|
|
@@ -2909,7 +3133,7 @@
|
|
|
2909
3133
|
'Knowledge BLOCK',
|
|
2910
3134
|
// 'Knowledge', // <- Note: [⛱] For execution blocks which are also separate commands shortcut does not work
|
|
2911
3135
|
//---
|
|
2912
|
-
/*
|
|
3136
|
+
/* Note: Not implemented block types will be in examples in future -> */
|
|
2913
3137
|
'Instrument BLOCK',
|
|
2914
3138
|
// 'Instrument', // <- Note: [⛱]
|
|
2915
3139
|
'Action BLOCK',
|
|
@@ -2925,13 +3149,12 @@
|
|
|
2925
3149
|
normalized = normalized.split('EXAMPLE').join('SAMPLE');
|
|
2926
3150
|
var blockTypes = BlockTypes.filter(function (blockType) { return normalized.includes(blockType); });
|
|
2927
3151
|
if (blockTypes.length !== 1) {
|
|
2928
|
-
// console.log('!!!', { blockType });
|
|
2929
3152
|
throw new ParsingError(spaceTrim__default["default"](function (block) { return "\n Unknown block type in BLOCK command\n\n Supported block types are:\n ".concat(block(BlockTypes.join(', ')), "\n "); }));
|
|
2930
3153
|
}
|
|
2931
|
-
|
|
3154
|
+
var blockType = blockTypes[0];
|
|
2932
3155
|
return {
|
|
2933
3156
|
type: 'BLOCK',
|
|
2934
|
-
blockType:
|
|
3157
|
+
blockType: blockType,
|
|
2935
3158
|
};
|
|
2936
3159
|
},
|
|
2937
3160
|
};
|
|
@@ -3174,92 +3397,12 @@
|
|
|
3174
3397
|
},
|
|
3175
3398
|
};
|
|
3176
3399
|
|
|
3177
|
-
/**
|
|
3178
|
-
* Tests if given string is valid URL.
|
|
3179
|
-
*
|
|
3180
|
-
* Note: This does not check if the file exists only if the path is valid
|
|
3181
|
-
*/
|
|
3182
|
-
function isValidFilePath(filePath) {
|
|
3183
|
-
if (typeof filePath !== 'string') {
|
|
3184
|
-
return false;
|
|
3185
|
-
}
|
|
3186
|
-
var filePathSlashes = filePath.split('\\').join('/');
|
|
3187
|
-
// Absolute Unix path: /hello.txt
|
|
3188
|
-
if (/^(\/)/i.test(filePathSlashes)) {
|
|
3189
|
-
return true;
|
|
3190
|
-
}
|
|
3191
|
-
// Absolute Windows path: /hello.txt
|
|
3192
|
-
if (/^([A-Z]{1,2}:\/?)\//i.test(filePathSlashes)) {
|
|
3193
|
-
return true;
|
|
3194
|
-
}
|
|
3195
|
-
// Relative path: ./hello.txt
|
|
3196
|
-
if (/^(\.\.?\/)+/i.test(filePathSlashes)) {
|
|
3197
|
-
return true;
|
|
3198
|
-
}
|
|
3199
|
-
return false;
|
|
3200
|
-
}
|
|
3201
|
-
|
|
3202
|
-
/**
|
|
3203
|
-
* Parses the knowledge command
|
|
3204
|
-
*
|
|
3205
|
-
* @see ./KNOWLEDGE-README.md for more details
|
|
3206
|
-
* @private within the commands folder
|
|
3207
|
-
*/
|
|
3208
|
-
var knowledgeCommandParser = {
|
|
3209
|
-
/**
|
|
3210
|
-
* Name of the command
|
|
3211
|
-
*/
|
|
3212
|
-
name: 'KNOWLEDGE',
|
|
3213
|
-
/**
|
|
3214
|
-
* BOILERPLATE command can be used in:
|
|
3215
|
-
*/
|
|
3216
|
-
usagePlaces: ['PIPELINE_HEAD'],
|
|
3217
|
-
/**
|
|
3218
|
-
* Description of the KNOWLEDGE command
|
|
3219
|
-
*/
|
|
3220
|
-
description: "Tells promptbook which external knowledge to use",
|
|
3221
|
-
/**
|
|
3222
|
-
* Link to discussion
|
|
3223
|
-
*/
|
|
3224
|
-
discussionUrl: 'https://github.com/webgptorg/promptbook/discussions/41',
|
|
3225
|
-
/**
|
|
3226
|
-
* Example usages of the KNOWLEDGE command
|
|
3227
|
-
*/
|
|
3228
|
-
examples: [
|
|
3229
|
-
'KNOWLEDGE https://www.pavolhejny.com/',
|
|
3230
|
-
'KNOWLEDGE ./hejny-cv.txt',
|
|
3231
|
-
'KNOWLEDGE ./hejny-cv.md',
|
|
3232
|
-
'KNOWLEDGE ./hejny-cv.pdf',
|
|
3233
|
-
'KNOWLEDGE ./hejny-cv.docx',
|
|
3234
|
-
],
|
|
3235
|
-
/**
|
|
3236
|
-
* Parses the KNOWLEDGE command
|
|
3237
|
-
*/
|
|
3238
|
-
parse: function (input) {
|
|
3239
|
-
var args = input.args;
|
|
3240
|
-
var source = args[0];
|
|
3241
|
-
if (source === undefined) {
|
|
3242
|
-
throw new ParsingError("Source is not defined");
|
|
3243
|
-
}
|
|
3244
|
-
if (source.startsWith('http://')) {
|
|
3245
|
-
throw new ParsingError("Source is not secure");
|
|
3246
|
-
}
|
|
3247
|
-
if (!(isValidFilePath(source) || isValidUrl(source))) {
|
|
3248
|
-
throw new ParsingError("Source not valid");
|
|
3249
|
-
}
|
|
3250
|
-
if (source.startsWith('../') || source.startsWith('/') || /^[A-Z]:[\\/]+/i.test(source)) {
|
|
3251
|
-
throw new ParsingError("Source cannot be outside of the .ptbk.md folder");
|
|
3252
|
-
}
|
|
3253
|
-
return {
|
|
3254
|
-
type: 'KNOWLEDGE',
|
|
3255
|
-
source: source,
|
|
3256
|
-
};
|
|
3257
|
-
},
|
|
3258
|
-
};
|
|
3259
|
-
|
|
3260
3400
|
var MODEL_VARIANTS = ['COMPLETION', 'CHAT', 'EMBEDDING' /* <- TODO [🏳] */ /* <- [🤖] */];
|
|
3261
3401
|
/**
|
|
3262
|
-
* TODO:
|
|
3402
|
+
* TODO: [🧠][🈁] `seed` should maybe be somewhere else (not in `ModelRequirements`) (simmilar that `user` identification is not here)
|
|
3403
|
+
* TODO: [🧠][💱] Add more model options: `stop_token`, `logit_bias`, `logprobs` (`top_logprobs`), `top_k`, `top_p`, `presence_penalty`, `frequency_penalty`, `bestOf`, `logitBias`, `logitBiasType`,...
|
|
3404
|
+
* [💱] Probbably keep using just `temperature` in Promptbook (not `top_k` and `top_p`)
|
|
3405
|
+
* TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
3263
3406
|
* TODO: Maybe figure out better word than "variant"
|
|
3264
3407
|
* TODO: Add here more requirement options like max context size, max tokens, etc.
|
|
3265
3408
|
* TODO: [💕][🧠] Just selecting gpt3 or gpt4 level of model
|
|
@@ -3401,59 +3544,6 @@
|
|
|
3401
3544
|
},
|
|
3402
3545
|
};
|
|
3403
3546
|
|
|
3404
|
-
/**
|
|
3405
|
-
* Parses the persona command
|
|
3406
|
-
*
|
|
3407
|
-
* @see ./PERSONA-README.md for more details
|
|
3408
|
-
* @private within the commands folder
|
|
3409
|
-
*/
|
|
3410
|
-
var personaCommandParser = {
|
|
3411
|
-
/**
|
|
3412
|
-
* Name of the command
|
|
3413
|
-
*/
|
|
3414
|
-
name: 'PERSONA',
|
|
3415
|
-
/**
|
|
3416
|
-
* Aliases for the PERSONA command
|
|
3417
|
-
*/
|
|
3418
|
-
aliasNames: ['PERSON'],
|
|
3419
|
-
/**
|
|
3420
|
-
* PERSONA command can be used in:
|
|
3421
|
-
*/
|
|
3422
|
-
usagePlaces: ['PIPELINE_HEAD', 'PIPELINE_TEMPLATE'],
|
|
3423
|
-
/**
|
|
3424
|
-
* Description of the PERSONA command
|
|
3425
|
-
*/
|
|
3426
|
-
description: "Persona command is used to specify who the system is, it will be transformed into system message, top_t,...",
|
|
3427
|
-
/**
|
|
3428
|
-
* Link to discussion
|
|
3429
|
-
*/
|
|
3430
|
-
discussionUrl: 'https://github.com/webgptorg/promptbook/discussions/22',
|
|
3431
|
-
/**
|
|
3432
|
-
* Example usages of the PERSONA command
|
|
3433
|
-
*/
|
|
3434
|
-
examples: ['PERSONA Jane, skilled copywriter', 'PERSONA Joe, male 28 years old, programmer'],
|
|
3435
|
-
/**
|
|
3436
|
-
* Parses the PERSONA command
|
|
3437
|
-
*/
|
|
3438
|
-
parse: function (input) {
|
|
3439
|
-
var rawArgs = input.rawArgs;
|
|
3440
|
-
var _a = __read(rawArgs.split(/[,;:]/, 2), 2), personaNameRaw = _a[0], personaDescriptionRaw = _a[1];
|
|
3441
|
-
var personaName = (personaNameRaw || '').trim();
|
|
3442
|
-
if (personaName === '') {
|
|
3443
|
-
throw new ParsingError("You must set name for the persona");
|
|
3444
|
-
}
|
|
3445
|
-
var personaDescription = (personaDescriptionRaw || '').trim();
|
|
3446
|
-
if (personaDescription === '') {
|
|
3447
|
-
personaDescription = null;
|
|
3448
|
-
}
|
|
3449
|
-
return {
|
|
3450
|
-
type: 'PERSONA',
|
|
3451
|
-
personaName: personaName,
|
|
3452
|
-
personaDescription: personaDescription,
|
|
3453
|
-
};
|
|
3454
|
-
},
|
|
3455
|
-
};
|
|
3456
|
-
|
|
3457
3547
|
function isValidJavascriptName(javascriptName) {
|
|
3458
3548
|
if (typeof javascriptName !== 'string') {
|
|
3459
3549
|
return false;
|
|
@@ -3671,7 +3761,8 @@
|
|
|
3671
3761
|
* Parses the ACTION command
|
|
3672
3762
|
*/
|
|
3673
3763
|
parse: function (input) {
|
|
3674
|
-
input.args;
|
|
3764
|
+
var args = input.args;
|
|
3765
|
+
TODO_USE(args);
|
|
3675
3766
|
return {
|
|
3676
3767
|
type: 'ACTION',
|
|
3677
3768
|
};
|
|
@@ -3709,7 +3800,8 @@
|
|
|
3709
3800
|
* Parses the INSTRUMENT command
|
|
3710
3801
|
*/
|
|
3711
3802
|
parse: function (input) {
|
|
3712
|
-
input.args;
|
|
3803
|
+
var args = input.args;
|
|
3804
|
+
TODO_USE(args);
|
|
3713
3805
|
return {
|
|
3714
3806
|
type: 'INSTRUMENT',
|
|
3715
3807
|
};
|
|
@@ -3767,6 +3859,7 @@
|
|
|
3767
3859
|
};
|
|
3768
3860
|
/**
|
|
3769
3861
|
* TODO: [💐] Implement BOILERPLATE command into `pipelineStringToJsonSync` function
|
|
3862
|
+
* Note: [⚪] This should never be in any released package
|
|
3770
3863
|
*/
|
|
3771
3864
|
|
|
3772
3865
|
/**
|
|
@@ -3785,7 +3878,7 @@
|
|
|
3785
3878
|
actionCommandParser,
|
|
3786
3879
|
instrumentCommandParser,
|
|
3787
3880
|
personaCommandParser,
|
|
3788
|
-
boilerplateCommandParser, // <- TODO:
|
|
3881
|
+
boilerplateCommandParser, // <- TODO: !! Only in development, remove in production
|
|
3789
3882
|
];
|
|
3790
3883
|
|
|
3791
3884
|
/**
|
|
@@ -3871,7 +3964,7 @@
|
|
|
3871
3964
|
}));
|
|
3872
3965
|
}
|
|
3873
3966
|
/**
|
|
3874
|
-
*
|
|
3967
|
+
* @@@
|
|
3875
3968
|
*/
|
|
3876
3969
|
function getSupportedCommandsMessage() {
|
|
3877
3970
|
return COMMANDS.flatMap(function (_a) {
|
|
@@ -3882,7 +3975,7 @@
|
|
|
3882
3975
|
}).join('\n');
|
|
3883
3976
|
}
|
|
3884
3977
|
/**
|
|
3885
|
-
*
|
|
3978
|
+
* @@@
|
|
3886
3979
|
*/
|
|
3887
3980
|
function parseCommandVariant(input) {
|
|
3888
3981
|
var e_1, _a;
|
|
@@ -3891,7 +3984,6 @@
|
|
|
3891
3984
|
var _loop_1 = function (commandParser) {
|
|
3892
3985
|
var name_1 = commandParser.name, aliasNames = commandParser.aliasNames, deprecatedNames = commandParser.deprecatedNames, parse = commandParser.parse;
|
|
3893
3986
|
var names = __spreadArray(__spreadArray([name_1], __read((aliasNames || [])), false), __read((deprecatedNames || [])), false);
|
|
3894
|
-
// console.log('!!!', { commandName, names });
|
|
3895
3987
|
if (names.includes(commandName)) {
|
|
3896
3988
|
try {
|
|
3897
3989
|
return { value: parse({ usagePlace: usagePlace, raw: raw, rawArgs: rawArgs, normalized: normalized, args: args }) };
|
|
@@ -4001,25 +4093,42 @@
|
|
|
4001
4093
|
var e_1, _a;
|
|
4002
4094
|
var codeBlocks = [];
|
|
4003
4095
|
var lines = markdown.split('\n');
|
|
4096
|
+
// Note: [0] Ensure that the last block notated by gt > will be closed
|
|
4097
|
+
lines.push('');
|
|
4004
4098
|
var currentCodeBlock = null;
|
|
4005
4099
|
try {
|
|
4006
4100
|
for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
|
|
4007
4101
|
var line = lines_1_1.value;
|
|
4102
|
+
if (line.startsWith('> ') || line === '>') {
|
|
4103
|
+
if (currentCodeBlock === null) {
|
|
4104
|
+
currentCodeBlock = { blockNotation: '>', language: null, content: '' };
|
|
4105
|
+
} /* not else */
|
|
4106
|
+
if (currentCodeBlock.blockNotation === '>') {
|
|
4107
|
+
if (currentCodeBlock.content !== '') {
|
|
4108
|
+
currentCodeBlock.content += '\n';
|
|
4109
|
+
}
|
|
4110
|
+
currentCodeBlock.content += line.slice(2);
|
|
4111
|
+
}
|
|
4112
|
+
}
|
|
4113
|
+
else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '>' /* <- Note: [0] */) {
|
|
4114
|
+
codeBlocks.push(currentCodeBlock);
|
|
4115
|
+
currentCodeBlock = null;
|
|
4116
|
+
}
|
|
4117
|
+
/* not else */
|
|
4008
4118
|
if (line.startsWith('```')) {
|
|
4009
4119
|
var language = line.slice(3).trim() || null;
|
|
4010
4120
|
if (currentCodeBlock === null) {
|
|
4011
|
-
currentCodeBlock = { language: language, content: '' };
|
|
4121
|
+
currentCodeBlock = { blockNotation: '```', language: language, content: '' };
|
|
4012
4122
|
}
|
|
4013
4123
|
else {
|
|
4014
4124
|
if (language !== null) {
|
|
4015
|
-
|
|
4016
|
-
throw new Error("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed and already opening new ").concat(language, " code block"));
|
|
4125
|
+
throw new ParsingError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed and already opening new ").concat(language, " code block"));
|
|
4017
4126
|
}
|
|
4018
4127
|
codeBlocks.push(currentCodeBlock);
|
|
4019
4128
|
currentCodeBlock = null;
|
|
4020
4129
|
}
|
|
4021
4130
|
}
|
|
4022
|
-
else if (currentCodeBlock !== null) {
|
|
4131
|
+
else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '```') {
|
|
4023
4132
|
if (currentCodeBlock.content !== '') {
|
|
4024
4133
|
currentCodeBlock.content += '\n';
|
|
4025
4134
|
}
|
|
@@ -4035,11 +4144,13 @@
|
|
|
4035
4144
|
finally { if (e_1) throw e_1.error; }
|
|
4036
4145
|
}
|
|
4037
4146
|
if (currentCodeBlock !== null) {
|
|
4038
|
-
|
|
4039
|
-
throw new Error("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed at the end of the markdown"));
|
|
4147
|
+
throw new ParsingError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed at the end of the markdown"));
|
|
4040
4148
|
}
|
|
4041
4149
|
return codeBlocks;
|
|
4042
4150
|
}
|
|
4151
|
+
/**
|
|
4152
|
+
* TODO: Maybe name for `blockNotation` instead of '```' and '>'
|
|
4153
|
+
*/
|
|
4043
4154
|
|
|
4044
4155
|
/**
|
|
4045
4156
|
* Extracts exactly ONE code block from markdown.
|
|
@@ -4057,13 +4168,12 @@
|
|
|
4057
4168
|
function extractOneBlockFromMarkdown(markdown) {
|
|
4058
4169
|
var codeBlocks = extractAllBlocksFromMarkdown(markdown);
|
|
4059
4170
|
if (codeBlocks.length !== 1) {
|
|
4060
|
-
|
|
4061
|
-
throw new Error(/* <- [🌻] */ 'There should be exactly one code block in the markdown');
|
|
4171
|
+
throw new ParsingError(spaceTrim__default["default"](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 "); }));
|
|
4062
4172
|
}
|
|
4063
4173
|
return codeBlocks[0];
|
|
4064
4174
|
}
|
|
4065
4175
|
/***
|
|
4066
|
-
* TODO: [🍓][🌻]
|
|
4176
|
+
* TODO: [🍓][🌻] Decide of this is internal util, external util OR validator/postprocessor
|
|
4067
4177
|
*/
|
|
4068
4178
|
|
|
4069
4179
|
/**
|
|
@@ -4073,13 +4183,13 @@
|
|
|
4073
4183
|
var _a, _b;
|
|
4074
4184
|
var lines = value.split('\n');
|
|
4075
4185
|
if (!lines[0].startsWith('#')) {
|
|
4076
|
-
throw new
|
|
4186
|
+
throw new ParsingError('Markdown section must start with heading');
|
|
4077
4187
|
}
|
|
4078
4188
|
var title = lines[0].replace(/^#+\s*/, '');
|
|
4079
4189
|
var level = (_b = (_a = lines[0].match(/^#+/)) === null || _a === void 0 ? void 0 : _a[0].length) !== null && _b !== void 0 ? _b : 0;
|
|
4080
4190
|
var content = spaceTrim__default["default"](lines.slice(1).join('\n'));
|
|
4081
4191
|
if (level < 1 || level > 6) {
|
|
4082
|
-
throw new
|
|
4192
|
+
throw new ParsingError('Markdown section must have heading level between 1 and 6');
|
|
4083
4193
|
}
|
|
4084
4194
|
return { title: title, level: level, content: content };
|
|
4085
4195
|
}
|
|
@@ -4461,7 +4571,7 @@
|
|
|
4461
4571
|
existingParameter.description &&
|
|
4462
4572
|
existingParameter.description !== parameterDescription &&
|
|
4463
4573
|
parameterDescription) {
|
|
4464
|
-
throw new ParsingError(spaceTrim.spaceTrim(function (block) { return "\n Parameter {".concat(parameterName, "} is defined multiple times with different description
|
|
4574
|
+
throw new ParsingError(spaceTrim.spaceTrim(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 "); }));
|
|
4465
4575
|
}
|
|
4466
4576
|
if (existingParameter) {
|
|
4467
4577
|
if (parameterDescription) {
|
|
@@ -4480,11 +4590,12 @@
|
|
|
4480
4590
|
// =============================================================
|
|
4481
4591
|
// Note: 3️⃣ Process pipeline head
|
|
4482
4592
|
pipelineJson.title = pipelineHead.title;
|
|
4483
|
-
// TODO: [1] DRY description
|
|
4593
|
+
// TODO: [🎾][1] DRY description
|
|
4484
4594
|
var description = pipelineHead.content;
|
|
4485
|
-
// Note: Remove codeblocks - TODO:
|
|
4595
|
+
// Note: Remove codeblocks - TODO: [🎾] Make util removeAllBlocksFromMarkdown (exported from `@promptbool/utils`)
|
|
4486
4596
|
description = description.split(/^```.*^```/gms).join('');
|
|
4487
|
-
|
|
4597
|
+
description = description.split(/^>.*$/gm).join('');
|
|
4598
|
+
//Note: Remove lists and return statement - TODO: [🎾] Make util (exported from `@promptbool/utils`)
|
|
4488
4599
|
description = description.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
4489
4600
|
description = spaceTrim.spaceTrim(description);
|
|
4490
4601
|
if (description === '') {
|
|
@@ -4512,7 +4623,7 @@
|
|
|
4512
4623
|
pipelineJson.pipelineUrl = command.pipelineUrl.href;
|
|
4513
4624
|
break;
|
|
4514
4625
|
case 'KNOWLEDGE':
|
|
4515
|
-
|
|
4626
|
+
knowledgeCommandParser.applyToPipelineJson(pipelineJson, command);
|
|
4516
4627
|
break;
|
|
4517
4628
|
case 'ACTION':
|
|
4518
4629
|
console.error(new NotYetImplementedError('Actions are not implemented yet'));
|
|
@@ -4521,7 +4632,8 @@
|
|
|
4521
4632
|
console.error(new NotYetImplementedError('Instruments are not implemented yet'));
|
|
4522
4633
|
break;
|
|
4523
4634
|
case 'PERSONA':
|
|
4524
|
-
|
|
4635
|
+
personaCommandParser.applyToPipelineJson(pipelineJson, command);
|
|
4636
|
+
// <- Note: Prototype of [🍧] (remove this comment after full implementation)
|
|
4525
4637
|
break;
|
|
4526
4638
|
case 'BOILERPLATE':
|
|
4527
4639
|
throw new ParsingError('BOILERPLATE command is only for testing purposes and should not be used in the .ptbk.md file'); // <- TODO: [🚞]
|
|
@@ -4550,7 +4662,27 @@
|
|
|
4550
4662
|
var postprocessing = [];
|
|
4551
4663
|
var expectAmount = {};
|
|
4552
4664
|
var expectFormat = undefined;
|
|
4553
|
-
var
|
|
4665
|
+
var isBlockTypeSet = false;
|
|
4666
|
+
var lastLine = section.content.split('\n').pop();
|
|
4667
|
+
var resultingParameterNameMatch = /^->\s*\{(?<resultingParamName>[a-z0-9_]+)\}/im.exec(lastLine);
|
|
4668
|
+
var resultingParameterName = null;
|
|
4669
|
+
if (resultingParameterNameMatch &&
|
|
4670
|
+
resultingParameterNameMatch.groups !== undefined &&
|
|
4671
|
+
resultingParameterNameMatch.groups.resultingParamName !== undefined) {
|
|
4672
|
+
resultingParameterName = resultingParameterNameMatch.groups.resultingParamName;
|
|
4673
|
+
}
|
|
4674
|
+
var expectResultingParameterName = function () {
|
|
4675
|
+
if (resultingParameterName !== null) {
|
|
4676
|
+
return resultingParameterName;
|
|
4677
|
+
}
|
|
4678
|
+
throw new ParsingError(spaceTrim.spaceTrim(function (block) { return "\n Template section must end with -> {parameterName}\n\n Invalid section:\n ".concat(block(
|
|
4679
|
+
// TODO: Show code of invalid sections each time + DRY
|
|
4680
|
+
section.content
|
|
4681
|
+
.split('\n')
|
|
4682
|
+
.map(function (line) { return " | ".concat(line); } /* <- TODO: [🚞] */)
|
|
4683
|
+
.join('\n')), "\n "); }));
|
|
4684
|
+
};
|
|
4685
|
+
var _e = extractOneBlockFromMarkdown(section.content), language = _e.language, content = _e.content;
|
|
4554
4686
|
try {
|
|
4555
4687
|
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()) {
|
|
4556
4688
|
var listItem = listItems_2_1.value;
|
|
@@ -4558,15 +4690,24 @@
|
|
|
4558
4690
|
switch (command.type) {
|
|
4559
4691
|
// TODO: [🍧] Use here applyToPipelineJson and remove switch statement
|
|
4560
4692
|
case 'BLOCK':
|
|
4561
|
-
if (
|
|
4693
|
+
if (isBlockTypeSet) {
|
|
4562
4694
|
throw new ParsingError('Block type is already defined in the prompt template. It can be defined only once.');
|
|
4563
4695
|
}
|
|
4564
4696
|
if (command.blockType === 'SAMPLE') {
|
|
4565
|
-
|
|
4697
|
+
expectResultingParameterName();
|
|
4698
|
+
var parameter = pipelineJson.parameters.find(function (param) { return param.name === resultingParameterName; });
|
|
4699
|
+
if (parameter === undefined) {
|
|
4700
|
+
throw new UnexpectedError("Can not find parameter {".concat(resultingParameterName, "} to assign sample value"));
|
|
4701
|
+
}
|
|
4702
|
+
parameter.sampleValues = parameter.sampleValues || [];
|
|
4703
|
+
parameter.sampleValues.push(content);
|
|
4566
4704
|
return "continue-templates";
|
|
4567
4705
|
}
|
|
4568
4706
|
if (command.blockType === 'KNOWLEDGE') {
|
|
4569
|
-
|
|
4707
|
+
knowledgeCommandParser.applyToPipelineJson(pipelineJson, {
|
|
4708
|
+
type: 'KNOWLEDGE',
|
|
4709
|
+
source: content, // <- TODO: [🐝] !!!! Work with KNOWLEDGE which not referring to the source file/wweb, but its content itself
|
|
4710
|
+
});
|
|
4570
4711
|
return "continue-templates";
|
|
4571
4712
|
}
|
|
4572
4713
|
if (command.blockType === 'ACTION') {
|
|
@@ -4577,8 +4718,9 @@
|
|
|
4577
4718
|
console.error(new NotYetImplementedError('Instruments are not implemented yet'));
|
|
4578
4719
|
return "continue-templates";
|
|
4579
4720
|
}
|
|
4721
|
+
expectResultingParameterName();
|
|
4580
4722
|
blockType = command.blockType;
|
|
4581
|
-
|
|
4723
|
+
isBlockTypeSet = true;
|
|
4582
4724
|
break;
|
|
4583
4725
|
case 'EXPECT_AMOUNT':
|
|
4584
4726
|
// eslint-disable-next-line no-case-declarations
|
|
@@ -4618,16 +4760,20 @@
|
|
|
4618
4760
|
postprocessing.push(command.functionName);
|
|
4619
4761
|
break;
|
|
4620
4762
|
case 'KNOWLEDGE':
|
|
4621
|
-
|
|
4763
|
+
// TODO: [👙] The knowledge is maybe relevant for just this template
|
|
4764
|
+
knowledgeCommandParser.applyToPipelineJson(pipelineJson, command);
|
|
4622
4765
|
break;
|
|
4623
4766
|
case 'ACTION':
|
|
4767
|
+
// TODO: [👙] The action is maybe relevant for just this template
|
|
4624
4768
|
console.error(new NotYetImplementedError('Actions are not implemented yet'));
|
|
4625
4769
|
break;
|
|
4626
4770
|
case 'INSTRUMENT':
|
|
4771
|
+
// TODO: [👙] The instrument is maybe relevant for just this template
|
|
4627
4772
|
console.error(new NotYetImplementedError('Instruments are not implemented yet'));
|
|
4628
4773
|
break;
|
|
4629
4774
|
case 'PERSONA':
|
|
4630
|
-
|
|
4775
|
+
personaCommandParser.applyToPipelineJson(pipelineJson, command);
|
|
4776
|
+
// <- Note: Prototype of [🍧] (remove this comment after full implementation)
|
|
4631
4777
|
break;
|
|
4632
4778
|
case 'BOILERPLATE':
|
|
4633
4779
|
console.error(new ParsingError('BOILERPLATE command is only for testing purposes and should not be used in the .ptbk.md file'));
|
|
@@ -4645,7 +4791,6 @@
|
|
|
4645
4791
|
}
|
|
4646
4792
|
finally { if (e_3) throw e_3.error; }
|
|
4647
4793
|
}
|
|
4648
|
-
var _e = extractOneBlockFromMarkdown(section.content), language = _e.language, content = _e.content;
|
|
4649
4794
|
if (blockType === 'SCRIPT') {
|
|
4650
4795
|
if (!language) {
|
|
4651
4796
|
throw new ParsingError('You must specify the language of the script in the prompt template');
|
|
@@ -4654,22 +4799,12 @@
|
|
|
4654
4799
|
throw new ParsingError(spaceTrim.spaceTrim(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 "); }));
|
|
4655
4800
|
}
|
|
4656
4801
|
}
|
|
4657
|
-
|
|
4658
|
-
var match = /^->\s*\{(?<resultingParamName>[a-z0-9_]+)\}/im.exec(lastLine);
|
|
4659
|
-
if (!match || match.groups === undefined || match.groups.resultingParamName === undefined) {
|
|
4660
|
-
throw new ParsingError(spaceTrim.spaceTrim(function (block) { return "\n Each section must end with -> {parameterName}\n\n Invalid section:\n ".concat(block(
|
|
4661
|
-
// TODO: Show code of invalid sections each time + DRY
|
|
4662
|
-
section.content
|
|
4663
|
-
.split('\n')
|
|
4664
|
-
.map(function (line) { return " | ".concat(line); } /* <- TODO: [🚞] */)
|
|
4665
|
-
.join('\n')), "\n "); }));
|
|
4666
|
-
}
|
|
4667
|
-
var resultingParameterName = match.groups.resultingParamName;
|
|
4668
|
-
// TODO: [1] DRY description
|
|
4802
|
+
// TODO: [🎾][1] DRY description
|
|
4669
4803
|
var description_1 = section.content;
|
|
4670
|
-
// Note: Remove codeblocks
|
|
4804
|
+
// Note: Remove codeblocks - TODO: [🎾]
|
|
4671
4805
|
description_1 = description_1.split(/^```.*^```/gms).join('');
|
|
4672
|
-
|
|
4806
|
+
description_1 = description_1.split(/^>.*$/gm).join('');
|
|
4807
|
+
//Note: Remove lists and return statement - TODO: [🎾]
|
|
4673
4808
|
description_1 = description_1.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
4674
4809
|
description_1 = spaceTrim.spaceTrim(description_1);
|
|
4675
4810
|
if (description_1 === '') {
|
|
@@ -4703,13 +4838,13 @@
|
|
|
4703
4838
|
modelRequirements: templateModelRequirements,
|
|
4704
4839
|
contentLanguage: blockType === 'SCRIPT' ? language : undefined,
|
|
4705
4840
|
content: content,
|
|
4706
|
-
resultingParameterName:
|
|
4841
|
+
resultingParameterName: expectResultingParameterName( /* <- Note: This is once more redundant */),
|
|
4707
4842
|
};
|
|
4708
4843
|
if (blockType !== 'PROMPT_TEMPLATE') {
|
|
4709
4844
|
delete template.modelRequirements;
|
|
4710
4845
|
}
|
|
4711
4846
|
// TODO: [🍧] What actually about preparation and pushing the block into `promptTemplates`
|
|
4712
|
-
pipelineJson.promptTemplates.push(template
|
|
4847
|
+
pipelineJson.promptTemplates.push(template);
|
|
4713
4848
|
};
|
|
4714
4849
|
try {
|
|
4715
4850
|
// =============================================================
|
|
@@ -4776,6 +4911,8 @@
|
|
|
4776
4911
|
* TODO: Use spaceTrim more effectively
|
|
4777
4912
|
* TODO: [🧠] Parameter flags - isInput, isOutput, isInternal
|
|
4778
4913
|
* TODO: [🥞] Not optimal parsing because `splitMarkdownIntoSections` is executed twice with same string, once through `flattenMarkdown` and second directly here
|
|
4914
|
+
* TODO: [♈] Probbably move expectations from templates to parameters
|
|
4915
|
+
* TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
4779
4916
|
*/
|
|
4780
4917
|
|
|
4781
4918
|
/**
|
|
@@ -4815,6 +4952,7 @@
|
|
|
4815
4952
|
}
|
|
4816
4953
|
/**
|
|
4817
4954
|
* TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
|
|
4955
|
+
* TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
4818
4956
|
*/
|
|
4819
4957
|
|
|
4820
4958
|
/**
|
|
@@ -4843,6 +4981,9 @@
|
|
|
4843
4981
|
* Detects if the code is running in a web worker
|
|
4844
4982
|
*/
|
|
4845
4983
|
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");
|
|
4984
|
+
/**
|
|
4985
|
+
* TODO: [🔼] !!! Export via `@promptbook/utils`
|
|
4986
|
+
*/
|
|
4846
4987
|
|
|
4847
4988
|
/**
|
|
4848
4989
|
* Constructs Promptbook from async sources
|
|
@@ -4961,6 +5102,7 @@
|
|
|
4961
5102
|
else {
|
|
4962
5103
|
colors__default["default"].green("(In future, not implemented yet) Using your prebuild pipeline collection ".concat(makedLibraryFilePath));
|
|
4963
5104
|
// TODO: !! Implement;
|
|
5105
|
+
// TODO: [🌗]
|
|
4964
5106
|
}
|
|
4965
5107
|
_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;
|
|
4966
5108
|
collection = createCollectionFromPromise(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
@@ -5005,6 +5147,7 @@
|
|
|
5005
5147
|
case 5:
|
|
5006
5148
|
// TODO: Handle non-valid JSON files
|
|
5007
5149
|
promptbook = _d.apply(_c, [_e.sent()]);
|
|
5150
|
+
// TODO: [🌗]
|
|
5008
5151
|
promptbook = __assign(__assign({}, promptbook), { sourceFile: sourceFile });
|
|
5009
5152
|
return [3 /*break*/, 7];
|
|
5010
5153
|
case 6:
|
|
@@ -5151,6 +5294,7 @@
|
|
|
5151
5294
|
}
|
|
5152
5295
|
/**
|
|
5153
5296
|
* TODO: !!!! [🧠] Library precompilation and do not mix markdown and json promptbooks
|
|
5297
|
+
* Note: [🟢] This code should never be published outside of `@promptbook/node`
|
|
5154
5298
|
*/
|
|
5155
5299
|
|
|
5156
5300
|
exports.PROMPTBOOK_VERSION = PROMPTBOOK_VERSION;
|