@promptbook/pdf 0.89.0-9 โ 0.92.0-10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -7
- package/esm/index.es.js +303 -68
- package/esm/index.es.js.map +1 -1
- package/esm/typings/servers.d.ts +40 -0
- package/esm/typings/src/_packages/core.index.d.ts +14 -4
- package/esm/typings/src/_packages/deepseek.index.d.ts +2 -0
- package/esm/typings/src/_packages/google.index.d.ts +2 -0
- package/esm/typings/src/_packages/types.index.d.ts +18 -0
- package/esm/typings/src/_packages/utils.index.d.ts +6 -0
- package/esm/typings/src/cli/cli-commands/login.d.ts +0 -1
- package/esm/typings/src/cli/common/$provideLlmToolsForCli.d.ts +16 -3
- package/esm/typings/src/cli/test/ptbk.d.ts +1 -1
- package/esm/typings/src/commands/EXPECT/expectCommandParser.d.ts +2 -0
- package/esm/typings/src/config.d.ts +10 -19
- package/esm/typings/src/conversion/archive/loadArchive.d.ts +2 -2
- package/esm/typings/src/errors/0-index.d.ts +7 -4
- package/esm/typings/src/errors/PipelineExecutionError.d.ts +1 -1
- package/esm/typings/src/errors/WrappedError.d.ts +10 -0
- package/esm/typings/src/errors/assertsError.d.ts +11 -0
- package/esm/typings/src/execution/CommonToolsOptions.d.ts +4 -0
- package/esm/typings/src/execution/PromptbookFetch.d.ts +1 -1
- package/esm/typings/src/execution/createPipelineExecutor/getKnowledgeForTask.d.ts +12 -0
- package/esm/typings/src/execution/createPipelineExecutor/getReservedParametersForTask.d.ts +5 -0
- package/esm/typings/src/formats/csv/utils/csvParse.d.ts +12 -0
- package/esm/typings/src/formats/csv/utils/isValidCsvString.d.ts +9 -0
- package/esm/typings/src/formats/csv/utils/isValidCsvString.test.d.ts +1 -0
- package/esm/typings/src/formats/json/utils/isValidJsonString.d.ts +3 -0
- package/esm/typings/src/formats/json/utils/jsonParse.d.ts +11 -0
- package/esm/typings/src/formats/xml/utils/isValidXmlString.d.ts +9 -0
- package/esm/typings/src/formats/xml/utils/isValidXmlString.test.d.ts +1 -0
- package/esm/typings/src/llm-providers/_common/filterModels.d.ts +15 -0
- package/esm/typings/src/llm-providers/_common/register/{$provideEnvFilepath.d.ts โ $provideEnvFilename.d.ts} +2 -2
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsConfigurationFromEnv.d.ts +1 -1
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForTestingAndScriptsAndPlayground.d.ts +1 -1
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForWizzardOrCli.d.ts +11 -2
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsFromEnv.d.ts +1 -1
- package/esm/typings/src/llm-providers/_common/register/LlmToolsMetadata.d.ts +43 -0
- package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.d.ts +4 -0
- package/esm/typings/src/llm-providers/deepseek/deepseek-models.d.ts +23 -0
- package/esm/typings/src/llm-providers/google/google-models.d.ts +23 -0
- package/esm/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +4 -0
- package/esm/typings/src/personas/preparePersona.d.ts +1 -1
- package/esm/typings/src/pipeline/PipelineJson/PersonaJson.d.ts +4 -2
- package/esm/typings/src/remote-server/openapi-types.d.ts +626 -0
- package/esm/typings/src/remote-server/openapi.d.ts +581 -0
- package/esm/typings/src/remote-server/socket-types/_subtypes/Identification.d.ts +7 -1
- package/esm/typings/src/remote-server/socket-types/_subtypes/identificationToPromptbookToken.d.ts +11 -0
- package/esm/typings/src/remote-server/socket-types/_subtypes/promptbookTokenToIdentification.d.ts +10 -0
- package/esm/typings/src/remote-server/startRemoteServer.d.ts +1 -2
- package/esm/typings/src/remote-server/types/RemoteServerOptions.d.ts +15 -9
- package/esm/typings/src/storage/env-storage/$EnvStorage.d.ts +40 -0
- package/esm/typings/src/types/typeAliases.d.ts +26 -0
- package/package.json +9 -5
- package/umd/index.umd.js +303 -68
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/cli/test/ptbk2.d.ts +0 -5
package/umd/index.umd.js
CHANGED
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
* @generated
|
|
26
26
|
* @see https://github.com/webgptorg/promptbook
|
|
27
27
|
*/
|
|
28
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.
|
|
28
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.92.0-10';
|
|
29
29
|
/**
|
|
30
30
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
31
31
|
* Note: [๐] Ignore a discrepancy between file name and entity name
|
|
@@ -88,6 +88,7 @@
|
|
|
88
88
|
* @public exported from `@promptbook/core`
|
|
89
89
|
*/
|
|
90
90
|
const ADMIN_GITHUB_NAME = 'hejny';
|
|
91
|
+
// <- TODO: [๐] Pick the best claim
|
|
91
92
|
/**
|
|
92
93
|
* When the title is not provided, the default title is used
|
|
93
94
|
*
|
|
@@ -120,6 +121,7 @@
|
|
|
120
121
|
infinity: '(infinity; โ)',
|
|
121
122
|
negativeInfinity: '(negative infinity; -โ)',
|
|
122
123
|
unserializable: '(unserializable value)',
|
|
124
|
+
circular: '(circular JSON)',
|
|
123
125
|
};
|
|
124
126
|
/**
|
|
125
127
|
* Small number limit
|
|
@@ -159,7 +161,7 @@
|
|
|
159
161
|
*/
|
|
160
162
|
const DEFAULT_MAX_EXECUTION_ATTEMPTS = 10; // <- TODO: [๐คนโโ๏ธ]
|
|
161
163
|
// <- TODO: [๐] Make also `BOOKS_DIRNAME_ALTERNATIVES`
|
|
162
|
-
// TODO:
|
|
164
|
+
// TODO: Just `.promptbook` in config, hardcode subfolders like `download-cache` or `execution-cache`
|
|
163
165
|
/**
|
|
164
166
|
* Where to store the temporary downloads
|
|
165
167
|
*
|
|
@@ -857,7 +859,7 @@
|
|
|
857
859
|
* Note: [๐ข] Code in this file should never be never released in packages that could be imported into browser environment
|
|
858
860
|
*/
|
|
859
861
|
|
|
860
|
-
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.book",formfactorName:"GENERIC",parameters:[{name:"knowledgeContent",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",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> {knowledgeContent}",resultingParameterName:"knowledgePieces",dependentParameterNames:["knowledgeContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Knowledge from Markdown\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.book`\n- INPUT PARAMETER `{knowledgeContent}` Markdown document content\n- OUTPUT PARAMETER `{knowledgePieces}` The knowledge JSON object\n\n## Knowledge\n\n<!-- TODO: [๐] -FORMAT JSON -->\n\n```markdown\nYou 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> {knowledgeContent}\n```\n\n`-> {knowledgePieces}`\n"}],sourceFile:"./books/prepare-knowledge-from-markdown.book"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.book",formfactorName:"GENERIC",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",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> {knowledgePieceContent}",resultingParameterName:"keywords",dependentParameterNames:["knowledgePieceContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Keywords\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-knowledge-keywords.book`\n- INPUT PARAMETER `{knowledgePieceContent}` The content\n- OUTPUT PARAMETER `{keywords}` Keywords separated by comma\n\n## Knowledge\n\n<!-- TODO: [๐] -FORMAT JSON -->\n\n```markdown\nYou 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> {knowledgePieceContent}\n```\n\n`-> {keywords}`\n"}],sourceFile:"./books/prepare-knowledge-keywords.book"},{title:"Prepare Knowledge-piece Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.book",formfactorName:"GENERIC",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",content:"You are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Write maximum 5 words for the title\n\n# The document\n\n> {knowledgePieceContent}",resultingParameterName:"title",expectations:{words:{min:1,max:8}},dependentParameterNames:["knowledgePieceContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Knowledge-piece Title\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-knowledge-title.book`\n- INPUT PARAMETER `{knowledgePieceContent}` The content\n- OUTPUT PARAMETER `{title}` The title of the document\n\n## Knowledge\n\n- EXPECT MIN 1 WORD\n- EXPECT MAX 8 WORDS\n\n```markdown\nYou are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Write maximum 5 words for the title\n\n# The document\n\n> {knowledgePieceContent}\n```\n\n`-> {title}`\n"}],sourceFile:"./books/prepare-knowledge-title.book"},{title:"Prepare Persona",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.book",formfactorName:"GENERIC",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}],tasks:[{taskType:"PROMPT_TASK",name:"make-model-requirements",title:"Make modelRequirements",content:"You are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Example\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- Your output format is JSON object\n- Write just the JSON object, no other text should be present\n- It contains the following keys:\n - `modelName`: The name of the model to use\n - `systemMessage`: The system message to provide context to the model\n - `temperature`: The sampling temperature to use\n\n### Key `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Key `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### Key `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",format:"JSON",dependentParameterNames:["availableModelNames","personaDescription"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Persona\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-persona.book`\n- INPUT PARAMETER `{availableModelNames}` List of available model names separated by comma (,)\n- INPUT PARAMETER `{personaDescription}` Description of the persona\n- OUTPUT PARAMETER `{modelRequirements}` Specific requirements for the model\n\n## Make modelRequirements\n\n- FORMAT JSON\n\n```markdown\nYou are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Example\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- Your output format is JSON object\n- Write just the JSON object, no other text should be present\n- It contains the following keys:\n - `modelName`: The name of the model to use\n - `systemMessage`: The system message to provide context to the model\n - `temperature`: The sampling temperature to use\n\n### Key `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Key `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### Key `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}\n```\n\n`-> {modelRequirements}`\n"}],sourceFile:"./books/prepare-persona.book"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-title.book",formfactorName:"GENERIC",parameters:[{name:"book",description:"The book to prepare the title for",isInput:true,isOutput:false},{name:"title",description:"Best title for the book",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"make-title",title:"Make title",content:"Make best title for given text which describes the workflow:\n\n## Rules\n\n- Write just title, nothing else\n- Title should be concise and clear - Write maximum ideally 2 words, maximum 5 words\n- Title starts with emoticon\n- Title should not mention the input and output of the workflow but the main purpose of the workflow\n _For example, not \"โ Convert Knowledge-piece to title\" but \"โ Title\"_\n\n## The workflow\n\n> {book}",resultingParameterName:"title",expectations:{words:{min:1,max:8},lines:{min:1,max:1}},dependentParameterNames:["book"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Title\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-title.book`\n- INPUT PARAMETER `{book}` The book to prepare the title for\n- OUTPUT PARAMETER `{title}` Best title for the book\n\n## Make title\n\n- EXPECT MIN 1 Word\n- EXPECT MAX 8 Words\n- EXPECT EXACTLY 1 Line\n\n```markdown\nMake best title for given text which describes the workflow:\n\n## Rules\n\n- Write just title, nothing else\n- Title should be concise and clear - Write maximum ideally 2 words, maximum 5 words\n- Title starts with emoticon\n- Title should not mention the input and output of the workflow but the main purpose of the workflow\n _For example, not \"โ Convert Knowledge-piece to title\" but \"โ Title\"_\n\n## The workflow\n\n> {book}\n```\n\n`-> {title}`\n"}],sourceFile:"./books/prepare-title.book"}];
|
|
862
|
+
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.book",formfactorName:"GENERIC",parameters:[{name:"knowledgeContent",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",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> {knowledgeContent}",resultingParameterName:"knowledgePieces",dependentParameterNames:["knowledgeContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Knowledge from Markdown\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.book`\n- INPUT PARAMETER `{knowledgeContent}` Markdown document content\n- OUTPUT PARAMETER `{knowledgePieces}` The knowledge JSON object\n\n## Knowledge\n\n<!-- TODO: [๐] -FORMAT JSON -->\n\n```markdown\nYou 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> {knowledgeContent}\n```\n\n`-> {knowledgePieces}`\n"}],sourceFile:"./books/prepare-knowledge-from-markdown.book"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.book",formfactorName:"GENERIC",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",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> {knowledgePieceContent}",resultingParameterName:"keywords",dependentParameterNames:["knowledgePieceContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Keywords\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-knowledge-keywords.book`\n- INPUT PARAMETER `{knowledgePieceContent}` The content\n- OUTPUT PARAMETER `{keywords}` Keywords separated by comma\n\n## Knowledge\n\n<!-- TODO: [๐] -FORMAT JSON -->\n\n```markdown\nYou 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> {knowledgePieceContent}\n```\n\n`-> {keywords}`\n"}],sourceFile:"./books/prepare-knowledge-keywords.book"},{title:"Prepare Knowledge-piece Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.book",formfactorName:"GENERIC",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",content:"You are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Write maximum 5 words for the title\n\n# The document\n\n> {knowledgePieceContent}",resultingParameterName:"title",expectations:{words:{min:1,max:8}},dependentParameterNames:["knowledgePieceContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Knowledge-piece Title\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-knowledge-title.book`\n- INPUT PARAMETER `{knowledgePieceContent}` The content\n- OUTPUT PARAMETER `{title}` The title of the document\n\n## Knowledge\n\n- EXPECT MIN 1 WORD\n- EXPECT MAX 8 WORDS\n\n```markdown\nYou are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Write maximum 5 words for the title\n\n# The document\n\n> {knowledgePieceContent}\n```\n\n`-> {title}`\n"}],sourceFile:"./books/prepare-knowledge-title.book"},{title:"Prepare Persona",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.book",formfactorName:"GENERIC",parameters:[{name:"availableModels",description:"List of available model names together with their descriptions as JSON",isInput:true,isOutput:false},{name:"personaDescription",description:"Description of the persona",isInput:true,isOutput:false},{name:"modelsRequirements",description:"Specific requirements for the model",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"make-model-requirements",title:"Make modelRequirements",content:"You are an experienced AI engineer, you need to find the best models for virtual assistants:\n\n## Example\n\n```json\n[\n {\n \"modelName\": \"gpt-4o\",\n \"systemMessage\": \"You are experienced AI engineer and helpfull assistant.\",\n \"temperature\": 0.7\n },\n {\n \"modelName\": \"claude-3-5-sonnet\",\n \"systemMessage\": \"You are a friendly and knowledgeable chatbot.\",\n \"temperature\": 0.5\n }\n]\n```\n\n## Instructions\n\n- Your output format is JSON array\n- Sort best-fitting models first\n- Omit any models that are not suitable\n- Write just the JSON, no other text should be present\n- Array contain items with following keys:\n - `modelName`: The name of the model to use\n - `systemMessage`: The system message to provide context to the model\n - `temperature`: The sampling temperature to use\n\n### Key `modelName`\n\nHere are the available models:\n\n```json\n{availableModels}\n```\n\n### Key `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### Key `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:"modelsRequirements",format:"JSON",dependentParameterNames:["availableModels","personaDescription"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Persona\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-persona.book`\n- INPUT PARAMETER `{availableModels}` List of available model names together with their descriptions as JSON\n- INPUT PARAMETER `{personaDescription}` Description of the persona\n- OUTPUT PARAMETER `{modelsRequirements}` Specific requirements for the model\n\n## Make modelRequirements\n\n- FORMAT JSON\n\n```markdown\nYou are an experienced AI engineer, you need to find the best models for virtual assistants:\n\n## Example\n\n\\`\\`\\`json\n[\n {\n \"modelName\": \"gpt-4o\",\n \"systemMessage\": \"You are experienced AI engineer and helpfull assistant.\",\n \"temperature\": 0.7\n },\n {\n \"modelName\": \"claude-3-5-sonnet\",\n \"systemMessage\": \"You are a friendly and knowledgeable chatbot.\",\n \"temperature\": 0.5\n }\n]\n\\`\\`\\`\n\n## Instructions\n\n- Your output format is JSON array\n- Sort best-fitting models first\n- Omit any models that are not suitable\n- Write just the JSON, no other text should be present\n- Array contain items with following keys:\n - `modelName`: The name of the model to use\n - `systemMessage`: The system message to provide context to the model\n - `temperature`: The sampling temperature to use\n\n### Key `modelName`\n\nHere are the available models:\n\n\\`\\`\\`json\n{availableModels}\n\\`\\`\\`\n\n### Key `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### Key `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}\n```\n\n`-> {modelsRequirements}`\n"}],sourceFile:"./books/prepare-persona.book"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-title.book",formfactorName:"GENERIC",parameters:[{name:"book",description:"The book to prepare the title for",isInput:true,isOutput:false},{name:"title",description:"Best title for the book",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"make-title",title:"Make title",content:"Make best title for given text which describes the workflow:\n\n## Rules\n\n- Write just title, nothing else\n- Title should be concise and clear - Write maximum ideally 2 words, maximum 5 words\n- Title starts with emoticon\n- Title should not mention the input and output of the workflow but the main purpose of the workflow\n _For example, not \"โ Convert Knowledge-piece to title\" but \"โ Title\"_\n\n## The workflow\n\n> {book}",resultingParameterName:"title",expectations:{words:{min:1,max:8},lines:{min:1,max:1}},dependentParameterNames:["book"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Title\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-title.book`\n- INPUT PARAMETER `{book}` The book to prepare the title for\n- OUTPUT PARAMETER `{title}` Best title for the book\n\n## Make title\n\n- EXPECT MIN 1 Word\n- EXPECT MAX 8 Words\n- EXPECT EXACTLY 1 Line\n\n```markdown\nMake best title for given text which describes the workflow:\n\n## Rules\n\n- Write just title, nothing else\n- Title should be concise and clear - Write maximum ideally 2 words, maximum 5 words\n- Title starts with emoticon\n- Title should not mention the input and output of the workflow but the main purpose of the workflow\n _For example, not \"โ Convert Knowledge-piece to title\" but \"โ Title\"_\n\n## The workflow\n\n> {book}\n```\n\n`-> {title}`\n"}],sourceFile:"./books/prepare-title.book"}];
|
|
861
863
|
|
|
862
864
|
/**
|
|
863
865
|
* Checks if value is valid email
|
|
@@ -890,9 +892,60 @@
|
|
|
890
892
|
* TODO: Maybe split `ParseError` and `ApplyError`
|
|
891
893
|
*/
|
|
892
894
|
|
|
895
|
+
/**
|
|
896
|
+
* This error type indicates that somewhere in the code non-Error object was thrown and it was wrapped into the `WrappedError`
|
|
897
|
+
*
|
|
898
|
+
* @public exported from `@promptbook/core`
|
|
899
|
+
*/
|
|
900
|
+
class WrappedError extends Error {
|
|
901
|
+
constructor(whatWasThrown) {
|
|
902
|
+
const tag = `[๐คฎ]`;
|
|
903
|
+
console.error(tag, whatWasThrown);
|
|
904
|
+
super(spaceTrim.spaceTrim(`
|
|
905
|
+
Non-Error object was thrown
|
|
906
|
+
|
|
907
|
+
Note: Look for ${tag} in the console for more details
|
|
908
|
+
Please report issue on ${ADMIN_EMAIL}
|
|
909
|
+
`));
|
|
910
|
+
this.name = 'WrappedError';
|
|
911
|
+
Object.setPrototypeOf(this, WrappedError.prototype);
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
/**
|
|
916
|
+
* Helper used in catch blocks to assert that the error is an instance of `Error`
|
|
917
|
+
*
|
|
918
|
+
* @param whatWasThrown Any object that was thrown
|
|
919
|
+
* @returns Nothing if the error is an instance of `Error`
|
|
920
|
+
* @throws `WrappedError` or `UnexpectedError` if the error is not standard
|
|
921
|
+
*
|
|
922
|
+
* @private within the repository
|
|
923
|
+
*/
|
|
924
|
+
function assertsError(whatWasThrown) {
|
|
925
|
+
// Case 1: Handle error which was rethrown as `WrappedError`
|
|
926
|
+
if (whatWasThrown instanceof WrappedError) {
|
|
927
|
+
const wrappedError = whatWasThrown;
|
|
928
|
+
throw wrappedError;
|
|
929
|
+
}
|
|
930
|
+
// Case 2: Handle unexpected errors
|
|
931
|
+
if (whatWasThrown instanceof UnexpectedError) {
|
|
932
|
+
const unexpectedError = whatWasThrown;
|
|
933
|
+
throw unexpectedError;
|
|
934
|
+
}
|
|
935
|
+
// Case 3: Handle standard errors - keep them up to consumer
|
|
936
|
+
if (whatWasThrown instanceof Error) {
|
|
937
|
+
return;
|
|
938
|
+
}
|
|
939
|
+
// Case 4: Handle non-standard errors - wrap them into `WrappedError` and throw
|
|
940
|
+
throw new WrappedError(whatWasThrown);
|
|
941
|
+
}
|
|
942
|
+
|
|
893
943
|
/**
|
|
894
944
|
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
895
945
|
*
|
|
946
|
+
* @param value The string to check
|
|
947
|
+
* @returns True if the string is a valid JSON string, false otherwise
|
|
948
|
+
*
|
|
896
949
|
* @public exported from `@promptbook/utils`
|
|
897
950
|
*/
|
|
898
951
|
function isValidJsonString(value /* <- [๐จโโ๏ธ] */) {
|
|
@@ -901,9 +954,7 @@
|
|
|
901
954
|
return true;
|
|
902
955
|
}
|
|
903
956
|
catch (error) {
|
|
904
|
-
|
|
905
|
-
throw error;
|
|
906
|
-
}
|
|
957
|
+
assertsError(error);
|
|
907
958
|
if (error.message.includes('Unexpected token')) {
|
|
908
959
|
return false;
|
|
909
960
|
}
|
|
@@ -1256,9 +1307,7 @@
|
|
|
1256
1307
|
JSON.stringify(value); // <- TODO: [0]
|
|
1257
1308
|
}
|
|
1258
1309
|
catch (error) {
|
|
1259
|
-
|
|
1260
|
-
throw error;
|
|
1261
|
-
}
|
|
1310
|
+
assertsError(error);
|
|
1262
1311
|
throw new UnexpectedError(spaceTrim__default["default"]((block) => `
|
|
1263
1312
|
\`${name}\` is not serializable
|
|
1264
1313
|
|
|
@@ -1853,7 +1902,7 @@
|
|
|
1853
1902
|
*/
|
|
1854
1903
|
function unpreparePipeline(pipeline) {
|
|
1855
1904
|
let { personas, knowledgeSources, tasks } = pipeline;
|
|
1856
|
-
personas = personas.map((persona) => ({ ...persona,
|
|
1905
|
+
personas = personas.map((persona) => ({ ...persona, modelsRequirements: undefined, preparationIds: undefined }));
|
|
1857
1906
|
knowledgeSources = knowledgeSources.map((knowledgeSource) => ({ ...knowledgeSource, preparationIds: undefined }));
|
|
1858
1907
|
tasks = tasks.map((task) => {
|
|
1859
1908
|
let { dependentParameterNames } = task;
|
|
@@ -2047,7 +2096,7 @@
|
|
|
2047
2096
|
}
|
|
2048
2097
|
}
|
|
2049
2098
|
/**
|
|
2050
|
-
* TODO:
|
|
2099
|
+
* TODO: [๐ง ][๐] Add id to all errors
|
|
2051
2100
|
*/
|
|
2052
2101
|
|
|
2053
2102
|
/**
|
|
@@ -2063,7 +2112,7 @@
|
|
|
2063
2112
|
if (pipeline.title === undefined || pipeline.title === '' || pipeline.title === DEFAULT_BOOK_TITLE) {
|
|
2064
2113
|
return false;
|
|
2065
2114
|
}
|
|
2066
|
-
if (!pipeline.personas.every((persona) => persona.
|
|
2115
|
+
if (!pipeline.personas.every((persona) => persona.modelsRequirements !== undefined)) {
|
|
2067
2116
|
return false;
|
|
2068
2117
|
}
|
|
2069
2118
|
if (!pipeline.knowledgeSources.every((knowledgeSource) => knowledgeSource.preparationIds !== undefined)) {
|
|
@@ -2087,6 +2136,45 @@
|
|
|
2087
2136
|
* - [โจ] Are tasks prepared
|
|
2088
2137
|
*/
|
|
2089
2138
|
|
|
2139
|
+
/**
|
|
2140
|
+
* Converts a JavaScript Object Notation (JSON) string into an object.
|
|
2141
|
+
*
|
|
2142
|
+
* Note: This is wrapper around `JSON.parse()` with better error and type handling
|
|
2143
|
+
*
|
|
2144
|
+
* @public exported from `@promptbook/utils`
|
|
2145
|
+
*/
|
|
2146
|
+
function jsonParse(value) {
|
|
2147
|
+
if (value === undefined) {
|
|
2148
|
+
throw new Error(`Can not parse JSON from undefined value.`);
|
|
2149
|
+
}
|
|
2150
|
+
else if (typeof value !== 'string') {
|
|
2151
|
+
console.error('Can not parse JSON from non-string value.', { text: value });
|
|
2152
|
+
throw new Error(spaceTrim__default["default"](`
|
|
2153
|
+
Can not parse JSON from non-string value.
|
|
2154
|
+
|
|
2155
|
+
The value type: ${typeof value}
|
|
2156
|
+
See more in console.
|
|
2157
|
+
`));
|
|
2158
|
+
}
|
|
2159
|
+
try {
|
|
2160
|
+
return JSON.parse(value);
|
|
2161
|
+
}
|
|
2162
|
+
catch (error) {
|
|
2163
|
+
if (!(error instanceof Error)) {
|
|
2164
|
+
throw error;
|
|
2165
|
+
}
|
|
2166
|
+
throw new Error(spaceTrim__default["default"]((block) => `
|
|
2167
|
+
${block(error.message)}
|
|
2168
|
+
|
|
2169
|
+
The JSON text:
|
|
2170
|
+
${block(value)}
|
|
2171
|
+
`));
|
|
2172
|
+
}
|
|
2173
|
+
}
|
|
2174
|
+
/**
|
|
2175
|
+
* TODO: !!!! Use in Promptbook.studio
|
|
2176
|
+
*/
|
|
2177
|
+
|
|
2090
2178
|
/**
|
|
2091
2179
|
* Recursively converts JSON strings to JSON objects
|
|
2092
2180
|
|
|
@@ -2105,7 +2193,7 @@
|
|
|
2105
2193
|
const newObject = { ...object };
|
|
2106
2194
|
for (const [key, value] of Object.entries(object)) {
|
|
2107
2195
|
if (typeof value === 'string' && isValidJsonString(value)) {
|
|
2108
|
-
newObject[key] =
|
|
2196
|
+
newObject[key] = jsonParse(value);
|
|
2109
2197
|
}
|
|
2110
2198
|
else {
|
|
2111
2199
|
newObject[key] = jsonStringsToJsons(value);
|
|
@@ -2258,7 +2346,10 @@
|
|
|
2258
2346
|
PipelineExecutionError,
|
|
2259
2347
|
PipelineLogicError,
|
|
2260
2348
|
PipelineUrlError,
|
|
2349
|
+
AuthenticationError,
|
|
2350
|
+
PromptbookFetchError,
|
|
2261
2351
|
UnexpectedError,
|
|
2352
|
+
WrappedError,
|
|
2262
2353
|
// TODO: [๐ช]> VersionMismatchError,
|
|
2263
2354
|
};
|
|
2264
2355
|
/**
|
|
@@ -2275,8 +2366,6 @@
|
|
|
2275
2366
|
TypeError,
|
|
2276
2367
|
URIError,
|
|
2277
2368
|
AggregateError,
|
|
2278
|
-
AuthenticationError,
|
|
2279
|
-
PromptbookFetchError,
|
|
2280
2369
|
/*
|
|
2281
2370
|
Note: Not widely supported
|
|
2282
2371
|
> InternalError,
|
|
@@ -2399,8 +2488,8 @@
|
|
|
2399
2488
|
updatedAt = new Date();
|
|
2400
2489
|
errors.push(...executionResult.errors);
|
|
2401
2490
|
warnings.push(...executionResult.warnings);
|
|
2402
|
-
// <- TODO:
|
|
2403
|
-
// TODO: [๐ง ]
|
|
2491
|
+
// <- TODO: [๐] Only unique errors and warnings should be added (or filtered)
|
|
2492
|
+
// TODO: [๐ง ] !! errors, warning, isSuccessful are redundant both in `ExecutionTask` and `ExecutionTask.currentValue`
|
|
2404
2493
|
// Also maybe move `ExecutionTask.currentValue.usage` -> `ExecutionTask.usage`
|
|
2405
2494
|
// And delete `ExecutionTask.currentValue.preparedPipeline`
|
|
2406
2495
|
assertsTaskSuccessful(executionResult);
|
|
@@ -2410,6 +2499,7 @@
|
|
|
2410
2499
|
partialResultSubject.next(executionResult);
|
|
2411
2500
|
}
|
|
2412
2501
|
catch (error) {
|
|
2502
|
+
assertsError(error);
|
|
2413
2503
|
status = 'ERROR';
|
|
2414
2504
|
errors.push(error);
|
|
2415
2505
|
partialResultSubject.error(error);
|
|
@@ -2801,14 +2891,15 @@
|
|
|
2801
2891
|
}
|
|
2802
2892
|
}
|
|
2803
2893
|
catch (error) {
|
|
2804
|
-
|
|
2894
|
+
assertsError(error);
|
|
2895
|
+
if (error instanceof UnexpectedError) {
|
|
2805
2896
|
throw error;
|
|
2806
2897
|
}
|
|
2807
2898
|
errors.push({ llmExecutionTools, error });
|
|
2808
2899
|
}
|
|
2809
2900
|
}
|
|
2810
2901
|
if (errors.length === 1) {
|
|
2811
|
-
throw errors[0];
|
|
2902
|
+
throw errors[0].error;
|
|
2812
2903
|
}
|
|
2813
2904
|
else if (errors.length > 1) {
|
|
2814
2905
|
throw new PipelineExecutionError(
|
|
@@ -2934,27 +3025,48 @@
|
|
|
2934
3025
|
pipeline: await collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-persona.book'),
|
|
2935
3026
|
tools,
|
|
2936
3027
|
});
|
|
2937
|
-
// TODO: [๐] Make arrayable LLMs -> single LLM DRY
|
|
2938
3028
|
const _llms = arrayableToArray(tools.llm);
|
|
2939
3029
|
const llmTools = _llms.length === 1 ? _llms[0] : joinLlmExecutionTools(..._llms);
|
|
2940
|
-
const availableModels = await llmTools.listModels()
|
|
2941
|
-
const availableModelNames = availableModels
|
|
3030
|
+
const availableModels = (await llmTools.listModels())
|
|
2942
3031
|
.filter(({ modelVariant }) => modelVariant === 'CHAT')
|
|
2943
|
-
.map(({ modelName }) =>
|
|
2944
|
-
|
|
2945
|
-
|
|
3032
|
+
.map(({ modelName, modelDescription }) => ({
|
|
3033
|
+
modelName,
|
|
3034
|
+
modelDescription,
|
|
3035
|
+
// <- Note: `modelTitle` and `modelVariant` is not relevant for this task
|
|
3036
|
+
}));
|
|
3037
|
+
const result = await preparePersonaExecutor({
|
|
3038
|
+
availableModels /* <- Note: Passing as JSON */,
|
|
3039
|
+
personaDescription,
|
|
3040
|
+
}).asPromise();
|
|
2946
3041
|
const { outputParameters } = result;
|
|
2947
|
-
const {
|
|
2948
|
-
|
|
3042
|
+
const { modelsRequirements: modelsRequirementsJson } = outputParameters;
|
|
3043
|
+
let modelsRequirementsUnchecked = jsonParse(modelsRequirementsJson);
|
|
2949
3044
|
if (isVerbose) {
|
|
2950
|
-
console.info(`PERSONA ${personaDescription}`,
|
|
3045
|
+
console.info(`PERSONA ${personaDescription}`, modelsRequirementsUnchecked);
|
|
2951
3046
|
}
|
|
2952
|
-
|
|
2953
|
-
|
|
3047
|
+
if (!Array.isArray(modelsRequirementsUnchecked)) {
|
|
3048
|
+
// <- TODO: Book should have syntax and system to enforce shape of JSON
|
|
3049
|
+
modelsRequirementsUnchecked = [modelsRequirementsUnchecked];
|
|
3050
|
+
/*
|
|
3051
|
+
throw new UnexpectedError(
|
|
3052
|
+
spaceTrim(
|
|
3053
|
+
(block) => `
|
|
3054
|
+
Invalid \`modelsRequirements\`:
|
|
3055
|
+
|
|
3056
|
+
\`\`\`json
|
|
3057
|
+
${block(JSON.stringify(modelsRequirementsUnchecked, null, 4))}
|
|
3058
|
+
\`\`\`
|
|
3059
|
+
`,
|
|
3060
|
+
),
|
|
3061
|
+
);
|
|
3062
|
+
*/
|
|
3063
|
+
}
|
|
3064
|
+
const modelsRequirements = modelsRequirementsUnchecked.map((modelRequirements) => ({
|
|
2954
3065
|
modelVariant: 'CHAT',
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
|
|
3066
|
+
...modelRequirements,
|
|
3067
|
+
}));
|
|
3068
|
+
return {
|
|
3069
|
+
modelsRequirements,
|
|
2958
3070
|
};
|
|
2959
3071
|
}
|
|
2960
3072
|
/**
|
|
@@ -3263,9 +3375,7 @@
|
|
|
3263
3375
|
return await fetch(urlOrRequest, init);
|
|
3264
3376
|
}
|
|
3265
3377
|
catch (error) {
|
|
3266
|
-
|
|
3267
|
-
throw error;
|
|
3268
|
-
}
|
|
3378
|
+
assertsError(error);
|
|
3269
3379
|
let url;
|
|
3270
3380
|
if (typeof urlOrRequest === 'string') {
|
|
3271
3381
|
url = urlOrRequest;
|
|
@@ -3394,7 +3504,7 @@
|
|
|
3394
3504
|
> },
|
|
3395
3505
|
*/
|
|
3396
3506
|
async asJson() {
|
|
3397
|
-
return
|
|
3507
|
+
return jsonParse(await tools.fs.readFile(filename, 'utf-8'));
|
|
3398
3508
|
},
|
|
3399
3509
|
async asText() {
|
|
3400
3510
|
return await tools.fs.readFile(filename, 'utf-8');
|
|
@@ -3496,9 +3606,7 @@
|
|
|
3496
3606
|
knowledgePreparedUnflatten[index] = pieces;
|
|
3497
3607
|
}
|
|
3498
3608
|
catch (error) {
|
|
3499
|
-
|
|
3500
|
-
throw error;
|
|
3501
|
-
}
|
|
3609
|
+
assertsError(error);
|
|
3502
3610
|
console.warn(error);
|
|
3503
3611
|
// <- TODO: [๐ฎ] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
3504
3612
|
}
|
|
@@ -3654,14 +3762,14 @@
|
|
|
3654
3762
|
// TODO: [๐][๐ง ] Implement some `mapAsync` function
|
|
3655
3763
|
const preparedPersonas = new Array(personas.length);
|
|
3656
3764
|
await forEachAsync(personas, { maxParallelCount /* <- TODO: [๐ช] When there are subtasks, this maximul limit can be broken */ }, async (persona, index) => {
|
|
3657
|
-
const
|
|
3765
|
+
const { modelsRequirements } = await preparePersona(persona.description, { ...tools, llm: llmToolsWithUsage }, {
|
|
3658
3766
|
rootDirname,
|
|
3659
3767
|
maxParallelCount /* <- TODO: [๐ช] */,
|
|
3660
3768
|
isVerbose,
|
|
3661
3769
|
});
|
|
3662
3770
|
const preparedPersona = {
|
|
3663
3771
|
...persona,
|
|
3664
|
-
|
|
3772
|
+
modelsRequirements,
|
|
3665
3773
|
preparationIds: [/* TODO: [๐ง] -> */ currentPreparation.id],
|
|
3666
3774
|
// <- TODO: [๐] Make some standard order of json properties
|
|
3667
3775
|
};
|
|
@@ -3790,13 +3898,19 @@
|
|
|
3790
3898
|
return value.toISOString();
|
|
3791
3899
|
}
|
|
3792
3900
|
else {
|
|
3793
|
-
|
|
3901
|
+
try {
|
|
3902
|
+
return JSON.stringify(value);
|
|
3903
|
+
}
|
|
3904
|
+
catch (error) {
|
|
3905
|
+
if (error instanceof TypeError && error.message.includes('circular structure')) {
|
|
3906
|
+
return VALUE_STRINGS.circular;
|
|
3907
|
+
}
|
|
3908
|
+
throw error;
|
|
3909
|
+
}
|
|
3794
3910
|
}
|
|
3795
3911
|
}
|
|
3796
3912
|
catch (error) {
|
|
3797
|
-
|
|
3798
|
-
throw error;
|
|
3799
|
-
}
|
|
3913
|
+
assertsError(error);
|
|
3800
3914
|
console.error(error);
|
|
3801
3915
|
return VALUE_STRINGS.unserializable;
|
|
3802
3916
|
}
|
|
@@ -3853,9 +3967,7 @@
|
|
|
3853
3967
|
}
|
|
3854
3968
|
}
|
|
3855
3969
|
catch (error) {
|
|
3856
|
-
|
|
3857
|
-
throw error;
|
|
3858
|
-
}
|
|
3970
|
+
assertsError(error);
|
|
3859
3971
|
throw new ParseError(spaceTrim.spaceTrim((block) => `
|
|
3860
3972
|
Can not extract variables from the script
|
|
3861
3973
|
${block(error.stack || error.message)}
|
|
@@ -3974,6 +4086,46 @@
|
|
|
3974
4086
|
// encoding: 'utf-8',
|
|
3975
4087
|
});
|
|
3976
4088
|
|
|
4089
|
+
/**
|
|
4090
|
+
* Function to check if a string is valid CSV
|
|
4091
|
+
*
|
|
4092
|
+
* @param value The string to check
|
|
4093
|
+
* @returns True if the string is a valid CSV string, false otherwise
|
|
4094
|
+
*
|
|
4095
|
+
* @public exported from `@promptbook/utils`
|
|
4096
|
+
*/
|
|
4097
|
+
function isValidCsvString(value) {
|
|
4098
|
+
try {
|
|
4099
|
+
// A simple check for CSV format: at least one comma and no invalid characters
|
|
4100
|
+
if (value.includes(',') && /^[\w\s,"']+$/.test(value)) {
|
|
4101
|
+
return true;
|
|
4102
|
+
}
|
|
4103
|
+
return false;
|
|
4104
|
+
}
|
|
4105
|
+
catch (error) {
|
|
4106
|
+
assertsError(error);
|
|
4107
|
+
return false;
|
|
4108
|
+
}
|
|
4109
|
+
}
|
|
4110
|
+
|
|
4111
|
+
/**
|
|
4112
|
+
* Converts a CSV string into an object
|
|
4113
|
+
*
|
|
4114
|
+
* Note: This is wrapper around `papaparse.parse()` with better autohealing
|
|
4115
|
+
*
|
|
4116
|
+
* @private - for now until `@promptbook/csv` is released
|
|
4117
|
+
*/
|
|
4118
|
+
function csvParse(value /* <- TODO: string_csv */, settings, schema /* <- TODO: Make CSV Schemas */) {
|
|
4119
|
+
settings = { ...settings, ...MANDATORY_CSV_SETTINGS };
|
|
4120
|
+
// Note: Autoheal invalid '\n' characters
|
|
4121
|
+
if (settings.newline && !settings.newline.includes('\r') && value.includes('\r')) {
|
|
4122
|
+
console.warn('CSV string contains carriage return characters, but in the CSV settings the `newline` setting does not include them. Autohealing the CSV string.');
|
|
4123
|
+
value = value.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
|
|
4124
|
+
}
|
|
4125
|
+
const csv = papaparse.parse(value, settings);
|
|
4126
|
+
return csv;
|
|
4127
|
+
}
|
|
4128
|
+
|
|
3977
4129
|
/**
|
|
3978
4130
|
* Definition for CSV spreadsheet
|
|
3979
4131
|
*
|
|
@@ -3984,7 +4136,7 @@
|
|
|
3984
4136
|
formatName: 'CSV',
|
|
3985
4137
|
aliases: ['SPREADSHEET', 'TABLE'],
|
|
3986
4138
|
isValid(value, settings, schema) {
|
|
3987
|
-
return
|
|
4139
|
+
return isValidCsvString(value);
|
|
3988
4140
|
},
|
|
3989
4141
|
canBeValid(partialValue, settings, schema) {
|
|
3990
4142
|
return true;
|
|
@@ -3996,8 +4148,7 @@
|
|
|
3996
4148
|
{
|
|
3997
4149
|
subvalueName: 'ROW',
|
|
3998
4150
|
async mapValues(value, outputParameterName, settings, mapCallback) {
|
|
3999
|
-
|
|
4000
|
-
const csv = papaparse.parse(value, { ...settings, ...MANDATORY_CSV_SETTINGS });
|
|
4151
|
+
const csv = csvParse(value, settings);
|
|
4001
4152
|
if (csv.errors.length !== 0) {
|
|
4002
4153
|
throw new CsvFormatError(spaceTrim__default["default"]((block) => `
|
|
4003
4154
|
CSV parsing error
|
|
@@ -4027,8 +4178,7 @@
|
|
|
4027
4178
|
{
|
|
4028
4179
|
subvalueName: 'CELL',
|
|
4029
4180
|
async mapValues(value, outputParameterName, settings, mapCallback) {
|
|
4030
|
-
|
|
4031
|
-
const csv = papaparse.parse(value, { ...settings, ...MANDATORY_CSV_SETTINGS });
|
|
4181
|
+
const csv = csvParse(value, settings);
|
|
4032
4182
|
if (csv.errors.length !== 0) {
|
|
4033
4183
|
throw new CsvFormatError(spaceTrim__default["default"]((block) => `
|
|
4034
4184
|
CSV parsing error
|
|
@@ -4138,6 +4288,30 @@
|
|
|
4138
4288
|
* TODO: [๐ข] Allow to expect something inside each item of list and other formats
|
|
4139
4289
|
*/
|
|
4140
4290
|
|
|
4291
|
+
/**
|
|
4292
|
+
* Function to check if a string is valid XML
|
|
4293
|
+
*
|
|
4294
|
+
* @param value
|
|
4295
|
+
* @returns True if the string is a valid XML string, false otherwise
|
|
4296
|
+
*
|
|
4297
|
+
* @public exported from `@promptbook/utils`
|
|
4298
|
+
*/
|
|
4299
|
+
function isValidXmlString(value) {
|
|
4300
|
+
try {
|
|
4301
|
+
const parser = new DOMParser();
|
|
4302
|
+
const parsedDocument = parser.parseFromString(value, 'application/xml');
|
|
4303
|
+
const parserError = parsedDocument.getElementsByTagName('parsererror');
|
|
4304
|
+
if (parserError.length > 0) {
|
|
4305
|
+
return false;
|
|
4306
|
+
}
|
|
4307
|
+
return true;
|
|
4308
|
+
}
|
|
4309
|
+
catch (error) {
|
|
4310
|
+
assertsError(error);
|
|
4311
|
+
return false;
|
|
4312
|
+
}
|
|
4313
|
+
}
|
|
4314
|
+
|
|
4141
4315
|
/**
|
|
4142
4316
|
* Definition for XML format
|
|
4143
4317
|
*
|
|
@@ -4147,7 +4321,7 @@
|
|
|
4147
4321
|
formatName: 'XML',
|
|
4148
4322
|
mimeType: 'application/xml',
|
|
4149
4323
|
isValid(value, settings, schema) {
|
|
4150
|
-
return
|
|
4324
|
+
return isValidXmlString(value);
|
|
4151
4325
|
},
|
|
4152
4326
|
canBeValid(partialValue, settings, schema) {
|
|
4153
4327
|
return true;
|
|
@@ -4720,9 +4894,7 @@
|
|
|
4720
4894
|
break scripts;
|
|
4721
4895
|
}
|
|
4722
4896
|
catch (error) {
|
|
4723
|
-
|
|
4724
|
-
throw error;
|
|
4725
|
-
}
|
|
4897
|
+
assertsError(error);
|
|
4726
4898
|
if (error instanceof UnexpectedError) {
|
|
4727
4899
|
throw error;
|
|
4728
4900
|
}
|
|
@@ -4792,9 +4964,7 @@
|
|
|
4792
4964
|
break scripts;
|
|
4793
4965
|
}
|
|
4794
4966
|
catch (error) {
|
|
4795
|
-
|
|
4796
|
-
throw error;
|
|
4797
|
-
}
|
|
4967
|
+
assertsError(error);
|
|
4798
4968
|
if (error instanceof UnexpectedError) {
|
|
4799
4969
|
throw error;
|
|
4800
4970
|
}
|
|
@@ -5037,13 +5207,79 @@
|
|
|
5037
5207
|
/**
|
|
5038
5208
|
* @@@
|
|
5039
5209
|
*
|
|
5210
|
+
* Here is the place where RAG (retrieval-augmented generation) happens
|
|
5211
|
+
*
|
|
5040
5212
|
* @private internal utility of `createPipelineExecutor`
|
|
5041
5213
|
*/
|
|
5042
5214
|
async function getKnowledgeForTask(options) {
|
|
5043
|
-
const { preparedPipeline, task } = options;
|
|
5044
|
-
|
|
5215
|
+
const { tools, preparedPipeline, task } = options;
|
|
5216
|
+
const firstKnowlegePiece = preparedPipeline.knowledgePieces[0];
|
|
5217
|
+
const firstKnowlegeIndex = firstKnowlegePiece === null || firstKnowlegePiece === void 0 ? void 0 : firstKnowlegePiece.index[0];
|
|
5218
|
+
// <- TODO: Do not use just first knowledge piece and first index to determine embedding model, use also keyword search
|
|
5219
|
+
if (firstKnowlegePiece === undefined || firstKnowlegeIndex === undefined) {
|
|
5220
|
+
return 'No knowledge pieces found';
|
|
5221
|
+
}
|
|
5222
|
+
// TODO: [๐] Make arrayable LLMs -> single LLM DRY
|
|
5223
|
+
const _llms = arrayableToArray(tools.llm);
|
|
5224
|
+
const llmTools = _llms.length === 1 ? _llms[0] : joinLlmExecutionTools(..._llms);
|
|
5225
|
+
const taskEmbeddingPrompt = {
|
|
5226
|
+
title: 'Knowledge Search',
|
|
5227
|
+
modelRequirements: {
|
|
5228
|
+
modelVariant: 'EMBEDDING',
|
|
5229
|
+
modelName: firstKnowlegeIndex.modelName,
|
|
5230
|
+
},
|
|
5231
|
+
content: task.content,
|
|
5232
|
+
parameters: {
|
|
5233
|
+
/* !!!!!!!! */
|
|
5234
|
+
},
|
|
5235
|
+
};
|
|
5236
|
+
const taskEmbeddingResult = await llmTools.callEmbeddingModel(taskEmbeddingPrompt);
|
|
5237
|
+
const knowledgePiecesWithRelevance = preparedPipeline.knowledgePieces.map((knowledgePiece) => {
|
|
5238
|
+
const { index } = knowledgePiece;
|
|
5239
|
+
const knowledgePieceIndex = index.find((i) => i.modelName === firstKnowlegeIndex.modelName);
|
|
5240
|
+
// <- TODO: Do not use just first knowledge piece and first index to determine embedding model
|
|
5241
|
+
if (knowledgePieceIndex === undefined) {
|
|
5242
|
+
return {
|
|
5243
|
+
content: knowledgePiece.content,
|
|
5244
|
+
relevance: 0,
|
|
5245
|
+
};
|
|
5246
|
+
}
|
|
5247
|
+
const relevance = computeCosineSimilarity(knowledgePieceIndex.position, taskEmbeddingResult.content);
|
|
5248
|
+
return {
|
|
5249
|
+
content: knowledgePiece.content,
|
|
5250
|
+
relevance,
|
|
5251
|
+
};
|
|
5252
|
+
});
|
|
5253
|
+
const knowledgePiecesSorted = knowledgePiecesWithRelevance.sort((a, b) => a.relevance - b.relevance);
|
|
5254
|
+
const knowledgePiecesLimited = knowledgePiecesSorted.slice(0, 5);
|
|
5255
|
+
console.log('!!! Embedding', {
|
|
5256
|
+
task,
|
|
5257
|
+
taskEmbeddingPrompt,
|
|
5258
|
+
taskEmbeddingResult,
|
|
5259
|
+
firstKnowlegePiece,
|
|
5260
|
+
firstKnowlegeIndex,
|
|
5261
|
+
knowledgePiecesWithRelevance,
|
|
5262
|
+
knowledgePiecesSorted,
|
|
5263
|
+
knowledgePiecesLimited,
|
|
5264
|
+
});
|
|
5265
|
+
return knowledgePiecesLimited.map(({ content }) => `- ${content}`).join('\n');
|
|
5045
5266
|
// <- TODO: [๐ง ] Some smart aggregation of knowledge pieces, single-line vs multi-line vs mixed
|
|
5046
5267
|
}
|
|
5268
|
+
// TODO: !!!!!! Annotate + to new file
|
|
5269
|
+
function computeCosineSimilarity(embeddingVector1, embeddingVector2) {
|
|
5270
|
+
if (embeddingVector1.length !== embeddingVector2.length) {
|
|
5271
|
+
throw new TypeError('Embedding vectors must have the same length');
|
|
5272
|
+
}
|
|
5273
|
+
const dotProduct = embeddingVector1.reduce((sum, value, index) => sum + value * embeddingVector2[index], 0);
|
|
5274
|
+
const magnitude1 = Math.sqrt(embeddingVector1.reduce((sum, value) => sum + value * value, 0));
|
|
5275
|
+
const magnitude2 = Math.sqrt(embeddingVector2.reduce((sum, value) => sum + value * value, 0));
|
|
5276
|
+
return 1 - dotProduct / (magnitude1 * magnitude2);
|
|
5277
|
+
}
|
|
5278
|
+
/**
|
|
5279
|
+
* TODO: !!!! Verify if this is working
|
|
5280
|
+
* TODO: [โจ] Implement Better - use keyword search
|
|
5281
|
+
* TODO: [โจ] Examples of values
|
|
5282
|
+
*/
|
|
5047
5283
|
|
|
5048
5284
|
/**
|
|
5049
5285
|
* @@@
|
|
@@ -5051,9 +5287,9 @@
|
|
|
5051
5287
|
* @private internal utility of `createPipelineExecutor`
|
|
5052
5288
|
*/
|
|
5053
5289
|
async function getReservedParametersForTask(options) {
|
|
5054
|
-
const { preparedPipeline, task, pipelineIdentification } = options;
|
|
5290
|
+
const { tools, preparedPipeline, task, pipelineIdentification } = options;
|
|
5055
5291
|
const context = await getContextForTask(); // <- [๐]
|
|
5056
|
-
const knowledge = await getKnowledgeForTask({ preparedPipeline, task });
|
|
5292
|
+
const knowledge = await getKnowledgeForTask({ tools, preparedPipeline, task });
|
|
5057
5293
|
const examples = await getExamplesForTask();
|
|
5058
5294
|
const currentDate = new Date().toISOString(); // <- TODO: [๐ง ][๐ฉ] Better
|
|
5059
5295
|
const modelName = RESERVED_PARAMETER_MISSING_VALUE;
|
|
@@ -5115,6 +5351,7 @@
|
|
|
5115
5351
|
}
|
|
5116
5352
|
const definedParameters = Object.freeze({
|
|
5117
5353
|
...(await getReservedParametersForTask({
|
|
5354
|
+
tools,
|
|
5118
5355
|
preparedPipeline,
|
|
5119
5356
|
task: currentTask,
|
|
5120
5357
|
pipelineIdentification,
|
|
@@ -5415,9 +5652,7 @@
|
|
|
5415
5652
|
await Promise.all(resolving);
|
|
5416
5653
|
}
|
|
5417
5654
|
catch (error /* <- Note: [3] */) {
|
|
5418
|
-
|
|
5419
|
-
throw error;
|
|
5420
|
-
}
|
|
5655
|
+
assertsError(error);
|
|
5421
5656
|
// Note: No need to rethrow UnexpectedError
|
|
5422
5657
|
// if (error instanceof UnexpectedError) {
|
|
5423
5658
|
// Note: Count usage, [๐ง ] Maybe put to separate function executionReportJsonToUsage + DRY [๐คนโโ๏ธ]
|