@promptbook/remote-server 0.92.0-11 → 0.92.0-13
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 +162 -139
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/browser.index.d.ts +2 -0
- package/esm/typings/src/_packages/core.index.d.ts +6 -4
- package/esm/typings/src/_packages/types.index.d.ts +2 -2
- package/esm/typings/src/execution/PipelineExecutorResult.d.ts +3 -1
- package/esm/typings/src/execution/createPipelineExecutor/computeCosineSimilarity.d.ts +13 -0
- package/esm/typings/src/execution/utils/checkExpectations.d.ts +1 -1
- package/esm/typings/src/formats/_common/{FormatDefinition.d.ts → FormatParser.d.ts} +3 -3
- package/esm/typings/src/formats/_common/{FormatSubvalueDefinition.d.ts → FormatSubvalueParser.d.ts} +1 -1
- package/esm/typings/src/formats/csv/CsvFormatParser.d.ts +17 -0
- package/esm/typings/src/formats/index.d.ts +2 -2
- package/esm/typings/src/formats/json/{JsonFormatDefinition.d.ts → JsonFormatParser.d.ts} +6 -6
- package/esm/typings/src/formats/text/{TextFormatDefinition.d.ts → TextFormatParser.d.ts} +7 -7
- package/esm/typings/src/formats/xml/XmlFormatParser.d.ts +19 -0
- package/esm/typings/src/postprocessing/utils/extractJsonBlock.d.ts +1 -1
- package/esm/typings/src/storage/local-storage/getIndexedDbStorage.d.ts +10 -0
- package/esm/typings/src/storage/local-storage/utils/makePromptbookStorageFromIndexedDb.d.ts +7 -0
- package/esm/typings/src/utils/expectation-counters/index.d.ts +1 -1
- package/package.json +2 -2
- package/umd/index.umd.js +162 -139
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/formats/csv/CsvFormatDefinition.d.ts +0 -17
- package/esm/typings/src/formats/xml/XmlFormatDefinition.d.ts +0 -19
package/esm/index.es.js
CHANGED
|
@@ -33,7 +33,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
33
33
|
* @generated
|
|
34
34
|
* @see https://github.com/webgptorg/promptbook
|
|
35
35
|
*/
|
|
36
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.92.0-
|
|
36
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.92.0-13';
|
|
37
37
|
/**
|
|
38
38
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
39
39
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -2067,6 +2067,74 @@ function createTask(options) {
|
|
|
2067
2067
|
* TODO: [🐚] Split into more files and make `PrepareTask` & `RemoteTask` + split the function
|
|
2068
2068
|
*/
|
|
2069
2069
|
|
|
2070
|
+
/**
|
|
2071
|
+
* Represents the uncertain value
|
|
2072
|
+
*
|
|
2073
|
+
* @public exported from `@promptbook/core`
|
|
2074
|
+
*/
|
|
2075
|
+
const ZERO_VALUE = $deepFreeze({ value: 0 });
|
|
2076
|
+
/**
|
|
2077
|
+
* Represents the uncertain value
|
|
2078
|
+
*
|
|
2079
|
+
* @public exported from `@promptbook/core`
|
|
2080
|
+
*/
|
|
2081
|
+
const UNCERTAIN_ZERO_VALUE = $deepFreeze({ value: 0, isUncertain: true });
|
|
2082
|
+
/**
|
|
2083
|
+
* Represents the usage with no resources consumed
|
|
2084
|
+
*
|
|
2085
|
+
* @public exported from `@promptbook/core`
|
|
2086
|
+
*/
|
|
2087
|
+
const ZERO_USAGE = $deepFreeze({
|
|
2088
|
+
price: ZERO_VALUE,
|
|
2089
|
+
input: {
|
|
2090
|
+
tokensCount: ZERO_VALUE,
|
|
2091
|
+
charactersCount: ZERO_VALUE,
|
|
2092
|
+
wordsCount: ZERO_VALUE,
|
|
2093
|
+
sentencesCount: ZERO_VALUE,
|
|
2094
|
+
linesCount: ZERO_VALUE,
|
|
2095
|
+
paragraphsCount: ZERO_VALUE,
|
|
2096
|
+
pagesCount: ZERO_VALUE,
|
|
2097
|
+
},
|
|
2098
|
+
output: {
|
|
2099
|
+
tokensCount: ZERO_VALUE,
|
|
2100
|
+
charactersCount: ZERO_VALUE,
|
|
2101
|
+
wordsCount: ZERO_VALUE,
|
|
2102
|
+
sentencesCount: ZERO_VALUE,
|
|
2103
|
+
linesCount: ZERO_VALUE,
|
|
2104
|
+
paragraphsCount: ZERO_VALUE,
|
|
2105
|
+
pagesCount: ZERO_VALUE,
|
|
2106
|
+
},
|
|
2107
|
+
});
|
|
2108
|
+
/**
|
|
2109
|
+
* Represents the usage with unknown resources consumed
|
|
2110
|
+
*
|
|
2111
|
+
* @public exported from `@promptbook/core`
|
|
2112
|
+
*/
|
|
2113
|
+
const UNCERTAIN_USAGE = $deepFreeze({
|
|
2114
|
+
price: UNCERTAIN_ZERO_VALUE,
|
|
2115
|
+
input: {
|
|
2116
|
+
tokensCount: UNCERTAIN_ZERO_VALUE,
|
|
2117
|
+
charactersCount: UNCERTAIN_ZERO_VALUE,
|
|
2118
|
+
wordsCount: UNCERTAIN_ZERO_VALUE,
|
|
2119
|
+
sentencesCount: UNCERTAIN_ZERO_VALUE,
|
|
2120
|
+
linesCount: UNCERTAIN_ZERO_VALUE,
|
|
2121
|
+
paragraphsCount: UNCERTAIN_ZERO_VALUE,
|
|
2122
|
+
pagesCount: UNCERTAIN_ZERO_VALUE,
|
|
2123
|
+
},
|
|
2124
|
+
output: {
|
|
2125
|
+
tokensCount: UNCERTAIN_ZERO_VALUE,
|
|
2126
|
+
charactersCount: UNCERTAIN_ZERO_VALUE,
|
|
2127
|
+
wordsCount: UNCERTAIN_ZERO_VALUE,
|
|
2128
|
+
sentencesCount: UNCERTAIN_ZERO_VALUE,
|
|
2129
|
+
linesCount: UNCERTAIN_ZERO_VALUE,
|
|
2130
|
+
paragraphsCount: UNCERTAIN_ZERO_VALUE,
|
|
2131
|
+
pagesCount: UNCERTAIN_ZERO_VALUE,
|
|
2132
|
+
},
|
|
2133
|
+
});
|
|
2134
|
+
/**
|
|
2135
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
2136
|
+
*/
|
|
2137
|
+
|
|
2070
2138
|
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"}];
|
|
2071
2139
|
|
|
2072
2140
|
/**
|
|
@@ -2544,74 +2612,6 @@ async function forEachAsync(array, options, callbackfunction) {
|
|
|
2544
2612
|
await Promise.all(tasks);
|
|
2545
2613
|
}
|
|
2546
2614
|
|
|
2547
|
-
/**
|
|
2548
|
-
* Represents the uncertain value
|
|
2549
|
-
*
|
|
2550
|
-
* @public exported from `@promptbook/core`
|
|
2551
|
-
*/
|
|
2552
|
-
const ZERO_VALUE = $deepFreeze({ value: 0 });
|
|
2553
|
-
/**
|
|
2554
|
-
* Represents the uncertain value
|
|
2555
|
-
*
|
|
2556
|
-
* @public exported from `@promptbook/core`
|
|
2557
|
-
*/
|
|
2558
|
-
const UNCERTAIN_ZERO_VALUE = $deepFreeze({ value: 0, isUncertain: true });
|
|
2559
|
-
/**
|
|
2560
|
-
* Represents the usage with no resources consumed
|
|
2561
|
-
*
|
|
2562
|
-
* @public exported from `@promptbook/core`
|
|
2563
|
-
*/
|
|
2564
|
-
const ZERO_USAGE = $deepFreeze({
|
|
2565
|
-
price: ZERO_VALUE,
|
|
2566
|
-
input: {
|
|
2567
|
-
tokensCount: ZERO_VALUE,
|
|
2568
|
-
charactersCount: ZERO_VALUE,
|
|
2569
|
-
wordsCount: ZERO_VALUE,
|
|
2570
|
-
sentencesCount: ZERO_VALUE,
|
|
2571
|
-
linesCount: ZERO_VALUE,
|
|
2572
|
-
paragraphsCount: ZERO_VALUE,
|
|
2573
|
-
pagesCount: ZERO_VALUE,
|
|
2574
|
-
},
|
|
2575
|
-
output: {
|
|
2576
|
-
tokensCount: ZERO_VALUE,
|
|
2577
|
-
charactersCount: ZERO_VALUE,
|
|
2578
|
-
wordsCount: ZERO_VALUE,
|
|
2579
|
-
sentencesCount: ZERO_VALUE,
|
|
2580
|
-
linesCount: ZERO_VALUE,
|
|
2581
|
-
paragraphsCount: ZERO_VALUE,
|
|
2582
|
-
pagesCount: ZERO_VALUE,
|
|
2583
|
-
},
|
|
2584
|
-
});
|
|
2585
|
-
/**
|
|
2586
|
-
* Represents the usage with unknown resources consumed
|
|
2587
|
-
*
|
|
2588
|
-
* @public exported from `@promptbook/core`
|
|
2589
|
-
*/
|
|
2590
|
-
$deepFreeze({
|
|
2591
|
-
price: UNCERTAIN_ZERO_VALUE,
|
|
2592
|
-
input: {
|
|
2593
|
-
tokensCount: UNCERTAIN_ZERO_VALUE,
|
|
2594
|
-
charactersCount: UNCERTAIN_ZERO_VALUE,
|
|
2595
|
-
wordsCount: UNCERTAIN_ZERO_VALUE,
|
|
2596
|
-
sentencesCount: UNCERTAIN_ZERO_VALUE,
|
|
2597
|
-
linesCount: UNCERTAIN_ZERO_VALUE,
|
|
2598
|
-
paragraphsCount: UNCERTAIN_ZERO_VALUE,
|
|
2599
|
-
pagesCount: UNCERTAIN_ZERO_VALUE,
|
|
2600
|
-
},
|
|
2601
|
-
output: {
|
|
2602
|
-
tokensCount: UNCERTAIN_ZERO_VALUE,
|
|
2603
|
-
charactersCount: UNCERTAIN_ZERO_VALUE,
|
|
2604
|
-
wordsCount: UNCERTAIN_ZERO_VALUE,
|
|
2605
|
-
sentencesCount: UNCERTAIN_ZERO_VALUE,
|
|
2606
|
-
linesCount: UNCERTAIN_ZERO_VALUE,
|
|
2607
|
-
paragraphsCount: UNCERTAIN_ZERO_VALUE,
|
|
2608
|
-
pagesCount: UNCERTAIN_ZERO_VALUE,
|
|
2609
|
-
},
|
|
2610
|
-
});
|
|
2611
|
-
/**
|
|
2612
|
-
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
2613
|
-
*/
|
|
2614
|
-
|
|
2615
2615
|
/**
|
|
2616
2616
|
* Function `addUsage` will add multiple usages into one
|
|
2617
2617
|
*
|
|
@@ -4405,6 +4405,24 @@ const MANDATORY_CSV_SETTINGS = Object.freeze({
|
|
|
4405
4405
|
// encoding: 'utf-8',
|
|
4406
4406
|
});
|
|
4407
4407
|
|
|
4408
|
+
/**
|
|
4409
|
+
* Converts a CSV string into an object
|
|
4410
|
+
*
|
|
4411
|
+
* Note: This is wrapper around `papaparse.parse()` with better autohealing
|
|
4412
|
+
*
|
|
4413
|
+
* @private - for now until `@promptbook/csv` is released
|
|
4414
|
+
*/
|
|
4415
|
+
function csvParse(value /* <- TODO: string_csv */, settings, schema /* <- TODO: Make CSV Schemas */) {
|
|
4416
|
+
settings = { ...settings, ...MANDATORY_CSV_SETTINGS };
|
|
4417
|
+
// Note: Autoheal invalid '\n' characters
|
|
4418
|
+
if (settings.newline && !settings.newline.includes('\r') && value.includes('\r')) {
|
|
4419
|
+
console.warn('CSV string contains carriage return characters, but in the CSV settings the `newline` setting does not include them. Autohealing the CSV string.');
|
|
4420
|
+
value = value.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
|
|
4421
|
+
}
|
|
4422
|
+
const csv = parse(value, settings);
|
|
4423
|
+
return csv;
|
|
4424
|
+
}
|
|
4425
|
+
|
|
4408
4426
|
/**
|
|
4409
4427
|
* Function to check if a string is valid CSV
|
|
4410
4428
|
*
|
|
@@ -4427,31 +4445,13 @@ function isValidCsvString(value) {
|
|
|
4427
4445
|
}
|
|
4428
4446
|
}
|
|
4429
4447
|
|
|
4430
|
-
/**
|
|
4431
|
-
* Converts a CSV string into an object
|
|
4432
|
-
*
|
|
4433
|
-
* Note: This is wrapper around `papaparse.parse()` with better autohealing
|
|
4434
|
-
*
|
|
4435
|
-
* @private - for now until `@promptbook/csv` is released
|
|
4436
|
-
*/
|
|
4437
|
-
function csvParse(value /* <- TODO: string_csv */, settings, schema /* <- TODO: Make CSV Schemas */) {
|
|
4438
|
-
settings = { ...settings, ...MANDATORY_CSV_SETTINGS };
|
|
4439
|
-
// Note: Autoheal invalid '\n' characters
|
|
4440
|
-
if (settings.newline && !settings.newline.includes('\r') && value.includes('\r')) {
|
|
4441
|
-
console.warn('CSV string contains carriage return characters, but in the CSV settings the `newline` setting does not include them. Autohealing the CSV string.');
|
|
4442
|
-
value = value.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
|
|
4443
|
-
}
|
|
4444
|
-
const csv = parse(value, settings);
|
|
4445
|
-
return csv;
|
|
4446
|
-
}
|
|
4447
|
-
|
|
4448
4448
|
/**
|
|
4449
4449
|
* Definition for CSV spreadsheet
|
|
4450
4450
|
*
|
|
4451
4451
|
* @public exported from `@promptbook/core`
|
|
4452
4452
|
* <- TODO: [🏢] Export from package `@promptbook/csv`
|
|
4453
4453
|
*/
|
|
4454
|
-
const
|
|
4454
|
+
const CsvFormatParser = {
|
|
4455
4455
|
formatName: 'CSV',
|
|
4456
4456
|
aliases: ['SPREADSHEET', 'TABLE'],
|
|
4457
4457
|
isValid(value, settings, schema) {
|
|
@@ -4463,7 +4463,7 @@ const CsvFormatDefinition = {
|
|
|
4463
4463
|
heal(value, settings, schema) {
|
|
4464
4464
|
throw new Error('Not implemented');
|
|
4465
4465
|
},
|
|
4466
|
-
|
|
4466
|
+
subvalueParsers: [
|
|
4467
4467
|
{
|
|
4468
4468
|
subvalueName: 'ROW',
|
|
4469
4469
|
async mapValues(value, outputParameterName, settings, mapCallback) {
|
|
@@ -4524,10 +4524,10 @@ const CsvFormatDefinition = {
|
|
|
4524
4524
|
],
|
|
4525
4525
|
};
|
|
4526
4526
|
/**
|
|
4527
|
-
* TODO: [🍓] In `
|
|
4528
|
-
* TODO: [🍓] In `
|
|
4529
|
-
* TODO: [🍓] In `
|
|
4530
|
-
* TODO: [🍓] In `
|
|
4527
|
+
* TODO: [🍓] In `CsvFormatParser` implement simple `isValid`
|
|
4528
|
+
* TODO: [🍓] In `CsvFormatParser` implement partial `canBeValid`
|
|
4529
|
+
* TODO: [🍓] In `CsvFormatParser` implement `heal
|
|
4530
|
+
* TODO: [🍓] In `CsvFormatParser` implement `subvalueParsers`
|
|
4531
4531
|
* TODO: [🏢] Allow to expect something inside CSV objects and other formats
|
|
4532
4532
|
*/
|
|
4533
4533
|
|
|
@@ -4536,7 +4536,7 @@ const CsvFormatDefinition = {
|
|
|
4536
4536
|
*
|
|
4537
4537
|
* @private still in development [🏢]
|
|
4538
4538
|
*/
|
|
4539
|
-
const
|
|
4539
|
+
const JsonFormatParser = {
|
|
4540
4540
|
formatName: 'JSON',
|
|
4541
4541
|
mimeType: 'application/json',
|
|
4542
4542
|
isValid(value, settings, schema) {
|
|
@@ -4548,28 +4548,28 @@ const JsonFormatDefinition = {
|
|
|
4548
4548
|
heal(value, settings, schema) {
|
|
4549
4549
|
throw new Error('Not implemented');
|
|
4550
4550
|
},
|
|
4551
|
-
|
|
4551
|
+
subvalueParsers: [],
|
|
4552
4552
|
};
|
|
4553
4553
|
/**
|
|
4554
4554
|
* TODO: [🧠] Maybe propper instance of object
|
|
4555
4555
|
* TODO: [0] Make string_serialized_json
|
|
4556
4556
|
* TODO: [1] Make type for JSON Settings and Schema
|
|
4557
4557
|
* TODO: [🧠] What to use for validating JSONs - JSON Schema, ZoD, typescript types/interfaces,...?
|
|
4558
|
-
* TODO: [🍓] In `
|
|
4559
|
-
* TODO: [🍓] In `
|
|
4560
|
-
* TODO: [🍓] In `
|
|
4561
|
-
* TODO: [🍓] In `
|
|
4558
|
+
* TODO: [🍓] In `JsonFormatParser` implement simple `isValid`
|
|
4559
|
+
* TODO: [🍓] In `JsonFormatParser` implement partial `canBeValid`
|
|
4560
|
+
* TODO: [🍓] In `JsonFormatParser` implement `heal
|
|
4561
|
+
* TODO: [🍓] In `JsonFormatParser` implement `subvalueParsers`
|
|
4562
4562
|
* TODO: [🏢] Allow to expect something inside JSON objects and other formats
|
|
4563
4563
|
*/
|
|
4564
4564
|
|
|
4565
4565
|
/**
|
|
4566
4566
|
* Definition for any text - this will be always valid
|
|
4567
4567
|
*
|
|
4568
|
-
* Note: This is not useful for validation, but for splitting and mapping with `
|
|
4568
|
+
* Note: This is not useful for validation, but for splitting and mapping with `subvalueParsers`
|
|
4569
4569
|
*
|
|
4570
4570
|
* @public exported from `@promptbook/core`
|
|
4571
4571
|
*/
|
|
4572
|
-
const
|
|
4572
|
+
const TextFormatParser = {
|
|
4573
4573
|
formatName: 'TEXT',
|
|
4574
4574
|
isValid(value) {
|
|
4575
4575
|
return typeof value === 'string';
|
|
@@ -4578,9 +4578,9 @@ const TextFormatDefinition = {
|
|
|
4578
4578
|
return typeof partialValue === 'string';
|
|
4579
4579
|
},
|
|
4580
4580
|
heal() {
|
|
4581
|
-
throw new UnexpectedError('It does not make sense to call `
|
|
4581
|
+
throw new UnexpectedError('It does not make sense to call `TextFormatParser.heal`');
|
|
4582
4582
|
},
|
|
4583
|
-
|
|
4583
|
+
subvalueParsers: [
|
|
4584
4584
|
{
|
|
4585
4585
|
subvalueName: 'LINE',
|
|
4586
4586
|
async mapValues(value, outputParameterName, settings, mapCallback) {
|
|
@@ -4600,10 +4600,10 @@ const TextFormatDefinition = {
|
|
|
4600
4600
|
/**
|
|
4601
4601
|
* TODO: [1] Make type for XML Text and Schema
|
|
4602
4602
|
* TODO: [🧠][🤠] Here should be all words, characters, lines, paragraphs, pages available as subvalues
|
|
4603
|
-
* TODO: [🍓] In `
|
|
4604
|
-
* TODO: [🍓] In `
|
|
4605
|
-
* TODO: [🍓] In `
|
|
4606
|
-
* TODO: [🍓] In `
|
|
4603
|
+
* TODO: [🍓] In `TextFormatParser` implement simple `isValid`
|
|
4604
|
+
* TODO: [🍓] In `TextFormatParser` implement partial `canBeValid`
|
|
4605
|
+
* TODO: [🍓] In `TextFormatParser` implement `heal
|
|
4606
|
+
* TODO: [🍓] In `TextFormatParser` implement `subvalueParsers`
|
|
4607
4607
|
* TODO: [🏢] Allow to expect something inside each item of list and other formats
|
|
4608
4608
|
*/
|
|
4609
4609
|
|
|
@@ -4636,7 +4636,7 @@ function isValidXmlString(value) {
|
|
|
4636
4636
|
*
|
|
4637
4637
|
* @private still in development [🏢]
|
|
4638
4638
|
*/
|
|
4639
|
-
const
|
|
4639
|
+
const XmlFormatParser = {
|
|
4640
4640
|
formatName: 'XML',
|
|
4641
4641
|
mimeType: 'application/xml',
|
|
4642
4642
|
isValid(value, settings, schema) {
|
|
@@ -4648,17 +4648,17 @@ const XmlFormatDefinition = {
|
|
|
4648
4648
|
heal(value, settings, schema) {
|
|
4649
4649
|
throw new Error('Not implemented');
|
|
4650
4650
|
},
|
|
4651
|
-
|
|
4651
|
+
subvalueParsers: [],
|
|
4652
4652
|
};
|
|
4653
4653
|
/**
|
|
4654
4654
|
* TODO: [🧠] Maybe propper instance of object
|
|
4655
4655
|
* TODO: [0] Make string_serialized_xml
|
|
4656
4656
|
* TODO: [1] Make type for XML Settings and Schema
|
|
4657
4657
|
* TODO: [🧠] What to use for validating XMLs - XSD,...
|
|
4658
|
-
* TODO: [🍓] In `
|
|
4659
|
-
* TODO: [🍓] In `
|
|
4660
|
-
* TODO: [🍓] In `
|
|
4661
|
-
* TODO: [🍓] In `
|
|
4658
|
+
* TODO: [🍓] In `XmlFormatParser` implement simple `isValid`
|
|
4659
|
+
* TODO: [🍓] In `XmlFormatParser` implement partial `canBeValid`
|
|
4660
|
+
* TODO: [🍓] In `XmlFormatParser` implement `heal
|
|
4661
|
+
* TODO: [🍓] In `XmlFormatParser` implement `subvalueParsers`
|
|
4662
4662
|
* TODO: [🏢] Allow to expect something inside XML and other formats
|
|
4663
4663
|
*/
|
|
4664
4664
|
|
|
@@ -4667,12 +4667,7 @@ const XmlFormatDefinition = {
|
|
|
4667
4667
|
*
|
|
4668
4668
|
* @private internal index of `...` <- TODO [🏢]
|
|
4669
4669
|
*/
|
|
4670
|
-
const FORMAT_DEFINITIONS = [
|
|
4671
|
-
JsonFormatDefinition,
|
|
4672
|
-
XmlFormatDefinition,
|
|
4673
|
-
TextFormatDefinition,
|
|
4674
|
-
CsvFormatDefinition,
|
|
4675
|
-
];
|
|
4670
|
+
const FORMAT_DEFINITIONS = [JsonFormatParser, XmlFormatParser, TextFormatParser, CsvFormatParser];
|
|
4676
4671
|
/**
|
|
4677
4672
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
4678
4673
|
*/
|
|
@@ -4842,7 +4837,7 @@ function extractJsonBlock(markdown) {
|
|
|
4842
4837
|
}
|
|
4843
4838
|
/**
|
|
4844
4839
|
* TODO: Add some auto-healing logic + extract YAML, JSON5, TOML, etc.
|
|
4845
|
-
* TODO: [🏢] Make this logic part of `
|
|
4840
|
+
* TODO: [🏢] Make this logic part of `JsonFormatParser` or `isValidJsonString`
|
|
4846
4841
|
*/
|
|
4847
4842
|
|
|
4848
4843
|
/**
|
|
@@ -5061,7 +5056,7 @@ const CountUtils = {
|
|
|
5061
5056
|
PAGES: countPages,
|
|
5062
5057
|
};
|
|
5063
5058
|
/**
|
|
5064
|
-
* TODO: [🧠][🤠] This should be probbably as part of `
|
|
5059
|
+
* TODO: [🧠][🤠] This should be probbably as part of `TextFormatParser`
|
|
5065
5060
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
5066
5061
|
*/
|
|
5067
5062
|
|
|
@@ -5089,7 +5084,7 @@ function checkExpectations(expectations, value) {
|
|
|
5089
5084
|
}
|
|
5090
5085
|
/**
|
|
5091
5086
|
* TODO: [💝] Unite object for expecting amount and format
|
|
5092
|
-
* TODO: [🧠][🤠] This should be part of `
|
|
5087
|
+
* TODO: [🧠][🤠] This should be part of `TextFormatParser`
|
|
5093
5088
|
* Note: [💝] and [🤠] are interconnected together
|
|
5094
5089
|
*/
|
|
5095
5090
|
|
|
@@ -5317,7 +5312,7 @@ async function executeAttempts(options) {
|
|
|
5317
5312
|
if (task.format) {
|
|
5318
5313
|
if (task.format === 'JSON') {
|
|
5319
5314
|
if (!isValidJsonString($ongoingTaskResult.$resultString || '')) {
|
|
5320
|
-
// TODO: [🏢] Do more universally via `
|
|
5315
|
+
// TODO: [🏢] Do more universally via `FormatParser`
|
|
5321
5316
|
try {
|
|
5322
5317
|
$ongoingTaskResult.$resultString = extractJsonBlock($ongoingTaskResult.$resultString || '');
|
|
5323
5318
|
}
|
|
@@ -5455,16 +5450,16 @@ async function executeFormatSubvalues(options) {
|
|
|
5455
5450
|
${block(pipelineIdentification)}
|
|
5456
5451
|
`));
|
|
5457
5452
|
}
|
|
5458
|
-
const
|
|
5459
|
-
if (
|
|
5453
|
+
const subvalueParser = formatDefinition.subvalueParsers.find((subvalueParser) => [subvalueParser.subvalueName, ...(subvalueParser.aliases || [])].includes(task.foreach.subformatName));
|
|
5454
|
+
if (subvalueParser === undefined) {
|
|
5460
5455
|
throw new UnexpectedError(
|
|
5461
5456
|
// <- TODO: [🧠][🧐] Should be formats fixed per promptbook version or behave as plugins (=> change UnexpectedError)
|
|
5462
5457
|
spaceTrim((block) => `
|
|
5463
5458
|
Unsupported subformat name "${task.foreach.subformatName}" for format "${task.foreach.formatName}"
|
|
5464
5459
|
|
|
5465
5460
|
Available subformat names for format "${formatDefinition.formatName}":
|
|
5466
|
-
${block(formatDefinition.
|
|
5467
|
-
.map((
|
|
5461
|
+
${block(formatDefinition.subvalueParsers
|
|
5462
|
+
.map((subvalueParser) => subvalueParser.subvalueName)
|
|
5468
5463
|
.map((subvalueName) => `- ${subvalueName}`)
|
|
5469
5464
|
.join('\n'))}
|
|
5470
5465
|
|
|
@@ -5478,7 +5473,7 @@ async function executeFormatSubvalues(options) {
|
|
|
5478
5473
|
formatSettings = csvSettings;
|
|
5479
5474
|
// <- TODO: [🤹♂️] More universal, make simmilar pattern for other formats for example \n vs \r\n in text
|
|
5480
5475
|
}
|
|
5481
|
-
const resultString = await
|
|
5476
|
+
const resultString = await subvalueParser.mapValues(parameterValue, task.foreach.outputSubparameterName, formatSettings, async (subparameters, index) => {
|
|
5482
5477
|
let mappedParameters;
|
|
5483
5478
|
// TODO: [🤹♂️][🪂] Limit to N concurrent executions
|
|
5484
5479
|
// TODO: When done [🐚] Report progress also for each subvalue here
|
|
@@ -5540,6 +5535,27 @@ async function getExamplesForTask(task) {
|
|
|
5540
5535
|
return RESERVED_PARAMETER_MISSING_VALUE /* <- TODO: [♨] Implement */;
|
|
5541
5536
|
}
|
|
5542
5537
|
|
|
5538
|
+
/**
|
|
5539
|
+
* Computes the cosine similarity between two embedding vectors
|
|
5540
|
+
*
|
|
5541
|
+
* Note: This is helping function for RAG (retrieval-augmented generation)
|
|
5542
|
+
*
|
|
5543
|
+
* @param embeddingVector1
|
|
5544
|
+
* @param embeddingVector2
|
|
5545
|
+
* @returns Cosine similarity between the two vectors
|
|
5546
|
+
*
|
|
5547
|
+
* @public exported from `@promptbook/core`
|
|
5548
|
+
*/
|
|
5549
|
+
function computeCosineSimilarity(embeddingVector1, embeddingVector2) {
|
|
5550
|
+
if (embeddingVector1.length !== embeddingVector2.length) {
|
|
5551
|
+
throw new TypeError('Embedding vectors must have the same length');
|
|
5552
|
+
}
|
|
5553
|
+
const dotProduct = embeddingVector1.reduce((sum, value, index) => sum + value * embeddingVector2[index], 0);
|
|
5554
|
+
const magnitude1 = Math.sqrt(embeddingVector1.reduce((sum, value) => sum + value * value, 0));
|
|
5555
|
+
const magnitude2 = Math.sqrt(embeddingVector2.reduce((sum, value) => sum + value * value, 0));
|
|
5556
|
+
return 1 - dotProduct / (magnitude1 * magnitude2);
|
|
5557
|
+
}
|
|
5558
|
+
|
|
5543
5559
|
/**
|
|
5544
5560
|
* @@@
|
|
5545
5561
|
*
|
|
@@ -5566,7 +5582,7 @@ async function getKnowledgeForTask(options) {
|
|
|
5566
5582
|
},
|
|
5567
5583
|
content: task.content,
|
|
5568
5584
|
parameters: {
|
|
5569
|
-
/*
|
|
5585
|
+
/* !!!! */
|
|
5570
5586
|
},
|
|
5571
5587
|
};
|
|
5572
5588
|
const taskEmbeddingResult = await llmTools.callEmbeddingModel(taskEmbeddingPrompt);
|
|
@@ -5601,16 +5617,6 @@ async function getKnowledgeForTask(options) {
|
|
|
5601
5617
|
return knowledgePiecesLimited.map(({ content }) => `- ${content}`).join('\n');
|
|
5602
5618
|
// <- TODO: [🧠] Some smart aggregation of knowledge pieces, single-line vs multi-line vs mixed
|
|
5603
5619
|
}
|
|
5604
|
-
// TODO: !!!!!! Annotate + to new file
|
|
5605
|
-
function computeCosineSimilarity(embeddingVector1, embeddingVector2) {
|
|
5606
|
-
if (embeddingVector1.length !== embeddingVector2.length) {
|
|
5607
|
-
throw new TypeError('Embedding vectors must have the same length');
|
|
5608
|
-
}
|
|
5609
|
-
const dotProduct = embeddingVector1.reduce((sum, value, index) => sum + value * embeddingVector2[index], 0);
|
|
5610
|
-
const magnitude1 = Math.sqrt(embeddingVector1.reduce((sum, value) => sum + value * value, 0));
|
|
5611
|
-
const magnitude2 = Math.sqrt(embeddingVector2.reduce((sum, value) => sum + value * value, 0));
|
|
5612
|
-
return 1 - dotProduct / (magnitude1 * magnitude2);
|
|
5613
|
-
}
|
|
5614
5620
|
/**
|
|
5615
5621
|
* TODO: !!!! Verify if this is working
|
|
5616
5622
|
* TODO: [♨] Implement Better - use keyword search
|
|
@@ -5819,6 +5825,7 @@ async function executePipeline(options) {
|
|
|
5819
5825
|
* Note: This is a flag to prevent `onProgress` call after the pipeline execution is finished
|
|
5820
5826
|
*/
|
|
5821
5827
|
let isReturned = false;
|
|
5828
|
+
console.log(`!!! preparedPipeline`, preparedPipeline);
|
|
5822
5829
|
// Note: Check that all input input parameters are defined
|
|
5823
5830
|
for (const parameter of preparedPipeline.parameters.filter(({ isInput }) => isInput)) {
|
|
5824
5831
|
if (inputParameters[parameter.name] === undefined) {
|
|
@@ -6113,6 +6120,22 @@ function createPipelineExecutor(options) {
|
|
|
6113
6120
|
cacheDirname,
|
|
6114
6121
|
intermediateFilesStrategy,
|
|
6115
6122
|
isAutoInstalled,
|
|
6123
|
+
}).catch((error) => {
|
|
6124
|
+
assertsError(error);
|
|
6125
|
+
return exportJson({
|
|
6126
|
+
name: 'pipelineExecutorResult',
|
|
6127
|
+
message: `Unuccessful PipelineExecutorResult, last catch`,
|
|
6128
|
+
order: [],
|
|
6129
|
+
value: {
|
|
6130
|
+
isSuccessful: false,
|
|
6131
|
+
errors: [serializeError(error)],
|
|
6132
|
+
warnings: [],
|
|
6133
|
+
usage: UNCERTAIN_USAGE,
|
|
6134
|
+
executionReport: null,
|
|
6135
|
+
outputParameters: {},
|
|
6136
|
+
preparedPipeline,
|
|
6137
|
+
},
|
|
6138
|
+
});
|
|
6116
6139
|
});
|
|
6117
6140
|
};
|
|
6118
6141
|
const pipelineExecutor = (inputParameters) => createTask({
|