@promptbook/cli 0.69.0-8 → 0.69.0
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 +4 -1
- package/esm/index.es.js +1076 -397
- package/esm/index.es.js.map +1 -1
- package/esm/typings/promptbook-collection/index.d.ts +0 -3
- package/esm/typings/src/_packages/core.index.d.ts +12 -0
- package/esm/typings/src/_packages/types.index.d.ts +6 -0
- package/esm/typings/src/_packages/utils.index.d.ts +4 -4
- package/esm/typings/src/cli/cli-commands/make.d.ts +1 -1
- package/esm/typings/src/collection/constructors/createCollectionFromUrl.d.ts +1 -1
- package/esm/typings/src/commands/FOREACH/ForeachCommand.d.ts +1 -1
- package/esm/typings/src/commands/FOREACH/ForeachJson.d.ts +6 -5
- package/esm/typings/src/commands/FOREACH/foreachCommandParser.d.ts +1 -2
- package/esm/typings/src/commands/_common/types/CommandParser.d.ts +1 -1
- package/esm/typings/src/config.d.ts +11 -4
- package/esm/typings/src/conversion/pipelineStringToJsonSync.d.ts +1 -1
- package/esm/typings/src/conversion/prettify/renderPipelineMermaidOptions.d.ts +3 -3
- package/esm/typings/src/conversion/validation/validatePipeline.d.ts +6 -5
- package/esm/typings/src/errors/AbstractFormatError.d.ts +11 -0
- package/esm/typings/src/execution/PipelineExecutor.d.ts +1 -0
- package/esm/typings/src/execution/PipelineExecutorResult.d.ts +5 -6
- package/esm/typings/src/execution/createPipelineExecutor/$OngoingTemplateResult.d.ts +24 -0
- package/esm/typings/src/execution/createPipelineExecutor/00-CreatePipelineExecutorSettings.d.ts +7 -0
- package/esm/typings/src/execution/createPipelineExecutor/00-createPipelineExecutor.d.ts +3 -0
- package/esm/typings/src/execution/createPipelineExecutor/10-executePipeline.d.ts +4 -1
- package/esm/typings/src/execution/createPipelineExecutor/20-executeTemplate.d.ts +3 -0
- package/esm/typings/src/execution/createPipelineExecutor/{30-executeFormatCells.d.ts → 30-executeFormatSubvalues.d.ts} +2 -2
- package/esm/typings/src/execution/createPipelineExecutor/40-executeAttempts.d.ts +2 -8
- package/esm/typings/src/execution/embeddingVectorToString.d.ts +1 -1
- package/esm/typings/src/execution/utils/checkExpectations.d.ts +2 -0
- package/esm/typings/src/execution/utils/usageToHuman.d.ts +3 -4
- package/esm/typings/src/formats/_common/FormatDefinition.d.ts +14 -15
- package/esm/typings/src/formats/_common/FormatSubvalueDefinition.d.ts +31 -0
- package/esm/typings/src/formats/csv/{ListFormatDefinition.d.ts → CsvFormatDefinition.d.ts} +6 -3
- package/esm/typings/src/formats/csv/CsvFormatError.d.ts +10 -0
- package/esm/typings/src/formats/csv/CsvSettings.d.ts +13 -0
- package/esm/typings/src/formats/index.d.ts +1 -1
- package/esm/typings/src/formats/json/JsonFormatDefinition.d.ts +4 -3
- package/esm/typings/src/formats/text/TextFormatDefinition.d.ts +19 -0
- package/esm/typings/src/formats/xml/XmlFormatDefinition.d.ts +4 -3
- package/esm/typings/src/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.d.ts +1 -1
- package/esm/typings/src/knowledge/prepare-knowledge/pdf/prepareKnowledgeFromPdf.d.ts +1 -1
- package/esm/typings/src/llm-providers/_common/utils/cache/CacheItem.d.ts +1 -1
- package/esm/typings/src/llm-providers/anthropic-claude/anthropic-claude-models.d.ts +1 -1
- package/esm/typings/src/llm-providers/anthropic-claude/createAnthropicClaudeExecutionTools.d.ts +2 -2
- package/esm/typings/src/llm-providers/anthropic-claude/playground/playground.d.ts +2 -2
- package/esm/typings/src/llm-providers/openai/playground/playground.d.ts +1 -1
- package/esm/typings/src/personas/preparePersona.d.ts +1 -1
- package/esm/typings/src/prepare/isPipelinePrepared.d.ts +1 -1
- package/esm/typings/src/prepare/prepareTemplates.d.ts +1 -1
- package/esm/typings/src/types/PipelineJson/ParameterJson.d.ts +1 -1
- package/esm/typings/src/types/PipelineJson/PipelineJson.d.ts +1 -1
- package/esm/typings/src/types/execution-report/ExecutionReportJson.d.ts +0 -3
- package/esm/typings/src/types/execution-report/executionReportJsonToString.d.ts +2 -1
- package/esm/typings/src/types/typeAliases.d.ts +1 -1
- package/esm/typings/src/utils/expectation-counters/index.d.ts +3 -0
- package/esm/typings/src/utils/organization/{f.d.ts → empty_object.d.ts} +5 -1
- package/esm/typings/src/utils/organization/just_empty_object.d.ts +12 -0
- package/esm/typings/src/utils/{extractParameterNames.d.ts → parameters/extractParameterNames.d.ts} +2 -2
- package/esm/typings/src/utils/parameters/mapAvailableToExpectedParameters.d.ts +27 -0
- package/esm/typings/src/utils/{replaceParameters.d.ts → parameters/replaceParameters.d.ts} +2 -2
- package/esm/typings/src/utils/serialization/checkSerializableAsJson.d.ts +1 -1
- package/esm/typings/src/utils/serialization/isSerializableAsJson.d.ts +1 -1
- package/esm/typings/src/utils/validators/parameterName/validateParameterName.d.ts +10 -0
- package/package.json +17 -12
- package/umd/index.umd.js +1079 -401
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/formats/list/ListFormatDefinition.d.ts +0 -16
- /package/esm/typings/src/utils/{extractParameterNames.test.d.ts → parameters/extractParameterNames.test.d.ts} +0 -0
- /package/esm/typings/src/{execution/utils/usageToHuman.test.d.ts → utils/parameters/mapAvailableToExpectedParameters.test.d.ts} +0 -0
- /package/esm/typings/src/utils/{replaceParameters.test.d.ts → parameters/replaceParameters.test.d.ts} +0 -0
- /package/esm/typings/src/{personas/preparePersona.test.d.ts → utils/validators/parameterName/validateParameterName.test.d.ts} +0 -0
package/umd/index.umd.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('commander'), require('spacetrim'), require('colors'), require('waitasecond'), require('fs/promises'), require('path'), require('prettier'), require('prettier/parser-html'), require('crypto-js/enc-hex'), require('crypto-js/sha256'), require('path/posix'), require('dotenv'), require('glob-promise'), require('socket.io-client'), require('@anthropic-ai/sdk'), require('@azure/openai'), require('openai')) :
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports', 'commander', 'spacetrim', 'colors', 'waitasecond', 'fs/promises', 'path', 'prettier', 'prettier/parser-html', 'crypto-js/enc-hex', 'crypto-js/sha256', 'path/posix', 'dotenv', 'glob-promise', 'socket.io-client', '@anthropic-ai/sdk', '@azure/openai', 'openai'], factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-cli"] = {}, global.commander, global.spaceTrim, global.colors, global.waitasecond, global.promises, global.path, global.prettier, global.parserHtml, global.hexEncoder, global.sha256, global.posix, global.dotenv, global.glob, global.socket_ioClient, global.Anthropic, global.openai, global.OpenAI));
|
|
5
|
-
})(this, (function (exports, commander, spaceTrim, colors, waitasecond, promises, path, prettier, parserHtml, hexEncoder, sha256, posix, dotenv, glob, socket_ioClient, Anthropic, openai, OpenAI) { 'use strict';
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('commander'), require('spacetrim'), require('colors'), require('waitasecond'), require('fs/promises'), require('path'), require('prettier'), require('prettier/parser-html'), require('papaparse'), require('crypto-js/enc-hex'), require('crypto-js/sha256'), require('path/posix'), require('dotenv'), require('glob-promise'), require('socket.io-client'), require('@anthropic-ai/sdk'), require('@azure/openai'), require('openai')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', 'commander', 'spacetrim', 'colors', 'waitasecond', 'fs/promises', 'path', 'prettier', 'prettier/parser-html', 'papaparse', 'crypto-js/enc-hex', 'crypto-js/sha256', 'path/posix', 'dotenv', 'glob-promise', 'socket.io-client', '@anthropic-ai/sdk', '@azure/openai', 'openai'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-cli"] = {}, global.commander, global.spaceTrim, global.colors, global.waitasecond, global.promises, global.path, global.prettier, global.parserHtml, global.papaparse, global.hexEncoder, global.sha256, global.posix, global.dotenv, global.glob, global.socket_ioClient, global.Anthropic, global.openai, global.OpenAI));
|
|
5
|
+
})(this, (function (exports, commander, spaceTrim, colors, waitasecond, promises, path, prettier, parserHtml, papaparse, hexEncoder, sha256, posix, dotenv, glob, socket_ioClient, Anthropic, openai, OpenAI) { 'use strict';
|
|
6
6
|
|
|
7
7
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
8
|
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
/**
|
|
40
40
|
* The version of the Promptbook library
|
|
41
41
|
*/
|
|
42
|
-
var PROMPTBOOK_VERSION = '0.69.0-
|
|
43
|
-
// TODO: !!!! List here all the versions and annotate + put into script
|
|
42
|
+
var PROMPTBOOK_VERSION = '0.69.0-21';
|
|
43
|
+
// TODO: [main] !!!! List here all the versions and annotate + put into script
|
|
44
44
|
|
|
45
45
|
/*! *****************************************************************************
|
|
46
46
|
Copyright (c) Microsoft Corporation.
|
|
@@ -375,7 +375,7 @@
|
|
|
375
375
|
}
|
|
376
376
|
/**
|
|
377
377
|
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
378
|
-
* TODO: [🧠] !!! In-memory cache of same values to prevent multiple checks
|
|
378
|
+
* TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
|
|
379
379
|
* Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
|
|
380
380
|
*/
|
|
381
381
|
|
|
@@ -521,6 +521,17 @@
|
|
|
521
521
|
*/
|
|
522
522
|
var DEFAULT_REMOTE_URL_PATH = '/promptbook/socket.io';
|
|
523
523
|
// <- TODO: [🧜♂️]
|
|
524
|
+
/**
|
|
525
|
+
* @@@
|
|
526
|
+
*
|
|
527
|
+
* @public exported from `@promptbook/core`
|
|
528
|
+
*/
|
|
529
|
+
var DEFAULT_CSV_SETTINGS = Object.freeze({
|
|
530
|
+
delimiter: ',',
|
|
531
|
+
quoteChar: '"',
|
|
532
|
+
newline: '\n',
|
|
533
|
+
skipEmptyLines: true,
|
|
534
|
+
});
|
|
524
535
|
/**
|
|
525
536
|
* @@@
|
|
526
537
|
*
|
|
@@ -689,7 +700,7 @@
|
|
|
689
700
|
commands.push("PIPELINE URL ".concat(pipelineUrl));
|
|
690
701
|
}
|
|
691
702
|
commands.push("PROMPTBOOK VERSION ".concat(promptbookVersion));
|
|
692
|
-
// TODO: !!! This increase size of the bundle and is probbably not necessary
|
|
703
|
+
// TODO: [main] !!! This increase size of the bundle and is probbably not necessary
|
|
693
704
|
pipelineString = prettifyMarkdown(pipelineString);
|
|
694
705
|
try {
|
|
695
706
|
for (var _g = __values(parameters.filter(function (_a) {
|
|
@@ -837,12 +848,12 @@
|
|
|
837
848
|
pipelineString += '```' + contentLanguage;
|
|
838
849
|
pipelineString += '\n';
|
|
839
850
|
pipelineString += spaceTrim__default["default"](content);
|
|
840
|
-
// <- TODO: !!! Escape
|
|
851
|
+
// <- TODO: [main] !!! Escape
|
|
841
852
|
// <- TODO: [🧠] Some clear strategy how to spaceTrim the blocks
|
|
842
853
|
pipelineString += '\n';
|
|
843
854
|
pipelineString += '```';
|
|
844
855
|
pipelineString += '\n\n';
|
|
845
|
-
pipelineString += "`-> {".concat(resultingParameterName, "}`"); // <- TODO: !!! If the parameter here has description, add it and use templateParameterJsonToString
|
|
856
|
+
pipelineString += "`-> {".concat(resultingParameterName, "}`"); // <- TODO: [main] !!! If the parameter here has description, add it and use templateParameterJsonToString
|
|
846
857
|
}
|
|
847
858
|
}
|
|
848
859
|
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
@@ -1069,7 +1080,7 @@
|
|
|
1069
1080
|
});
|
|
1070
1081
|
}
|
|
1071
1082
|
|
|
1072
|
-
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",
|
|
1083
|
+
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",parameters:[{name:"knowledgeContent",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],templates:[{templateType:"PROMPT_TEMPLATE",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"]}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-from-markdown.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.ptbk.md",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],templates:[{templateType:"PROMPT_TEMPLATE",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"]}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-keywords.ptbk.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.ptbk.md",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],templates:[{templateType:"PROMPT_TEMPLATE",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- Title should be concise and clear\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"]}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-title.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.ptbk.md",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}],templates:[{templateType:"PROMPT_TEMPLATE",name:"make-model-requirements",title:"Make modelRequirements",content:"You are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Sample\n\n```json\n{\n\"modelName\": \"gpt-4o\",\n\"systemMessage\": \"You are experienced AI engineer and helpfull assistant.\",\n\"temperature\": 0.7\n}\n```\n\n## Instructions\n\n- 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"]}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-persona.ptbk.md"}];
|
|
1073
1084
|
|
|
1074
1085
|
/**
|
|
1075
1086
|
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
@@ -1144,7 +1155,7 @@
|
|
|
1144
1155
|
if ( /* version === '1.0.0' || */version === '2.0.0' || version === '3.0.0') {
|
|
1145
1156
|
return false;
|
|
1146
1157
|
}
|
|
1147
|
-
// <- TODO: !!! Check isValidPromptbookVersion against PROMPTBOOK_VERSIONS
|
|
1158
|
+
// <- TODO: [main] !!! Check isValidPromptbookVersion against PROMPTBOOK_VERSIONS
|
|
1148
1159
|
return true;
|
|
1149
1160
|
}
|
|
1150
1161
|
|
|
@@ -1313,7 +1324,7 @@
|
|
|
1313
1324
|
// <- Note: [🚲]
|
|
1314
1325
|
throw new PipelineLogicError(spaceTrim.spaceTrim(function (block) { return "\n Invalid promptbook URL \"".concat(pipeline.pipelineUrl, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
1315
1326
|
}
|
|
1316
|
-
if (!isValidPromptbookVersion(pipeline.promptbookVersion)) {
|
|
1327
|
+
if (pipeline.promptbookVersion !== undefined && !isValidPromptbookVersion(pipeline.promptbookVersion)) {
|
|
1317
1328
|
// <- Note: [🚲]
|
|
1318
1329
|
throw new PipelineLogicError(spaceTrim.spaceTrim(function (block) { return "\n Invalid Promptbook Version \"".concat(pipeline.promptbookVersion, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
1319
1330
|
}
|
|
@@ -1496,6 +1507,7 @@
|
|
|
1496
1507
|
}
|
|
1497
1508
|
}
|
|
1498
1509
|
/**
|
|
1510
|
+
* TODO: !!!!! [🧞♀️] Do not allow joker + foreach
|
|
1499
1511
|
* TODO: [🧠] Work with promptbookVersion
|
|
1500
1512
|
* TODO: Use here some json-schema, Zod or something similar and change it to:
|
|
1501
1513
|
* > /**
|
|
@@ -1507,11 +1519,11 @@
|
|
|
1507
1519
|
* > ex port function validatePipeline(promptbook: really_unknown): asserts promptbook is PipelineJson {
|
|
1508
1520
|
*/
|
|
1509
1521
|
/**
|
|
1510
|
-
* TODO: [🐣] !!!! Validate that all samples match expectations
|
|
1511
|
-
* TODO: [🐣][🐝] !!!! Validate that knowledge is valid (non-void)
|
|
1512
|
-
* TODO: [🐣] !!!! Validate that persona can be used only with CHAT variant
|
|
1513
|
-
* TODO: [🐣] !!!! Validate that parameter with reserved name not used RESERVED_PARAMETER_NAMES
|
|
1514
|
-
* TODO: [🐣] !!!! Validate that reserved parameter is not used as joker
|
|
1522
|
+
* TODO: [🐣][main] !!!! Validate that all samples match expectations
|
|
1523
|
+
* TODO: [🐣][🐝][main] !!!! Validate that knowledge is valid (non-void)
|
|
1524
|
+
* TODO: [🐣][main] !!!! Validate that persona can be used only with CHAT variant
|
|
1525
|
+
* TODO: [🐣][main] !!!! Validate that parameter with reserved name not used RESERVED_PARAMETER_NAMES
|
|
1526
|
+
* TODO: [🐣][main] !!!! Validate that reserved parameter is not used as joker
|
|
1515
1527
|
* TODO: [🧠] Validation not only logic itself but imports around - files and websites and rerefenced pipelines exists
|
|
1516
1528
|
* TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
1517
1529
|
*/
|
|
@@ -2239,7 +2251,7 @@
|
|
|
2239
2251
|
return true;
|
|
2240
2252
|
}
|
|
2241
2253
|
/**
|
|
2242
|
-
* TODO: [🔃] !!!!! If the pipeline was prepared with different version or different set of models, prepare it once again
|
|
2254
|
+
* TODO: [🔃][main] !!!!! If the pipeline was prepared with different version or different set of models, prepare it once again
|
|
2243
2255
|
* TODO: [🐠] Maybe base this on `makeValidator`
|
|
2244
2256
|
* TODO: [🧊] Pipeline can be partially prepared, this should return true ONLY if fully prepared
|
|
2245
2257
|
* TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
|
|
@@ -2291,9 +2303,10 @@
|
|
|
2291
2303
|
});
|
|
2292
2304
|
Object.defineProperty(MultipleLlmExecutionTools.prototype, "description", {
|
|
2293
2305
|
get: function () {
|
|
2294
|
-
return this.llmExecutionTools
|
|
2295
|
-
|
|
2296
|
-
.
|
|
2306
|
+
return this.llmExecutionTools.map(function (_a, index) {
|
|
2307
|
+
var title = _a.title;
|
|
2308
|
+
return "".concat(index + 1, ") `").concat(title, "`");
|
|
2309
|
+
}).join('\n');
|
|
2297
2310
|
},
|
|
2298
2311
|
enumerable: false,
|
|
2299
2312
|
configurable: true
|
|
@@ -2491,9 +2504,7 @@
|
|
|
2491
2504
|
throw new PipelineExecutionError("You have not provided any `LlmExecutionTools`");
|
|
2492
2505
|
}
|
|
2493
2506
|
else {
|
|
2494
|
-
throw new PipelineExecutionError(spaceTrim__default["default"](function (block) { return "\n You have not provided any `LlmExecutionTools` that support model variant \"".concat(prompt.modelRequirements.modelVariant, "\n\n Available `LlmExecutionTools`:\n ").concat(block(_this.
|
|
2495
|
-
.map(function (tools) { return "- ".concat(tools.title, " ").concat(tools.description || ''); })
|
|
2496
|
-
.join('\n')), "\n\n "); }));
|
|
2507
|
+
throw new PipelineExecutionError(spaceTrim__default["default"](function (block) { return "\n You have not provided any `LlmExecutionTools` that support model variant \"".concat(prompt.modelRequirements.modelVariant, "\"\n\n Available `LlmExecutionTools`:\n ").concat(block(_this.description), "\n\n "); }));
|
|
2497
2508
|
}
|
|
2498
2509
|
}
|
|
2499
2510
|
});
|
|
@@ -2635,47 +2646,47 @@
|
|
|
2635
2646
|
* @public exported from `@promptbook/utils`
|
|
2636
2647
|
*/
|
|
2637
2648
|
function extractParameterNamesFromTemplate(template) {
|
|
2638
|
-
var e_1, _a, e_2, _b, e_3, _c;
|
|
2649
|
+
var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
|
|
2639
2650
|
var title = template.title, description = template.description, templateType = template.templateType, content = template.content, preparedContent = template.preparedContent, jokerParameterNames = template.jokerParameterNames, foreach = template.foreach;
|
|
2640
2651
|
var parameterNames = new Set();
|
|
2641
2652
|
try {
|
|
2642
|
-
for (var
|
|
2643
|
-
var parameterName =
|
|
2653
|
+
for (var _e = __values(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(extractParameterNames(title)), false), __read(extractParameterNames(description || '')), false), __read(extractParameterNames(content)), false), __read(extractParameterNames(preparedContent || '')), false)), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
2654
|
+
var parameterName = _f.value;
|
|
2644
2655
|
parameterNames.add(parameterName);
|
|
2645
2656
|
}
|
|
2646
2657
|
}
|
|
2647
2658
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2648
2659
|
finally {
|
|
2649
2660
|
try {
|
|
2650
|
-
if (
|
|
2661
|
+
if (_f && !_f.done && (_a = _e.return)) _a.call(_e);
|
|
2651
2662
|
}
|
|
2652
2663
|
finally { if (e_1) throw e_1.error; }
|
|
2653
2664
|
}
|
|
2654
2665
|
if (templateType === 'SCRIPT_TEMPLATE') {
|
|
2655
2666
|
try {
|
|
2656
|
-
for (var
|
|
2657
|
-
var parameterName =
|
|
2667
|
+
for (var _g = __values(extractVariables(content)), _h = _g.next(); !_h.done; _h = _g.next()) {
|
|
2668
|
+
var parameterName = _h.value;
|
|
2658
2669
|
parameterNames.add(parameterName);
|
|
2659
2670
|
}
|
|
2660
2671
|
}
|
|
2661
2672
|
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
2662
2673
|
finally {
|
|
2663
2674
|
try {
|
|
2664
|
-
if (
|
|
2675
|
+
if (_h && !_h.done && (_b = _g.return)) _b.call(_g);
|
|
2665
2676
|
}
|
|
2666
2677
|
finally { if (e_2) throw e_2.error; }
|
|
2667
2678
|
}
|
|
2668
2679
|
}
|
|
2669
2680
|
try {
|
|
2670
|
-
for (var
|
|
2671
|
-
var jokerName =
|
|
2681
|
+
for (var _j = __values(jokerParameterNames || []), _k = _j.next(); !_k.done; _k = _j.next()) {
|
|
2682
|
+
var jokerName = _k.value;
|
|
2672
2683
|
parameterNames.add(jokerName);
|
|
2673
2684
|
}
|
|
2674
2685
|
}
|
|
2675
2686
|
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
2676
2687
|
finally {
|
|
2677
2688
|
try {
|
|
2678
|
-
if (
|
|
2689
|
+
if (_k && !_k.done && (_c = _j.return)) _c.call(_j);
|
|
2679
2690
|
}
|
|
2680
2691
|
finally { if (e_3) throw e_3.error; }
|
|
2681
2692
|
}
|
|
@@ -2683,10 +2694,22 @@
|
|
|
2683
2694
|
// <- Note {websiteContent} is used in `preparedContent`
|
|
2684
2695
|
// Note: [🍭] Fixing dependent subparameterName from FOREACH command
|
|
2685
2696
|
if (foreach !== undefined) {
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
|
|
2697
|
+
try {
|
|
2698
|
+
for (var _l = __values(foreach.inputSubparameterNames), _m = _l.next(); !_m.done; _m = _l.next()) {
|
|
2699
|
+
var subparameterName = _m.value;
|
|
2700
|
+
if (parameterNames.has(subparameterName)) {
|
|
2701
|
+
parameterNames.delete(subparameterName);
|
|
2702
|
+
parameterNames.add(foreach.parameterName);
|
|
2703
|
+
// <- TODO: [🚎] Warn/logic error when `subparameterName` not used
|
|
2704
|
+
}
|
|
2705
|
+
}
|
|
2706
|
+
}
|
|
2707
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
2708
|
+
finally {
|
|
2709
|
+
try {
|
|
2710
|
+
if (_m && !_m.done && (_d = _l.return)) _d.call(_l);
|
|
2711
|
+
}
|
|
2712
|
+
finally { if (e_4) throw e_4.error; }
|
|
2690
2713
|
}
|
|
2691
2714
|
}
|
|
2692
2715
|
return parameterNames;
|
|
@@ -2770,6 +2793,183 @@
|
|
|
2770
2793
|
return union;
|
|
2771
2794
|
}
|
|
2772
2795
|
|
|
2796
|
+
/**
|
|
2797
|
+
* Just marks a place of place where should be something implemented
|
|
2798
|
+
* No side effects.
|
|
2799
|
+
*
|
|
2800
|
+
* Note: It can be usefull suppressing eslint errors of unused variables
|
|
2801
|
+
*
|
|
2802
|
+
* @param value any values
|
|
2803
|
+
* @returns void
|
|
2804
|
+
* @private within the repository
|
|
2805
|
+
*/
|
|
2806
|
+
function TODO_USE() {
|
|
2807
|
+
var value = [];
|
|
2808
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2809
|
+
value[_i] = arguments[_i];
|
|
2810
|
+
}
|
|
2811
|
+
}
|
|
2812
|
+
|
|
2813
|
+
/**
|
|
2814
|
+
* This error indicates problems parsing the format value
|
|
2815
|
+
*
|
|
2816
|
+
* For example, when the format value is not a valid JSON or CSV
|
|
2817
|
+
* This is not thrown directly but in extended classes
|
|
2818
|
+
*
|
|
2819
|
+
* @public exported from `@promptbook/core`
|
|
2820
|
+
*/
|
|
2821
|
+
var AbstractFormatError = /** @class */ (function (_super) {
|
|
2822
|
+
__extends(AbstractFormatError, _super);
|
|
2823
|
+
// Note: To allow instanceof do not put here error `name`
|
|
2824
|
+
// public readonly name = 'AbstractFormatError';
|
|
2825
|
+
function AbstractFormatError(message) {
|
|
2826
|
+
var _this = _super.call(this, message) || this;
|
|
2827
|
+
Object.setPrototypeOf(_this, AbstractFormatError.prototype);
|
|
2828
|
+
return _this;
|
|
2829
|
+
}
|
|
2830
|
+
return AbstractFormatError;
|
|
2831
|
+
}(Error));
|
|
2832
|
+
|
|
2833
|
+
/**
|
|
2834
|
+
* This error indicates problem with parsing of CSV
|
|
2835
|
+
*
|
|
2836
|
+
* @public exported from `@promptbook/core`
|
|
2837
|
+
*/
|
|
2838
|
+
var CsvFormatError = /** @class */ (function (_super) {
|
|
2839
|
+
__extends(CsvFormatError, _super);
|
|
2840
|
+
function CsvFormatError(message) {
|
|
2841
|
+
var _this = _super.call(this, message) || this;
|
|
2842
|
+
_this.name = 'CsvFormatError';
|
|
2843
|
+
Object.setPrototypeOf(_this, CsvFormatError.prototype);
|
|
2844
|
+
return _this;
|
|
2845
|
+
}
|
|
2846
|
+
return CsvFormatError;
|
|
2847
|
+
}(AbstractFormatError));
|
|
2848
|
+
|
|
2849
|
+
/**
|
|
2850
|
+
* @@@
|
|
2851
|
+
*
|
|
2852
|
+
* @public exported from `@promptbook/core`
|
|
2853
|
+
*/
|
|
2854
|
+
var MANDATORY_CSV_SETTINGS = Object.freeze({
|
|
2855
|
+
header: true,
|
|
2856
|
+
// encoding: 'utf8',
|
|
2857
|
+
});
|
|
2858
|
+
|
|
2859
|
+
/**
|
|
2860
|
+
* Definition for CSV spreadsheet
|
|
2861
|
+
*
|
|
2862
|
+
* @public exported from `@promptbook/core`
|
|
2863
|
+
* <- TODO: [🏢] Export from package `@promptbook/csv`
|
|
2864
|
+
*/
|
|
2865
|
+
var CsvFormatDefinition = {
|
|
2866
|
+
formatName: 'CSV',
|
|
2867
|
+
aliases: ['SPREADSHEET', 'TABLE'],
|
|
2868
|
+
isValid: function (value, settings, schema) {
|
|
2869
|
+
// TODO: Implement CSV validation
|
|
2870
|
+
TODO_USE(value /* <- TODO: Use value here */);
|
|
2871
|
+
TODO_USE(settings /* <- TODO: Use settings here */);
|
|
2872
|
+
TODO_USE(schema /* <- TODO: Use schema here */);
|
|
2873
|
+
return true;
|
|
2874
|
+
},
|
|
2875
|
+
canBeValid: function (partialValue, settings, schema) {
|
|
2876
|
+
TODO_USE(partialValue /* <- TODO: Use partialValue here */);
|
|
2877
|
+
TODO_USE(settings /* <- TODO: Use settings here */);
|
|
2878
|
+
TODO_USE(schema /* <- TODO: Use schema here */);
|
|
2879
|
+
return true;
|
|
2880
|
+
},
|
|
2881
|
+
heal: function (value, settings, schema) {
|
|
2882
|
+
TODO_USE(value /* <- TODO: Use partialValue here */);
|
|
2883
|
+
TODO_USE(settings /* <- TODO: Use settings here */);
|
|
2884
|
+
TODO_USE(schema /* <- TODO: Use schema here */);
|
|
2885
|
+
throw new Error('Not implemented');
|
|
2886
|
+
},
|
|
2887
|
+
subvalueDefinitions: [
|
|
2888
|
+
{
|
|
2889
|
+
subvalueName: 'ROW',
|
|
2890
|
+
mapValues: function (value, outputParameterName, settings, mapCallback) {
|
|
2891
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2892
|
+
var csv, mappedData;
|
|
2893
|
+
var _this = this;
|
|
2894
|
+
return __generator(this, function (_a) {
|
|
2895
|
+
switch (_a.label) {
|
|
2896
|
+
case 0:
|
|
2897
|
+
csv = papaparse.parse(value, __assign(__assign({}, settings), MANDATORY_CSV_SETTINGS));
|
|
2898
|
+
if (csv.errors.length !== 0) {
|
|
2899
|
+
throw new CsvFormatError(spaceTrim__default["default"](function (block) { return "\n CSV parsing error\n\n ".concat(block(csv.errors.map(function (error) { return error.message; }).join('\n\n')), "\n "); }));
|
|
2900
|
+
}
|
|
2901
|
+
return [4 /*yield*/, Promise.all(csv.data.map(function (row, index) { return __awaiter(_this, void 0, void 0, function () {
|
|
2902
|
+
var _a, _b;
|
|
2903
|
+
var _c;
|
|
2904
|
+
return __generator(this, function (_d) {
|
|
2905
|
+
switch (_d.label) {
|
|
2906
|
+
case 0:
|
|
2907
|
+
if (row[outputParameterName]) {
|
|
2908
|
+
throw new CsvFormatError("Can not overwrite existing column \"".concat(outputParameterName, "\" in CSV row"));
|
|
2909
|
+
}
|
|
2910
|
+
_a = [__assign({}, row)];
|
|
2911
|
+
_c = {};
|
|
2912
|
+
_b = outputParameterName;
|
|
2913
|
+
return [4 /*yield*/, mapCallback(row, index)];
|
|
2914
|
+
case 1: return [2 /*return*/, __assign.apply(void 0, _a.concat([(_c[_b] = _d.sent(), _c)]))];
|
|
2915
|
+
}
|
|
2916
|
+
});
|
|
2917
|
+
}); }))];
|
|
2918
|
+
case 1:
|
|
2919
|
+
mappedData = _a.sent();
|
|
2920
|
+
return [2 /*return*/, papaparse.unparse(mappedData, __assign(__assign({}, settings), MANDATORY_CSV_SETTINGS))];
|
|
2921
|
+
}
|
|
2922
|
+
});
|
|
2923
|
+
});
|
|
2924
|
+
},
|
|
2925
|
+
},
|
|
2926
|
+
{
|
|
2927
|
+
subvalueName: 'CELL',
|
|
2928
|
+
mapValues: function (value, outputParameterName, settings, mapCallback) {
|
|
2929
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2930
|
+
var csv, mappedData;
|
|
2931
|
+
var _this = this;
|
|
2932
|
+
return __generator(this, function (_a) {
|
|
2933
|
+
switch (_a.label) {
|
|
2934
|
+
case 0:
|
|
2935
|
+
csv = papaparse.parse(value, __assign(__assign({}, settings), MANDATORY_CSV_SETTINGS));
|
|
2936
|
+
if (csv.errors.length !== 0) {
|
|
2937
|
+
throw new CsvFormatError(spaceTrim__default["default"](function (block) { return "\n CSV parsing error\n\n ".concat(block(csv.errors.map(function (error) { return error.message; }).join('\n\n')), "\n "); }));
|
|
2938
|
+
}
|
|
2939
|
+
return [4 /*yield*/, Promise.all(csv.data.map(function (row, rowIndex) { return __awaiter(_this, void 0, void 0, function () {
|
|
2940
|
+
var _this = this;
|
|
2941
|
+
return __generator(this, function (_a) {
|
|
2942
|
+
return [2 /*return*/, /* not await */ Promise.all(Object.entries(row).map(function (_a, columnIndex) {
|
|
2943
|
+
var _b = __read(_a, 2), key = _b[0], value = _b[1];
|
|
2944
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
2945
|
+
var index;
|
|
2946
|
+
var _c;
|
|
2947
|
+
return __generator(this, function (_d) {
|
|
2948
|
+
index = rowIndex * Object.keys(row).length + columnIndex;
|
|
2949
|
+
return [2 /*return*/, /* not await */ mapCallback((_c = {}, _c[key] = value, _c), index)];
|
|
2950
|
+
});
|
|
2951
|
+
});
|
|
2952
|
+
}))];
|
|
2953
|
+
});
|
|
2954
|
+
}); }))];
|
|
2955
|
+
case 1:
|
|
2956
|
+
mappedData = _a.sent();
|
|
2957
|
+
return [2 /*return*/, papaparse.unparse(mappedData, __assign(__assign({}, settings), MANDATORY_CSV_SETTINGS))];
|
|
2958
|
+
}
|
|
2959
|
+
});
|
|
2960
|
+
});
|
|
2961
|
+
},
|
|
2962
|
+
},
|
|
2963
|
+
],
|
|
2964
|
+
};
|
|
2965
|
+
/**
|
|
2966
|
+
* TODO: [🍓] In `CsvFormatDefinition` implement simple `isValid`
|
|
2967
|
+
* TODO: [🍓] In `CsvFormatDefinition` implement partial `canBeValid`
|
|
2968
|
+
* TODO: [🍓] In `CsvFormatDefinition` implement `heal
|
|
2969
|
+
* TODO: [🍓] In `CsvFormatDefinition` implement `subvalueDefinitions`
|
|
2970
|
+
* TODO: [🏢] Allow to expect something inside CSV objects and other formats
|
|
2971
|
+
*/
|
|
2972
|
+
|
|
2773
2973
|
/**
|
|
2774
2974
|
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
2775
2975
|
*
|
|
@@ -2791,6 +2991,222 @@
|
|
|
2791
2991
|
}
|
|
2792
2992
|
}
|
|
2793
2993
|
|
|
2994
|
+
/**
|
|
2995
|
+
* Definition for JSON format
|
|
2996
|
+
*
|
|
2997
|
+
* @private still in development [🏢]
|
|
2998
|
+
*/
|
|
2999
|
+
var JsonFormatDefinition = {
|
|
3000
|
+
formatName: 'JSON',
|
|
3001
|
+
mimeType: 'application/json',
|
|
3002
|
+
isValid: function (value, settings, schema) {
|
|
3003
|
+
TODO_USE(schema /* <- TODO: Use schema here */);
|
|
3004
|
+
TODO_USE(settings /* <- TODO: Use settings here */);
|
|
3005
|
+
return isValidJsonString(value);
|
|
3006
|
+
},
|
|
3007
|
+
canBeValid: function (partialValue, settings, schema) {
|
|
3008
|
+
TODO_USE(partialValue /* <- TODO: Use partialValue here */);
|
|
3009
|
+
TODO_USE(settings /* <- TODO: Use settings here */);
|
|
3010
|
+
TODO_USE(schema /* <- TODO: Use schema here */);
|
|
3011
|
+
return true;
|
|
3012
|
+
},
|
|
3013
|
+
heal: function (value, settings, schema) {
|
|
3014
|
+
TODO_USE(value /* <- TODO: Use partialValue here */);
|
|
3015
|
+
TODO_USE(settings /* <- TODO: Use settings here */);
|
|
3016
|
+
TODO_USE(schema /* <- TODO: Use schema here */);
|
|
3017
|
+
throw new Error('Not implemented');
|
|
3018
|
+
},
|
|
3019
|
+
subvalueDefinitions: [],
|
|
3020
|
+
};
|
|
3021
|
+
/**
|
|
3022
|
+
* TODO: [🧠] Maybe propper instance of object
|
|
3023
|
+
* TODO: [0] Make string_serialized_json
|
|
3024
|
+
* TODO: [1] Make type for JSON Settings and Schema
|
|
3025
|
+
* TODO: [🧠] What to use for validating JSONs - JSON Schema, ZoD, typescript types/interfaces,...?
|
|
3026
|
+
* TODO: [🍓] In `JsonFormatDefinition` implement simple `isValid`
|
|
3027
|
+
* TODO: [🍓] In `JsonFormatDefinition` implement partial `canBeValid`
|
|
3028
|
+
* TODO: [🍓] In `JsonFormatDefinition` implement `heal
|
|
3029
|
+
* TODO: [🍓] In `JsonFormatDefinition` implement `subvalueDefinitions`
|
|
3030
|
+
* TODO: [🏢] Allow to expect something inside JSON objects and other formats
|
|
3031
|
+
*/
|
|
3032
|
+
|
|
3033
|
+
/**
|
|
3034
|
+
* Definition for any text - this will be always valid
|
|
3035
|
+
*
|
|
3036
|
+
* Note: This is not useful for validation, but for splitting and mapping with `subvalueDefinitions`
|
|
3037
|
+
*
|
|
3038
|
+
* @public exported from `@promptbook/core`
|
|
3039
|
+
*/
|
|
3040
|
+
var TextFormatDefinition = {
|
|
3041
|
+
formatName: 'TEXT',
|
|
3042
|
+
isValid: function (value) {
|
|
3043
|
+
return typeof value === 'string';
|
|
3044
|
+
},
|
|
3045
|
+
canBeValid: function (partialValue) {
|
|
3046
|
+
return typeof partialValue === 'string';
|
|
3047
|
+
},
|
|
3048
|
+
heal: function () {
|
|
3049
|
+
throw new UnexpectedError('It does not make sense to call `TextFormatDefinition.heal`');
|
|
3050
|
+
},
|
|
3051
|
+
subvalueDefinitions: [
|
|
3052
|
+
{
|
|
3053
|
+
subvalueName: 'LINE',
|
|
3054
|
+
mapValues: function (value, outputParameterName, settings, mapCallback) {
|
|
3055
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3056
|
+
var lines, mappedLines;
|
|
3057
|
+
return __generator(this, function (_a) {
|
|
3058
|
+
switch (_a.label) {
|
|
3059
|
+
case 0:
|
|
3060
|
+
lines = value.split('\n');
|
|
3061
|
+
return [4 /*yield*/, Promise.all(lines.map(function (lineContent, lineNumber) {
|
|
3062
|
+
// TODO: [🧠] Maybe option to skip empty line
|
|
3063
|
+
/* not await */ return mapCallback({
|
|
3064
|
+
lineContent: lineContent,
|
|
3065
|
+
// TODO: [🧠] Maybe also put here `lineNumber`
|
|
3066
|
+
}, lineNumber);
|
|
3067
|
+
}))];
|
|
3068
|
+
case 1:
|
|
3069
|
+
mappedLines = _a.sent();
|
|
3070
|
+
return [2 /*return*/, mappedLines.join('\n')];
|
|
3071
|
+
}
|
|
3072
|
+
});
|
|
3073
|
+
});
|
|
3074
|
+
},
|
|
3075
|
+
},
|
|
3076
|
+
// <- TODO: [🧠][🤠] Here should be all words, characters, lines, paragraphs, pages aviable as subvalues
|
|
3077
|
+
],
|
|
3078
|
+
};
|
|
3079
|
+
/**
|
|
3080
|
+
* TODO: [1] Make type for XML Text and Schema
|
|
3081
|
+
* TODO: [🧠][🤠] Here should be all words, characters, lines, paragraphs, pages aviable as subvalues
|
|
3082
|
+
* TODO: [🍓] In `TextFormatDefinition` implement simple `isValid`
|
|
3083
|
+
* TODO: [🍓] In `TextFormatDefinition` implement partial `canBeValid`
|
|
3084
|
+
* TODO: [🍓] In `TextFormatDefinition` implement `heal
|
|
3085
|
+
* TODO: [🍓] In `TextFormatDefinition` implement `subvalueDefinitions`
|
|
3086
|
+
* TODO: [🏢] Allow to expect something inside each item of list and other formats
|
|
3087
|
+
*/
|
|
3088
|
+
|
|
3089
|
+
/**
|
|
3090
|
+
* Definition for XML format
|
|
3091
|
+
*
|
|
3092
|
+
* @private still in development [🏢]
|
|
3093
|
+
*/
|
|
3094
|
+
var XmlFormatDefinition = {
|
|
3095
|
+
formatName: 'XML',
|
|
3096
|
+
mimeType: 'application/xml',
|
|
3097
|
+
isValid: function (value, settings, schema) {
|
|
3098
|
+
TODO_USE(value /* <- TODO: Use value here */);
|
|
3099
|
+
TODO_USE(settings /* <- TODO: Use settings here */);
|
|
3100
|
+
TODO_USE(schema /* <- TODO: Use schema here */);
|
|
3101
|
+
return true;
|
|
3102
|
+
},
|
|
3103
|
+
canBeValid: function (partialValue, settings, schema) {
|
|
3104
|
+
TODO_USE(partialValue /* <- TODO: Use partialValue here */);
|
|
3105
|
+
TODO_USE(settings /* <- TODO: Use settings here */);
|
|
3106
|
+
TODO_USE(schema /* <- TODO: Use schema here */);
|
|
3107
|
+
return true;
|
|
3108
|
+
},
|
|
3109
|
+
heal: function (value, settings, schema) {
|
|
3110
|
+
TODO_USE(value /* <- TODO: Use partialValue here */);
|
|
3111
|
+
TODO_USE(settings /* <- TODO: Use settings here */);
|
|
3112
|
+
TODO_USE(schema /* <- TODO: Use schema here */);
|
|
3113
|
+
throw new Error('Not implemented');
|
|
3114
|
+
},
|
|
3115
|
+
subvalueDefinitions: [],
|
|
3116
|
+
};
|
|
3117
|
+
/**
|
|
3118
|
+
* TODO: [🧠] Maybe propper instance of object
|
|
3119
|
+
* TODO: [0] Make string_serialized_xml
|
|
3120
|
+
* TODO: [1] Make type for XML Settings and Schema
|
|
3121
|
+
* TODO: [🧠] What to use for validating XMLs - XSD,...
|
|
3122
|
+
* TODO: [🍓] In `XmlFormatDefinition` implement simple `isValid`
|
|
3123
|
+
* TODO: [🍓] In `XmlFormatDefinition` implement partial `canBeValid`
|
|
3124
|
+
* TODO: [🍓] In `XmlFormatDefinition` implement `heal
|
|
3125
|
+
* TODO: [🍓] In `XmlFormatDefinition` implement `subvalueDefinitions`
|
|
3126
|
+
* TODO: [🏢] Allow to expect something inside XML and other formats
|
|
3127
|
+
*/
|
|
3128
|
+
|
|
3129
|
+
/**
|
|
3130
|
+
* Definitions for all formats supported by Promptbook
|
|
3131
|
+
*
|
|
3132
|
+
* @private internal index of `...` <- TODO [🏢]
|
|
3133
|
+
*/
|
|
3134
|
+
var FORMAT_DEFINITIONS = [
|
|
3135
|
+
JsonFormatDefinition,
|
|
3136
|
+
XmlFormatDefinition,
|
|
3137
|
+
TextFormatDefinition,
|
|
3138
|
+
CsvFormatDefinition,
|
|
3139
|
+
];
|
|
3140
|
+
|
|
3141
|
+
/**
|
|
3142
|
+
* Maps available parameters to expected parameters
|
|
3143
|
+
*
|
|
3144
|
+
* The strategy is:
|
|
3145
|
+
* 1) @@@
|
|
3146
|
+
* 2) @@@
|
|
3147
|
+
*
|
|
3148
|
+
* @throws {PipelineExecutionError} @@@
|
|
3149
|
+
* @private within the repository used in `createPipelineExecutor`
|
|
3150
|
+
*/
|
|
3151
|
+
function mapAvailableToExpectedParameters(options) {
|
|
3152
|
+
var e_1, _a;
|
|
3153
|
+
var expectedParameters = options.expectedParameters, availableParameters = options.availableParameters;
|
|
3154
|
+
var availableParametersNames = new Set(Object.keys(availableParameters));
|
|
3155
|
+
var expectedParameterNames = new Set(Object.keys(expectedParameters));
|
|
3156
|
+
var mappedParameters = {};
|
|
3157
|
+
try {
|
|
3158
|
+
// Phase 1️⃣: Matching mapping
|
|
3159
|
+
for (var _b = __values(Array.from(union(availableParametersNames, expectedParameterNames))), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
3160
|
+
var parameterName = _c.value;
|
|
3161
|
+
// Situation: Parameter is available and expected
|
|
3162
|
+
if (availableParametersNames.has(parameterName) && expectedParameterNames.has(parameterName)) {
|
|
3163
|
+
mappedParameters[parameterName] = availableParameters[parameterName];
|
|
3164
|
+
// <- Note: [👩👩👧] Maybe detect parameter collision here?
|
|
3165
|
+
availableParametersNames.delete(parameterName);
|
|
3166
|
+
expectedParameterNames.delete(parameterName);
|
|
3167
|
+
}
|
|
3168
|
+
// Situation: Parameter is available but NOT expected
|
|
3169
|
+
else if (availableParametersNames.has(parameterName) && !expectedParameterNames.has(parameterName)) {
|
|
3170
|
+
// [🐱👤] Do not pass this parameter to prompt - Maybe use it non-matching mapping
|
|
3171
|
+
}
|
|
3172
|
+
// Situation: Parameter is NOT available BUT expected
|
|
3173
|
+
else if (!availableParametersNames.has(parameterName) && expectedParameterNames.has(parameterName)) {
|
|
3174
|
+
// Do nothing here - this will be maybe fixed in the non-matching mapping
|
|
3175
|
+
}
|
|
3176
|
+
}
|
|
3177
|
+
}
|
|
3178
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
3179
|
+
finally {
|
|
3180
|
+
try {
|
|
3181
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
3182
|
+
}
|
|
3183
|
+
finally { if (e_1) throw e_1.error; }
|
|
3184
|
+
}
|
|
3185
|
+
if (expectedParameterNames.size === 0) {
|
|
3186
|
+
// Note: [👨👨👧] Now we can freeze `mappedParameters` to prevent @@@
|
|
3187
|
+
Object.freeze(mappedParameters);
|
|
3188
|
+
return mappedParameters;
|
|
3189
|
+
}
|
|
3190
|
+
// Phase 2️⃣: Non-matching mapping
|
|
3191
|
+
if (expectedParameterNames.size !== availableParametersNames.size) {
|
|
3192
|
+
throw new PipelineExecutionError(spaceTrim__default["default"](function (block) { return "\n Can not map available parameters to expected parameters\n\n Mapped parameters:\n ".concat(block(Object.keys(mappedParameters)
|
|
3193
|
+
.map(function (parameterName) { return "- {".concat(parameterName, "}"); })
|
|
3194
|
+
.join('\n')), "\n\n Expected parameters which can not be mapped:\n ").concat(block(Array.from(expectedParameterNames)
|
|
3195
|
+
.map(function (parameterName) { return "- {".concat(parameterName, "}"); })
|
|
3196
|
+
.join('\n')), "\n\n Remaining available parameters:\n ").concat(block(Array.from(availableParametersNames)
|
|
3197
|
+
.map(function (parameterName) { return "- {".concat(parameterName, "}"); })
|
|
3198
|
+
.join('\n')), "\n\n "); }));
|
|
3199
|
+
}
|
|
3200
|
+
var expectedParameterNamesArray = Array.from(expectedParameterNames);
|
|
3201
|
+
var availableParametersNamesArray = Array.from(availableParametersNames);
|
|
3202
|
+
for (var i = 0; i < expectedParameterNames.size; i++) {
|
|
3203
|
+
mappedParameters[expectedParameterNamesArray[i]] = availableParameters[availableParametersNamesArray[i]];
|
|
3204
|
+
}
|
|
3205
|
+
// Note: [👨👨👧] Now we can freeze `mappedParameters` to prevent @@@
|
|
3206
|
+
Object.freeze(mappedParameters);
|
|
3207
|
+
return mappedParameters;
|
|
3208
|
+
}
|
|
3209
|
+
|
|
2794
3210
|
/**
|
|
2795
3211
|
* Extracts all code blocks from markdown.
|
|
2796
3212
|
*
|
|
@@ -3096,6 +3512,9 @@
|
|
|
3096
3512
|
LINES: countLines,
|
|
3097
3513
|
PAGES: countPages,
|
|
3098
3514
|
};
|
|
3515
|
+
/**
|
|
3516
|
+
* TODO: [🧠][🤠] This should be probbably as part of `TextFormatDefinition`
|
|
3517
|
+
*/
|
|
3099
3518
|
|
|
3100
3519
|
/**
|
|
3101
3520
|
* Function checkExpectations will check if the expectations on given value are met
|
|
@@ -3132,6 +3551,8 @@
|
|
|
3132
3551
|
}
|
|
3133
3552
|
/**
|
|
3134
3553
|
* TODO: [💝] Unite object for expecting amount and format
|
|
3554
|
+
* TODO: [🧠][🤠] This should be part of `TextFormatDefinition`
|
|
3555
|
+
* Note: [💝] and [🤠] are interconnected together
|
|
3135
3556
|
*/
|
|
3136
3557
|
|
|
3137
3558
|
/**
|
|
@@ -3141,58 +3562,66 @@
|
|
|
3141
3562
|
*/
|
|
3142
3563
|
function executeAttempts(options) {
|
|
3143
3564
|
return __awaiter(this, void 0, void 0, function () {
|
|
3144
|
-
var
|
|
3565
|
+
var jokerParameterNames, priority, maxAttempts, preparedContent, parameters, template, preparedPipeline, tools, llmTools, settings, $executionReport, pipelineIdentification, maxExecutionAttempts, $ongoingTemplateResult, _loop_1, attempt, state_1;
|
|
3145
3566
|
return __generator(this, function (_a) {
|
|
3146
3567
|
switch (_a.label) {
|
|
3147
3568
|
case 0:
|
|
3148
|
-
|
|
3569
|
+
jokerParameterNames = options.jokerParameterNames, priority = options.priority, maxAttempts = options.maxAttempts, preparedContent = options.preparedContent, parameters = options.parameters, template = options.template, preparedPipeline = options.preparedPipeline, tools = options.tools, llmTools = options.llmTools, settings = options.settings, $executionReport = options.$executionReport, pipelineIdentification = options.pipelineIdentification;
|
|
3149
3570
|
maxExecutionAttempts = settings.maxExecutionAttempts;
|
|
3571
|
+
$ongoingTemplateResult = {
|
|
3572
|
+
$result: null,
|
|
3573
|
+
$resultString: null,
|
|
3574
|
+
$expectError: null,
|
|
3575
|
+
$scriptPipelineExecutionErrors: [],
|
|
3576
|
+
};
|
|
3150
3577
|
_loop_1 = function (attempt) {
|
|
3151
|
-
var isJokerAttempt, jokerParameterName, _b, modelRequirements, _c, _d, _e, _f, _g,
|
|
3152
|
-
var e_1,
|
|
3153
|
-
return __generator(this, function (
|
|
3154
|
-
switch (
|
|
3578
|
+
var isJokerAttempt, jokerParameterName, _b, modelRequirements, _c, _d, _e, _f, _g, scriptTools, _h, error_1, e_1_1, _j, _k, _l, functionName, postprocessingError, _m, _o, scriptTools, _p, error_2, e_2_1, e_3_1, error_3;
|
|
3579
|
+
var e_1, _q, e_3, _r, e_2, _s;
|
|
3580
|
+
return __generator(this, function (_t) {
|
|
3581
|
+
switch (_t.label) {
|
|
3155
3582
|
case 0:
|
|
3156
3583
|
isJokerAttempt = attempt < 0;
|
|
3157
3584
|
jokerParameterName = jokerParameterNames[jokerParameterNames.length + attempt];
|
|
3158
|
-
// TODO: [🧠]
|
|
3585
|
+
// TODO: [🧠][🍭] JOKERS, EXPECTATIONS, POSTPROCESSING and FOREACH
|
|
3159
3586
|
if (isJokerAttempt && !jokerParameterName) {
|
|
3160
|
-
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n
|
|
3587
|
+
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Joker not found in attempt ".concat(attempt, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3161
3588
|
}
|
|
3162
3589
|
$ongoingTemplateResult.$result = null;
|
|
3163
3590
|
$ongoingTemplateResult.$resultString = null;
|
|
3164
3591
|
$ongoingTemplateResult.$expectError = null;
|
|
3165
3592
|
if (isJokerAttempt) {
|
|
3166
3593
|
if (parameters[jokerParameterName] === undefined) {
|
|
3167
|
-
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n
|
|
3594
|
+
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Joker parameter {".concat(jokerParameterName, "} not defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3168
3595
|
// <- TODO: This is maybe `PipelineLogicError` which should be detected in `validatePipeline` and here just thrown as `UnexpectedError`
|
|
3169
3596
|
}
|
|
3170
3597
|
else {
|
|
3171
3598
|
$ongoingTemplateResult.$resultString = parameters[jokerParameterName];
|
|
3172
3599
|
}
|
|
3173
3600
|
}
|
|
3174
|
-
|
|
3601
|
+
_t.label = 1;
|
|
3175
3602
|
case 1:
|
|
3176
|
-
|
|
3177
|
-
if (!!isJokerAttempt) return [3 /*break*/,
|
|
3603
|
+
_t.trys.push([1, 43, 44, 45]);
|
|
3604
|
+
if (!!isJokerAttempt) return [3 /*break*/, 25];
|
|
3178
3605
|
_b = template.templateType;
|
|
3179
3606
|
switch (_b) {
|
|
3180
3607
|
case 'SIMPLE_TEMPLATE': return [3 /*break*/, 2];
|
|
3181
3608
|
case 'PROMPT_TEMPLATE': return [3 /*break*/, 3];
|
|
3182
|
-
case 'SCRIPT_TEMPLATE': return [3 /*break*/,
|
|
3183
|
-
case 'DIALOG_TEMPLATE': return [3 /*break*/,
|
|
3609
|
+
case 'SCRIPT_TEMPLATE': return [3 /*break*/, 11];
|
|
3610
|
+
case 'DIALOG_TEMPLATE': return [3 /*break*/, 22];
|
|
3184
3611
|
}
|
|
3185
|
-
return [3 /*break*/,
|
|
3612
|
+
return [3 /*break*/, 24];
|
|
3186
3613
|
case 2:
|
|
3187
3614
|
$ongoingTemplateResult.$resultString = replaceParameters(preparedContent, parameters);
|
|
3188
|
-
return [3 /*break*/,
|
|
3615
|
+
return [3 /*break*/, 25];
|
|
3189
3616
|
case 3:
|
|
3190
3617
|
modelRequirements = __assign(__assign({ modelVariant: 'CHAT' }, (preparedPipeline.defaultModelRequirements || {})), (template.modelRequirements || {}));
|
|
3191
3618
|
$ongoingTemplateResult.$prompt = {
|
|
3192
3619
|
title: template.title,
|
|
3193
3620
|
pipelineUrl: "".concat(preparedPipeline.pipelineUrl
|
|
3194
3621
|
? preparedPipeline.pipelineUrl
|
|
3195
|
-
: 'anonymous' /* <- TODO: [🧠] How to deal with anonymous pipelines, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(template.name
|
|
3622
|
+
: 'anonymous' /* <- TODO: [🧠] How to deal with anonymous pipelines, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(template.name
|
|
3623
|
+
// <- TODO: Here should be maybe also subformat index to distinguish between same template with different subformat values
|
|
3624
|
+
),
|
|
3196
3625
|
parameters: parameters,
|
|
3197
3626
|
content: preparedContent,
|
|
3198
3627
|
modelRequirements: modelRequirements,
|
|
@@ -3210,67 +3639,57 @@
|
|
|
3210
3639
|
case 'COMPLETION': return [3 /*break*/, 6];
|
|
3211
3640
|
case 'EMBEDDING': return [3 /*break*/, 8];
|
|
3212
3641
|
}
|
|
3213
|
-
return [3 /*break*/,
|
|
3642
|
+
return [3 /*break*/, 9];
|
|
3214
3643
|
case 4:
|
|
3215
3644
|
_d = $ongoingTemplateResult;
|
|
3216
3645
|
return [4 /*yield*/, llmTools.callChatModel($deepFreeze($ongoingTemplateResult.$prompt))];
|
|
3217
3646
|
case 5:
|
|
3218
|
-
_d.$chatResult =
|
|
3647
|
+
_d.$chatResult = _t.sent();
|
|
3219
3648
|
// TODO: [🍬] Destroy chatThread
|
|
3220
3649
|
$ongoingTemplateResult.$result = $ongoingTemplateResult.$chatResult;
|
|
3221
3650
|
$ongoingTemplateResult.$resultString = $ongoingTemplateResult.$chatResult.content;
|
|
3222
|
-
return [3 /*break*/,
|
|
3651
|
+
return [3 /*break*/, 10];
|
|
3223
3652
|
case 6:
|
|
3224
3653
|
_e = $ongoingTemplateResult;
|
|
3225
3654
|
return [4 /*yield*/, llmTools.callCompletionModel($deepFreeze($ongoingTemplateResult.$prompt))];
|
|
3226
3655
|
case 7:
|
|
3227
|
-
_e.$completionResult =
|
|
3656
|
+
_e.$completionResult = _t.sent();
|
|
3228
3657
|
$ongoingTemplateResult.$result = $ongoingTemplateResult.$completionResult;
|
|
3229
3658
|
$ongoingTemplateResult.$resultString =
|
|
3230
3659
|
$ongoingTemplateResult.$completionResult.content;
|
|
3231
|
-
return [3 /*break*/,
|
|
3232
|
-
case 8:
|
|
3233
|
-
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
case 9:
|
|
3237
|
-
// TODO: [🧠] This is weird, embedding model can not be used such a way in the pipeline
|
|
3238
|
-
_f.$embeddingResult = _u.sent();
|
|
3239
|
-
$ongoingTemplateResult.$result = $ongoingTemplateResult.$embeddingResult;
|
|
3240
|
-
$ongoingTemplateResult.$resultString =
|
|
3241
|
-
$ongoingTemplateResult.$embeddingResult.content.join(',');
|
|
3242
|
-
return [3 /*break*/, 11];
|
|
3243
|
-
case 10: throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Unknown model variant \"".concat(template.modelRequirements.modelVariant, "\"\n\n ").concat(block(pipelineIdentification), "\n\n "); }));
|
|
3244
|
-
case 11: return [3 /*break*/, 26];
|
|
3245
|
-
case 12:
|
|
3660
|
+
return [3 /*break*/, 10];
|
|
3661
|
+
case 8: throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Embedding model can not be used in pipeline\n\n This should be catched during parsing\n\n ".concat(block(pipelineIdentification), "\n\n "); }));
|
|
3662
|
+
case 9: throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Unknown model variant \"".concat(template.modelRequirements.modelVariant, "\"\n\n ").concat(block(pipelineIdentification), "\n\n "); }));
|
|
3663
|
+
case 10: return [3 /*break*/, 25];
|
|
3664
|
+
case 11:
|
|
3246
3665
|
if (arrayableToArray(tools.script).length === 0) {
|
|
3247
|
-
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n
|
|
3666
|
+
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n No script execution tools are available\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
3248
3667
|
}
|
|
3249
3668
|
if (!template.contentLanguage) {
|
|
3250
|
-
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n
|
|
3669
|
+
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Script language is not defined for SCRIPT TEMPLATE \"".concat(template.name, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3251
3670
|
}
|
|
3252
|
-
|
|
3671
|
+
_t.label = 12;
|
|
3672
|
+
case 12:
|
|
3673
|
+
_t.trys.push([12, 19, 20, 21]);
|
|
3674
|
+
_f = (e_1 = void 0, __values(arrayableToArray(tools.script))), _g = _f.next();
|
|
3675
|
+
_t.label = 13;
|
|
3253
3676
|
case 13:
|
|
3254
|
-
|
|
3255
|
-
|
|
3256
|
-
|
|
3677
|
+
if (!!_g.done) return [3 /*break*/, 18];
|
|
3678
|
+
scriptTools = _g.value;
|
|
3679
|
+
_t.label = 14;
|
|
3257
3680
|
case 14:
|
|
3258
|
-
|
|
3259
|
-
|
|
3260
|
-
_u.label = 15;
|
|
3261
|
-
case 15:
|
|
3262
|
-
_u.trys.push([15, 17, , 18]);
|
|
3263
|
-
_j = $ongoingTemplateResult;
|
|
3681
|
+
_t.trys.push([14, 16, , 17]);
|
|
3682
|
+
_h = $ongoingTemplateResult;
|
|
3264
3683
|
return [4 /*yield*/, scriptTools.execute($deepFreeze({
|
|
3265
3684
|
scriptLanguage: template.contentLanguage,
|
|
3266
3685
|
script: preparedContent,
|
|
3267
3686
|
parameters: parameters,
|
|
3268
3687
|
}))];
|
|
3688
|
+
case 15:
|
|
3689
|
+
_h.$resultString = _t.sent();
|
|
3690
|
+
return [3 /*break*/, 18];
|
|
3269
3691
|
case 16:
|
|
3270
|
-
|
|
3271
|
-
return [3 /*break*/, 19];
|
|
3272
|
-
case 17:
|
|
3273
|
-
error_1 = _u.sent();
|
|
3692
|
+
error_1 = _t.sent();
|
|
3274
3693
|
if (!(error_1 instanceof Error)) {
|
|
3275
3694
|
throw error_1;
|
|
3276
3695
|
}
|
|
@@ -3278,39 +3697,39 @@
|
|
|
3278
3697
|
throw error_1;
|
|
3279
3698
|
}
|
|
3280
3699
|
$ongoingTemplateResult.$scriptPipelineExecutionErrors.push(error_1);
|
|
3281
|
-
return [3 /*break*/,
|
|
3282
|
-
case
|
|
3283
|
-
|
|
3284
|
-
return [3 /*break*/,
|
|
3285
|
-
case
|
|
3286
|
-
case
|
|
3287
|
-
e_1_1 =
|
|
3700
|
+
return [3 /*break*/, 17];
|
|
3701
|
+
case 17:
|
|
3702
|
+
_g = _f.next();
|
|
3703
|
+
return [3 /*break*/, 13];
|
|
3704
|
+
case 18: return [3 /*break*/, 21];
|
|
3705
|
+
case 19:
|
|
3706
|
+
e_1_1 = _t.sent();
|
|
3288
3707
|
e_1 = { error: e_1_1 };
|
|
3289
|
-
return [3 /*break*/,
|
|
3290
|
-
case
|
|
3708
|
+
return [3 /*break*/, 21];
|
|
3709
|
+
case 20:
|
|
3291
3710
|
try {
|
|
3292
|
-
if (
|
|
3711
|
+
if (_g && !_g.done && (_q = _f.return)) _q.call(_f);
|
|
3293
3712
|
}
|
|
3294
3713
|
finally { if (e_1) throw e_1.error; }
|
|
3295
3714
|
return [7 /*endfinally*/];
|
|
3296
|
-
case
|
|
3715
|
+
case 21:
|
|
3297
3716
|
if ($ongoingTemplateResult.$resultString !== null) {
|
|
3298
|
-
return [3 /*break*/,
|
|
3717
|
+
return [3 /*break*/, 25];
|
|
3299
3718
|
}
|
|
3300
3719
|
if ($ongoingTemplateResult.$scriptPipelineExecutionErrors.length === 1) {
|
|
3301
3720
|
throw $ongoingTemplateResult.$scriptPipelineExecutionErrors[0];
|
|
3302
3721
|
}
|
|
3303
3722
|
else {
|
|
3304
|
-
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n
|
|
3723
|
+
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Script execution failed ".concat($ongoingTemplateResult.$scriptPipelineExecutionErrors.length, "x\n\n ").concat(block(pipelineIdentification), "\n\n ").concat(block($ongoingTemplateResult.$scriptPipelineExecutionErrors
|
|
3305
3724
|
.map(function (error) { return '- ' + error.message; })
|
|
3306
|
-
.join('\n\n')), "\n
|
|
3725
|
+
.join('\n\n')), "\n "); }));
|
|
3307
3726
|
}
|
|
3308
|
-
case
|
|
3727
|
+
case 22:
|
|
3309
3728
|
if (tools.userInterface === undefined) {
|
|
3310
|
-
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n
|
|
3729
|
+
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n User interface tools are not available\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
3311
3730
|
}
|
|
3312
3731
|
// TODO: [🌹] When making next attempt for `DIALOG TEMPLATE`, preserve the previous user input
|
|
3313
|
-
|
|
3732
|
+
_j = $ongoingTemplateResult;
|
|
3314
3733
|
return [4 /*yield*/, tools.userInterface.promptDialog($deepFreeze({
|
|
3315
3734
|
promptTitle: template.title,
|
|
3316
3735
|
promptMessage: replaceParameters(template.description || '', parameters),
|
|
@@ -3319,34 +3738,34 @@
|
|
|
3319
3738
|
placeholder: undefined,
|
|
3320
3739
|
priority: priority,
|
|
3321
3740
|
}))];
|
|
3322
|
-
case
|
|
3741
|
+
case 23:
|
|
3323
3742
|
// TODO: [🌹] When making next attempt for `DIALOG TEMPLATE`, preserve the previous user input
|
|
3324
|
-
|
|
3325
|
-
return [3 /*break*/,
|
|
3326
|
-
case
|
|
3743
|
+
_j.$resultString = _t.sent();
|
|
3744
|
+
return [3 /*break*/, 25];
|
|
3745
|
+
case 24: throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Unknown execution type \"".concat(template.templateType, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3746
|
+
case 25:
|
|
3747
|
+
if (!(!isJokerAttempt && template.postprocessingFunctionNames)) return [3 /*break*/, 42];
|
|
3748
|
+
_t.label = 26;
|
|
3327
3749
|
case 26:
|
|
3328
|
-
|
|
3329
|
-
|
|
3750
|
+
_t.trys.push([26, 40, 41, 42]);
|
|
3751
|
+
_k = (e_3 = void 0, __values(template.postprocessingFunctionNames)), _l = _k.next();
|
|
3752
|
+
_t.label = 27;
|
|
3330
3753
|
case 27:
|
|
3331
|
-
|
|
3332
|
-
|
|
3333
|
-
_u.label = 28;
|
|
3334
|
-
case 28:
|
|
3335
|
-
if (!!_m.done) return [3 /*break*/, 40];
|
|
3336
|
-
functionName = _m.value;
|
|
3754
|
+
if (!!_l.done) return [3 /*break*/, 39];
|
|
3755
|
+
functionName = _l.value;
|
|
3337
3756
|
postprocessingError = null;
|
|
3338
|
-
|
|
3757
|
+
_t.label = 28;
|
|
3758
|
+
case 28:
|
|
3759
|
+
_t.trys.push([28, 35, 36, 37]);
|
|
3760
|
+
_m = (e_2 = void 0, __values(arrayableToArray(tools.script))), _o = _m.next();
|
|
3761
|
+
_t.label = 29;
|
|
3339
3762
|
case 29:
|
|
3340
|
-
|
|
3341
|
-
|
|
3342
|
-
|
|
3763
|
+
if (!!_o.done) return [3 /*break*/, 34];
|
|
3764
|
+
scriptTools = _o.value;
|
|
3765
|
+
_t.label = 30;
|
|
3343
3766
|
case 30:
|
|
3344
|
-
|
|
3345
|
-
|
|
3346
|
-
_u.label = 31;
|
|
3347
|
-
case 31:
|
|
3348
|
-
_u.trys.push([31, 33, , 34]);
|
|
3349
|
-
_q = $ongoingTemplateResult;
|
|
3767
|
+
_t.trys.push([30, 32, , 33]);
|
|
3768
|
+
_p = $ongoingTemplateResult;
|
|
3350
3769
|
return [4 /*yield*/, scriptTools.execute({
|
|
3351
3770
|
scriptLanguage: "javascript" /* <- TODO: Try it in each languages; In future allow postprocessing with arbitrary combination of languages to combine */,
|
|
3352
3771
|
script: "".concat(functionName, "(resultString)"),
|
|
@@ -3355,12 +3774,12 @@
|
|
|
3355
3774
|
// Note: No ...parametersForTemplate, because working with result only
|
|
3356
3775
|
},
|
|
3357
3776
|
})];
|
|
3358
|
-
case
|
|
3359
|
-
|
|
3777
|
+
case 31:
|
|
3778
|
+
_p.$resultString = _t.sent();
|
|
3360
3779
|
postprocessingError = null;
|
|
3361
|
-
return [3 /*break*/,
|
|
3362
|
-
case
|
|
3363
|
-
error_2 =
|
|
3780
|
+
return [3 /*break*/, 34];
|
|
3781
|
+
case 32:
|
|
3782
|
+
error_2 = _t.sent();
|
|
3364
3783
|
if (!(error_2 instanceof Error)) {
|
|
3365
3784
|
throw error_2;
|
|
3366
3785
|
}
|
|
@@ -3369,41 +3788,41 @@
|
|
|
3369
3788
|
}
|
|
3370
3789
|
postprocessingError = error_2;
|
|
3371
3790
|
$ongoingTemplateResult.$scriptPipelineExecutionErrors.push(error_2);
|
|
3372
|
-
return [3 /*break*/,
|
|
3373
|
-
case
|
|
3374
|
-
|
|
3375
|
-
return [3 /*break*/,
|
|
3376
|
-
case
|
|
3377
|
-
case
|
|
3378
|
-
e_2_1 =
|
|
3791
|
+
return [3 /*break*/, 33];
|
|
3792
|
+
case 33:
|
|
3793
|
+
_o = _m.next();
|
|
3794
|
+
return [3 /*break*/, 29];
|
|
3795
|
+
case 34: return [3 /*break*/, 37];
|
|
3796
|
+
case 35:
|
|
3797
|
+
e_2_1 = _t.sent();
|
|
3379
3798
|
e_2 = { error: e_2_1 };
|
|
3380
|
-
return [3 /*break*/,
|
|
3381
|
-
case
|
|
3799
|
+
return [3 /*break*/, 37];
|
|
3800
|
+
case 36:
|
|
3382
3801
|
try {
|
|
3383
|
-
if (
|
|
3802
|
+
if (_o && !_o.done && (_s = _m.return)) _s.call(_m);
|
|
3384
3803
|
}
|
|
3385
3804
|
finally { if (e_2) throw e_2.error; }
|
|
3386
3805
|
return [7 /*endfinally*/];
|
|
3387
|
-
case
|
|
3806
|
+
case 37:
|
|
3388
3807
|
if (postprocessingError) {
|
|
3389
3808
|
throw postprocessingError;
|
|
3390
3809
|
}
|
|
3391
|
-
|
|
3392
|
-
case
|
|
3393
|
-
|
|
3394
|
-
return [3 /*break*/,
|
|
3395
|
-
case
|
|
3396
|
-
case
|
|
3397
|
-
e_3_1 =
|
|
3810
|
+
_t.label = 38;
|
|
3811
|
+
case 38:
|
|
3812
|
+
_l = _k.next();
|
|
3813
|
+
return [3 /*break*/, 27];
|
|
3814
|
+
case 39: return [3 /*break*/, 42];
|
|
3815
|
+
case 40:
|
|
3816
|
+
e_3_1 = _t.sent();
|
|
3398
3817
|
e_3 = { error: e_3_1 };
|
|
3399
|
-
return [3 /*break*/,
|
|
3400
|
-
case
|
|
3818
|
+
return [3 /*break*/, 42];
|
|
3819
|
+
case 41:
|
|
3401
3820
|
try {
|
|
3402
|
-
if (
|
|
3821
|
+
if (_l && !_l.done && (_r = _k.return)) _r.call(_k);
|
|
3403
3822
|
}
|
|
3404
3823
|
finally { if (e_3) throw e_3.error; }
|
|
3405
3824
|
return [7 /*endfinally*/];
|
|
3406
|
-
case
|
|
3825
|
+
case 42:
|
|
3407
3826
|
// TODO: [💝] Unite object for expecting amount and format
|
|
3408
3827
|
if (template.format) {
|
|
3409
3828
|
if (template.format === 'JSON') {
|
|
@@ -3414,13 +3833,13 @@
|
|
|
3414
3833
|
}
|
|
3415
3834
|
catch (error) {
|
|
3416
3835
|
keepUnused(error);
|
|
3417
|
-
throw new ExpectError(spaceTrim.spaceTrim(function (block) { return "\n
|
|
3418
|
-
/*<- Note: No need for `pipelineIdentification`, it will be catched and added later */ ''), "\n
|
|
3836
|
+
throw new ExpectError(spaceTrim.spaceTrim(function (block) { return "\n Expected valid JSON string\n\n ".concat(block(
|
|
3837
|
+
/*<- Note: No need for `pipelineIdentification`, it will be catched and added later */ ''), "\n "); }));
|
|
3419
3838
|
}
|
|
3420
3839
|
}
|
|
3421
3840
|
}
|
|
3422
3841
|
else {
|
|
3423
|
-
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n
|
|
3842
|
+
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Unknown format \"".concat(template.format, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3424
3843
|
}
|
|
3425
3844
|
}
|
|
3426
3845
|
// TODO: [💝] Unite object for expecting amount and format
|
|
@@ -3428,14 +3847,14 @@
|
|
|
3428
3847
|
checkExpectations(template.expectations, $ongoingTemplateResult.$resultString || '');
|
|
3429
3848
|
}
|
|
3430
3849
|
return [2 /*return*/, "break-attempts"];
|
|
3431
|
-
case
|
|
3432
|
-
error_3 =
|
|
3850
|
+
case 43:
|
|
3851
|
+
error_3 = _t.sent();
|
|
3433
3852
|
if (!(error_3 instanceof ExpectError)) {
|
|
3434
3853
|
throw error_3;
|
|
3435
3854
|
}
|
|
3436
3855
|
$ongoingTemplateResult.$expectError = error_3;
|
|
3437
|
-
return [3 /*break*/,
|
|
3438
|
-
case
|
|
3856
|
+
return [3 /*break*/, 45];
|
|
3857
|
+
case 44:
|
|
3439
3858
|
if (!isJokerAttempt &&
|
|
3440
3859
|
template.templateType === 'PROMPT_TEMPLATE' &&
|
|
3441
3860
|
$ongoingTemplateResult.$prompt
|
|
@@ -3452,22 +3871,22 @@
|
|
|
3452
3871
|
});
|
|
3453
3872
|
}
|
|
3454
3873
|
return [7 /*endfinally*/];
|
|
3455
|
-
case
|
|
3874
|
+
case 45:
|
|
3456
3875
|
if ($ongoingTemplateResult.$expectError !== null && attempt === maxAttempts - 1) {
|
|
3457
3876
|
throw new PipelineExecutionError(spaceTrim.spaceTrim(function (block) {
|
|
3458
3877
|
var _a, _b, _c;
|
|
3459
|
-
return "\n
|
|
3878
|
+
return "\n LLM execution failed ".concat(maxExecutionAttempts, "x\n\n ").concat(block(pipelineIdentification), "\n\n ---\n The Prompt:\n ").concat(block((((_a = $ongoingTemplateResult.$prompt) === null || _a === void 0 ? void 0 : _a.content) || '')
|
|
3460
3879
|
.split('\n')
|
|
3461
3880
|
.map(function (line) { return "> ".concat(line); })
|
|
3462
|
-
.join('\n')), "\n\n
|
|
3881
|
+
.join('\n')), "\n\n Last error ").concat(((_b = $ongoingTemplateResult.$expectError) === null || _b === void 0 ? void 0 : _b.name) || '', ":\n ").concat(block((((_c = $ongoingTemplateResult.$expectError) === null || _c === void 0 ? void 0 : _c.message) || '')
|
|
3463
3882
|
.split('\n')
|
|
3464
3883
|
.map(function (line) { return "> ".concat(line); })
|
|
3465
|
-
.join('\n')), "\n\n
|
|
3884
|
+
.join('\n')), "\n\n Last result:\n ").concat(block($ongoingTemplateResult.$resultString === null
|
|
3466
3885
|
? 'null'
|
|
3467
3886
|
: $ongoingTemplateResult.$resultString
|
|
3468
3887
|
.split('\n')
|
|
3469
3888
|
.map(function (line) { return "> ".concat(line); })
|
|
3470
|
-
.join('\n')), "\n
|
|
3889
|
+
.join('\n')), "\n ---\n ");
|
|
3471
3890
|
}));
|
|
3472
3891
|
}
|
|
3473
3892
|
return [2 /*return*/];
|
|
@@ -3488,7 +3907,11 @@
|
|
|
3488
3907
|
case 3:
|
|
3489
3908
|
attempt++;
|
|
3490
3909
|
return [3 /*break*/, 1];
|
|
3491
|
-
case 4:
|
|
3910
|
+
case 4:
|
|
3911
|
+
if ($ongoingTemplateResult.$resultString === null) {
|
|
3912
|
+
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Something went wrong and prompt result is null\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
3913
|
+
}
|
|
3914
|
+
return [2 /*return*/, $ongoingTemplateResult.$resultString];
|
|
3492
3915
|
}
|
|
3493
3916
|
});
|
|
3494
3917
|
});
|
|
@@ -3502,36 +3925,83 @@
|
|
|
3502
3925
|
*
|
|
3503
3926
|
* @private internal utility of `createPipelineExecutor`
|
|
3504
3927
|
*/
|
|
3505
|
-
function
|
|
3928
|
+
function executeFormatSubvalues(options) {
|
|
3506
3929
|
return __awaiter(this, void 0, void 0, function () {
|
|
3507
|
-
var template;
|
|
3930
|
+
var template, jokerParameterNames, parameters, priority, pipelineIdentification, settings, parameterValue, formatDefinition, subvalueDefinition, formatSettings, resultString;
|
|
3931
|
+
var _this = this;
|
|
3508
3932
|
return __generator(this, function (_a) {
|
|
3509
|
-
|
|
3510
|
-
|
|
3511
|
-
|
|
3933
|
+
switch (_a.label) {
|
|
3934
|
+
case 0:
|
|
3935
|
+
template = options.template, jokerParameterNames = options.jokerParameterNames, parameters = options.parameters, priority = options.priority, pipelineIdentification = options.pipelineIdentification, settings = options.settings;
|
|
3936
|
+
if (template.foreach === undefined) {
|
|
3937
|
+
return [2 /*return*/, /* not await */ executeAttempts(options)];
|
|
3938
|
+
}
|
|
3939
|
+
if (jokerParameterNames.length !== 0) {
|
|
3940
|
+
throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n JOKER parameters are not supported together with FOREACH command\n\n [\uD83E\uDDDE\u200D\u2640\uFE0F] This should be prevented in `validatePipeline`\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
3941
|
+
}
|
|
3942
|
+
parameterValue = parameters[template.foreach.parameterName] || '';
|
|
3943
|
+
formatDefinition = FORMAT_DEFINITIONS.find(function (formatDefinition) {
|
|
3944
|
+
return __spreadArray([formatDefinition.formatName], __read((formatDefinition.aliases || [])), false).includes(template.foreach.formatName);
|
|
3945
|
+
});
|
|
3946
|
+
if (formatDefinition === undefined) {
|
|
3947
|
+
throw new UnexpectedError(
|
|
3948
|
+
// <- TODO: [🧠][🧐] Should be formats fixed per promptbook version or behave as plugins (=> change UnexpectedError)
|
|
3949
|
+
spaceTrim__default["default"](function (block) { return "\n Unsupported format \"".concat(template.foreach.formatName, "\"\n\n Available formats:\n ").concat(block(FORMAT_DEFINITIONS.map(function (formatDefinition) { return formatDefinition.formatName; })
|
|
3950
|
+
.map(function (formatName) { return "- ".concat(formatName); })
|
|
3951
|
+
.join('\n')), "\n\n [\u26F7] This should never happen because format name should be validated during parsing\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3952
|
+
}
|
|
3953
|
+
subvalueDefinition = formatDefinition.subvalueDefinitions.find(function (subvalueDefinition) {
|
|
3954
|
+
return __spreadArray([subvalueDefinition.subvalueName], __read((subvalueDefinition.aliases || [])), false).includes(template.foreach.subformatName);
|
|
3955
|
+
});
|
|
3956
|
+
if (subvalueDefinition === undefined) {
|
|
3957
|
+
throw new UnexpectedError(
|
|
3958
|
+
// <- TODO: [🧠][🧐] Should be formats fixed per promptbook version or behave as plugins (=> change UnexpectedError)
|
|
3959
|
+
spaceTrim__default["default"](function (block) { return "\n Unsupported subformat name \"".concat(template.foreach.subformatName, "\" for format \"").concat(template.foreach.formatName, "\"\n\n Available subformat names for format \"").concat(formatDefinition.formatName, "\":\n ").concat(block(formatDefinition.subvalueDefinitions
|
|
3960
|
+
.map(function (subvalueDefinition) { return subvalueDefinition.subvalueName; })
|
|
3961
|
+
.map(function (subvalueName) { return "- ".concat(subvalueName); })
|
|
3962
|
+
.join('\n')), "\n\n [\u26F7] This should never happen because subformat name should be validated during parsing\n\n ").concat(block(pipelineIdentification), "\n "); }));
|
|
3963
|
+
}
|
|
3964
|
+
if (formatDefinition.formatName === 'CSV') {
|
|
3965
|
+
formatSettings = settings.csvSettings;
|
|
3966
|
+
// <- TODO: [🤹♂️] More universal, make simmilar pattern for other formats for example \n vs \r\n in text
|
|
3967
|
+
}
|
|
3968
|
+
return [4 /*yield*/, subvalueDefinition.mapValues(parameterValue, template.foreach.outputSubparameterName, formatSettings, function (subparameters, index) { return __awaiter(_this, void 0, void 0, function () {
|
|
3969
|
+
var mappedParameters, allSubparameters, subresultString;
|
|
3970
|
+
return __generator(this, function (_a) {
|
|
3971
|
+
switch (_a.label) {
|
|
3972
|
+
case 0:
|
|
3973
|
+
// TODO: [🤹♂️][🪂] Limit to N concurrent executions
|
|
3974
|
+
// TODO: When done [🐚] Report progress also for each subvalue here
|
|
3975
|
+
try {
|
|
3976
|
+
mappedParameters = mapAvailableToExpectedParameters({
|
|
3977
|
+
expectedParameters: Object.fromEntries(template.foreach.inputSubparameterNames.map(function (subparameterName) { return [subparameterName, null]; })),
|
|
3978
|
+
availableParameters: subparameters,
|
|
3979
|
+
});
|
|
3980
|
+
}
|
|
3981
|
+
catch (error) {
|
|
3982
|
+
if (!(error instanceof PipelineExecutionError)) {
|
|
3983
|
+
throw error;
|
|
3984
|
+
}
|
|
3985
|
+
throw new PipelineExecutionError(spaceTrim__default["default"](function (block) { return "\n ".concat(error.message, "\n\n This is error in FOREACH command\n You have probbably passed wrong data to pipeline or wrong data was generated which are processed by FOREACH command\n\n ").concat(block(pipelineIdentification), "\n Subparameter index: ").concat(index, "\n "); }));
|
|
3986
|
+
}
|
|
3987
|
+
allSubparameters = __assign(__assign({}, parameters), mappedParameters);
|
|
3988
|
+
// Note: [👨👨👧] Now we can freeze `subparameters` because we are sure that all and only used parameters are defined and are not going to be changed
|
|
3989
|
+
Object.freeze(allSubparameters);
|
|
3990
|
+
return [4 /*yield*/, executeAttempts(__assign(__assign({}, options), { priority: priority + index, parameters: allSubparameters, pipelineIdentification: spaceTrim__default["default"](function (block) { return "\n ".concat(block(pipelineIdentification), "\n Subparameter index: ").concat(index, "\n "); }) }))];
|
|
3991
|
+
case 1:
|
|
3992
|
+
subresultString = _a.sent();
|
|
3993
|
+
return [2 /*return*/, subresultString];
|
|
3994
|
+
}
|
|
3995
|
+
});
|
|
3996
|
+
}); })];
|
|
3997
|
+
case 1:
|
|
3998
|
+
resultString = _a.sent();
|
|
3999
|
+
return [2 /*return*/, resultString];
|
|
3512
4000
|
}
|
|
3513
|
-
throw new NotYetImplementedError('FOREACH execution not implemented yet');
|
|
3514
4001
|
});
|
|
3515
4002
|
});
|
|
3516
4003
|
}
|
|
3517
4004
|
|
|
3518
|
-
/**
|
|
3519
|
-
* Just marks a place of place where should be something implemented
|
|
3520
|
-
* No side effects.
|
|
3521
|
-
*
|
|
3522
|
-
* Note: It can be usefull suppressing eslint errors of unused variables
|
|
3523
|
-
*
|
|
3524
|
-
* @param value any values
|
|
3525
|
-
* @returns void
|
|
3526
|
-
* @private within the repository
|
|
3527
|
-
*/
|
|
3528
|
-
function TODO_USE() {
|
|
3529
|
-
var value = [];
|
|
3530
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
3531
|
-
value[_i] = arguments[_i];
|
|
3532
|
-
}
|
|
3533
|
-
}
|
|
3534
|
-
|
|
3535
4005
|
/**
|
|
3536
4006
|
* @@@
|
|
3537
4007
|
*
|
|
@@ -3645,7 +4115,7 @@
|
|
|
3645
4115
|
*/
|
|
3646
4116
|
function executeTemplate(options) {
|
|
3647
4117
|
return __awaiter(this, void 0, void 0, function () {
|
|
3648
|
-
var currentTemplate, preparedPipeline, parametersToPass, tools, llmTools, onProgress, settings, $executionReport, pipelineIdentification, maxExecutionAttempts, name, title, priority, usedParameterNames, dependentParameterNames, definedParameters, _a, _b, _c, definedParameterNames, parameters, _loop_1, _d, _e, parameterName,
|
|
4118
|
+
var currentTemplate, preparedPipeline, parametersToPass, tools, llmTools, onProgress, settings, $executionReport, pipelineIdentification, maxExecutionAttempts, name, title, priority, usedParameterNames, dependentParameterNames, definedParameters, _a, _b, _c, definedParameterNames, parameters, _loop_1, _d, _e, parameterName, maxAttempts, jokerParameterNames, preparedContent, resultString;
|
|
3649
4119
|
var e_1, _f, _g;
|
|
3650
4120
|
return __generator(this, function (_h) {
|
|
3651
4121
|
switch (_h.label) {
|
|
@@ -3669,12 +4139,13 @@
|
|
|
3669
4139
|
_h.sent();
|
|
3670
4140
|
usedParameterNames = extractParameterNamesFromTemplate(currentTemplate);
|
|
3671
4141
|
dependentParameterNames = new Set(currentTemplate.dependentParameterNames);
|
|
4142
|
+
// TODO: [👩🏾🤝👩🏻] Use here `mapAvailableToExpectedParameters`
|
|
3672
4143
|
if (union(difference(usedParameterNames, dependentParameterNames), difference(dependentParameterNames, usedParameterNames)).size !== 0) {
|
|
3673
|
-
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Dependent parameters are not consistent with used parameters:\n\n
|
|
4144
|
+
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Dependent parameters are not consistent with used parameters:\n\n Dependent parameters:\n ".concat(Array.from(dependentParameterNames)
|
|
3674
4145
|
.map(function (name) { return "{".concat(name, "}"); })
|
|
3675
4146
|
.join(', '), "\n\n Used parameters:\n ").concat(Array.from(usedParameterNames)
|
|
3676
4147
|
.map(function (name) { return "{".concat(name, "}"); })
|
|
3677
|
-
.join(', '), "\n\n "); }));
|
|
4148
|
+
.join(', '), "\n\n ").concat(block(pipelineIdentification), "\n\n "); }));
|
|
3678
4149
|
}
|
|
3679
4150
|
_b = (_a = Object).freeze;
|
|
3680
4151
|
_c = [{}];
|
|
@@ -3703,6 +4174,7 @@
|
|
|
3703
4174
|
};
|
|
3704
4175
|
try {
|
|
3705
4176
|
// Note: [2] Check that all used parameters are defined and removing unused parameters for this template
|
|
4177
|
+
// TODO: [👩🏾🤝👩🏻] Use here `mapAvailableToExpectedParameters`
|
|
3706
4178
|
for (_d = __values(Array.from(union(definedParameterNames, usedParameterNames, dependentParameterNames))), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
3707
4179
|
parameterName = _e.value;
|
|
3708
4180
|
_loop_1(parameterName);
|
|
@@ -3715,22 +4187,14 @@
|
|
|
3715
4187
|
}
|
|
3716
4188
|
finally { if (e_1) throw e_1.error; }
|
|
3717
4189
|
}
|
|
3718
|
-
// Note: Now we can freeze `parameters` because we are sure that all and only used parameters are defined and are not going to be changed
|
|
4190
|
+
// Note: [👨👨👧] Now we can freeze `parameters` because we are sure that all and only used parameters are defined and are not going to be changed
|
|
3719
4191
|
Object.freeze(parameters);
|
|
3720
|
-
$ongoingTemplateResult = {
|
|
3721
|
-
$result: null,
|
|
3722
|
-
$resultString: null,
|
|
3723
|
-
$expectError: null,
|
|
3724
|
-
$scriptPipelineExecutionErrors: [],
|
|
3725
|
-
};
|
|
3726
4192
|
maxAttempts = currentTemplate.templateType === 'DIALOG_TEMPLATE' ? Infinity : maxExecutionAttempts;
|
|
3727
4193
|
jokerParameterNames = currentTemplate.jokerParameterNames || [];
|
|
3728
4194
|
preparedContent = (currentTemplate.preparedContent || '{content}')
|
|
3729
4195
|
.split('{content}')
|
|
3730
4196
|
.join(currentTemplate.content);
|
|
3731
|
-
|
|
3732
|
-
return [4 /*yield*/, executeFormatCells({
|
|
3733
|
-
$ongoingTemplateResult: $ongoingTemplateResult,
|
|
4197
|
+
return [4 /*yield*/, executeFormatSubvalues({
|
|
3734
4198
|
jokerParameterNames: jokerParameterNames,
|
|
3735
4199
|
priority: priority,
|
|
3736
4200
|
maxAttempts: maxAttempts,
|
|
@@ -3745,11 +4209,7 @@
|
|
|
3745
4209
|
pipelineIdentification: pipelineIdentification,
|
|
3746
4210
|
})];
|
|
3747
4211
|
case 3:
|
|
3748
|
-
|
|
3749
|
-
_h.sent();
|
|
3750
|
-
if ($ongoingTemplateResult.$resultString === null) {
|
|
3751
|
-
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Something went wrong and prompt result is null\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
3752
|
-
}
|
|
4212
|
+
resultString = _h.sent();
|
|
3753
4213
|
return [4 /*yield*/, onProgress({
|
|
3754
4214
|
name: name,
|
|
3755
4215
|
title: title,
|
|
@@ -3757,13 +4217,15 @@
|
|
|
3757
4217
|
isDone: true,
|
|
3758
4218
|
templateType: currentTemplate.templateType,
|
|
3759
4219
|
parameterName: currentTemplate.resultingParameterName,
|
|
3760
|
-
parameterValue:
|
|
4220
|
+
parameterValue: resultString,
|
|
3761
4221
|
// <- [🍸]
|
|
3762
4222
|
})];
|
|
3763
4223
|
case 4:
|
|
3764
4224
|
_h.sent();
|
|
3765
4225
|
return [2 /*return*/, Object.freeze((_g = {},
|
|
3766
|
-
_g[currentTemplate.resultingParameterName] =
|
|
4226
|
+
_g[currentTemplate.resultingParameterName] =
|
|
4227
|
+
// <- Note: [👩👩👧] No need to detect parameter collision here because pipeline checks logic consistency during construction
|
|
4228
|
+
resultString,
|
|
3767
4229
|
_g))];
|
|
3768
4230
|
}
|
|
3769
4231
|
});
|
|
@@ -3772,6 +4234,9 @@
|
|
|
3772
4234
|
/**
|
|
3773
4235
|
* TODO: [🤹♂️]
|
|
3774
4236
|
*/
|
|
4237
|
+
/**
|
|
4238
|
+
* TODO: [🐚] Change onProgress to object that represents the running execution, can be subscribed via RxJS to and also awaited
|
|
4239
|
+
*/
|
|
3775
4240
|
|
|
3776
4241
|
/**
|
|
3777
4242
|
* @@@
|
|
@@ -3792,6 +4257,7 @@
|
|
|
3792
4257
|
};
|
|
3793
4258
|
try {
|
|
3794
4259
|
// Note: Filter ONLY output parameters
|
|
4260
|
+
// TODO: [👩🏾🤝👩🏻] Maybe use here `mapAvailableToExpectedParameters`
|
|
3795
4261
|
for (var _b = __values(preparedPipeline.parameters.filter(function (_a) {
|
|
3796
4262
|
var isOutput = _a.isOutput;
|
|
3797
4263
|
return isOutput;
|
|
@@ -3906,7 +4372,7 @@
|
|
|
3906
4372
|
return name === parameterName;
|
|
3907
4373
|
});
|
|
3908
4374
|
if (!(parameter === undefined)) return [3 /*break*/, 1];
|
|
3909
|
-
warnings.push(new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n
|
|
4375
|
+
warnings.push(new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Extra parameter {".concat(parameterName, "} is being passed which is not part of the pipeline.\n\n ").concat(block(pipelineIdentification), "\n "); })));
|
|
3910
4376
|
return [3 /*break*/, 4];
|
|
3911
4377
|
case 1:
|
|
3912
4378
|
if (!(parameter.isInput === false)) return [3 /*break*/, 4];
|
|
@@ -3918,10 +4384,10 @@
|
|
|
3918
4384
|
// Note: Wait a short time to prevent race conditions
|
|
3919
4385
|
_h.sent();
|
|
3920
4386
|
_h.label = 3;
|
|
3921
|
-
case 3: return [2 /*return*/, { value: $asDeeplyFrozenSerializableJson(spaceTrim.spaceTrim(function (block) { return "\n
|
|
4387
|
+
case 3: return [2 /*return*/, { value: $asDeeplyFrozenSerializableJson(spaceTrim.spaceTrim(function (block) { return "\n Unuccessful PipelineExecutorResult (with extra parameter {".concat(parameter.name, "}) PipelineExecutorResult\n\n ").concat(block(pipelineIdentification), "\n "); }), {
|
|
3922
4388
|
isSuccessful: false,
|
|
3923
4389
|
errors: __spreadArray([
|
|
3924
|
-
new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n
|
|
4390
|
+
new PipelineExecutionError(spaceTrim.spaceTrim(function (block) { return "\n Parameter {".concat(parameter.name, "} is passed as input parameter but it is not input\n\n ").concat(block(pipelineIdentification), "\n "); }))
|
|
3925
4391
|
], __read(errors), false).map(serializeError),
|
|
3926
4392
|
warnings: warnings.map(serializeError),
|
|
3927
4393
|
executionReport: executionReport,
|
|
@@ -3985,7 +4451,7 @@
|
|
|
3985
4451
|
case 0:
|
|
3986
4452
|
if (loopLimit-- < 0) {
|
|
3987
4453
|
// Note: Really UnexpectedError not LimitReachedError - this should be catched during validatePipeline
|
|
3988
|
-
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n
|
|
4454
|
+
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Loop limit reached during resolving parameters pipeline execution\n\n ".concat(block(pipelineIdentification), "\n "); }));
|
|
3989
4455
|
}
|
|
3990
4456
|
currentTemplate = unresovedTemplates_1.find(function (template) {
|
|
3991
4457
|
return template.dependentParameterNames.every(function (name) {
|
|
@@ -3995,14 +4461,14 @@
|
|
|
3995
4461
|
if (!(!currentTemplate && resolving_1.length === 0)) return [3 /*break*/, 1];
|
|
3996
4462
|
throw new UnexpectedError(
|
|
3997
4463
|
// TODO: [🐎] DRY
|
|
3998
|
-
spaceTrim.spaceTrim(function (block) { return "\n
|
|
4464
|
+
spaceTrim.spaceTrim(function (block) { return "\n Can not resolve some parameters:\n\n ".concat(block(pipelineIdentification), "\n\n Can not resolve:\n ").concat(block(unresovedTemplates_1
|
|
3999
4465
|
.map(function (_a) {
|
|
4000
4466
|
var resultingParameterName = _a.resultingParameterName, dependentParameterNames = _a.dependentParameterNames;
|
|
4001
4467
|
return "- Parameter {".concat(resultingParameterName, "} which depends on ").concat(dependentParameterNames
|
|
4002
4468
|
.map(function (dependentParameterName) { return "{".concat(dependentParameterName, "}"); })
|
|
4003
4469
|
.join(' and '));
|
|
4004
4470
|
})
|
|
4005
|
-
.join('\n')), "\n\n
|
|
4471
|
+
.join('\n')), "\n\n Resolved:\n ").concat(block(resovedParameterNames_1.map(function (name) { return "- Parameter {".concat(name, "}"); }).join('\n')), "\n\n Note: This should be catched in `validatePipeline`\n "); }));
|
|
4006
4472
|
case 1:
|
|
4007
4473
|
if (!!currentTemplate) return [3 /*break*/, 3];
|
|
4008
4474
|
/* [🤹♂️] */ return [4 /*yield*/, Promise.race(resolving_1)];
|
|
@@ -4019,10 +4485,10 @@
|
|
|
4019
4485
|
llmTools: llmTools,
|
|
4020
4486
|
onProgress: function (progress) {
|
|
4021
4487
|
if (isReturned) {
|
|
4022
|
-
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n
|
|
4488
|
+
throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Can not call `onProgress` after pipeline execution is finished\n\n ".concat(block(pipelineIdentification), "\n\n ").concat(block(JSON.stringify(progress, null, 4)
|
|
4023
4489
|
.split('\n')
|
|
4024
4490
|
.map(function (line) { return "> ".concat(line); })
|
|
4025
|
-
.join('\n')), "\n
|
|
4491
|
+
.join('\n')), "\n "); }));
|
|
4026
4492
|
}
|
|
4027
4493
|
if (onProgress) {
|
|
4028
4494
|
onProgress(progress);
|
|
@@ -4030,7 +4496,7 @@
|
|
|
4030
4496
|
},
|
|
4031
4497
|
settings: settings,
|
|
4032
4498
|
$executionReport: executionReport,
|
|
4033
|
-
pipelineIdentification: pipelineIdentification,
|
|
4499
|
+
pipelineIdentification: spaceTrim.spaceTrim(function (block) { return "\n ".concat(block(pipelineIdentification), "\n Template name: ").concat(currentTemplate.name, "\n Template title: ").concat(currentTemplate.title, "\n "); }),
|
|
4034
4500
|
})
|
|
4035
4501
|
.then(function (newParametersToPass) {
|
|
4036
4502
|
parametersToPass = __assign(__assign({}, newParametersToPass), parametersToPass);
|
|
@@ -4122,6 +4588,9 @@
|
|
|
4122
4588
|
});
|
|
4123
4589
|
});
|
|
4124
4590
|
}
|
|
4591
|
+
/**
|
|
4592
|
+
* TODO: [🐚] Change onProgress to object that represents the running execution, can be subscribed via RxJS to and also awaited
|
|
4593
|
+
*/
|
|
4125
4594
|
|
|
4126
4595
|
/**
|
|
4127
4596
|
* Creates executor function from pipeline and execution tools.
|
|
@@ -4133,7 +4602,7 @@
|
|
|
4133
4602
|
function createPipelineExecutor(options) {
|
|
4134
4603
|
var _this = this;
|
|
4135
4604
|
var pipeline = options.pipeline, tools = options.tools, _a = options.settings, settings = _a === void 0 ? {} : _a;
|
|
4136
|
-
var _b = settings.maxExecutionAttempts, maxExecutionAttempts = _b === void 0 ? MAX_EXECUTION_ATTEMPTS : _b, _c = settings.maxParallelCount, maxParallelCount = _c === void 0 ? MAX_PARALLEL_COUNT : _c, _d = settings.
|
|
4605
|
+
var _b = settings.maxExecutionAttempts, maxExecutionAttempts = _b === void 0 ? MAX_EXECUTION_ATTEMPTS : _b, _c = settings.maxParallelCount, maxParallelCount = _c === void 0 ? MAX_PARALLEL_COUNT : _c, _d = settings.csvSettings, csvSettings = _d === void 0 ? DEFAULT_CSV_SETTINGS : _d, _e = settings.isVerbose, isVerbose = _e === void 0 ? IS_VERBOSE : _e, _f = settings.isNotPreparedWarningSupressed, isNotPreparedWarningSupressed = _f === void 0 ? false : _f;
|
|
4137
4606
|
validatePipeline(pipeline);
|
|
4138
4607
|
var pipelineIdentification = (function () {
|
|
4139
4608
|
// Note: This is a 😐 implementation of [🚞]
|
|
@@ -4153,9 +4622,11 @@
|
|
|
4153
4622
|
else if (isNotPreparedWarningSupressed !== true) {
|
|
4154
4623
|
console.warn(spaceTrim.spaceTrim(function (block) { return "\n Pipeline is not prepared\n\n ".concat(block(pipelineIdentification), "\n\n It will be prepared ad-hoc before the first execution and **returned as `preparedPipeline` in `PipelineExecutorResult`**\n But it is recommended to prepare the pipeline during collection preparation\n\n @see more at https://ptbk.io/prepare-pipeline\n "); }));
|
|
4155
4624
|
}
|
|
4625
|
+
var runCount = 0;
|
|
4156
4626
|
var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
|
|
4157
4627
|
return __generator(this, function (_a) {
|
|
4158
|
-
|
|
4628
|
+
runCount++;
|
|
4629
|
+
return [2 /*return*/, /* not await */ executePipeline({
|
|
4159
4630
|
pipeline: pipeline,
|
|
4160
4631
|
preparedPipeline: preparedPipeline,
|
|
4161
4632
|
setPreparedPipeline: function (newPreparedPipeline) {
|
|
@@ -4164,10 +4635,11 @@
|
|
|
4164
4635
|
inputParameters: inputParameters,
|
|
4165
4636
|
tools: tools,
|
|
4166
4637
|
onProgress: onProgress,
|
|
4167
|
-
pipelineIdentification: pipelineIdentification,
|
|
4638
|
+
pipelineIdentification: spaceTrim.spaceTrim(function (block) { return "\n ".concat(block(pipelineIdentification), "\n ").concat(runCount === 1 ? '' : "Run #".concat(runCount), "\n "); }),
|
|
4168
4639
|
settings: {
|
|
4169
4640
|
maxExecutionAttempts: maxExecutionAttempts,
|
|
4170
4641
|
maxParallelCount: maxParallelCount,
|
|
4642
|
+
csvSettings: csvSettings,
|
|
4171
4643
|
isVerbose: isVerbose,
|
|
4172
4644
|
isNotPreparedWarningSupressed: isNotPreparedWarningSupressed,
|
|
4173
4645
|
},
|
|
@@ -4176,6 +4648,9 @@
|
|
|
4176
4648
|
}); };
|
|
4177
4649
|
return pipelineExecutor;
|
|
4178
4650
|
}
|
|
4651
|
+
/**
|
|
4652
|
+
* TODO: [🐚] Change onProgress to object that represents the running execution, can be subscribed via RxJS to and also awaited
|
|
4653
|
+
*/
|
|
4179
4654
|
|
|
4180
4655
|
/**
|
|
4181
4656
|
* @@@
|
|
@@ -4227,7 +4702,7 @@
|
|
|
4227
4702
|
outputParameters = result.outputParameters;
|
|
4228
4703
|
knowledgePiecesRaw = outputParameters.knowledgePieces;
|
|
4229
4704
|
knowledgeTextPieces = (knowledgePiecesRaw || '').split('\n---\n');
|
|
4230
|
-
// <- TODO: !!!!! Smarter split and filter out empty pieces
|
|
4705
|
+
// <- TODO: [main] !!!!! Smarter split and filter out empty pieces
|
|
4231
4706
|
if (isVerbose) {
|
|
4232
4707
|
console.info('knowledgeTextPieces:', knowledgeTextPieces);
|
|
4233
4708
|
}
|
|
@@ -4285,8 +4760,13 @@
|
|
|
4285
4760
|
case 6: return [3 /*break*/, 8];
|
|
4286
4761
|
case 7:
|
|
4287
4762
|
error_1 = _c.sent();
|
|
4763
|
+
// Note: Here is expected error:
|
|
4764
|
+
// > PipelineExecutionError: You have not provided any `LlmExecutionTools` that support model variant "EMBEDDING
|
|
4765
|
+
if (!(error_1 instanceof PipelineExecutionError)) {
|
|
4766
|
+
throw error_1;
|
|
4767
|
+
}
|
|
4288
4768
|
// TODO: [🟥] Detect browser / node and make it colorfull
|
|
4289
|
-
console.error(error_1);
|
|
4769
|
+
console.error(error_1, "<- Note: This error is not critical to prepare the pipeline, just knowledge pieces won't have embeddings");
|
|
4290
4770
|
return [3 /*break*/, 8];
|
|
4291
4771
|
case 8: return [2 /*return*/, {
|
|
4292
4772
|
name: name,
|
|
@@ -4307,7 +4787,7 @@
|
|
|
4307
4787
|
});
|
|
4308
4788
|
}
|
|
4309
4789
|
/**
|
|
4310
|
-
* TODO: [🐝][🔼] !!! Export via `@promptbook/markdown`
|
|
4790
|
+
* TODO: [🐝][🔼][main] !!! Export via `@promptbook/markdown`
|
|
4311
4791
|
* TODO: [🪂] Do it in parallel 11:11
|
|
4312
4792
|
* Note: No need to aggregate usage here, it is done by intercepting the llmTools
|
|
4313
4793
|
*/
|
|
@@ -4331,7 +4811,7 @@
|
|
|
4331
4811
|
var partialPieces, pieces;
|
|
4332
4812
|
return __generator(this, function (_a) {
|
|
4333
4813
|
switch (_a.label) {
|
|
4334
|
-
case 0: return [4 /*yield*/, prepareKnowledgeFromMarkdown(knowledgeSource.sourceContent, // <- TODO: [🐝] !!! Unhardcode markdown, detect which type it is - BE AWARE of big package size
|
|
4814
|
+
case 0: return [4 /*yield*/, prepareKnowledgeFromMarkdown(knowledgeSource.sourceContent, // <- TODO: [🐝][main] !!! Unhardcode markdown, detect which type it is - BE AWARE of big package size
|
|
4335
4815
|
options)];
|
|
4336
4816
|
case 1:
|
|
4337
4817
|
partialPieces = _a.sent();
|
|
@@ -4523,7 +5003,7 @@
|
|
|
4523
5003
|
});
|
|
4524
5004
|
}
|
|
4525
5005
|
/**
|
|
4526
|
-
* TODO: [🔃] !!!!! If the persona was prepared with different version or different set of models, prepare it once again
|
|
5006
|
+
* TODO: [🔃][main] !!!!! If the persona was prepared with different version or different set of models, prepare it once again
|
|
4527
5007
|
* TODO: [🏢] !! Check validity of `modelName` in pipeline
|
|
4528
5008
|
* TODO: [🏢] !! Check validity of `systemMessage` in pipeline
|
|
4529
5009
|
* TODO: [🏢] !! Check validity of `temperature` in pipeline
|
|
@@ -4572,7 +5052,7 @@
|
|
|
4572
5052
|
case 0:
|
|
4573
5053
|
_a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a;
|
|
4574
5054
|
templates = pipeline.templates, parameters = pipeline.parameters, knowledgePiecesCount = pipeline.knowledgePiecesCount;
|
|
4575
|
-
// TODO: !!!!! Apply samples to each template (if missing and is for the template defined)
|
|
5055
|
+
// TODO: [main] !!!!! Apply samples to each template (if missing and is for the template defined)
|
|
4576
5056
|
TODO_USE(parameters);
|
|
4577
5057
|
templatesPrepared = new Array(
|
|
4578
5058
|
// <- TODO: [🧱] Implement in a functional (not new Class) way
|
|
@@ -4604,7 +5084,7 @@
|
|
|
4604
5084
|
/**
|
|
4605
5085
|
* TODO: [🧠] Add context to each template (if missing)
|
|
4606
5086
|
* TODO: [🧠] What is better name `prepareTemplate` or `prepareTemplateAndParameters`
|
|
4607
|
-
* TODO: [♨] !!! Prepare index the samples and maybe templates
|
|
5087
|
+
* TODO: [♨][main] !!! Prepare index the samples and maybe templates
|
|
4608
5088
|
* TODO: Write tests for `preparePipeline`
|
|
4609
5089
|
* TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
|
|
4610
5090
|
* TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
|
|
@@ -4776,7 +5256,7 @@
|
|
|
4776
5256
|
if (sourceContent === '') {
|
|
4777
5257
|
throw new ParseError("Source is not defined");
|
|
4778
5258
|
}
|
|
4779
|
-
// TODO: !!!! Following checks should be applied every link in the `sourceContent`
|
|
5259
|
+
// TODO: [main] !!!! Following checks should be applied every link in the `sourceContent`
|
|
4780
5260
|
if (sourceContent.startsWith('http://')) {
|
|
4781
5261
|
throw new ParseError("Source is not secure");
|
|
4782
5262
|
}
|
|
@@ -4979,7 +5459,7 @@
|
|
|
4979
5459
|
if (command.templateType === 'KNOWLEDGE') {
|
|
4980
5460
|
knowledgeCommandParser.$applyToPipelineJson({
|
|
4981
5461
|
type: 'KNOWLEDGE',
|
|
4982
|
-
sourceContent: $templateJson.content, // <- TODO: [🐝] !!! Work with KNOWLEDGE which not referring to the source file or website, but its content itself
|
|
5462
|
+
sourceContent: $templateJson.content, // <- TODO: [🐝][main] !!! Work with KNOWLEDGE which not referring to the source file or website, but its content itself
|
|
4983
5463
|
}, $pipelineJson);
|
|
4984
5464
|
$templateJson.isTemplate = false;
|
|
4985
5465
|
return;
|
|
@@ -5329,6 +5809,171 @@
|
|
|
5329
5809
|
* TODO: [🌺] Use some intermediate util splitWords
|
|
5330
5810
|
*/
|
|
5331
5811
|
|
|
5812
|
+
/**
|
|
5813
|
+
* @@@
|
|
5814
|
+
*
|
|
5815
|
+
* @param text @@@
|
|
5816
|
+
* @param _isFirstLetterCapital @@@
|
|
5817
|
+
* @returns @@@
|
|
5818
|
+
* @example 'helloWorld'
|
|
5819
|
+
* @example 'iLovePromptbook'
|
|
5820
|
+
* @public exported from `@promptbook/utils`
|
|
5821
|
+
*/
|
|
5822
|
+
function normalizeTo_camelCase(text, _isFirstLetterCapital) {
|
|
5823
|
+
var e_1, _a;
|
|
5824
|
+
if (_isFirstLetterCapital === void 0) { _isFirstLetterCapital = false; }
|
|
5825
|
+
var charType;
|
|
5826
|
+
var lastCharType = null;
|
|
5827
|
+
var normalizedName = '';
|
|
5828
|
+
try {
|
|
5829
|
+
for (var text_1 = __values(text), text_1_1 = text_1.next(); !text_1_1.done; text_1_1 = text_1.next()) {
|
|
5830
|
+
var char = text_1_1.value;
|
|
5831
|
+
var normalizedChar = void 0;
|
|
5832
|
+
if (/^[a-z]$/.test(char)) {
|
|
5833
|
+
charType = 'LOWERCASE';
|
|
5834
|
+
normalizedChar = char;
|
|
5835
|
+
}
|
|
5836
|
+
else if (/^[A-Z]$/.test(char)) {
|
|
5837
|
+
charType = 'UPPERCASE';
|
|
5838
|
+
normalizedChar = char.toLowerCase();
|
|
5839
|
+
}
|
|
5840
|
+
else if (/^[0-9]$/.test(char)) {
|
|
5841
|
+
charType = 'NUMBER';
|
|
5842
|
+
normalizedChar = char;
|
|
5843
|
+
}
|
|
5844
|
+
else {
|
|
5845
|
+
charType = 'OTHER';
|
|
5846
|
+
normalizedChar = '';
|
|
5847
|
+
}
|
|
5848
|
+
if (!lastCharType) {
|
|
5849
|
+
if (_isFirstLetterCapital) {
|
|
5850
|
+
normalizedChar = normalizedChar.toUpperCase(); //TODO: DRY
|
|
5851
|
+
}
|
|
5852
|
+
}
|
|
5853
|
+
else if (charType !== lastCharType &&
|
|
5854
|
+
!(charType === 'LOWERCASE' && lastCharType === 'UPPERCASE') &&
|
|
5855
|
+
!(lastCharType === 'NUMBER') &&
|
|
5856
|
+
!(charType === 'NUMBER')) {
|
|
5857
|
+
normalizedChar = normalizedChar.toUpperCase(); //TODO: [🌺] DRY
|
|
5858
|
+
}
|
|
5859
|
+
normalizedName += normalizedChar;
|
|
5860
|
+
lastCharType = charType;
|
|
5861
|
+
}
|
|
5862
|
+
}
|
|
5863
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
5864
|
+
finally {
|
|
5865
|
+
try {
|
|
5866
|
+
if (text_1_1 && !text_1_1.done && (_a = text_1.return)) _a.call(text_1);
|
|
5867
|
+
}
|
|
5868
|
+
finally { if (e_1) throw e_1.error; }
|
|
5869
|
+
}
|
|
5870
|
+
return normalizedName;
|
|
5871
|
+
}
|
|
5872
|
+
/**
|
|
5873
|
+
* TODO: [🌺] Use some intermediate util splitWords
|
|
5874
|
+
*/
|
|
5875
|
+
|
|
5876
|
+
/**
|
|
5877
|
+
* Removes quotes from a string
|
|
5878
|
+
*
|
|
5879
|
+
* Tip: This is very usefull for post-processing of the result of the LLM model
|
|
5880
|
+
* Note: This function removes only the same quotes from the beginning and the end of the string
|
|
5881
|
+
* Note: There are two simmilar functions:
|
|
5882
|
+
* - `removeQuotes` which removes only bounding quotes
|
|
5883
|
+
* - `unwrapResult` which removes whole introduce sentence
|
|
5884
|
+
*
|
|
5885
|
+
* @param text optionally quoted text
|
|
5886
|
+
* @returns text without quotes
|
|
5887
|
+
* @public exported from `@promptbook/utils`
|
|
5888
|
+
*/
|
|
5889
|
+
function removeQuotes(text) {
|
|
5890
|
+
if (text.startsWith('"') && text.endsWith('"')) {
|
|
5891
|
+
return text.slice(1, -1);
|
|
5892
|
+
}
|
|
5893
|
+
if (text.startsWith('\'') && text.endsWith('\'')) {
|
|
5894
|
+
return text.slice(1, -1);
|
|
5895
|
+
}
|
|
5896
|
+
return text;
|
|
5897
|
+
}
|
|
5898
|
+
|
|
5899
|
+
/**
|
|
5900
|
+
* Function `validateParameterName` will @@@
|
|
5901
|
+
*
|
|
5902
|
+
* @param parameterName @@@
|
|
5903
|
+
* @returns @@@
|
|
5904
|
+
* @throws {ParseError} @@@
|
|
5905
|
+
* @private within the repository
|
|
5906
|
+
*/
|
|
5907
|
+
function validateParameterName(parameterName) {
|
|
5908
|
+
var e_1, _a;
|
|
5909
|
+
var rawParameterName = parameterName;
|
|
5910
|
+
try {
|
|
5911
|
+
for (var _b = __values([
|
|
5912
|
+
['`', '`'],
|
|
5913
|
+
['{', '}'],
|
|
5914
|
+
['[', ']'],
|
|
5915
|
+
['(', ')'],
|
|
5916
|
+
['<', '>'],
|
|
5917
|
+
]), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
5918
|
+
var _d = __read(_c.value, 2), start = _d[0], end = _d[1];
|
|
5919
|
+
if (parameterName.substring(0, 1) === start &&
|
|
5920
|
+
parameterName.substring(parameterName.length - 1, parameterName.length) === end
|
|
5921
|
+
// <- TODO: More universal that 1 character
|
|
5922
|
+
) {
|
|
5923
|
+
parameterName = parameterName.substring(1, parameterName.length - 1);
|
|
5924
|
+
// <- TODO: More universal that 1 character
|
|
5925
|
+
}
|
|
5926
|
+
}
|
|
5927
|
+
}
|
|
5928
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
5929
|
+
finally {
|
|
5930
|
+
try {
|
|
5931
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
5932
|
+
}
|
|
5933
|
+
finally { if (e_1) throw e_1.error; }
|
|
5934
|
+
}
|
|
5935
|
+
// TODO: [🐠] Following try-catch block should be part of common validators logic
|
|
5936
|
+
try {
|
|
5937
|
+
/*
|
|
5938
|
+
Note: We don't need to check for spaces because we are going to normalize the parameter name to camelCase
|
|
5939
|
+
if (parameterName.includes(' ')) {
|
|
5940
|
+
throw new ParseError(`Parameter name cannot contain spaces`);
|
|
5941
|
+
}
|
|
5942
|
+
*/
|
|
5943
|
+
if (parameterName.includes('.')) {
|
|
5944
|
+
throw new ParseError("Parameter name cannot contain dots");
|
|
5945
|
+
}
|
|
5946
|
+
if (parameterName.includes('/') || parameterName.includes('\\')) {
|
|
5947
|
+
throw new ParseError("Parameter name cannot contain slashes");
|
|
5948
|
+
}
|
|
5949
|
+
if (parameterName.includes('(') ||
|
|
5950
|
+
parameterName.includes(')') ||
|
|
5951
|
+
parameterName.includes('{') ||
|
|
5952
|
+
parameterName.includes('}') ||
|
|
5953
|
+
parameterName.includes('[') ||
|
|
5954
|
+
parameterName.includes(']')) {
|
|
5955
|
+
throw new ParseError("Parameter name cannot contain braces");
|
|
5956
|
+
}
|
|
5957
|
+
parameterName = removeDiacritics(parameterName);
|
|
5958
|
+
parameterName = removeEmojis(parameterName);
|
|
5959
|
+
parameterName = removeQuotes(parameterName);
|
|
5960
|
+
parameterName = normalizeTo_camelCase(parameterName);
|
|
5961
|
+
if (parameterName === '') {
|
|
5962
|
+
throw new ParseError("Parameter name cannot be empty");
|
|
5963
|
+
}
|
|
5964
|
+
if (RESERVED_PARAMETER_NAMES.includes(parameterName)) {
|
|
5965
|
+
throw new ParseError("{".concat(parameterName, "} is a reserved parameter name"));
|
|
5966
|
+
}
|
|
5967
|
+
}
|
|
5968
|
+
catch (error) {
|
|
5969
|
+
if (!(error instanceof ParseError)) {
|
|
5970
|
+
throw error;
|
|
5971
|
+
}
|
|
5972
|
+
throw new ParseError(spaceTrim__default["default"](function (block) { return "\n ".concat(block(error.message), "\n\n Tried to validate parameter name:\n ").concat(block(rawParameterName), "\n "); }));
|
|
5973
|
+
}
|
|
5974
|
+
return parameterName;
|
|
5975
|
+
}
|
|
5976
|
+
|
|
5332
5977
|
/**
|
|
5333
5978
|
* Parses the foreach command
|
|
5334
5979
|
*
|
|
@@ -5358,15 +6003,16 @@
|
|
|
5358
6003
|
/**
|
|
5359
6004
|
* Link to discussion
|
|
5360
6005
|
*/
|
|
5361
|
-
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions
|
|
6006
|
+
documentationUrl: 'https://github.com/webgptorg/promptbook/discussions/148',
|
|
5362
6007
|
/**
|
|
5363
6008
|
* Example usages of the FOREACH command
|
|
5364
6009
|
*/
|
|
5365
6010
|
examples: [
|
|
5366
|
-
'FOREACH
|
|
5367
|
-
'
|
|
5368
|
-
'
|
|
5369
|
-
|
|
6011
|
+
'FOREACH Text Line `{customers}` -> `{customer}`',
|
|
6012
|
+
'FOREACH Csv Cell `{customers}` -> `{cell}`',
|
|
6013
|
+
'FOREACH Csv Row `{customers}` -> `{firstName}`, `{lastName}`, `+{email}`',
|
|
6014
|
+
'FOR Text Line `{customers}` -> `{customer}`',
|
|
6015
|
+
'EACH Text Line `{customers}` -> `{customer}`',
|
|
5370
6016
|
],
|
|
5371
6017
|
/**
|
|
5372
6018
|
* Parses the FOREACH command
|
|
@@ -5374,55 +6020,75 @@
|
|
|
5374
6020
|
parse: function (input) {
|
|
5375
6021
|
var args = input.args;
|
|
5376
6022
|
var formatName = normalizeTo_SCREAMING_CASE(args[0] || '');
|
|
5377
|
-
var
|
|
5378
|
-
var
|
|
6023
|
+
var subformatName = normalizeTo_SCREAMING_CASE(args[1] || '');
|
|
6024
|
+
var parameterNameArg = args[2] || '';
|
|
5379
6025
|
var assignSign = args[3];
|
|
5380
|
-
var
|
|
5381
|
-
|
|
5382
|
-
|
|
5383
|
-
|
|
5384
|
-
|
|
5385
|
-
|
|
5386
|
-
|
|
5387
|
-
throw new Error("Unsupported format \"".concat(formatName, "\""));
|
|
6026
|
+
var formatDefinition = FORMAT_DEFINITIONS.find(function (formatDefinition) {
|
|
6027
|
+
return __spreadArray([formatDefinition.formatName], __read((formatDefinition.aliases || [])), false).includes(formatName);
|
|
6028
|
+
});
|
|
6029
|
+
if (formatDefinition === undefined) {
|
|
6030
|
+
throw new ParseError(spaceTrim__default["default"](function (block) { return "\n Unsupported format \"".concat(formatName, "\"\n\n Available formats:\n ").concat(block(FORMAT_DEFINITIONS.map(function (formatDefinition) { return formatDefinition.formatName; })
|
|
6031
|
+
.map(function (formatName) { return "- ".concat(formatName); })
|
|
6032
|
+
.join('\n')), "\n "); }));
|
|
5388
6033
|
// <- TODO: [🏢] List all supported format names
|
|
5389
6034
|
}
|
|
5390
|
-
|
|
5391
|
-
|
|
5392
|
-
|
|
5393
|
-
|
|
5394
|
-
|
|
5395
|
-
|
|
5396
|
-
|
|
5397
|
-
|
|
5398
|
-
|
|
5399
|
-
// <- TODO: [🏢] List all supported cell names for the format
|
|
6035
|
+
var subvalueDefinition = formatDefinition.subvalueDefinitions.find(function (subvalueDefinition) {
|
|
6036
|
+
return __spreadArray([subvalueDefinition.subvalueName], __read((subvalueDefinition.aliases || [])), false).includes(subformatName);
|
|
6037
|
+
});
|
|
6038
|
+
if (subvalueDefinition === undefined) {
|
|
6039
|
+
throw new ParseError(spaceTrim__default["default"](function (block) { return "\n Unsupported subformat name \"".concat(subformatName, "\" for format \"").concat(formatName, "\"\n\n Available subformat names for format \"").concat(formatDefinition.formatName, "\":\n ").concat(block(formatDefinition.subvalueDefinitions
|
|
6040
|
+
.map(function (subvalueDefinition) { return subvalueDefinition.subvalueName; })
|
|
6041
|
+
.map(function (subvalueName) { return "- ".concat(subvalueName); })
|
|
6042
|
+
.join('\n')), "\n "); }));
|
|
6043
|
+
// <- TODO: [🏢] List all supported subformat names for the format
|
|
5400
6044
|
}
|
|
5401
6045
|
if (assignSign !== '->') {
|
|
5402
|
-
|
|
5403
|
-
|
|
5404
|
-
|
|
5405
|
-
|
|
5406
|
-
|
|
5407
|
-
|
|
5408
|
-
|
|
5409
|
-
|
|
5410
|
-
|
|
5411
|
-
|
|
5412
|
-
|
|
5413
|
-
|
|
5414
|
-
|
|
5415
|
-
|
|
5416
|
-
|
|
5417
|
-
|
|
5418
|
-
|
|
5419
|
-
|
|
6046
|
+
throw new ParseError("FOREACH command must have '->' to assign the value to the parameter");
|
|
6047
|
+
}
|
|
6048
|
+
var parameterName = validateParameterName(parameterNameArg);
|
|
6049
|
+
var outputSubparameterName = null;
|
|
6050
|
+
// TODO: [4] DRY
|
|
6051
|
+
var inputSubparameterNames = args
|
|
6052
|
+
.slice(4)
|
|
6053
|
+
.map(function (parameterName) { return parameterName.split(',').join(' ').trim(); })
|
|
6054
|
+
.filter(function (parameterName) { return !parameterName.includes('+'); })
|
|
6055
|
+
.filter(function (parameterName) { return parameterName !== ''; })
|
|
6056
|
+
.map(validateParameterName);
|
|
6057
|
+
// TODO: [4] DRY
|
|
6058
|
+
var outputSubparameterNames = args
|
|
6059
|
+
.slice(4)
|
|
6060
|
+
.map(function (parameterName) { return parameterName.split(',').join(' ').trim(); })
|
|
6061
|
+
.filter(function (parameterName) { return parameterName.includes('+'); })
|
|
6062
|
+
.map(function (parameterName) { return parameterName.split('+').join(''); })
|
|
6063
|
+
.map(validateParameterName);
|
|
6064
|
+
if (outputSubparameterNames.length === 1) {
|
|
6065
|
+
outputSubparameterName = outputSubparameterNames[0];
|
|
6066
|
+
}
|
|
6067
|
+
else if (outputSubparameterNames.length > 1) {
|
|
6068
|
+
throw new ParseError("FOREACH command can not have more than one output subparameter");
|
|
6069
|
+
}
|
|
6070
|
+
if (inputSubparameterNames.length === 0) {
|
|
6071
|
+
throw new ParseError("FOREACH command must have at least one input subparameter");
|
|
6072
|
+
}
|
|
6073
|
+
if (outputSubparameterName === null) {
|
|
6074
|
+
// TODO: Following code should be unhardcoded from here and moved to the format definition
|
|
6075
|
+
if (formatName === 'CSV' && subformatName === 'CELL') {
|
|
6076
|
+
outputSubparameterName = 'newCell';
|
|
6077
|
+
}
|
|
6078
|
+
else if (formatName === 'TEXT' && subformatName === 'LINE') {
|
|
6079
|
+
outputSubparameterName = 'newLine';
|
|
6080
|
+
}
|
|
6081
|
+
else {
|
|
6082
|
+
throw new ParseError(spaceTrim__default["default"]("\n FOREACH ".concat(formatName, " ").concat(subformatName, " must specify output subparameter\n\n Correct example:\n - FOREACH ").concat(formatName, " ").concat(subformatName, " {").concat(parameterName, "} -> {inputSubparameterName1}, {inputSubparameterName2}, +{outputSubparameterName}\n\n ")));
|
|
6083
|
+
}
|
|
6084
|
+
}
|
|
5420
6085
|
return {
|
|
5421
6086
|
type: 'FOREACH',
|
|
5422
6087
|
formatName: formatName,
|
|
5423
|
-
|
|
6088
|
+
subformatName: subformatName,
|
|
5424
6089
|
parameterName: parameterName,
|
|
5425
|
-
|
|
6090
|
+
inputSubparameterNames: inputSubparameterNames,
|
|
6091
|
+
outputSubparameterName: outputSubparameterName,
|
|
5426
6092
|
};
|
|
5427
6093
|
},
|
|
5428
6094
|
/**
|
|
@@ -5431,11 +6097,17 @@
|
|
|
5431
6097
|
* Note: `$` is used to indicate that this function mutates given `templateJson`
|
|
5432
6098
|
*/
|
|
5433
6099
|
$applyToTemplateJson: function (command, $templateJson, $pipelineJson) {
|
|
5434
|
-
var formatName = command.formatName,
|
|
5435
|
-
// TODO:
|
|
5436
|
-
// TODO:
|
|
5437
|
-
$templateJson.foreach = {
|
|
5438
|
-
|
|
6100
|
+
var formatName = command.formatName, subformatName = command.subformatName, parameterName = command.parameterName, inputSubparameterNames = command.inputSubparameterNames, outputSubparameterName = command.outputSubparameterName;
|
|
6101
|
+
// TODO: [🍭] Detect double use
|
|
6102
|
+
// TODO: [🍭] Detect usage with JOKER and don't allow it
|
|
6103
|
+
$templateJson.foreach = {
|
|
6104
|
+
formatName: formatName,
|
|
6105
|
+
subformatName: subformatName,
|
|
6106
|
+
parameterName: parameterName,
|
|
6107
|
+
inputSubparameterNames: inputSubparameterNames,
|
|
6108
|
+
outputSubparameterName: outputSubparameterName,
|
|
6109
|
+
};
|
|
6110
|
+
keepUnused($pipelineJson); // <- TODO: [🧠] Maybe register subparameter from foreach into parameters of the pipeline
|
|
5439
6111
|
// Note: [🍭] FOREACH apply has some sideeffects on different places in codebase
|
|
5440
6112
|
},
|
|
5441
6113
|
/**
|
|
@@ -5458,8 +6130,7 @@
|
|
|
5458
6130
|
},
|
|
5459
6131
|
};
|
|
5460
6132
|
/**
|
|
5461
|
-
* TODO:
|
|
5462
|
-
* TODO: [🍭] !!!!!! Make .ptbk.md file with examples of the FOREACH command and also with wrong parsing and logic
|
|
6133
|
+
* TODO: [🍭] Make .ptbk.md file with examples of the FOREACH with wrong parsing and logic
|
|
5463
6134
|
*/
|
|
5464
6135
|
|
|
5465
6136
|
/**
|
|
@@ -5569,12 +6240,11 @@
|
|
|
5569
6240
|
*/
|
|
5570
6241
|
parse: function (input) {
|
|
5571
6242
|
var args = input.args;
|
|
5572
|
-
|
|
5573
|
-
|
|
5574
|
-
if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
|
|
5575
|
-
throw new ParseError("Invalid joker");
|
|
6243
|
+
if (args.length !== 1) {
|
|
6244
|
+
throw new ParseError("JOKE command expects exactly one parameter name");
|
|
5576
6245
|
}
|
|
5577
|
-
var
|
|
6246
|
+
var parameterNameArg = args[0] || '';
|
|
6247
|
+
var parameterName = validateParameterName(parameterNameArg);
|
|
5578
6248
|
return {
|
|
5579
6249
|
type: 'JOKER',
|
|
5580
6250
|
parameterName: parameterName,
|
|
@@ -5649,6 +6319,9 @@
|
|
|
5649
6319
|
*/
|
|
5650
6320
|
parse: function (input) {
|
|
5651
6321
|
var args = input.args, normalized = input.normalized;
|
|
6322
|
+
var availableVariantsMessage = spaceTrim__default["default"](function (block) { return "\n Available variants are:\n ".concat(block(MODEL_VARIANTS.map(function (variantName) {
|
|
6323
|
+
return "- ".concat(variantName).concat(variantName !== 'EMBEDDING' ? '' : ' (Not available in pipeline)');
|
|
6324
|
+
}).join('\n')), "\n "); });
|
|
5652
6325
|
// TODO: Make this more elegant and dynamically
|
|
5653
6326
|
if (normalized.startsWith('MODEL_VARIANT')) {
|
|
5654
6327
|
if (normalized === 'MODEL_VARIANT_CHAT') {
|
|
@@ -5664,17 +6337,13 @@
|
|
|
5664
6337
|
key: 'modelVariant',
|
|
5665
6338
|
value: 'COMPLETION',
|
|
5666
6339
|
};
|
|
6340
|
+
// <- Note: [🤖]
|
|
5667
6341
|
}
|
|
5668
6342
|
else if (normalized.startsWith('MODEL_VARIANT_EMBED')) {
|
|
5669
|
-
return
|
|
5670
|
-
type: 'MODEL',
|
|
5671
|
-
key: 'modelVariant',
|
|
5672
|
-
value: 'EMBEDDING',
|
|
5673
|
-
};
|
|
5674
|
-
// <- Note: [🤖]
|
|
6343
|
+
spaceTrim__default["default"](function (block) { return "\n Embedding model can not be used in pipeline\n\n ".concat(block(availableVariantsMessage), "\n "); });
|
|
5675
6344
|
}
|
|
5676
6345
|
else {
|
|
5677
|
-
throw new ParseError(spaceTrim__default["default"](function (block) { return "\n Unknown model variant in command:\n\n
|
|
6346
|
+
throw new ParseError(spaceTrim__default["default"](function (block) { return "\n Unknown model variant in command:\n\n ".concat(block(availableVariantsMessage), "\n "); }));
|
|
5678
6347
|
}
|
|
5679
6348
|
}
|
|
5680
6349
|
if (normalized.startsWith('MODEL_NAME')) {
|
|
@@ -5799,14 +6468,13 @@
|
|
|
5799
6468
|
* Parses the PARAMETER command
|
|
5800
6469
|
*/
|
|
5801
6470
|
parse: function (input) {
|
|
5802
|
-
var normalized = input.normalized, raw = input.raw;
|
|
5803
|
-
var
|
|
5804
|
-
|
|
5805
|
-
|
|
5806
|
-
|
|
5807
|
-
|
|
5808
|
-
|
|
5809
|
-
throw new ParseError("Parameter {".concat(parameterName, "} can not contain another parameter in description"));
|
|
6471
|
+
var normalized = input.normalized, args = input.args, raw = input.raw;
|
|
6472
|
+
var parameterNameRaw = args.shift() || '';
|
|
6473
|
+
var parameterDescriptionRaw = args.join(' ');
|
|
6474
|
+
// <- TODO: When [🥶] fixed, change to:
|
|
6475
|
+
// > const parameterDescriptionRaw = rawArgs.split(parameterNameRaw).join('').trim();
|
|
6476
|
+
if (parameterDescriptionRaw && parameterDescriptionRaw.match(/\{(?<embeddedParameterName>[a-z0-9_]+)\}/im)) {
|
|
6477
|
+
throw new ParseError(spaceTrim__default["default"](function (block) { return "\n Parameter {".concat(parameterNameRaw, "} can not contain another parameter in description\n\n The description:\n ").concat(block(parameterDescriptionRaw), "\n "); }));
|
|
5810
6478
|
}
|
|
5811
6479
|
var isInput = normalized.startsWith('INPUT');
|
|
5812
6480
|
var isOutput = normalized.startsWith('OUTPUT');
|
|
@@ -5814,11 +6482,12 @@
|
|
|
5814
6482
|
isInput = false;
|
|
5815
6483
|
isOutput = false;
|
|
5816
6484
|
}
|
|
5817
|
-
|
|
6485
|
+
var parameterName = validateParameterName(parameterNameRaw);
|
|
6486
|
+
var parameterDescription = parameterDescriptionRaw.trim() || null;
|
|
5818
6487
|
return {
|
|
5819
6488
|
type: 'PARAMETER',
|
|
5820
6489
|
parameterName: parameterName,
|
|
5821
|
-
parameterDescription: parameterDescription
|
|
6490
|
+
parameterDescription: parameterDescription,
|
|
5822
6491
|
isInput: isInput,
|
|
5823
6492
|
isOutput: isOutput,
|
|
5824
6493
|
};
|
|
@@ -6143,6 +6812,7 @@
|
|
|
6143
6812
|
* Note: `$` is used to indicate that this function mutates given `pipelineJson`
|
|
6144
6813
|
*/
|
|
6145
6814
|
$applyToPipelineJson: function (command, $pipelineJson) {
|
|
6815
|
+
// TODO: Warn if the version is overridden
|
|
6146
6816
|
$pipelineJson.promptbookVersion = command.promptbookVersion;
|
|
6147
6817
|
},
|
|
6148
6818
|
/**
|
|
@@ -6625,7 +7295,9 @@
|
|
|
6625
7295
|
for (var commandNameSegmentsCount = 0; commandNameSegmentsCount < Math.min(items.length, 3); commandNameSegmentsCount++) {
|
|
6626
7296
|
var commandNameRaw = items.slice(0, commandNameSegmentsCount + 1).join('_');
|
|
6627
7297
|
var args = items.slice(commandNameSegmentsCount + 1);
|
|
6628
|
-
var rawArgs = raw
|
|
7298
|
+
var rawArgs = raw
|
|
7299
|
+
.substring(commandNameRaw.length)
|
|
7300
|
+
.trim();
|
|
6629
7301
|
var command = parseCommandVariant({ usagePlace: usagePlace, raw: raw, rawArgs: rawArgs, normalized: normalized, args: args, commandNameRaw: commandNameRaw });
|
|
6630
7302
|
if (command !== null) {
|
|
6631
7303
|
return command;
|
|
@@ -6636,7 +7308,9 @@
|
|
|
6636
7308
|
{
|
|
6637
7309
|
var commandNameRaw = items.slice(-1).join('_');
|
|
6638
7310
|
var args = items.slice(0, -1); // <- Note: This is probbably not correct
|
|
6639
|
-
var rawArgs = raw
|
|
7311
|
+
var rawArgs = raw
|
|
7312
|
+
.substring(0, raw.length - commandNameRaw.length)
|
|
7313
|
+
.trim();
|
|
6640
7314
|
var command = parseCommandVariant({ usagePlace: usagePlace, raw: raw, rawArgs: rawArgs, normalized: normalized, args: args, commandNameRaw: commandNameRaw });
|
|
6641
7315
|
if (command !== null) {
|
|
6642
7316
|
return command;
|
|
@@ -6776,7 +7450,7 @@
|
|
|
6776
7450
|
function extractOneBlockFromMarkdown(markdown) {
|
|
6777
7451
|
var codeBlocks = extractAllBlocksFromMarkdown(markdown);
|
|
6778
7452
|
if (codeBlocks.length !== 1) {
|
|
6779
|
-
throw new ParseError(spaceTrim__default["default"](function (block) { return "\n There should be exactly 1 code block, found ".concat(codeBlocks.length, " code blocks\n\n ").concat(block(codeBlocks.map(function (block, i) { return "Block ".concat(i + 1, ":\n").concat(block.content); }).join('\n\n\n')), "\n "); }));
|
|
7453
|
+
throw new ParseError(spaceTrim__default["default"](function (block) { return "\n There should be exactly 1 code block in template, found ".concat(codeBlocks.length, " code blocks\n\n ").concat(block(codeBlocks.map(function (block, i) { return "Block ".concat(i + 1, ":\n").concat(block.content); }).join('\n\n\n')), "\n "); }));
|
|
6780
7454
|
}
|
|
6781
7455
|
return codeBlocks[0];
|
|
6782
7456
|
}
|
|
@@ -6963,7 +7637,7 @@
|
|
|
6963
7637
|
var $pipelineJson = {
|
|
6964
7638
|
title: undefined /* <- Note: [🍙] Putting here placeholder to keep `title` on top at final JSON */,
|
|
6965
7639
|
pipelineUrl: undefined /* <- Note: Putting here placeholder to keep `pipelineUrl` on top at final JSON */,
|
|
6966
|
-
promptbookVersion:
|
|
7640
|
+
promptbookVersion: undefined /* <- Note: By default no explicit version */,
|
|
6967
7641
|
description: undefined /* <- Note: [🍙] Putting here placeholder to keep `description` on top at final JSON */,
|
|
6968
7642
|
parameters: [],
|
|
6969
7643
|
templates: [],
|
|
@@ -7254,7 +7928,7 @@
|
|
|
7254
7928
|
return $asDeeplyFrozenSerializableJson('pipelineJson', $pipelineJson);
|
|
7255
7929
|
}
|
|
7256
7930
|
/**
|
|
7257
|
-
* TODO: !!!! Warn if used only sync version
|
|
7931
|
+
* TODO: [main] !!!! Warn if used only sync version
|
|
7258
7932
|
* TODO: [🚞] Report here line/column of error
|
|
7259
7933
|
* TODO: Use spaceTrim more effectively
|
|
7260
7934
|
* TODO: [🧠] Parameter flags - isInput, isOutput, isInternal
|
|
@@ -7759,7 +8433,7 @@
|
|
|
7759
8433
|
}
|
|
7760
8434
|
}
|
|
7761
8435
|
/**
|
|
7762
|
-
* TODO: [🧠] !!! In-memory cache of same values to prevent multiple checks
|
|
8436
|
+
* TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
|
|
7763
8437
|
* TODO: [🧠][💺] Can be done this on type-level?
|
|
7764
8438
|
*/
|
|
7765
8439
|
|
|
@@ -7816,21 +8490,41 @@
|
|
|
7816
8490
|
* @public exported from `@promptbook/core`
|
|
7817
8491
|
*/
|
|
7818
8492
|
function usageToHuman(usage) {
|
|
7819
|
-
var
|
|
8493
|
+
var reportItems = [];
|
|
7820
8494
|
var uncertainNumberToHuman = function (_a) {
|
|
7821
8495
|
var value = _a.value, isUncertain = _a.isUncertain;
|
|
7822
8496
|
return "".concat(isUncertain ? 'approximately ' : '').concat(Math.round(value * 100) / 100);
|
|
7823
8497
|
};
|
|
7824
|
-
|
|
7825
|
-
|
|
7826
|
-
|
|
8498
|
+
if (usage.price.value > 0.01
|
|
8499
|
+
// <- TODO: [🍓][🧞♂️][👩🏽🤝🧑🏻] Configure negligible value - default value to config + value to `UsageToHumanSettings`
|
|
8500
|
+
) {
|
|
8501
|
+
reportItems.push("Cost ".concat(uncertainNumberToHuman(usage.price), " USD"));
|
|
8502
|
+
}
|
|
8503
|
+
else {
|
|
8504
|
+
reportItems.push("Negligible cost");
|
|
8505
|
+
}
|
|
8506
|
+
var worktime = usageToWorktime(usage);
|
|
8507
|
+
if (worktime.value >
|
|
8508
|
+
1 / 60
|
|
8509
|
+
// <- TODO: [🍓][🧞♂️][👩🏽🤝🧑🏻]
|
|
8510
|
+
) {
|
|
8511
|
+
reportItems.push("Saved ".concat(uncertainNumberToHuman(usageToWorktime(usage)), " hours of human time"));
|
|
8512
|
+
// TODO: [🍓][🧞♂️] Show minutes, seconds, days NOT 0.1 hours
|
|
8513
|
+
}
|
|
8514
|
+
if (usage.output.charactersCount.value > 0) {
|
|
8515
|
+
reportItems.push("Written ".concat(uncertainNumberToHuman(usage.output.charactersCount), " characters"));
|
|
8516
|
+
}
|
|
8517
|
+
if (reportItems.length === 0) {
|
|
8518
|
+
// Note: For negligible usage, we report at least something
|
|
8519
|
+
reportItems.push('Negligible');
|
|
8520
|
+
}
|
|
8521
|
+
return spaceTrim__default["default"](function (block) { return "\n Usage:\n ".concat(block(reportItems.map(function (item) { return "- ".concat(item); }).join('\n')), "\n "); });
|
|
7827
8522
|
}
|
|
7828
8523
|
/**
|
|
7829
|
-
* TODO: Use "$1" not "1 USD"
|
|
7830
|
-
* TODO: Use markdown formatting like "Cost approximately **$1**"
|
|
7831
|
-
* TODO: Report in minutes, seconds, days NOT 0.1 hours
|
|
8524
|
+
* TODO: [🍓][🧞♂️] Use "$1" not "1 USD"
|
|
8525
|
+
* TODO: [🍓][🧞♂️] Use markdown formatting like "Cost approximately **$1**"
|
|
8526
|
+
* TODO: [🍓][🧞♂️] Report in minutes, seconds, days NOT 0.1 hours
|
|
7832
8527
|
* TODO: [🧠] Maybe make from `uncertainNumberToHuman` separate exported utility
|
|
7833
|
-
* TODO: When negligible usage, report "Negligible" or just don't report it
|
|
7834
8528
|
* TODO: [🧠] Maybe use "~" instead of "approximately"
|
|
7835
8529
|
* TODO: [🏛] Maybe make some markdown builder
|
|
7836
8530
|
*/
|
|
@@ -8600,7 +9294,7 @@
|
|
|
8600
9294
|
});
|
|
8601
9295
|
}
|
|
8602
9296
|
/**
|
|
8603
|
-
* TODO: [🥃] !!! Allow `ptbk make` without configuring any llm tools
|
|
9297
|
+
* TODO: [🥃][main] !!! Allow `ptbk make` without configuring any llm tools
|
|
8604
9298
|
* TODO: Maybe remove this command - "about" command should be enough?
|
|
8605
9299
|
* TODO: [0] DRY Javascript and typescript - Maybe make ONLY typescript and for javascript just remove types
|
|
8606
9300
|
* Note: [🟡] This code should never be published outside of `@promptbook/cli`
|
|
@@ -8634,70 +9328,6 @@
|
|
|
8634
9328
|
* TODO: [🏛] This can be part of markdown builder
|
|
8635
9329
|
*/
|
|
8636
9330
|
|
|
8637
|
-
/**
|
|
8638
|
-
* @@@
|
|
8639
|
-
*
|
|
8640
|
-
* @param text @@@
|
|
8641
|
-
* @param _isFirstLetterCapital @@@
|
|
8642
|
-
* @returns @@@
|
|
8643
|
-
* @example 'helloWorld'
|
|
8644
|
-
* @example 'iLovePromptbook'
|
|
8645
|
-
* @public exported from `@promptbook/utils`
|
|
8646
|
-
*/
|
|
8647
|
-
function normalizeTo_camelCase(text, _isFirstLetterCapital) {
|
|
8648
|
-
var e_1, _a;
|
|
8649
|
-
if (_isFirstLetterCapital === void 0) { _isFirstLetterCapital = false; }
|
|
8650
|
-
var charType;
|
|
8651
|
-
var lastCharType = null;
|
|
8652
|
-
var normalizedName = '';
|
|
8653
|
-
try {
|
|
8654
|
-
for (var text_1 = __values(text), text_1_1 = text_1.next(); !text_1_1.done; text_1_1 = text_1.next()) {
|
|
8655
|
-
var char = text_1_1.value;
|
|
8656
|
-
var normalizedChar = void 0;
|
|
8657
|
-
if (/^[a-z]$/.test(char)) {
|
|
8658
|
-
charType = 'LOWERCASE';
|
|
8659
|
-
normalizedChar = char;
|
|
8660
|
-
}
|
|
8661
|
-
else if (/^[A-Z]$/.test(char)) {
|
|
8662
|
-
charType = 'UPPERCASE';
|
|
8663
|
-
normalizedChar = char.toLowerCase();
|
|
8664
|
-
}
|
|
8665
|
-
else if (/^[0-9]$/.test(char)) {
|
|
8666
|
-
charType = 'NUMBER';
|
|
8667
|
-
normalizedChar = char;
|
|
8668
|
-
}
|
|
8669
|
-
else {
|
|
8670
|
-
charType = 'OTHER';
|
|
8671
|
-
normalizedChar = '';
|
|
8672
|
-
}
|
|
8673
|
-
if (!lastCharType) {
|
|
8674
|
-
if (_isFirstLetterCapital) {
|
|
8675
|
-
normalizedChar = normalizedChar.toUpperCase(); //TODO: DRY
|
|
8676
|
-
}
|
|
8677
|
-
}
|
|
8678
|
-
else if (charType !== lastCharType &&
|
|
8679
|
-
!(charType === 'LOWERCASE' && lastCharType === 'UPPERCASE') &&
|
|
8680
|
-
!(lastCharType === 'NUMBER') &&
|
|
8681
|
-
!(charType === 'NUMBER')) {
|
|
8682
|
-
normalizedChar = normalizedChar.toUpperCase(); //TODO: [🌺] DRY
|
|
8683
|
-
}
|
|
8684
|
-
normalizedName += normalizedChar;
|
|
8685
|
-
lastCharType = charType;
|
|
8686
|
-
}
|
|
8687
|
-
}
|
|
8688
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
8689
|
-
finally {
|
|
8690
|
-
try {
|
|
8691
|
-
if (text_1_1 && !text_1_1.done && (_a = text_1.return)) _a.call(text_1);
|
|
8692
|
-
}
|
|
8693
|
-
finally { if (e_1) throw e_1.error; }
|
|
8694
|
-
}
|
|
8695
|
-
return normalizedName;
|
|
8696
|
-
}
|
|
8697
|
-
/**
|
|
8698
|
-
* TODO: [🌺] Use some intermediate util splitWords
|
|
8699
|
-
*/
|
|
8700
|
-
|
|
8701
9331
|
/**
|
|
8702
9332
|
* Creates a Mermaid graph based on the promptbook
|
|
8703
9333
|
*
|
|
@@ -8754,9 +9384,9 @@
|
|
|
8754
9384
|
return promptbookMermaid;
|
|
8755
9385
|
}
|
|
8756
9386
|
/**
|
|
8757
|
-
* TODO:
|
|
8758
|
-
* TODO:
|
|
8759
|
-
* TODO:
|
|
9387
|
+
* TODO: !!!!! FOREACH in mermaid graph
|
|
9388
|
+
* TODO: !!!!! Knowledge in mermaid graph
|
|
9389
|
+
* TODO: !!!!! Personas in mermaid graph
|
|
8760
9390
|
* TODO: Maybe use some Mermaid package instead of string templating
|
|
8761
9391
|
* TODO: [🕌] When more than 2 functionalities, split into separate functions
|
|
8762
9392
|
*/
|
|
@@ -9082,7 +9712,7 @@
|
|
|
9082
9712
|
socket.on('connect', function () {
|
|
9083
9713
|
resolve(socket);
|
|
9084
9714
|
});
|
|
9085
|
-
// TODO: !!!! Better timeout handling
|
|
9715
|
+
// TODO: [main] !!!! Better timeout handling
|
|
9086
9716
|
setTimeout(function () {
|
|
9087
9717
|
reject(new Error("Timeout while connecting to ".concat(_this.options.remoteUrl)));
|
|
9088
9718
|
}, CONNECTION_TIMEOUT_MS);
|
|
@@ -9262,11 +9892,11 @@
|
|
|
9262
9892
|
output: computeUsage("$2.40 / 1M tokens"),
|
|
9263
9893
|
},
|
|
9264
9894
|
},
|
|
9265
|
-
// TODO: !!! Claude 1 and 2 has also completion versions - ask Hoagy
|
|
9895
|
+
// TODO: [main] !!! Claude 1 and 2 has also completion versions - ask Hoagy
|
|
9266
9896
|
]);
|
|
9267
9897
|
/**
|
|
9268
9898
|
* Note: [🤖] Add models of new variant
|
|
9269
|
-
* TODO: [🧠] !!! Add embedding models OR Anthropic has only chat+completion models?
|
|
9899
|
+
* TODO: [🧠][main] !!! Add embedding models OR Anthropic has only chat+completion models?
|
|
9270
9900
|
* TODO: [🧠] Some mechanism to propagate unsureness
|
|
9271
9901
|
* TODO: [🧠][👮♀️] Put here more info like description, isVision, trainingDateCutoff, languages, strengths ( Top-level performance, intelligence, fluency, and understanding), contextWindow,...
|
|
9272
9902
|
* TODO: [🎰] Some mechanism to auto-update available models
|
|
@@ -9475,7 +10105,7 @@
|
|
|
9475
10105
|
resultContent = contentBlock.text;
|
|
9476
10106
|
// eslint-disable-next-line prefer-const
|
|
9477
10107
|
complete = getCurrentIsoDate();
|
|
9478
|
-
usage = computeAnthropicClaudeUsage(
|
|
10108
|
+
usage = computeAnthropicClaudeUsage(rawPromptContent || '', resultContent || '', rawResponse);
|
|
9479
10109
|
return [2 /*return*/, $asDeeplyFrozenSerializableJson('AnthropicClaudeExecutionTools ChatPromptResult', {
|
|
9480
10110
|
content: resultContent,
|
|
9481
10111
|
modelName: rawResponse.model,
|
|
@@ -9622,8 +10252,8 @@
|
|
|
9622
10252
|
className: 'AnthropicClaudeExecutionTools',
|
|
9623
10253
|
});
|
|
9624
10254
|
/**
|
|
9625
|
-
* TODO: [🧠] !!!! Make anonymous this with all LLM providers
|
|
9626
|
-
* TODO: [🧠][🧱] !!!! Maybe change all `new AnthropicClaudeExecutionTools` -> `createAnthropicClaudeExecutionTools` in manual
|
|
10255
|
+
* TODO: [🧠][main] !!!! Make anonymous this with all LLM providers
|
|
10256
|
+
* TODO: [🧠][🧱][main] !!!! Maybe change all `new AnthropicClaudeExecutionTools` -> `createAnthropicClaudeExecutionTools` in manual
|
|
9627
10257
|
* TODO: [🧠] Maybe auto-detect usage in browser and determine default value of `isProxied`
|
|
9628
10258
|
* TODO: [🦺] Is there some way how to put `packageName` and `className` on top and function definition on bottom?
|
|
9629
10259
|
* TODO: [🎶] Naming "constructor" vs "creator" vs "factory"
|
|
@@ -10001,6 +10631,7 @@
|
|
|
10001
10631
|
prompt: computeUsage("$5.00 / 1M tokens"),
|
|
10002
10632
|
output: computeUsage("$15.00 / 1M tokens"),
|
|
10003
10633
|
},
|
|
10634
|
+
//TODO: [main] !!! Add gpt-4o-mini-2024-07-18 and all others to be up to date
|
|
10004
10635
|
},
|
|
10005
10636
|
/**/
|
|
10006
10637
|
/**/
|
|
@@ -10015,6 +10646,51 @@
|
|
|
10015
10646
|
},
|
|
10016
10647
|
/**/
|
|
10017
10648
|
/**/
|
|
10649
|
+
{
|
|
10650
|
+
modelVariant: 'CHAT',
|
|
10651
|
+
modelTitle: 'o1-preview',
|
|
10652
|
+
modelName: 'o1-preview',
|
|
10653
|
+
pricing: {
|
|
10654
|
+
prompt: computeUsage("$15.00 / 1M tokens"),
|
|
10655
|
+
output: computeUsage("$60.00 / 1M tokens"),
|
|
10656
|
+
},
|
|
10657
|
+
},
|
|
10658
|
+
/**/
|
|
10659
|
+
/**/
|
|
10660
|
+
{
|
|
10661
|
+
modelVariant: 'CHAT',
|
|
10662
|
+
modelTitle: 'o1-preview-2024-09-12',
|
|
10663
|
+
modelName: 'o1-preview-2024-09-12',
|
|
10664
|
+
// <- TODO: [main] !!! Some better system to organize theese date suffixes and versions
|
|
10665
|
+
pricing: {
|
|
10666
|
+
prompt: computeUsage("$15.00 / 1M tokens"),
|
|
10667
|
+
output: computeUsage("$60.00 / 1M tokens"),
|
|
10668
|
+
},
|
|
10669
|
+
},
|
|
10670
|
+
/**/
|
|
10671
|
+
/**/
|
|
10672
|
+
{
|
|
10673
|
+
modelVariant: 'CHAT',
|
|
10674
|
+
modelTitle: 'o1-mini',
|
|
10675
|
+
modelName: 'o1-mini',
|
|
10676
|
+
pricing: {
|
|
10677
|
+
prompt: computeUsage("$3.00 / 1M tokens"),
|
|
10678
|
+
output: computeUsage("$12.00 / 1M tokens"),
|
|
10679
|
+
},
|
|
10680
|
+
},
|
|
10681
|
+
/**/
|
|
10682
|
+
/**/
|
|
10683
|
+
{
|
|
10684
|
+
modelVariant: 'CHAT',
|
|
10685
|
+
modelTitle: 'o1-mini-2024-09-12',
|
|
10686
|
+
modelName: 'o1-mini-2024-09-12',
|
|
10687
|
+
pricing: {
|
|
10688
|
+
prompt: computeUsage("$3.00 / 1M tokens"),
|
|
10689
|
+
output: computeUsage("$12.00 / 1M tokens"),
|
|
10690
|
+
},
|
|
10691
|
+
},
|
|
10692
|
+
/**/
|
|
10693
|
+
/**/
|
|
10018
10694
|
{
|
|
10019
10695
|
modelVariant: 'CHAT',
|
|
10020
10696
|
modelTitle: 'gpt-3.5-turbo-16k-0613',
|
|
@@ -10103,7 +10779,7 @@
|
|
|
10103
10779
|
AzureOpenAiExecutionTools.prototype.listModels = function () {
|
|
10104
10780
|
return __awaiter(this, void 0, void 0, function () {
|
|
10105
10781
|
return __generator(this, function (_a) {
|
|
10106
|
-
// TODO: !!! Do here some filtering which models are really available as deployment
|
|
10782
|
+
// TODO: [main] !!! Do here some filtering which models are really available as deployment
|
|
10107
10783
|
// @see https://management.azure.com/subscriptions/subscriptionId/resourceGroups/resourceGroupName/providers/Microsoft.CognitiveServices/accounts/accountName/deployments?api-version=2023-05-01
|
|
10108
10784
|
return [2 /*return*/, OPENAI_MODELS.map(function (_a) {
|
|
10109
10785
|
var modelTitle = _a.modelTitle, modelName = _a.modelName, modelVariant = _a.modelVariant;
|
|
@@ -10589,7 +11265,7 @@
|
|
|
10589
11265
|
resultContent = rawResponse.choices[0].message.content;
|
|
10590
11266
|
// eslint-disable-next-line prefer-const
|
|
10591
11267
|
complete = getCurrentIsoDate();
|
|
10592
|
-
usage = computeOpenAiUsage(content, resultContent || '', rawResponse);
|
|
11268
|
+
usage = computeOpenAiUsage(content || '', resultContent || '', rawResponse);
|
|
10593
11269
|
if (resultContent === null) {
|
|
10594
11270
|
throw new PipelineExecutionError('No response message from OpenAI');
|
|
10595
11271
|
}
|
|
@@ -10661,7 +11337,7 @@
|
|
|
10661
11337
|
resultContent = rawResponse.choices[0].text;
|
|
10662
11338
|
// eslint-disable-next-line prefer-const
|
|
10663
11339
|
complete = getCurrentIsoDate();
|
|
10664
|
-
usage = computeOpenAiUsage(content, resultContent || '', rawResponse);
|
|
11340
|
+
usage = computeOpenAiUsage(content || '', resultContent || '', rawResponse);
|
|
10665
11341
|
return [2 /*return*/, $asDeeplyFrozenSerializableJson('OpenAiExecutionTools CompletionPromptResult', {
|
|
10666
11342
|
content: resultContent,
|
|
10667
11343
|
modelName: rawResponse.model || modelName,
|
|
@@ -10721,7 +11397,9 @@
|
|
|
10721
11397
|
resultContent = rawResponse.data[0].embedding;
|
|
10722
11398
|
// eslint-disable-next-line prefer-const
|
|
10723
11399
|
complete = getCurrentIsoDate();
|
|
10724
|
-
usage = computeOpenAiUsage(content, '',
|
|
11400
|
+
usage = computeOpenAiUsage(content || '', '',
|
|
11401
|
+
// <- Note: Embedding does not have result content
|
|
11402
|
+
rawResponse);
|
|
10725
11403
|
return [2 /*return*/, $asDeeplyFrozenSerializableJson('OpenAiExecutionTools EmbeddingPromptResult', {
|
|
10726
11404
|
content: resultContent,
|
|
10727
11405
|
modelName: rawResponse.model || modelName,
|
|
@@ -10792,7 +11470,7 @@
|
|
|
10792
11470
|
* @public exported from `@promptbook/openai`
|
|
10793
11471
|
*/
|
|
10794
11472
|
var createOpenAiExecutionTools = Object.assign(function (options) {
|
|
10795
|
-
// TODO: [🧠] !!!! If browser, auto add `dangerouslyAllowBrowser`
|
|
11473
|
+
// TODO: [🧠][main] !!!! If browser, auto add `dangerouslyAllowBrowser`
|
|
10796
11474
|
if (($isRunningInBrowser() || $isRunningInWebWorker()) && !options.dangerouslyAllowBrowser) {
|
|
10797
11475
|
options = __assign(__assign({}, options), { dangerouslyAllowBrowser: true });
|
|
10798
11476
|
}
|