@promptbook/remote-server 0.92.0-11 → 0.92.0-12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/index.es.js +161 -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 +161 -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/umd/index.umd.js
CHANGED
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
* @generated
|
|
49
49
|
* @see https://github.com/webgptorg/promptbook
|
|
50
50
|
*/
|
|
51
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.92.0-
|
|
51
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.92.0-12';
|
|
52
52
|
/**
|
|
53
53
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
54
54
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -2082,6 +2082,74 @@
|
|
|
2082
2082
|
* TODO: [🐚] Split into more files and make `PrepareTask` & `RemoteTask` + split the function
|
|
2083
2083
|
*/
|
|
2084
2084
|
|
|
2085
|
+
/**
|
|
2086
|
+
* Represents the uncertain value
|
|
2087
|
+
*
|
|
2088
|
+
* @public exported from `@promptbook/core`
|
|
2089
|
+
*/
|
|
2090
|
+
const ZERO_VALUE = $deepFreeze({ value: 0 });
|
|
2091
|
+
/**
|
|
2092
|
+
* Represents the uncertain value
|
|
2093
|
+
*
|
|
2094
|
+
* @public exported from `@promptbook/core`
|
|
2095
|
+
*/
|
|
2096
|
+
const UNCERTAIN_ZERO_VALUE = $deepFreeze({ value: 0, isUncertain: true });
|
|
2097
|
+
/**
|
|
2098
|
+
* Represents the usage with no resources consumed
|
|
2099
|
+
*
|
|
2100
|
+
* @public exported from `@promptbook/core`
|
|
2101
|
+
*/
|
|
2102
|
+
const ZERO_USAGE = $deepFreeze({
|
|
2103
|
+
price: ZERO_VALUE,
|
|
2104
|
+
input: {
|
|
2105
|
+
tokensCount: ZERO_VALUE,
|
|
2106
|
+
charactersCount: ZERO_VALUE,
|
|
2107
|
+
wordsCount: ZERO_VALUE,
|
|
2108
|
+
sentencesCount: ZERO_VALUE,
|
|
2109
|
+
linesCount: ZERO_VALUE,
|
|
2110
|
+
paragraphsCount: ZERO_VALUE,
|
|
2111
|
+
pagesCount: ZERO_VALUE,
|
|
2112
|
+
},
|
|
2113
|
+
output: {
|
|
2114
|
+
tokensCount: ZERO_VALUE,
|
|
2115
|
+
charactersCount: ZERO_VALUE,
|
|
2116
|
+
wordsCount: ZERO_VALUE,
|
|
2117
|
+
sentencesCount: ZERO_VALUE,
|
|
2118
|
+
linesCount: ZERO_VALUE,
|
|
2119
|
+
paragraphsCount: ZERO_VALUE,
|
|
2120
|
+
pagesCount: ZERO_VALUE,
|
|
2121
|
+
},
|
|
2122
|
+
});
|
|
2123
|
+
/**
|
|
2124
|
+
* Represents the usage with unknown resources consumed
|
|
2125
|
+
*
|
|
2126
|
+
* @public exported from `@promptbook/core`
|
|
2127
|
+
*/
|
|
2128
|
+
const UNCERTAIN_USAGE = $deepFreeze({
|
|
2129
|
+
price: UNCERTAIN_ZERO_VALUE,
|
|
2130
|
+
input: {
|
|
2131
|
+
tokensCount: UNCERTAIN_ZERO_VALUE,
|
|
2132
|
+
charactersCount: UNCERTAIN_ZERO_VALUE,
|
|
2133
|
+
wordsCount: UNCERTAIN_ZERO_VALUE,
|
|
2134
|
+
sentencesCount: UNCERTAIN_ZERO_VALUE,
|
|
2135
|
+
linesCount: UNCERTAIN_ZERO_VALUE,
|
|
2136
|
+
paragraphsCount: UNCERTAIN_ZERO_VALUE,
|
|
2137
|
+
pagesCount: UNCERTAIN_ZERO_VALUE,
|
|
2138
|
+
},
|
|
2139
|
+
output: {
|
|
2140
|
+
tokensCount: UNCERTAIN_ZERO_VALUE,
|
|
2141
|
+
charactersCount: UNCERTAIN_ZERO_VALUE,
|
|
2142
|
+
wordsCount: UNCERTAIN_ZERO_VALUE,
|
|
2143
|
+
sentencesCount: UNCERTAIN_ZERO_VALUE,
|
|
2144
|
+
linesCount: UNCERTAIN_ZERO_VALUE,
|
|
2145
|
+
paragraphsCount: UNCERTAIN_ZERO_VALUE,
|
|
2146
|
+
pagesCount: UNCERTAIN_ZERO_VALUE,
|
|
2147
|
+
},
|
|
2148
|
+
});
|
|
2149
|
+
/**
|
|
2150
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
2151
|
+
*/
|
|
2152
|
+
|
|
2085
2153
|
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"}];
|
|
2086
2154
|
|
|
2087
2155
|
/**
|
|
@@ -2559,74 +2627,6 @@
|
|
|
2559
2627
|
await Promise.all(tasks);
|
|
2560
2628
|
}
|
|
2561
2629
|
|
|
2562
|
-
/**
|
|
2563
|
-
* Represents the uncertain value
|
|
2564
|
-
*
|
|
2565
|
-
* @public exported from `@promptbook/core`
|
|
2566
|
-
*/
|
|
2567
|
-
const ZERO_VALUE = $deepFreeze({ value: 0 });
|
|
2568
|
-
/**
|
|
2569
|
-
* Represents the uncertain value
|
|
2570
|
-
*
|
|
2571
|
-
* @public exported from `@promptbook/core`
|
|
2572
|
-
*/
|
|
2573
|
-
const UNCERTAIN_ZERO_VALUE = $deepFreeze({ value: 0, isUncertain: true });
|
|
2574
|
-
/**
|
|
2575
|
-
* Represents the usage with no resources consumed
|
|
2576
|
-
*
|
|
2577
|
-
* @public exported from `@promptbook/core`
|
|
2578
|
-
*/
|
|
2579
|
-
const ZERO_USAGE = $deepFreeze({
|
|
2580
|
-
price: ZERO_VALUE,
|
|
2581
|
-
input: {
|
|
2582
|
-
tokensCount: ZERO_VALUE,
|
|
2583
|
-
charactersCount: ZERO_VALUE,
|
|
2584
|
-
wordsCount: ZERO_VALUE,
|
|
2585
|
-
sentencesCount: ZERO_VALUE,
|
|
2586
|
-
linesCount: ZERO_VALUE,
|
|
2587
|
-
paragraphsCount: ZERO_VALUE,
|
|
2588
|
-
pagesCount: ZERO_VALUE,
|
|
2589
|
-
},
|
|
2590
|
-
output: {
|
|
2591
|
-
tokensCount: ZERO_VALUE,
|
|
2592
|
-
charactersCount: ZERO_VALUE,
|
|
2593
|
-
wordsCount: ZERO_VALUE,
|
|
2594
|
-
sentencesCount: ZERO_VALUE,
|
|
2595
|
-
linesCount: ZERO_VALUE,
|
|
2596
|
-
paragraphsCount: ZERO_VALUE,
|
|
2597
|
-
pagesCount: ZERO_VALUE,
|
|
2598
|
-
},
|
|
2599
|
-
});
|
|
2600
|
-
/**
|
|
2601
|
-
* Represents the usage with unknown resources consumed
|
|
2602
|
-
*
|
|
2603
|
-
* @public exported from `@promptbook/core`
|
|
2604
|
-
*/
|
|
2605
|
-
$deepFreeze({
|
|
2606
|
-
price: UNCERTAIN_ZERO_VALUE,
|
|
2607
|
-
input: {
|
|
2608
|
-
tokensCount: UNCERTAIN_ZERO_VALUE,
|
|
2609
|
-
charactersCount: UNCERTAIN_ZERO_VALUE,
|
|
2610
|
-
wordsCount: UNCERTAIN_ZERO_VALUE,
|
|
2611
|
-
sentencesCount: UNCERTAIN_ZERO_VALUE,
|
|
2612
|
-
linesCount: UNCERTAIN_ZERO_VALUE,
|
|
2613
|
-
paragraphsCount: UNCERTAIN_ZERO_VALUE,
|
|
2614
|
-
pagesCount: UNCERTAIN_ZERO_VALUE,
|
|
2615
|
-
},
|
|
2616
|
-
output: {
|
|
2617
|
-
tokensCount: UNCERTAIN_ZERO_VALUE,
|
|
2618
|
-
charactersCount: UNCERTAIN_ZERO_VALUE,
|
|
2619
|
-
wordsCount: UNCERTAIN_ZERO_VALUE,
|
|
2620
|
-
sentencesCount: UNCERTAIN_ZERO_VALUE,
|
|
2621
|
-
linesCount: UNCERTAIN_ZERO_VALUE,
|
|
2622
|
-
paragraphsCount: UNCERTAIN_ZERO_VALUE,
|
|
2623
|
-
pagesCount: UNCERTAIN_ZERO_VALUE,
|
|
2624
|
-
},
|
|
2625
|
-
});
|
|
2626
|
-
/**
|
|
2627
|
-
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
2628
|
-
*/
|
|
2629
|
-
|
|
2630
2630
|
/**
|
|
2631
2631
|
* Function `addUsage` will add multiple usages into one
|
|
2632
2632
|
*
|
|
@@ -4420,6 +4420,24 @@
|
|
|
4420
4420
|
// encoding: 'utf-8',
|
|
4421
4421
|
});
|
|
4422
4422
|
|
|
4423
|
+
/**
|
|
4424
|
+
* Converts a CSV string into an object
|
|
4425
|
+
*
|
|
4426
|
+
* Note: This is wrapper around `papaparse.parse()` with better autohealing
|
|
4427
|
+
*
|
|
4428
|
+
* @private - for now until `@promptbook/csv` is released
|
|
4429
|
+
*/
|
|
4430
|
+
function csvParse(value /* <- TODO: string_csv */, settings, schema /* <- TODO: Make CSV Schemas */) {
|
|
4431
|
+
settings = { ...settings, ...MANDATORY_CSV_SETTINGS };
|
|
4432
|
+
// Note: Autoheal invalid '\n' characters
|
|
4433
|
+
if (settings.newline && !settings.newline.includes('\r') && value.includes('\r')) {
|
|
4434
|
+
console.warn('CSV string contains carriage return characters, but in the CSV settings the `newline` setting does not include them. Autohealing the CSV string.');
|
|
4435
|
+
value = value.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
|
|
4436
|
+
}
|
|
4437
|
+
const csv = papaparse.parse(value, settings);
|
|
4438
|
+
return csv;
|
|
4439
|
+
}
|
|
4440
|
+
|
|
4423
4441
|
/**
|
|
4424
4442
|
* Function to check if a string is valid CSV
|
|
4425
4443
|
*
|
|
@@ -4442,31 +4460,13 @@
|
|
|
4442
4460
|
}
|
|
4443
4461
|
}
|
|
4444
4462
|
|
|
4445
|
-
/**
|
|
4446
|
-
* Converts a CSV string into an object
|
|
4447
|
-
*
|
|
4448
|
-
* Note: This is wrapper around `papaparse.parse()` with better autohealing
|
|
4449
|
-
*
|
|
4450
|
-
* @private - for now until `@promptbook/csv` is released
|
|
4451
|
-
*/
|
|
4452
|
-
function csvParse(value /* <- TODO: string_csv */, settings, schema /* <- TODO: Make CSV Schemas */) {
|
|
4453
|
-
settings = { ...settings, ...MANDATORY_CSV_SETTINGS };
|
|
4454
|
-
// Note: Autoheal invalid '\n' characters
|
|
4455
|
-
if (settings.newline && !settings.newline.includes('\r') && value.includes('\r')) {
|
|
4456
|
-
console.warn('CSV string contains carriage return characters, but in the CSV settings the `newline` setting does not include them. Autohealing the CSV string.');
|
|
4457
|
-
value = value.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
|
|
4458
|
-
}
|
|
4459
|
-
const csv = papaparse.parse(value, settings);
|
|
4460
|
-
return csv;
|
|
4461
|
-
}
|
|
4462
|
-
|
|
4463
4463
|
/**
|
|
4464
4464
|
* Definition for CSV spreadsheet
|
|
4465
4465
|
*
|
|
4466
4466
|
* @public exported from `@promptbook/core`
|
|
4467
4467
|
* <- TODO: [🏢] Export from package `@promptbook/csv`
|
|
4468
4468
|
*/
|
|
4469
|
-
const
|
|
4469
|
+
const CsvFormatParser = {
|
|
4470
4470
|
formatName: 'CSV',
|
|
4471
4471
|
aliases: ['SPREADSHEET', 'TABLE'],
|
|
4472
4472
|
isValid(value, settings, schema) {
|
|
@@ -4478,7 +4478,7 @@
|
|
|
4478
4478
|
heal(value, settings, schema) {
|
|
4479
4479
|
throw new Error('Not implemented');
|
|
4480
4480
|
},
|
|
4481
|
-
|
|
4481
|
+
subvalueParsers: [
|
|
4482
4482
|
{
|
|
4483
4483
|
subvalueName: 'ROW',
|
|
4484
4484
|
async mapValues(value, outputParameterName, settings, mapCallback) {
|
|
@@ -4539,10 +4539,10 @@
|
|
|
4539
4539
|
],
|
|
4540
4540
|
};
|
|
4541
4541
|
/**
|
|
4542
|
-
* TODO: [🍓] In `
|
|
4543
|
-
* TODO: [🍓] In `
|
|
4544
|
-
* TODO: [🍓] In `
|
|
4545
|
-
* TODO: [🍓] In `
|
|
4542
|
+
* TODO: [🍓] In `CsvFormatParser` implement simple `isValid`
|
|
4543
|
+
* TODO: [🍓] In `CsvFormatParser` implement partial `canBeValid`
|
|
4544
|
+
* TODO: [🍓] In `CsvFormatParser` implement `heal
|
|
4545
|
+
* TODO: [🍓] In `CsvFormatParser` implement `subvalueParsers`
|
|
4546
4546
|
* TODO: [🏢] Allow to expect something inside CSV objects and other formats
|
|
4547
4547
|
*/
|
|
4548
4548
|
|
|
@@ -4551,7 +4551,7 @@
|
|
|
4551
4551
|
*
|
|
4552
4552
|
* @private still in development [🏢]
|
|
4553
4553
|
*/
|
|
4554
|
-
const
|
|
4554
|
+
const JsonFormatParser = {
|
|
4555
4555
|
formatName: 'JSON',
|
|
4556
4556
|
mimeType: 'application/json',
|
|
4557
4557
|
isValid(value, settings, schema) {
|
|
@@ -4563,28 +4563,28 @@
|
|
|
4563
4563
|
heal(value, settings, schema) {
|
|
4564
4564
|
throw new Error('Not implemented');
|
|
4565
4565
|
},
|
|
4566
|
-
|
|
4566
|
+
subvalueParsers: [],
|
|
4567
4567
|
};
|
|
4568
4568
|
/**
|
|
4569
4569
|
* TODO: [🧠] Maybe propper instance of object
|
|
4570
4570
|
* TODO: [0] Make string_serialized_json
|
|
4571
4571
|
* TODO: [1] Make type for JSON Settings and Schema
|
|
4572
4572
|
* TODO: [🧠] What to use for validating JSONs - JSON Schema, ZoD, typescript types/interfaces,...?
|
|
4573
|
-
* TODO: [🍓] In `
|
|
4574
|
-
* TODO: [🍓] In `
|
|
4575
|
-
* TODO: [🍓] In `
|
|
4576
|
-
* TODO: [🍓] In `
|
|
4573
|
+
* TODO: [🍓] In `JsonFormatParser` implement simple `isValid`
|
|
4574
|
+
* TODO: [🍓] In `JsonFormatParser` implement partial `canBeValid`
|
|
4575
|
+
* TODO: [🍓] In `JsonFormatParser` implement `heal
|
|
4576
|
+
* TODO: [🍓] In `JsonFormatParser` implement `subvalueParsers`
|
|
4577
4577
|
* TODO: [🏢] Allow to expect something inside JSON objects and other formats
|
|
4578
4578
|
*/
|
|
4579
4579
|
|
|
4580
4580
|
/**
|
|
4581
4581
|
* Definition for any text - this will be always valid
|
|
4582
4582
|
*
|
|
4583
|
-
* Note: This is not useful for validation, but for splitting and mapping with `
|
|
4583
|
+
* Note: This is not useful for validation, but for splitting and mapping with `subvalueParsers`
|
|
4584
4584
|
*
|
|
4585
4585
|
* @public exported from `@promptbook/core`
|
|
4586
4586
|
*/
|
|
4587
|
-
const
|
|
4587
|
+
const TextFormatParser = {
|
|
4588
4588
|
formatName: 'TEXT',
|
|
4589
4589
|
isValid(value) {
|
|
4590
4590
|
return typeof value === 'string';
|
|
@@ -4593,9 +4593,9 @@
|
|
|
4593
4593
|
return typeof partialValue === 'string';
|
|
4594
4594
|
},
|
|
4595
4595
|
heal() {
|
|
4596
|
-
throw new UnexpectedError('It does not make sense to call `
|
|
4596
|
+
throw new UnexpectedError('It does not make sense to call `TextFormatParser.heal`');
|
|
4597
4597
|
},
|
|
4598
|
-
|
|
4598
|
+
subvalueParsers: [
|
|
4599
4599
|
{
|
|
4600
4600
|
subvalueName: 'LINE',
|
|
4601
4601
|
async mapValues(value, outputParameterName, settings, mapCallback) {
|
|
@@ -4615,10 +4615,10 @@
|
|
|
4615
4615
|
/**
|
|
4616
4616
|
* TODO: [1] Make type for XML Text and Schema
|
|
4617
4617
|
* TODO: [🧠][🤠] Here should be all words, characters, lines, paragraphs, pages available as subvalues
|
|
4618
|
-
* TODO: [🍓] In `
|
|
4619
|
-
* TODO: [🍓] In `
|
|
4620
|
-
* TODO: [🍓] In `
|
|
4621
|
-
* TODO: [🍓] In `
|
|
4618
|
+
* TODO: [🍓] In `TextFormatParser` implement simple `isValid`
|
|
4619
|
+
* TODO: [🍓] In `TextFormatParser` implement partial `canBeValid`
|
|
4620
|
+
* TODO: [🍓] In `TextFormatParser` implement `heal
|
|
4621
|
+
* TODO: [🍓] In `TextFormatParser` implement `subvalueParsers`
|
|
4622
4622
|
* TODO: [🏢] Allow to expect something inside each item of list and other formats
|
|
4623
4623
|
*/
|
|
4624
4624
|
|
|
@@ -4651,7 +4651,7 @@
|
|
|
4651
4651
|
*
|
|
4652
4652
|
* @private still in development [🏢]
|
|
4653
4653
|
*/
|
|
4654
|
-
const
|
|
4654
|
+
const XmlFormatParser = {
|
|
4655
4655
|
formatName: 'XML',
|
|
4656
4656
|
mimeType: 'application/xml',
|
|
4657
4657
|
isValid(value, settings, schema) {
|
|
@@ -4663,17 +4663,17 @@
|
|
|
4663
4663
|
heal(value, settings, schema) {
|
|
4664
4664
|
throw new Error('Not implemented');
|
|
4665
4665
|
},
|
|
4666
|
-
|
|
4666
|
+
subvalueParsers: [],
|
|
4667
4667
|
};
|
|
4668
4668
|
/**
|
|
4669
4669
|
* TODO: [🧠] Maybe propper instance of object
|
|
4670
4670
|
* TODO: [0] Make string_serialized_xml
|
|
4671
4671
|
* TODO: [1] Make type for XML Settings and Schema
|
|
4672
4672
|
* TODO: [🧠] What to use for validating XMLs - XSD,...
|
|
4673
|
-
* TODO: [🍓] In `
|
|
4674
|
-
* TODO: [🍓] In `
|
|
4675
|
-
* TODO: [🍓] In `
|
|
4676
|
-
* TODO: [🍓] In `
|
|
4673
|
+
* TODO: [🍓] In `XmlFormatParser` implement simple `isValid`
|
|
4674
|
+
* TODO: [🍓] In `XmlFormatParser` implement partial `canBeValid`
|
|
4675
|
+
* TODO: [🍓] In `XmlFormatParser` implement `heal
|
|
4676
|
+
* TODO: [🍓] In `XmlFormatParser` implement `subvalueParsers`
|
|
4677
4677
|
* TODO: [🏢] Allow to expect something inside XML and other formats
|
|
4678
4678
|
*/
|
|
4679
4679
|
|
|
@@ -4682,12 +4682,7 @@
|
|
|
4682
4682
|
*
|
|
4683
4683
|
* @private internal index of `...` <- TODO [🏢]
|
|
4684
4684
|
*/
|
|
4685
|
-
const FORMAT_DEFINITIONS = [
|
|
4686
|
-
JsonFormatDefinition,
|
|
4687
|
-
XmlFormatDefinition,
|
|
4688
|
-
TextFormatDefinition,
|
|
4689
|
-
CsvFormatDefinition,
|
|
4690
|
-
];
|
|
4685
|
+
const FORMAT_DEFINITIONS = [JsonFormatParser, XmlFormatParser, TextFormatParser, CsvFormatParser];
|
|
4691
4686
|
/**
|
|
4692
4687
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
4693
4688
|
*/
|
|
@@ -4857,7 +4852,7 @@
|
|
|
4857
4852
|
}
|
|
4858
4853
|
/**
|
|
4859
4854
|
* TODO: Add some auto-healing logic + extract YAML, JSON5, TOML, etc.
|
|
4860
|
-
* TODO: [🏢] Make this logic part of `
|
|
4855
|
+
* TODO: [🏢] Make this logic part of `JsonFormatParser` or `isValidJsonString`
|
|
4861
4856
|
*/
|
|
4862
4857
|
|
|
4863
4858
|
/**
|
|
@@ -5076,7 +5071,7 @@
|
|
|
5076
5071
|
PAGES: countPages,
|
|
5077
5072
|
};
|
|
5078
5073
|
/**
|
|
5079
|
-
* TODO: [🧠][🤠] This should be probbably as part of `
|
|
5074
|
+
* TODO: [🧠][🤠] This should be probbably as part of `TextFormatParser`
|
|
5080
5075
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
5081
5076
|
*/
|
|
5082
5077
|
|
|
@@ -5104,7 +5099,7 @@
|
|
|
5104
5099
|
}
|
|
5105
5100
|
/**
|
|
5106
5101
|
* TODO: [💝] Unite object for expecting amount and format
|
|
5107
|
-
* TODO: [🧠][🤠] This should be part of `
|
|
5102
|
+
* TODO: [🧠][🤠] This should be part of `TextFormatParser`
|
|
5108
5103
|
* Note: [💝] and [🤠] are interconnected together
|
|
5109
5104
|
*/
|
|
5110
5105
|
|
|
@@ -5332,7 +5327,7 @@
|
|
|
5332
5327
|
if (task.format) {
|
|
5333
5328
|
if (task.format === 'JSON') {
|
|
5334
5329
|
if (!isValidJsonString($ongoingTaskResult.$resultString || '')) {
|
|
5335
|
-
// TODO: [🏢] Do more universally via `
|
|
5330
|
+
// TODO: [🏢] Do more universally via `FormatParser`
|
|
5336
5331
|
try {
|
|
5337
5332
|
$ongoingTaskResult.$resultString = extractJsonBlock($ongoingTaskResult.$resultString || '');
|
|
5338
5333
|
}
|
|
@@ -5470,16 +5465,16 @@
|
|
|
5470
5465
|
${block(pipelineIdentification)}
|
|
5471
5466
|
`));
|
|
5472
5467
|
}
|
|
5473
|
-
const
|
|
5474
|
-
if (
|
|
5468
|
+
const subvalueParser = formatDefinition.subvalueParsers.find((subvalueParser) => [subvalueParser.subvalueName, ...(subvalueParser.aliases || [])].includes(task.foreach.subformatName));
|
|
5469
|
+
if (subvalueParser === undefined) {
|
|
5475
5470
|
throw new UnexpectedError(
|
|
5476
5471
|
// <- TODO: [🧠][🧐] Should be formats fixed per promptbook version or behave as plugins (=> change UnexpectedError)
|
|
5477
5472
|
spaceTrim__default["default"]((block) => `
|
|
5478
5473
|
Unsupported subformat name "${task.foreach.subformatName}" for format "${task.foreach.formatName}"
|
|
5479
5474
|
|
|
5480
5475
|
Available subformat names for format "${formatDefinition.formatName}":
|
|
5481
|
-
${block(formatDefinition.
|
|
5482
|
-
.map((
|
|
5476
|
+
${block(formatDefinition.subvalueParsers
|
|
5477
|
+
.map((subvalueParser) => subvalueParser.subvalueName)
|
|
5483
5478
|
.map((subvalueName) => `- ${subvalueName}`)
|
|
5484
5479
|
.join('\n'))}
|
|
5485
5480
|
|
|
@@ -5493,7 +5488,7 @@
|
|
|
5493
5488
|
formatSettings = csvSettings;
|
|
5494
5489
|
// <- TODO: [🤹♂️] More universal, make simmilar pattern for other formats for example \n vs \r\n in text
|
|
5495
5490
|
}
|
|
5496
|
-
const resultString = await
|
|
5491
|
+
const resultString = await subvalueParser.mapValues(parameterValue, task.foreach.outputSubparameterName, formatSettings, async (subparameters, index) => {
|
|
5497
5492
|
let mappedParameters;
|
|
5498
5493
|
// TODO: [🤹♂️][🪂] Limit to N concurrent executions
|
|
5499
5494
|
// TODO: When done [🐚] Report progress also for each subvalue here
|
|
@@ -5555,6 +5550,27 @@
|
|
|
5555
5550
|
return RESERVED_PARAMETER_MISSING_VALUE /* <- TODO: [♨] Implement */;
|
|
5556
5551
|
}
|
|
5557
5552
|
|
|
5553
|
+
/**
|
|
5554
|
+
* Computes the cosine similarity between two embedding vectors
|
|
5555
|
+
*
|
|
5556
|
+
* Note: This is helping function for RAG (retrieval-augmented generation)
|
|
5557
|
+
*
|
|
5558
|
+
* @param embeddingVector1
|
|
5559
|
+
* @param embeddingVector2
|
|
5560
|
+
* @returns Cosine similarity between the two vectors
|
|
5561
|
+
*
|
|
5562
|
+
* @public exported from `@promptbook/core`
|
|
5563
|
+
*/
|
|
5564
|
+
function computeCosineSimilarity(embeddingVector1, embeddingVector2) {
|
|
5565
|
+
if (embeddingVector1.length !== embeddingVector2.length) {
|
|
5566
|
+
throw new TypeError('Embedding vectors must have the same length');
|
|
5567
|
+
}
|
|
5568
|
+
const dotProduct = embeddingVector1.reduce((sum, value, index) => sum + value * embeddingVector2[index], 0);
|
|
5569
|
+
const magnitude1 = Math.sqrt(embeddingVector1.reduce((sum, value) => sum + value * value, 0));
|
|
5570
|
+
const magnitude2 = Math.sqrt(embeddingVector2.reduce((sum, value) => sum + value * value, 0));
|
|
5571
|
+
return 1 - dotProduct / (magnitude1 * magnitude2);
|
|
5572
|
+
}
|
|
5573
|
+
|
|
5558
5574
|
/**
|
|
5559
5575
|
* @@@
|
|
5560
5576
|
*
|
|
@@ -5581,7 +5597,7 @@
|
|
|
5581
5597
|
},
|
|
5582
5598
|
content: task.content,
|
|
5583
5599
|
parameters: {
|
|
5584
|
-
/*
|
|
5600
|
+
/* !!!! */
|
|
5585
5601
|
},
|
|
5586
5602
|
};
|
|
5587
5603
|
const taskEmbeddingResult = await llmTools.callEmbeddingModel(taskEmbeddingPrompt);
|
|
@@ -5616,16 +5632,6 @@
|
|
|
5616
5632
|
return knowledgePiecesLimited.map(({ content }) => `- ${content}`).join('\n');
|
|
5617
5633
|
// <- TODO: [🧠] Some smart aggregation of knowledge pieces, single-line vs multi-line vs mixed
|
|
5618
5634
|
}
|
|
5619
|
-
// TODO: !!!!!! Annotate + to new file
|
|
5620
|
-
function computeCosineSimilarity(embeddingVector1, embeddingVector2) {
|
|
5621
|
-
if (embeddingVector1.length !== embeddingVector2.length) {
|
|
5622
|
-
throw new TypeError('Embedding vectors must have the same length');
|
|
5623
|
-
}
|
|
5624
|
-
const dotProduct = embeddingVector1.reduce((sum, value, index) => sum + value * embeddingVector2[index], 0);
|
|
5625
|
-
const magnitude1 = Math.sqrt(embeddingVector1.reduce((sum, value) => sum + value * value, 0));
|
|
5626
|
-
const magnitude2 = Math.sqrt(embeddingVector2.reduce((sum, value) => sum + value * value, 0));
|
|
5627
|
-
return 1 - dotProduct / (magnitude1 * magnitude2);
|
|
5628
|
-
}
|
|
5629
5635
|
/**
|
|
5630
5636
|
* TODO: !!!! Verify if this is working
|
|
5631
5637
|
* TODO: [♨] Implement Better - use keyword search
|
|
@@ -6128,6 +6134,22 @@
|
|
|
6128
6134
|
cacheDirname,
|
|
6129
6135
|
intermediateFilesStrategy,
|
|
6130
6136
|
isAutoInstalled,
|
|
6137
|
+
}).catch((error) => {
|
|
6138
|
+
assertsError(error);
|
|
6139
|
+
return exportJson({
|
|
6140
|
+
name: 'pipelineExecutorResult',
|
|
6141
|
+
message: `Unuccessful PipelineExecutorResult, last catch`,
|
|
6142
|
+
order: [],
|
|
6143
|
+
value: {
|
|
6144
|
+
isSuccessful: false,
|
|
6145
|
+
errors: [serializeError(error)],
|
|
6146
|
+
warnings: [],
|
|
6147
|
+
usage: UNCERTAIN_USAGE,
|
|
6148
|
+
executionReport: null,
|
|
6149
|
+
outputParameters: {},
|
|
6150
|
+
preparedPipeline,
|
|
6151
|
+
},
|
|
6152
|
+
});
|
|
6131
6153
|
});
|
|
6132
6154
|
};
|
|
6133
6155
|
const pipelineExecutor = (inputParameters) => createTask({
|