@promptbook/node 0.60.0-3 → 0.60.0-5
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 +3 -5
- package/esm/index.es.js +505 -502
- package/esm/index.es.js.map +1 -1
- package/esm/typings/promptbook-collection/index.d.ts +1 -1
- package/esm/typings/src/_packages/core.index.d.ts +9 -9
- package/esm/typings/src/_packages/node.index.d.ts +1 -1
- package/esm/typings/src/_packages/types.index.d.ts +3 -3
- package/{umd/typings/src/library → esm/typings/src/collection}/PipelineCollection.d.ts +4 -4
- package/{umd/typings/src/library → esm/typings/src/collection}/SimplePipelineCollection.d.ts +5 -5
- package/{umd/typings/src/library/libraryToJson.d.ts → esm/typings/src/collection/collectionToJson.d.ts} +2 -2
- package/esm/typings/src/{library → collection}/constructors/createCollectionFromDirectory.d.ts +3 -3
- package/esm/typings/src/{library → collection}/constructors/createCollectionFromJson.d.ts +1 -1
- package/{umd/typings/src/library → esm/typings/src/collection}/constructors/createCollectionFromPromise.d.ts +1 -1
- package/esm/typings/src/{library → collection}/constructors/createCollectionFromUrl.d.ts +1 -1
- package/esm/typings/src/collection/constructors/createSubcollection.d.ts +12 -0
- package/esm/typings/src/config.d.ts +2 -2
- package/esm/typings/src/conversion/prettify/prettifyPipelineString.d.ts +1 -1
- package/esm/typings/src/conversion/prettify/renderPipelineMermaidOptions.d.ts +1 -1
- package/esm/typings/src/errors/CollectionError.d.ts +1 -1
- package/esm/typings/src/errors/ExecutionError.d.ts +1 -1
- package/esm/typings/src/errors/NotFoundError.d.ts +1 -1
- package/esm/typings/src/execution/EmbeddingVector.d.ts +1 -1
- package/esm/typings/src/execution/{PromptbookExecutor.d.ts → PipelineExecutor.d.ts} +3 -3
- package/esm/typings/src/execution/assertsExecutionSuccessful.d.ts +2 -2
- package/{umd/typings/src/execution/createPromptbookExecutor.d.ts → esm/typings/src/execution/createPipelineExecutor.d.ts} +13 -13
- package/esm/typings/src/execution/utils/replaceParameters.d.ts +1 -1
- package/esm/typings/src/llm-providers/mocked/joker.test.d.ts +1 -1
- package/esm/typings/src/llm-providers/mocked/mocked-chat.test.d.ts +1 -1
- package/esm/typings/src/llm-providers/mocked/mocked-completion.test.d.ts +1 -1
- package/esm/typings/src/llm-providers/remote/interfaces/RemoteServerOptions.d.ts +4 -4
- package/esm/typings/src/llm-providers/remote/startRemoteServer.d.ts +1 -1
- package/esm/typings/src/types/Command.d.ts +2 -2
- package/esm/typings/src/types/PipelineJson/PipelineJson.d.ts +6 -6
- package/esm/typings/src/types/PipelineJson/PromptTemplateJson.d.ts +1 -1
- package/esm/typings/src/types/PipelineString.d.ts +1 -1
- package/esm/typings/src/types/Prompt.d.ts +4 -4
- package/esm/typings/src/types/TaskProgress.d.ts +1 -1
- package/esm/typings/src/types/execution-report/ExecutionReportJson.d.ts +3 -3
- package/esm/typings/src/types/execution-report/config.d.ts +1 -1
- package/esm/typings/src/types/typeAliases.d.ts +2 -2
- package/esm/typings/src/utils/emojis.d.ts +1 -1
- package/package.json +2 -2
- package/umd/index.umd.js +471 -468
- package/umd/index.umd.js.map +1 -1
- package/umd/typings/promptbook-collection/index.d.ts +1 -1
- package/umd/typings/src/_packages/core.index.d.ts +9 -9
- package/umd/typings/src/_packages/node.index.d.ts +1 -1
- package/umd/typings/src/_packages/types.index.d.ts +3 -3
- package/{esm/typings/src/library → umd/typings/src/collection}/PipelineCollection.d.ts +4 -4
- package/{esm/typings/src/library → umd/typings/src/collection}/SimplePipelineCollection.d.ts +5 -5
- package/{esm/typings/src/library/libraryToJson.d.ts → umd/typings/src/collection/collectionToJson.d.ts} +2 -2
- package/umd/typings/src/{library → collection}/constructors/createCollectionFromDirectory.d.ts +3 -3
- package/umd/typings/src/{library → collection}/constructors/createCollectionFromJson.d.ts +1 -1
- package/{esm/typings/src/library → umd/typings/src/collection}/constructors/createCollectionFromPromise.d.ts +1 -1
- package/umd/typings/src/{library → collection}/constructors/createCollectionFromUrl.d.ts +1 -1
- package/umd/typings/src/collection/constructors/createSubcollection.d.ts +12 -0
- package/umd/typings/src/config.d.ts +2 -2
- package/umd/typings/src/conversion/prettify/prettifyPipelineString.d.ts +1 -1
- package/umd/typings/src/conversion/prettify/renderPipelineMermaidOptions.d.ts +1 -1
- package/umd/typings/src/errors/CollectionError.d.ts +1 -1
- package/umd/typings/src/errors/ExecutionError.d.ts +1 -1
- package/umd/typings/src/errors/NotFoundError.d.ts +1 -1
- package/umd/typings/src/execution/EmbeddingVector.d.ts +1 -1
- package/umd/typings/src/execution/{PromptbookExecutor.d.ts → PipelineExecutor.d.ts} +3 -3
- package/umd/typings/src/execution/assertsExecutionSuccessful.d.ts +2 -2
- package/{esm/typings/src/execution/createPromptbookExecutor.d.ts → umd/typings/src/execution/createPipelineExecutor.d.ts} +13 -13
- package/umd/typings/src/execution/utils/replaceParameters.d.ts +1 -1
- package/umd/typings/src/llm-providers/mocked/joker.test.d.ts +1 -1
- package/umd/typings/src/llm-providers/mocked/mocked-chat.test.d.ts +1 -1
- package/umd/typings/src/llm-providers/mocked/mocked-completion.test.d.ts +1 -1
- package/umd/typings/src/llm-providers/remote/interfaces/RemoteServerOptions.d.ts +4 -4
- package/umd/typings/src/llm-providers/remote/startRemoteServer.d.ts +1 -1
- package/umd/typings/src/types/Command.d.ts +2 -2
- package/umd/typings/src/types/PipelineJson/PipelineJson.d.ts +6 -6
- package/umd/typings/src/types/PipelineJson/PromptTemplateJson.d.ts +1 -1
- package/umd/typings/src/types/PipelineString.d.ts +1 -1
- package/umd/typings/src/types/Prompt.d.ts +4 -4
- package/umd/typings/src/types/TaskProgress.d.ts +1 -1
- package/umd/typings/src/types/execution-report/ExecutionReportJson.d.ts +3 -3
- package/umd/typings/src/types/execution-report/config.d.ts +1 -1
- package/umd/typings/src/types/typeAliases.d.ts +2 -2
- package/umd/typings/src/utils/emojis.d.ts +1 -1
- package/esm/typings/src/library/constructors/createSubcollection.d.ts +0 -12
- package/umd/typings/src/library/constructors/createSubcollection.d.ts +0 -12
- /package/esm/typings/src/{library/constructors/createCollectionFromDirectory.test.d.ts → collection/collectionToJson.test.d.ts} +0 -0
- /package/{umd/typings/src/library → esm/typings/src/collection}/constructors/createCollectionFromDirectory.test.d.ts +0 -0
- /package/esm/typings/src/{library → collection}/constructors/createCollectionFromJson.test.d.ts +0 -0
- /package/esm/typings/src/{library → collection}/constructors/createCollectionFromPromise.test.d.ts +0 -0
- /package/esm/typings/src/{library → collection}/constructors/justTestFsImport.d.ts +0 -0
- /package/{esm/typings/src/library/libraryToJson.test.d.ts → umd/typings/src/collection/collectionToJson.test.d.ts} +0 -0
- /package/umd/typings/src/{library/constructors/createCollectionFromJson.test.d.ts → collection/constructors/createCollectionFromDirectory.test.d.ts} +0 -0
- /package/umd/typings/src/{library/constructors/createCollectionFromPromise.test.d.ts → collection/constructors/createCollectionFromJson.test.d.ts} +0 -0
- /package/umd/typings/src/{library/libraryToJson.test.d.ts → collection/constructors/createCollectionFromPromise.test.d.ts} +0 -0
- /package/umd/typings/src/{library → collection}/constructors/justTestFsImport.d.ts +0 -0
package/esm/index.es.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import colors from 'colors';
|
|
2
2
|
import { access, constants, readFile, readdir } from 'fs/promises';
|
|
3
3
|
import { join } from 'path';
|
|
4
|
-
import spaceTrim
|
|
4
|
+
import spaceTrim, { spaceTrim as spaceTrim$1 } from 'spacetrim';
|
|
5
5
|
import { format } from 'prettier';
|
|
6
6
|
import parserHtml from 'prettier/parser-html';
|
|
7
7
|
|
|
@@ -129,49 +129,249 @@ function __spreadArray(to, from, pack) {
|
|
|
129
129
|
*/
|
|
130
130
|
var LOOP_LIMIT = 1000;
|
|
131
131
|
/**
|
|
132
|
-
* The name of the builded
|
|
132
|
+
* The name of the builded pipeline collection made by CLI `promptbook make` and for lookup in `createCollectionFromDirectory`
|
|
133
133
|
*/
|
|
134
|
-
var
|
|
134
|
+
var PIPELINE_COLLECTION_BASE_FILENAME = "index";
|
|
135
135
|
|
|
136
|
-
var PipelineCollection = [{title:"Prepare Keywords",
|
|
136
|
+
var PipelineCollection = [{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-keywords.ptbk.md",promptbookVersion:"0.60.0-4",parameters:[{name:"content",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],promptTemplates:[{name:"knowledge",title:"Knowledge",dependentParameterNames:["content"],executionType:"PROMPT_TEMPLATE",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},content:"You are experienced data researcher, detect the important keywords in the document.\n\n# Rules\n\n- Write just keywords separated by comma\n\n# The document\n\nTake information from this document:\n\n> {content}",resultingParameterName:"keywords"}],knowledge:[]},{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.60.0-4",parameters:[{name:"content",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledge",description:"The knowledge JSON object",isInput:false,isOutput:true}],promptTemplates:[{name:"knowledge",title:"Knowledge",dependentParameterNames:["content"],executionType:"PROMPT_TEMPLATE",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},content:"You are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {content}",resultingParameterName:"knowledge"}],knowledge:[]}];
|
|
137
137
|
|
|
138
138
|
/**
|
|
139
|
-
*
|
|
139
|
+
* Prettify the html code
|
|
140
|
+
*
|
|
141
|
+
* @param content raw html code
|
|
142
|
+
* @returns formatted html code
|
|
140
143
|
*/
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
144
|
+
function prettifyMarkdown(content) {
|
|
145
|
+
try {
|
|
146
|
+
return format(content, {
|
|
147
|
+
parser: 'markdown',
|
|
148
|
+
plugins: [parserHtml],
|
|
149
|
+
// TODO: DRY - make some import or auto-copy of .prettierrc
|
|
150
|
+
endOfLine: 'lf',
|
|
151
|
+
tabWidth: 4,
|
|
152
|
+
singleQuote: true,
|
|
153
|
+
trailingComma: 'all',
|
|
154
|
+
arrowParens: 'always',
|
|
155
|
+
printWidth: 120,
|
|
156
|
+
htmlWhitespaceSensitivity: 'ignore',
|
|
157
|
+
jsxBracketSameLine: false,
|
|
158
|
+
bracketSpacing: true,
|
|
159
|
+
});
|
|
148
160
|
}
|
|
149
|
-
|
|
150
|
-
|
|
161
|
+
catch (error) {
|
|
162
|
+
console.error('There was an error with prettifying the markdown, using the original as the fallback', {
|
|
163
|
+
error: error,
|
|
164
|
+
html: content,
|
|
165
|
+
});
|
|
166
|
+
return content;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
151
169
|
|
|
152
170
|
/**
|
|
153
|
-
*
|
|
171
|
+
* Makes first letter of a string uppercase
|
|
154
172
|
*
|
|
155
|
-
* @param executionResult - The partial result of the promptnook execution
|
|
156
|
-
* @throws {ExecutionError} If the execution is not successful or if multiple errors occurred
|
|
157
173
|
*/
|
|
158
|
-
function
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
174
|
+
function capitalize(word) {
|
|
175
|
+
return word.substring(0, 1).toUpperCase() + word.substring(1);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Converts promptbook in JSON format to string format
|
|
180
|
+
*
|
|
181
|
+
* @param pipelineJson Promptbook in JSON format (.ptbk.json)
|
|
182
|
+
* @returns Promptbook in string format (.ptbk.md)
|
|
183
|
+
*/
|
|
184
|
+
function pipelineJsonToString(pipelineJson) {
|
|
185
|
+
var e_1, _a, e_2, _b, e_3, _c, e_4, _d, e_5, _e, e_6, _f;
|
|
186
|
+
var title = pipelineJson.title, pipelineUrl = pipelineJson.pipelineUrl, promptbookVersion = pipelineJson.promptbookVersion, description = pipelineJson.description, parameters = pipelineJson.parameters, promptTemplates = pipelineJson.promptTemplates;
|
|
187
|
+
var pipelineString = "# ".concat(title);
|
|
188
|
+
if (description) {
|
|
189
|
+
pipelineString += '\n\n';
|
|
190
|
+
pipelineString += description;
|
|
162
191
|
}
|
|
163
|
-
|
|
164
|
-
|
|
192
|
+
// TODO:> const commands: Array<Command>
|
|
193
|
+
var commands = [];
|
|
194
|
+
if (pipelineUrl) {
|
|
195
|
+
commands.push("PIPELINE URL ".concat(pipelineUrl));
|
|
165
196
|
}
|
|
166
|
-
|
|
167
|
-
|
|
197
|
+
commands.push("PROMPTBOOK VERSION ".concat(promptbookVersion));
|
|
198
|
+
pipelineString = prettifyMarkdown(pipelineString);
|
|
199
|
+
try {
|
|
200
|
+
for (var _g = __values(parameters.filter(function (_a) {
|
|
201
|
+
var isInput = _a.isInput;
|
|
202
|
+
return isInput;
|
|
203
|
+
})), _h = _g.next(); !_h.done; _h = _g.next()) {
|
|
204
|
+
var parameter = _h.value;
|
|
205
|
+
commands.push("INPUT PARAMETER ".concat(promptTemplateParameterJsonToString(parameter)));
|
|
206
|
+
}
|
|
168
207
|
}
|
|
169
|
-
|
|
170
|
-
|
|
208
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
209
|
+
finally {
|
|
210
|
+
try {
|
|
211
|
+
if (_h && !_h.done && (_a = _g.return)) _a.call(_g);
|
|
212
|
+
}
|
|
213
|
+
finally { if (e_1) throw e_1.error; }
|
|
214
|
+
}
|
|
215
|
+
try {
|
|
216
|
+
for (var _j = __values(parameters.filter(function (_a) {
|
|
217
|
+
var isOutput = _a.isOutput;
|
|
218
|
+
return isOutput;
|
|
219
|
+
})), _k = _j.next(); !_k.done; _k = _j.next()) {
|
|
220
|
+
var parameter = _k.value;
|
|
221
|
+
commands.push("OUTPUT PARAMETER ".concat(promptTemplateParameterJsonToString(parameter)));
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
225
|
+
finally {
|
|
226
|
+
try {
|
|
227
|
+
if (_k && !_k.done && (_b = _j.return)) _b.call(_j);
|
|
228
|
+
}
|
|
229
|
+
finally { if (e_2) throw e_2.error; }
|
|
230
|
+
}
|
|
231
|
+
pipelineString += '\n\n';
|
|
232
|
+
pipelineString += commands.map(function (command) { return "- ".concat(command); }).join('\n');
|
|
233
|
+
try {
|
|
234
|
+
for (var promptTemplates_1 = __values(promptTemplates), promptTemplates_1_1 = promptTemplates_1.next(); !promptTemplates_1_1.done; promptTemplates_1_1 = promptTemplates_1.next()) {
|
|
235
|
+
var promptTemplate = promptTemplates_1_1.value;
|
|
236
|
+
var
|
|
237
|
+
/* Note: Not using:> name, */
|
|
238
|
+
title_1 = promptTemplate.title, description_1 = promptTemplate.description,
|
|
239
|
+
/* Note: dependentParameterNames, */
|
|
240
|
+
jokers = promptTemplate.jokers, executionType = promptTemplate.executionType, content = promptTemplate.content, postprocessing = promptTemplate.postprocessing, expectations = promptTemplate.expectations, expectFormat = promptTemplate.expectFormat, resultingParameterName = promptTemplate.resultingParameterName;
|
|
241
|
+
pipelineString += '\n\n';
|
|
242
|
+
pipelineString += "## ".concat(title_1);
|
|
243
|
+
if (description_1) {
|
|
244
|
+
pipelineString += '\n\n';
|
|
245
|
+
pipelineString += description_1;
|
|
246
|
+
}
|
|
247
|
+
// TODO:> const commands: Array<Command>
|
|
248
|
+
var commands_1 = [];
|
|
249
|
+
var contentLanguage = 'text';
|
|
250
|
+
if (executionType === 'PROMPT_TEMPLATE') {
|
|
251
|
+
var modelRequirements = promptTemplate.modelRequirements;
|
|
252
|
+
var modelName = modelRequirements.modelName, modelVariant = modelRequirements.modelVariant;
|
|
253
|
+
commands_1.push("EXECUTE PROMPT TEMPLATE");
|
|
254
|
+
if (modelVariant) {
|
|
255
|
+
commands_1.push("MODEL VARIANT ".concat(capitalize(modelVariant)));
|
|
256
|
+
}
|
|
257
|
+
if (modelName) {
|
|
258
|
+
commands_1.push("MODEL NAME `".concat(modelName, "`"));
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
else if (executionType === 'SIMPLE_TEMPLATE') {
|
|
262
|
+
commands_1.push("SIMPLE TEMPLATE");
|
|
263
|
+
// Note: Nothing special here
|
|
264
|
+
}
|
|
265
|
+
else if (executionType === 'SCRIPT') {
|
|
266
|
+
commands_1.push("EXECUTE SCRIPT");
|
|
267
|
+
if (promptTemplate.contentLanguage) {
|
|
268
|
+
contentLanguage = promptTemplate.contentLanguage;
|
|
269
|
+
}
|
|
270
|
+
else {
|
|
271
|
+
contentLanguage = '';
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
else if (executionType === 'PROMPT_DIALOG') {
|
|
275
|
+
commands_1.push("PROMPT DIALOG");
|
|
276
|
+
// Note: Nothing special here
|
|
277
|
+
}
|
|
278
|
+
if (jokers) {
|
|
279
|
+
try {
|
|
280
|
+
for (var jokers_1 = (e_4 = void 0, __values(jokers)), jokers_1_1 = jokers_1.next(); !jokers_1_1.done; jokers_1_1 = jokers_1.next()) {
|
|
281
|
+
var joker = jokers_1_1.value;
|
|
282
|
+
commands_1.push("JOKER {".concat(joker, "}"));
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
286
|
+
finally {
|
|
287
|
+
try {
|
|
288
|
+
if (jokers_1_1 && !jokers_1_1.done && (_d = jokers_1.return)) _d.call(jokers_1);
|
|
289
|
+
}
|
|
290
|
+
finally { if (e_4) throw e_4.error; }
|
|
291
|
+
}
|
|
292
|
+
} /* not else */
|
|
293
|
+
if (postprocessing) {
|
|
294
|
+
try {
|
|
295
|
+
for (var postprocessing_1 = (e_5 = void 0, __values(postprocessing)), postprocessing_1_1 = postprocessing_1.next(); !postprocessing_1_1.done; postprocessing_1_1 = postprocessing_1.next()) {
|
|
296
|
+
var postprocessingFunctionName = postprocessing_1_1.value;
|
|
297
|
+
commands_1.push("POSTPROCESSING `".concat(postprocessingFunctionName, "`"));
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
301
|
+
finally {
|
|
302
|
+
try {
|
|
303
|
+
if (postprocessing_1_1 && !postprocessing_1_1.done && (_e = postprocessing_1.return)) _e.call(postprocessing_1);
|
|
304
|
+
}
|
|
305
|
+
finally { if (e_5) throw e_5.error; }
|
|
306
|
+
}
|
|
307
|
+
} /* not else */
|
|
308
|
+
if (expectations) {
|
|
309
|
+
try {
|
|
310
|
+
for (var _l = (e_6 = void 0, __values(Object.entries(expectations))), _m = _l.next(); !_m.done; _m = _l.next()) {
|
|
311
|
+
var _o = __read(_m.value, 2), unit = _o[0], _p = _o[1], min = _p.min, max = _p.max;
|
|
312
|
+
if (min === max) {
|
|
313
|
+
commands_1.push("EXPECT EXACTLY ".concat(min, " ").concat(capitalize(unit + (min > 1 ? 's' : ''))));
|
|
314
|
+
}
|
|
315
|
+
else {
|
|
316
|
+
if (min !== undefined) {
|
|
317
|
+
commands_1.push("EXPECT MIN ".concat(min, " ").concat(capitalize(unit + (min > 1 ? 's' : ''))));
|
|
318
|
+
} /* not else */
|
|
319
|
+
if (max !== undefined) {
|
|
320
|
+
commands_1.push("EXPECT MAX ".concat(max, " ").concat(capitalize(unit + (max > 1 ? 's' : ''))));
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
326
|
+
finally {
|
|
327
|
+
try {
|
|
328
|
+
if (_m && !_m.done && (_f = _l.return)) _f.call(_l);
|
|
329
|
+
}
|
|
330
|
+
finally { if (e_6) throw e_6.error; }
|
|
331
|
+
}
|
|
332
|
+
} /* not else */
|
|
333
|
+
if (expectFormat) {
|
|
334
|
+
if (expectFormat === 'JSON') {
|
|
335
|
+
// TODO: @deprecated remove
|
|
336
|
+
commands_1.push("EXPECT JSON");
|
|
337
|
+
}
|
|
338
|
+
} /* not else */
|
|
339
|
+
pipelineString += '\n\n';
|
|
340
|
+
pipelineString += commands_1.map(function (command) { return "- ".concat(command); }).join('\n');
|
|
341
|
+
pipelineString += '\n\n';
|
|
342
|
+
pipelineString += '```' + contentLanguage;
|
|
343
|
+
pipelineString += '\n';
|
|
344
|
+
pipelineString += spaceTrim(content);
|
|
345
|
+
// <- TODO: !!! Escape
|
|
346
|
+
// <- TODO: [🧠] Some clear strategy how to spaceTrim the blocks
|
|
347
|
+
pipelineString += '\n';
|
|
348
|
+
pipelineString += '```';
|
|
349
|
+
pipelineString += '\n\n';
|
|
350
|
+
pipelineString += "`-> {".concat(resultingParameterName, "}`"); // <- TODO: !!! If the parameter here has description, add it and use promptTemplateParameterJsonToString
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
354
|
+
finally {
|
|
355
|
+
try {
|
|
356
|
+
if (promptTemplates_1_1 && !promptTemplates_1_1.done && (_c = promptTemplates_1.return)) _c.call(promptTemplates_1);
|
|
357
|
+
}
|
|
358
|
+
finally { if (e_3) throw e_3.error; }
|
|
171
359
|
}
|
|
360
|
+
return pipelineString;
|
|
172
361
|
}
|
|
173
362
|
/**
|
|
174
|
-
*
|
|
363
|
+
* @private internal util of pipelineJsonToString
|
|
364
|
+
*/
|
|
365
|
+
function promptTemplateParameterJsonToString(promptTemplateParameterJson) {
|
|
366
|
+
var name = promptTemplateParameterJson.name, description = promptTemplateParameterJson.description;
|
|
367
|
+
var parameterString = "{".concat(name, "}");
|
|
368
|
+
if (description) {
|
|
369
|
+
parameterString = "".concat(parameterString, " ").concat(description);
|
|
370
|
+
}
|
|
371
|
+
return parameterString;
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* TODO: Escape all
|
|
175
375
|
*/
|
|
176
376
|
|
|
177
377
|
/**
|
|
@@ -208,7 +408,7 @@ var SyntaxError = /** @class */ (function (_super) {
|
|
|
208
408
|
var UnexpectedError = /** @class */ (function (_super) {
|
|
209
409
|
__extends(UnexpectedError, _super);
|
|
210
410
|
function UnexpectedError(message) {
|
|
211
|
-
var _this = _super.call(this, spaceTrim(function (block) { return "\n ".concat(block(message), "\n\n Note: This error should not happen.\n It's probbably a bug in the
|
|
411
|
+
var _this = _super.call(this, spaceTrim$1(function (block) { return "\n ".concat(block(message), "\n\n Note: This error should not happen.\n It's probbably a bug in the pipeline collection\n\n Please report issue:\n https://github.com/webgptorg/promptbook/issues\n\n Or contact us on me@pavolhejny.com\n\n "); })) || this;
|
|
212
412
|
_this.name = 'UnexpectedError';
|
|
213
413
|
Object.setPrototypeOf(_this, UnexpectedError.prototype);
|
|
214
414
|
return _this;
|
|
@@ -258,21 +458,21 @@ function isValidUrl(url) {
|
|
|
258
458
|
function validatePipeline(pipeline) {
|
|
259
459
|
// TODO: [🧠] Maybe test if promptbook is a promise and make specific error case for that
|
|
260
460
|
var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
|
|
261
|
-
if (pipeline.
|
|
262
|
-
if (!isValidUrl(pipeline.
|
|
461
|
+
if (pipeline.pipelineUrl !== undefined) {
|
|
462
|
+
if (!isValidUrl(pipeline.pipelineUrl)) {
|
|
263
463
|
// TODO: This should be maybe the syntax error detected during parsing
|
|
264
|
-
throw new PipelineLogicError("Invalid promptbook URL \"".concat(pipeline.
|
|
464
|
+
throw new PipelineLogicError("Invalid promptbook URL \"".concat(pipeline.pipelineUrl, "\""));
|
|
265
465
|
}
|
|
266
466
|
}
|
|
267
467
|
// TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
|
|
268
468
|
if (!Array.isArray(pipeline.parameters)) {
|
|
269
469
|
// TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
|
|
270
|
-
throw new SyntaxError(spaceTrim("\n Promptbook is valid JSON but with wrong structure\n\n promptbook.parameters expected to be an array, but got ".concat(typeof pipeline.parameters, "\n ")));
|
|
470
|
+
throw new SyntaxError(spaceTrim$1("\n Promptbook is valid JSON but with wrong structure\n\n promptbook.parameters expected to be an array, but got ".concat(typeof pipeline.parameters, "\n ")));
|
|
271
471
|
}
|
|
272
472
|
// TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
|
|
273
473
|
if (!Array.isArray(pipeline.promptTemplates)) {
|
|
274
474
|
// TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
|
|
275
|
-
throw new SyntaxError(spaceTrim("\n Promptbook is valid JSON but with wrong structure\n\n promptbook.promptTemplates expected to be an array, but got ".concat(typeof pipeline.promptTemplates, "\n ")));
|
|
475
|
+
throw new SyntaxError(spaceTrim$1("\n Promptbook is valid JSON but with wrong structure\n\n promptbook.promptTemplates expected to be an array, but got ".concat(typeof pipeline.promptTemplates, "\n ")));
|
|
276
476
|
}
|
|
277
477
|
var _loop_1 = function (parameter) {
|
|
278
478
|
if (parameter.isInput && parameter.isOutput) {
|
|
@@ -282,12 +482,12 @@ function validatePipeline(pipeline) {
|
|
|
282
482
|
if (!parameter.isInput &&
|
|
283
483
|
!parameter.isOutput &&
|
|
284
484
|
!pipeline.promptTemplates.some(function (template) { return template.dependentParameterNames.includes(parameter.name); })) {
|
|
285
|
-
throw new PipelineLogicError(spaceTrim("\n Parameter {".concat(parameter.name, "} is created but not used\n\n You can declare {").concat(parameter.name, "} as output parameter by adding in the header:\n - OUTPUT PARAMETER `{").concat(parameter.name, "}` ").concat(parameter.description || '', "\n\n ")));
|
|
485
|
+
throw new PipelineLogicError(spaceTrim$1("\n Parameter {".concat(parameter.name, "} is created but not used\n\n You can declare {").concat(parameter.name, "} as output parameter by adding in the header:\n - OUTPUT PARAMETER `{").concat(parameter.name, "}` ").concat(parameter.description || '', "\n\n ")));
|
|
286
486
|
}
|
|
287
487
|
// Note: Testing that parameter is either input or result of some template
|
|
288
488
|
if (!parameter.isInput &&
|
|
289
489
|
!pipeline.promptTemplates.some(function (template) { return template.resultingParameterName === parameter.name; })) {
|
|
290
|
-
throw new PipelineLogicError(spaceTrim("\n Parameter {".concat(parameter.name, "} is declared but not defined\n\n You can do one of these:\n - Remove declaration of {").concat(parameter.name, "}\n - Add prompt template that results in -> {").concat(parameter.name, "}\n\n ")));
|
|
490
|
+
throw new PipelineLogicError(spaceTrim$1("\n Parameter {".concat(parameter.name, "} is declared but not defined\n\n You can do one of these:\n - Remove declaration of {").concat(parameter.name, "}\n - Add prompt template that results in -> {").concat(parameter.name, "}\n\n ")));
|
|
291
491
|
}
|
|
292
492
|
};
|
|
293
493
|
try {
|
|
@@ -320,7 +520,7 @@ function validatePipeline(pipeline) {
|
|
|
320
520
|
}
|
|
321
521
|
definedParameters.add(template.resultingParameterName);
|
|
322
522
|
if (template.executionType === 'PROMPT_TEMPLATE' && template.modelRequirements.modelVariant === undefined) {
|
|
323
|
-
throw new PipelineLogicError(spaceTrim("\n\n You must specify MODEL VARIANT in the prompt template \"".concat(template.title, "\"\n\n For example:\n - MODEL VARIANT Chat\n - MODEL NAME `gpt-4-1106-preview`\n\n ")));
|
|
523
|
+
throw new PipelineLogicError(spaceTrim$1("\n\n You must specify MODEL VARIANT in the prompt template \"".concat(template.title, "\"\n\n For example:\n - MODEL VARIANT Chat\n - MODEL NAME `gpt-4-1106-preview`\n\n ")));
|
|
324
524
|
}
|
|
325
525
|
if (template.jokers && template.jokers.length > 0) {
|
|
326
526
|
if (!template.expectFormat &&
|
|
@@ -395,7 +595,7 @@ function validatePipeline(pipeline) {
|
|
|
395
595
|
return template.dependentParameterNames.every(function (name) { return resovedParameters.includes(name); });
|
|
396
596
|
});
|
|
397
597
|
if (currentlyResovedTemplates.length === 0) {
|
|
398
|
-
throw new PipelineLogicError(spaceTrim(function (block) { return "\n\n Can not resolve some parameters\n It may be circular dependencies\n\n Can not resolve:\n ".concat(block(unresovedTemplates
|
|
598
|
+
throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n\n Can not resolve some parameters\n It may be circular dependencies\n\n Can not resolve:\n ".concat(block(unresovedTemplates
|
|
399
599
|
.map(function (_a) {
|
|
400
600
|
var resultingParameterName = _a.resultingParameterName, dependentParameterNames = _a.dependentParameterNames;
|
|
401
601
|
return "- {".concat(resultingParameterName, "} depends on ").concat(dependentParameterNames
|
|
@@ -428,17 +628,181 @@ function validatePipeline(pipeline) {
|
|
|
428
628
|
*/
|
|
429
629
|
|
|
430
630
|
/**
|
|
431
|
-
* This error
|
|
432
|
-
*
|
|
433
|
-
* @private Always catched and rethrown as `ExecutionError`
|
|
434
|
-
* Note: This is a kindof subtype of ExecutionError
|
|
631
|
+
* This error indicates that promptbook not found in the collection
|
|
435
632
|
*/
|
|
436
|
-
var
|
|
437
|
-
__extends(
|
|
438
|
-
function
|
|
633
|
+
var NotFoundError = /** @class */ (function (_super) {
|
|
634
|
+
__extends(NotFoundError, _super);
|
|
635
|
+
function NotFoundError(message) {
|
|
439
636
|
var _this = _super.call(this, message) || this;
|
|
440
|
-
_this.name = '
|
|
441
|
-
Object.setPrototypeOf(_this,
|
|
637
|
+
_this.name = 'NotFoundError';
|
|
638
|
+
Object.setPrototypeOf(_this, NotFoundError.prototype);
|
|
639
|
+
return _this;
|
|
640
|
+
}
|
|
641
|
+
return NotFoundError;
|
|
642
|
+
}(Error));
|
|
643
|
+
|
|
644
|
+
/**
|
|
645
|
+
* This error indicates errors in referencing promptbooks between each other
|
|
646
|
+
*/
|
|
647
|
+
var ReferenceError$1 = /** @class */ (function (_super) {
|
|
648
|
+
__extends(ReferenceError, _super);
|
|
649
|
+
function ReferenceError(message) {
|
|
650
|
+
var _this = _super.call(this, message) || this;
|
|
651
|
+
_this.name = 'ReferenceError';
|
|
652
|
+
Object.setPrototypeOf(_this, ReferenceError.prototype);
|
|
653
|
+
return _this;
|
|
654
|
+
}
|
|
655
|
+
return ReferenceError;
|
|
656
|
+
}(Error));
|
|
657
|
+
|
|
658
|
+
/**
|
|
659
|
+
* Library of promptbooks that groups together promptbooks for an application.
|
|
660
|
+
* This implementation is a very thin wrapper around the Array / Map of promptbooks.
|
|
661
|
+
*
|
|
662
|
+
* @private use `createCollectionFromJson` instead
|
|
663
|
+
* @see https://github.com/webgptorg/promptbook#promptbook-collection
|
|
664
|
+
*/
|
|
665
|
+
var SimplePipelineCollection = /** @class */ (function () {
|
|
666
|
+
/**
|
|
667
|
+
* Constructs a pipeline collection from promptbooks
|
|
668
|
+
*
|
|
669
|
+
* @param promptbooks !!!
|
|
670
|
+
*
|
|
671
|
+
* @private Use instead `createCollectionFromJson`
|
|
672
|
+
* Note: During the construction logic of all promptbooks are validated
|
|
673
|
+
* Note: It is not recommended to use this constructor directly, use `createCollectionFromJson` *(or other variant)* instead
|
|
674
|
+
*/
|
|
675
|
+
function SimplePipelineCollection() {
|
|
676
|
+
var e_1, _a;
|
|
677
|
+
var promptbooks = [];
|
|
678
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
679
|
+
promptbooks[_i] = arguments[_i];
|
|
680
|
+
}
|
|
681
|
+
this.collection = new Map();
|
|
682
|
+
try {
|
|
683
|
+
for (var promptbooks_1 = __values(promptbooks), promptbooks_1_1 = promptbooks_1.next(); !promptbooks_1_1.done; promptbooks_1_1 = promptbooks_1.next()) {
|
|
684
|
+
var promptbook = promptbooks_1_1.value;
|
|
685
|
+
if (promptbook.pipelineUrl === undefined) {
|
|
686
|
+
throw new ReferenceError$1(spaceTrim$1("\n Promptbook with name \"".concat(promptbook.title, "\" does not have defined URL\n\n Note: Promptbooks without URLs are called anonymous promptbooks\n They can be used as standalone promptbooks, but they cannot be referenced by other promptbooks\n And also they cannot be used in the pipeline collection\n\n ")));
|
|
687
|
+
}
|
|
688
|
+
validatePipeline(promptbook);
|
|
689
|
+
// Note: [🦄]
|
|
690
|
+
if (this.collection.has(promptbook.pipelineUrl) &&
|
|
691
|
+
pipelineJsonToString(promptbook) !== pipelineJsonToString(this.collection.get(promptbook.pipelineUrl))) {
|
|
692
|
+
throw new ReferenceError$1(spaceTrim$1("\n Promptbook with URL \"".concat(promptbook.pipelineUrl, "\" is already in the collection\n\n Note: Promptbooks with the same URL are not allowed\n Note: Automatically check whether the promptbooks are the same BUT they are DIFFERENT\n\n ")));
|
|
693
|
+
}
|
|
694
|
+
this.collection.set(promptbook.pipelineUrl, promptbook);
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
698
|
+
finally {
|
|
699
|
+
try {
|
|
700
|
+
if (promptbooks_1_1 && !promptbooks_1_1.done && (_a = promptbooks_1.return)) _a.call(promptbooks_1);
|
|
701
|
+
}
|
|
702
|
+
finally { if (e_1) throw e_1.error; }
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
/**
|
|
706
|
+
* Gets all promptbooks in the collection
|
|
707
|
+
*/
|
|
708
|
+
SimplePipelineCollection.prototype.listPipelines = function () {
|
|
709
|
+
return Array.from(this.collection.keys());
|
|
710
|
+
};
|
|
711
|
+
/**
|
|
712
|
+
* Gets promptbook by its URL
|
|
713
|
+
*
|
|
714
|
+
* Note: This is not a direct fetching from the URL, but a lookup in the collection
|
|
715
|
+
*/
|
|
716
|
+
SimplePipelineCollection.prototype.getPipelineByUrl = function (url) {
|
|
717
|
+
var _this = this;
|
|
718
|
+
var promptbook = this.collection.get(url);
|
|
719
|
+
if (!promptbook) {
|
|
720
|
+
if (this.listPipelines().length === 0) {
|
|
721
|
+
throw new NotFoundError(spaceTrim$1("\n Promptbook with url \"".concat(url, "\" not found\n\n No promptbooks available\n ")));
|
|
722
|
+
}
|
|
723
|
+
throw new NotFoundError(spaceTrim$1(function (block) { return "\n Promptbook with url \"".concat(url, "\" not found\n\n Available promptbooks:\n ").concat(block(_this.listPipelines()
|
|
724
|
+
.map(function (pipelineUrl) { return "- ".concat(pipelineUrl); })
|
|
725
|
+
.join('\n')), "\n\n "); }));
|
|
726
|
+
}
|
|
727
|
+
return promptbook;
|
|
728
|
+
};
|
|
729
|
+
/**
|
|
730
|
+
* Checks whether given prompt was defined in any promptbook in the collection
|
|
731
|
+
*/
|
|
732
|
+
SimplePipelineCollection.prototype.isResponsibleForPrompt = function (prompt) {
|
|
733
|
+
return true;
|
|
734
|
+
};
|
|
735
|
+
return SimplePipelineCollection;
|
|
736
|
+
}());
|
|
737
|
+
|
|
738
|
+
/**
|
|
739
|
+
* Creates PipelineCollection from array of PipelineJson or PipelineString
|
|
740
|
+
*
|
|
741
|
+
* Note: Functions `collectionToJson` and `createCollectionFromJson` are complementary
|
|
742
|
+
* Note: During the construction syntax and logic of all sources are validated
|
|
743
|
+
*
|
|
744
|
+
* @param promptbookSources
|
|
745
|
+
* @returns PipelineCollection
|
|
746
|
+
*/
|
|
747
|
+
function createCollectionFromJson() {
|
|
748
|
+
var promptbooks = [];
|
|
749
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
750
|
+
promptbooks[_i] = arguments[_i];
|
|
751
|
+
}
|
|
752
|
+
return new (SimplePipelineCollection.bind.apply(SimplePipelineCollection, __spreadArray([void 0], __read(promptbooks), false)))();
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
/**
|
|
756
|
+
* This error indicates errors during the execution of the pipeline
|
|
757
|
+
*/
|
|
758
|
+
var ExecutionError = /** @class */ (function (_super) {
|
|
759
|
+
__extends(ExecutionError, _super);
|
|
760
|
+
function ExecutionError(message) {
|
|
761
|
+
var _this = _super.call(this, message) || this;
|
|
762
|
+
_this.name = 'ExecutionError';
|
|
763
|
+
Object.setPrototypeOf(_this, ExecutionError.prototype);
|
|
764
|
+
return _this;
|
|
765
|
+
}
|
|
766
|
+
return ExecutionError;
|
|
767
|
+
}(Error));
|
|
768
|
+
|
|
769
|
+
/**
|
|
770
|
+
* Asserts that the execution of a promptnook is successful
|
|
771
|
+
*
|
|
772
|
+
* @param executionResult - The partial result of the promptnook execution
|
|
773
|
+
* @throws {ExecutionError} If the execution is not successful or if multiple errors occurred
|
|
774
|
+
*/
|
|
775
|
+
function assertsExecutionSuccessful(executionResult) {
|
|
776
|
+
var isSuccessful = executionResult.isSuccessful, errors = executionResult.errors;
|
|
777
|
+
if (isSuccessful === true) {
|
|
778
|
+
return;
|
|
779
|
+
}
|
|
780
|
+
if (errors.length === 0) {
|
|
781
|
+
throw new ExecutionError("Promptnook Execution failed because of unknown reason");
|
|
782
|
+
}
|
|
783
|
+
else if (errors.length === 1) {
|
|
784
|
+
throw errors[0];
|
|
785
|
+
}
|
|
786
|
+
else {
|
|
787
|
+
throw new ExecutionError(spaceTrim$1(function (block) { return "\n Multiple errors occurred during promptnook execution\n\n ".concat(block(errors.map(function (error) { return '- ' + error.message; }).join('\n')), "\n "); }));
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
/**
|
|
791
|
+
* TODO: [🧠] Can this return type be better typed than void
|
|
792
|
+
*/
|
|
793
|
+
|
|
794
|
+
/**
|
|
795
|
+
* This error occurs when some expectation is not met in the execution of the pipeline
|
|
796
|
+
*
|
|
797
|
+
* @private Always catched and rethrown as `ExecutionError`
|
|
798
|
+
* Note: This is a kindof subtype of ExecutionError
|
|
799
|
+
*/
|
|
800
|
+
var ExpectError = /** @class */ (function (_super) {
|
|
801
|
+
__extends(ExpectError, _super);
|
|
802
|
+
function ExpectError(message) {
|
|
803
|
+
var _this = _super.call(this, message) || this;
|
|
804
|
+
_this.name = 'ExpectError';
|
|
805
|
+
Object.setPrototypeOf(_this, ExpectError.prototype);
|
|
442
806
|
return _this;
|
|
443
807
|
}
|
|
444
808
|
return ExpectError;
|
|
@@ -466,7 +830,7 @@ function isValidJsonString(value /* <-[👨⚖️] */) {
|
|
|
466
830
|
/**
|
|
467
831
|
* The version of the Promptbook library
|
|
468
832
|
*/
|
|
469
|
-
var PROMPTBOOK_VERSION = '0.60.0-
|
|
833
|
+
var PROMPTBOOK_VERSION = '0.60.0-4';
|
|
470
834
|
|
|
471
835
|
/**
|
|
472
836
|
* Function `addUsage` will add multiple usages into one
|
|
@@ -945,7 +1309,7 @@ var TemplateError = /** @class */ (function (_super) {
|
|
|
945
1309
|
* @returns the template with replaced parameters
|
|
946
1310
|
* @throws {TemplateError} if parameter is not defined, not closed, or not opened
|
|
947
1311
|
*
|
|
948
|
-
* @private within the
|
|
1312
|
+
* @private within the createPipelineExecutor
|
|
949
1313
|
*/
|
|
950
1314
|
function replaceParameters(template, parameters) {
|
|
951
1315
|
var replacedTemplate = template;
|
|
@@ -998,17 +1362,17 @@ function replaceParameters(template, parameters) {
|
|
|
998
1362
|
}
|
|
999
1363
|
|
|
1000
1364
|
/**
|
|
1001
|
-
* Creates executor function from
|
|
1365
|
+
* Creates executor function from pipeline and execution tools.
|
|
1002
1366
|
*
|
|
1003
1367
|
* @returns The executor function
|
|
1004
|
-
* @throws {PipelineLogicError} on logical error in the
|
|
1368
|
+
* @throws {PipelineLogicError} on logical error in the pipeline
|
|
1005
1369
|
*/
|
|
1006
|
-
function
|
|
1370
|
+
function createPipelineExecutor(options) {
|
|
1007
1371
|
var _this = this;
|
|
1008
|
-
var
|
|
1372
|
+
var pipeline = options.pipeline, tools = options.tools, _a = options.settings, settings = _a === void 0 ? {} : _a;
|
|
1009
1373
|
var _b = settings.maxExecutionAttempts, maxExecutionAttempts = _b === void 0 ? 3 : _b;
|
|
1010
|
-
validatePipeline(
|
|
1011
|
-
var
|
|
1374
|
+
validatePipeline(pipeline);
|
|
1375
|
+
var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
|
|
1012
1376
|
function executeSingleTemplate(currentTemplate) {
|
|
1013
1377
|
return __awaiter(this, void 0, void 0, function () {
|
|
1014
1378
|
var name, title, priority, prompt, chatThread, completionResult, result, resultString, expectError, scriptExecutionErrors, maxAttempts, jokers, attempt, isJokerAttempt, joker, _a, _b, _c, _d, scriptTools, error_2, e_2_1, _e, _f, functionName, postprocessingError, _g, _h, scriptTools, error_3, e_3_1, e_4_1, error_4;
|
|
@@ -1017,9 +1381,9 @@ function createPromptbookExecutor(options) {
|
|
|
1017
1381
|
return __generator(this, function (_o) {
|
|
1018
1382
|
switch (_o.label) {
|
|
1019
1383
|
case 0:
|
|
1020
|
-
name = "
|
|
1384
|
+
name = "pipeline-executor-frame-".concat(currentTemplate.name);
|
|
1021
1385
|
title = currentTemplate.title;
|
|
1022
|
-
priority =
|
|
1386
|
+
priority = pipeline.promptTemplates.length - pipeline.promptTemplates.indexOf(currentTemplate);
|
|
1023
1387
|
if (!onProgress /* <- [3] */) return [3 /*break*/, 2]; /* <- [3] */
|
|
1024
1388
|
return [4 /*yield*/, onProgress({
|
|
1025
1389
|
name: name,
|
|
@@ -1076,9 +1440,9 @@ function createPromptbookExecutor(options) {
|
|
|
1076
1440
|
case 6:
|
|
1077
1441
|
prompt = {
|
|
1078
1442
|
title: currentTemplate.title,
|
|
1079
|
-
|
|
1080
|
-
?
|
|
1081
|
-
: 'anonymous' /* <- TODO: [🧠] How to deal with anonymous
|
|
1443
|
+
pipelineUrl: "".concat(pipeline.pipelineUrl
|
|
1444
|
+
? pipeline.pipelineUrl
|
|
1445
|
+
: 'anonymous' /* <- TODO: [🧠] How to deal with anonymous pipelines, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(currentTemplate.name),
|
|
1082
1446
|
parameters: parametersToPass,
|
|
1083
1447
|
content: replaceParameters(currentTemplate.content, parametersToPass) /* <- [2] */,
|
|
1084
1448
|
modelRequirements: currentTemplate.modelRequirements,
|
|
@@ -1140,7 +1504,7 @@ function createPromptbookExecutor(options) {
|
|
|
1140
1504
|
throw errors[0];
|
|
1141
1505
|
}
|
|
1142
1506
|
else {
|
|
1143
|
-
throw new ExecutionError(spaceTrim(function (block) { return "\n Postprocessing in LlmExecutionTools failed ".concat(errors.length, "x\n\n ").concat(block(errors.map(function (error) { return '- ' + error.message; }).join('\n\n')), "\n "); }));
|
|
1507
|
+
throw new ExecutionError(spaceTrim$1(function (block) { return "\n Postprocessing in LlmExecutionTools failed ".concat(errors.length, "x\n\n ").concat(block(errors.map(function (error) { return '- ' + error.message; }).join('\n\n')), "\n "); }));
|
|
1144
1508
|
}
|
|
1145
1509
|
}
|
|
1146
1510
|
});
|
|
@@ -1224,7 +1588,7 @@ function createPromptbookExecutor(options) {
|
|
|
1224
1588
|
throw scriptExecutionErrors[0];
|
|
1225
1589
|
}
|
|
1226
1590
|
else {
|
|
1227
|
-
throw new ExecutionError(spaceTrim(function (block) { return "\n Script execution failed ".concat(scriptExecutionErrors.length, " times\n\n ").concat(block(scriptExecutionErrors
|
|
1591
|
+
throw new ExecutionError(spaceTrim$1(function (block) { return "\n Script execution failed ".concat(scriptExecutionErrors.length, " times\n\n ").concat(block(scriptExecutionErrors
|
|
1228
1592
|
.map(function (error) { return '- ' + error.message; })
|
|
1229
1593
|
.join('\n\n')), "\n "); }));
|
|
1230
1594
|
}
|
|
@@ -1355,7 +1719,7 @@ function createPromptbookExecutor(options) {
|
|
|
1355
1719
|
// TODO: [🧠] Maybe put other executionTypes into report
|
|
1356
1720
|
executionReport.promptExecutions.push({
|
|
1357
1721
|
prompt: {
|
|
1358
|
-
title: currentTemplate.title /* <- Note: If title in
|
|
1722
|
+
title: currentTemplate.title /* <- Note: If title in pipeline contains emojis, pass it innto report */,
|
|
1359
1723
|
content: prompt.content,
|
|
1360
1724
|
modelRequirements: prompt.modelRequirements,
|
|
1361
1725
|
expectations: prompt.expectations,
|
|
@@ -1369,7 +1733,7 @@ function createPromptbookExecutor(options) {
|
|
|
1369
1733
|
return [7 /*endfinally*/];
|
|
1370
1734
|
case 47:
|
|
1371
1735
|
if (expectError !== null && attempt === maxAttempts - 1) {
|
|
1372
|
-
throw new ExecutionError(spaceTrim(function (block) { return "\n LLM execution failed ".concat(maxExecutionAttempts, "x\n\n ---\n Last error ").concat((expectError === null || expectError === void 0 ? void 0 : expectError.name) || '', ":\n ").concat(block((expectError === null || expectError === void 0 ? void 0 : expectError.message) || ''), "\n\n Last result:\n ").concat(resultString, "\n ---\n "); }));
|
|
1736
|
+
throw new ExecutionError(spaceTrim$1(function (block) { return "\n LLM execution failed ".concat(maxExecutionAttempts, "x\n\n ---\n Last error ").concat((expectError === null || expectError === void 0 ? void 0 : expectError.name) || '', ":\n ").concat(block((expectError === null || expectError === void 0 ? void 0 : expectError.message) || ''), "\n\n Last result:\n ").concat(resultString, "\n ---\n "); }));
|
|
1373
1737
|
}
|
|
1374
1738
|
_o.label = 48;
|
|
1375
1739
|
case 48:
|
|
@@ -1391,7 +1755,7 @@ function createPromptbookExecutor(options) {
|
|
|
1391
1755
|
// <- [3]
|
|
1392
1756
|
});
|
|
1393
1757
|
}
|
|
1394
|
-
parametersToPass = __assign(__assign({}, parametersToPass), (_m = {}, _m[currentTemplate.resultingParameterName] = resultString /* <- Note: Not need to detect parameter collision here because
|
|
1758
|
+
parametersToPass = __assign(__assign({}, parametersToPass), (_m = {}, _m[currentTemplate.resultingParameterName] = resultString /* <- Note: Not need to detect parameter collision here because pipeline checks logic consistency during construction */, _m));
|
|
1395
1759
|
return [2 /*return*/];
|
|
1396
1760
|
}
|
|
1397
1761
|
});
|
|
@@ -1404,17 +1768,17 @@ function createPromptbookExecutor(options) {
|
|
|
1404
1768
|
case 0:
|
|
1405
1769
|
parametersToPass = inputParameters;
|
|
1406
1770
|
executionReport = {
|
|
1407
|
-
|
|
1408
|
-
title:
|
|
1771
|
+
pipelineUrl: pipeline.pipelineUrl,
|
|
1772
|
+
title: pipeline.title,
|
|
1409
1773
|
promptbookUsedVersion: PROMPTBOOK_VERSION,
|
|
1410
|
-
promptbookRequestedVersion:
|
|
1411
|
-
description:
|
|
1774
|
+
promptbookRequestedVersion: pipeline.promptbookVersion,
|
|
1775
|
+
description: pipeline.description,
|
|
1412
1776
|
promptExecutions: [],
|
|
1413
1777
|
};
|
|
1414
1778
|
_d.label = 1;
|
|
1415
1779
|
case 1:
|
|
1416
1780
|
_d.trys.push([1, 6, , 7]);
|
|
1417
|
-
resovedParameters_1 =
|
|
1781
|
+
resovedParameters_1 = pipeline.parameters
|
|
1418
1782
|
.filter(function (_a) {
|
|
1419
1783
|
var isInput = _a.isInput;
|
|
1420
1784
|
return isInput;
|
|
@@ -1423,7 +1787,7 @@ function createPromptbookExecutor(options) {
|
|
|
1423
1787
|
var name = _a.name;
|
|
1424
1788
|
return name;
|
|
1425
1789
|
});
|
|
1426
|
-
unresovedTemplates = __spreadArray([], __read(
|
|
1790
|
+
unresovedTemplates = __spreadArray([], __read(pipeline.promptTemplates), false);
|
|
1427
1791
|
resolving_1 = [];
|
|
1428
1792
|
loopLimit = LOOP_LIMIT;
|
|
1429
1793
|
_loop_1 = function () {
|
|
@@ -1432,13 +1796,13 @@ function createPromptbookExecutor(options) {
|
|
|
1432
1796
|
switch (_e.label) {
|
|
1433
1797
|
case 0:
|
|
1434
1798
|
if (loopLimit-- < 0) {
|
|
1435
|
-
throw new UnexpectedError('Loop limit reached during resolving parameters
|
|
1799
|
+
throw new UnexpectedError('Loop limit reached during resolving parameters pipeline execution');
|
|
1436
1800
|
}
|
|
1437
1801
|
currentTemplate = unresovedTemplates.find(function (template) {
|
|
1438
1802
|
return template.dependentParameterNames.every(function (name) { return resovedParameters_1.includes(name); });
|
|
1439
1803
|
});
|
|
1440
1804
|
if (!(!currentTemplate && resolving_1.length === 0)) return [3 /*break*/, 1];
|
|
1441
|
-
throw new UnexpectedError(spaceTrim("\n Can not resolve some parameters\n\n Note: This should be catched during validatePipeline\n "));
|
|
1805
|
+
throw new UnexpectedError(spaceTrim$1("\n Can not resolve some parameters\n\n Note: This should be catched during validatePipeline\n "));
|
|
1442
1806
|
case 1:
|
|
1443
1807
|
if (!!currentTemplate) return [3 /*break*/, 3];
|
|
1444
1808
|
/* [5] */ return [4 /*yield*/, Promise.race(resolving_1)];
|
|
@@ -1490,7 +1854,7 @@ function createPromptbookExecutor(options) {
|
|
|
1490
1854
|
case 7:
|
|
1491
1855
|
try {
|
|
1492
1856
|
// Note: Filter ONLY output parameters
|
|
1493
|
-
for (_a = __values(
|
|
1857
|
+
for (_a = __values(pipeline.parameters), _b = _a.next(); !_b.done; _b = _a.next()) {
|
|
1494
1858
|
parameter = _b.value;
|
|
1495
1859
|
if (parameter.isOutput) {
|
|
1496
1860
|
continue;
|
|
@@ -1519,379 +1883,15 @@ function createPromptbookExecutor(options) {
|
|
|
1519
1883
|
}
|
|
1520
1884
|
});
|
|
1521
1885
|
}); };
|
|
1522
|
-
return
|
|
1886
|
+
return pipelineExecutor;
|
|
1523
1887
|
}
|
|
1524
1888
|
/**
|
|
1525
1889
|
* TODO: [🧠] When not meet expectations in PROMPT_DIALOG, make some way to tell the user
|
|
1526
1890
|
* TODO: [👧] Strongly type the executors to avoid need of remove nullables whtn noUncheckedIndexedAccess in tsconfig.json
|
|
1527
|
-
* Note:
|
|
1891
|
+
* Note: CreatePipelineExecutorOptions are just connected to PipelineExecutor so do not extract to types folder
|
|
1528
1892
|
* TODO: [🧠][3] transparent = (report intermediate parameters) / opaque execution = (report only output parameters) progress reporting mode
|
|
1529
1893
|
*/
|
|
1530
1894
|
|
|
1531
|
-
/**
|
|
1532
|
-
* Prettify the html code
|
|
1533
|
-
*
|
|
1534
|
-
* @param content raw html code
|
|
1535
|
-
* @returns formatted html code
|
|
1536
|
-
*/
|
|
1537
|
-
function prettifyMarkdown(content) {
|
|
1538
|
-
try {
|
|
1539
|
-
return format(content, {
|
|
1540
|
-
parser: 'markdown',
|
|
1541
|
-
plugins: [parserHtml],
|
|
1542
|
-
// TODO: DRY - make some import or auto-copy of .prettierrc
|
|
1543
|
-
endOfLine: 'lf',
|
|
1544
|
-
tabWidth: 4,
|
|
1545
|
-
singleQuote: true,
|
|
1546
|
-
trailingComma: 'all',
|
|
1547
|
-
arrowParens: 'always',
|
|
1548
|
-
printWidth: 120,
|
|
1549
|
-
htmlWhitespaceSensitivity: 'ignore',
|
|
1550
|
-
jsxBracketSameLine: false,
|
|
1551
|
-
bracketSpacing: true,
|
|
1552
|
-
});
|
|
1553
|
-
}
|
|
1554
|
-
catch (error) {
|
|
1555
|
-
console.error('There was an error with prettifying the markdown, using the original as the fallback', {
|
|
1556
|
-
error: error,
|
|
1557
|
-
html: content,
|
|
1558
|
-
});
|
|
1559
|
-
return content;
|
|
1560
|
-
}
|
|
1561
|
-
}
|
|
1562
|
-
|
|
1563
|
-
/**
|
|
1564
|
-
* Makes first letter of a string uppercase
|
|
1565
|
-
*
|
|
1566
|
-
*/
|
|
1567
|
-
function capitalize(word) {
|
|
1568
|
-
return word.substring(0, 1).toUpperCase() + word.substring(1);
|
|
1569
|
-
}
|
|
1570
|
-
|
|
1571
|
-
/**
|
|
1572
|
-
* Converts promptbook in JSON format to string format
|
|
1573
|
-
*
|
|
1574
|
-
* @param pipelineJson Promptbook in JSON format (.ptbk.json)
|
|
1575
|
-
* @returns Promptbook in string format (.ptbk.md)
|
|
1576
|
-
*/
|
|
1577
|
-
function pipelineJsonToString(pipelineJson) {
|
|
1578
|
-
var e_1, _a, e_2, _b, e_3, _c, e_4, _d, e_5, _e, e_6, _f;
|
|
1579
|
-
var title = pipelineJson.title, promptbookUrl = pipelineJson.promptbookUrl, promptbookVersion = pipelineJson.promptbookVersion, description = pipelineJson.description, parameters = pipelineJson.parameters, promptTemplates = pipelineJson.promptTemplates;
|
|
1580
|
-
var pipelineString = "# ".concat(title);
|
|
1581
|
-
if (description) {
|
|
1582
|
-
pipelineString += '\n\n';
|
|
1583
|
-
pipelineString += description;
|
|
1584
|
-
}
|
|
1585
|
-
// TODO:> const commands: Array<Command>
|
|
1586
|
-
var commands = [];
|
|
1587
|
-
if (promptbookUrl) {
|
|
1588
|
-
commands.push("PROMPTBOOK URL ".concat(promptbookUrl));
|
|
1589
|
-
}
|
|
1590
|
-
commands.push("PROMPTBOOK VERSION ".concat(promptbookVersion));
|
|
1591
|
-
pipelineString = prettifyMarkdown(pipelineString);
|
|
1592
|
-
try {
|
|
1593
|
-
for (var _g = __values(parameters.filter(function (_a) {
|
|
1594
|
-
var isInput = _a.isInput;
|
|
1595
|
-
return isInput;
|
|
1596
|
-
})), _h = _g.next(); !_h.done; _h = _g.next()) {
|
|
1597
|
-
var parameter = _h.value;
|
|
1598
|
-
commands.push("INPUT PARAMETER ".concat(promptTemplateParameterJsonToString(parameter)));
|
|
1599
|
-
}
|
|
1600
|
-
}
|
|
1601
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1602
|
-
finally {
|
|
1603
|
-
try {
|
|
1604
|
-
if (_h && !_h.done && (_a = _g.return)) _a.call(_g);
|
|
1605
|
-
}
|
|
1606
|
-
finally { if (e_1) throw e_1.error; }
|
|
1607
|
-
}
|
|
1608
|
-
try {
|
|
1609
|
-
for (var _j = __values(parameters.filter(function (_a) {
|
|
1610
|
-
var isOutput = _a.isOutput;
|
|
1611
|
-
return isOutput;
|
|
1612
|
-
})), _k = _j.next(); !_k.done; _k = _j.next()) {
|
|
1613
|
-
var parameter = _k.value;
|
|
1614
|
-
commands.push("OUTPUT PARAMETER ".concat(promptTemplateParameterJsonToString(parameter)));
|
|
1615
|
-
}
|
|
1616
|
-
}
|
|
1617
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
1618
|
-
finally {
|
|
1619
|
-
try {
|
|
1620
|
-
if (_k && !_k.done && (_b = _j.return)) _b.call(_j);
|
|
1621
|
-
}
|
|
1622
|
-
finally { if (e_2) throw e_2.error; }
|
|
1623
|
-
}
|
|
1624
|
-
pipelineString += '\n\n';
|
|
1625
|
-
pipelineString += commands.map(function (command) { return "- ".concat(command); }).join('\n');
|
|
1626
|
-
try {
|
|
1627
|
-
for (var promptTemplates_1 = __values(promptTemplates), promptTemplates_1_1 = promptTemplates_1.next(); !promptTemplates_1_1.done; promptTemplates_1_1 = promptTemplates_1.next()) {
|
|
1628
|
-
var promptTemplate = promptTemplates_1_1.value;
|
|
1629
|
-
var
|
|
1630
|
-
/* Note: Not using:> name, */
|
|
1631
|
-
title_1 = promptTemplate.title, description_1 = promptTemplate.description,
|
|
1632
|
-
/* Note: dependentParameterNames, */
|
|
1633
|
-
jokers = promptTemplate.jokers, executionType = promptTemplate.executionType, content = promptTemplate.content, postprocessing = promptTemplate.postprocessing, expectations = promptTemplate.expectations, expectFormat = promptTemplate.expectFormat, resultingParameterName = promptTemplate.resultingParameterName;
|
|
1634
|
-
pipelineString += '\n\n';
|
|
1635
|
-
pipelineString += "## ".concat(title_1);
|
|
1636
|
-
if (description_1) {
|
|
1637
|
-
pipelineString += '\n\n';
|
|
1638
|
-
pipelineString += description_1;
|
|
1639
|
-
}
|
|
1640
|
-
// TODO:> const commands: Array<Command>
|
|
1641
|
-
var commands_1 = [];
|
|
1642
|
-
var contentLanguage = 'text';
|
|
1643
|
-
if (executionType === 'PROMPT_TEMPLATE') {
|
|
1644
|
-
var modelRequirements = promptTemplate.modelRequirements;
|
|
1645
|
-
var modelName = modelRequirements.modelName, modelVariant = modelRequirements.modelVariant;
|
|
1646
|
-
commands_1.push("EXECUTE PROMPT TEMPLATE");
|
|
1647
|
-
if (modelVariant) {
|
|
1648
|
-
commands_1.push("MODEL VARIANT ".concat(capitalize(modelVariant)));
|
|
1649
|
-
}
|
|
1650
|
-
if (modelName) {
|
|
1651
|
-
commands_1.push("MODEL NAME `".concat(modelName, "`"));
|
|
1652
|
-
}
|
|
1653
|
-
}
|
|
1654
|
-
else if (executionType === 'SIMPLE_TEMPLATE') {
|
|
1655
|
-
commands_1.push("SIMPLE TEMPLATE");
|
|
1656
|
-
// Note: Nothing special here
|
|
1657
|
-
}
|
|
1658
|
-
else if (executionType === 'SCRIPT') {
|
|
1659
|
-
commands_1.push("EXECUTE SCRIPT");
|
|
1660
|
-
if (promptTemplate.contentLanguage) {
|
|
1661
|
-
contentLanguage = promptTemplate.contentLanguage;
|
|
1662
|
-
}
|
|
1663
|
-
else {
|
|
1664
|
-
contentLanguage = '';
|
|
1665
|
-
}
|
|
1666
|
-
}
|
|
1667
|
-
else if (executionType === 'PROMPT_DIALOG') {
|
|
1668
|
-
commands_1.push("PROMPT DIALOG");
|
|
1669
|
-
// Note: Nothing special here
|
|
1670
|
-
}
|
|
1671
|
-
if (jokers) {
|
|
1672
|
-
try {
|
|
1673
|
-
for (var jokers_1 = (e_4 = void 0, __values(jokers)), jokers_1_1 = jokers_1.next(); !jokers_1_1.done; jokers_1_1 = jokers_1.next()) {
|
|
1674
|
-
var joker = jokers_1_1.value;
|
|
1675
|
-
commands_1.push("JOKER {".concat(joker, "}"));
|
|
1676
|
-
}
|
|
1677
|
-
}
|
|
1678
|
-
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
1679
|
-
finally {
|
|
1680
|
-
try {
|
|
1681
|
-
if (jokers_1_1 && !jokers_1_1.done && (_d = jokers_1.return)) _d.call(jokers_1);
|
|
1682
|
-
}
|
|
1683
|
-
finally { if (e_4) throw e_4.error; }
|
|
1684
|
-
}
|
|
1685
|
-
} /* not else */
|
|
1686
|
-
if (postprocessing) {
|
|
1687
|
-
try {
|
|
1688
|
-
for (var postprocessing_1 = (e_5 = void 0, __values(postprocessing)), postprocessing_1_1 = postprocessing_1.next(); !postprocessing_1_1.done; postprocessing_1_1 = postprocessing_1.next()) {
|
|
1689
|
-
var postprocessingFunctionName = postprocessing_1_1.value;
|
|
1690
|
-
commands_1.push("POSTPROCESSING `".concat(postprocessingFunctionName, "`"));
|
|
1691
|
-
}
|
|
1692
|
-
}
|
|
1693
|
-
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
1694
|
-
finally {
|
|
1695
|
-
try {
|
|
1696
|
-
if (postprocessing_1_1 && !postprocessing_1_1.done && (_e = postprocessing_1.return)) _e.call(postprocessing_1);
|
|
1697
|
-
}
|
|
1698
|
-
finally { if (e_5) throw e_5.error; }
|
|
1699
|
-
}
|
|
1700
|
-
} /* not else */
|
|
1701
|
-
if (expectations) {
|
|
1702
|
-
try {
|
|
1703
|
-
for (var _l = (e_6 = void 0, __values(Object.entries(expectations))), _m = _l.next(); !_m.done; _m = _l.next()) {
|
|
1704
|
-
var _o = __read(_m.value, 2), unit = _o[0], _p = _o[1], min = _p.min, max = _p.max;
|
|
1705
|
-
if (min === max) {
|
|
1706
|
-
commands_1.push("EXPECT EXACTLY ".concat(min, " ").concat(capitalize(unit + (min > 1 ? 's' : ''))));
|
|
1707
|
-
}
|
|
1708
|
-
else {
|
|
1709
|
-
if (min !== undefined) {
|
|
1710
|
-
commands_1.push("EXPECT MIN ".concat(min, " ").concat(capitalize(unit + (min > 1 ? 's' : ''))));
|
|
1711
|
-
} /* not else */
|
|
1712
|
-
if (max !== undefined) {
|
|
1713
|
-
commands_1.push("EXPECT MAX ".concat(max, " ").concat(capitalize(unit + (max > 1 ? 's' : ''))));
|
|
1714
|
-
}
|
|
1715
|
-
}
|
|
1716
|
-
}
|
|
1717
|
-
}
|
|
1718
|
-
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
1719
|
-
finally {
|
|
1720
|
-
try {
|
|
1721
|
-
if (_m && !_m.done && (_f = _l.return)) _f.call(_l);
|
|
1722
|
-
}
|
|
1723
|
-
finally { if (e_6) throw e_6.error; }
|
|
1724
|
-
}
|
|
1725
|
-
} /* not else */
|
|
1726
|
-
if (expectFormat) {
|
|
1727
|
-
if (expectFormat === 'JSON') {
|
|
1728
|
-
// TODO: @deprecated remove
|
|
1729
|
-
commands_1.push("EXPECT JSON");
|
|
1730
|
-
}
|
|
1731
|
-
} /* not else */
|
|
1732
|
-
pipelineString += '\n\n';
|
|
1733
|
-
pipelineString += commands_1.map(function (command) { return "- ".concat(command); }).join('\n');
|
|
1734
|
-
pipelineString += '\n\n';
|
|
1735
|
-
pipelineString += '```' + contentLanguage;
|
|
1736
|
-
pipelineString += '\n';
|
|
1737
|
-
pipelineString += spaceTrim$1(content);
|
|
1738
|
-
// <- TODO: !!! Escape
|
|
1739
|
-
// <- TODO: [🧠] Some clear strategy how to spaceTrim the blocks
|
|
1740
|
-
pipelineString += '\n';
|
|
1741
|
-
pipelineString += '```';
|
|
1742
|
-
pipelineString += '\n\n';
|
|
1743
|
-
pipelineString += "`-> {".concat(resultingParameterName, "}`"); // <- TODO: !!! If the parameter here has description, add it and use promptTemplateParameterJsonToString
|
|
1744
|
-
}
|
|
1745
|
-
}
|
|
1746
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
1747
|
-
finally {
|
|
1748
|
-
try {
|
|
1749
|
-
if (promptTemplates_1_1 && !promptTemplates_1_1.done && (_c = promptTemplates_1.return)) _c.call(promptTemplates_1);
|
|
1750
|
-
}
|
|
1751
|
-
finally { if (e_3) throw e_3.error; }
|
|
1752
|
-
}
|
|
1753
|
-
return pipelineString;
|
|
1754
|
-
}
|
|
1755
|
-
/**
|
|
1756
|
-
* @private internal util of pipelineJsonToString
|
|
1757
|
-
*/
|
|
1758
|
-
function promptTemplateParameterJsonToString(promptTemplateParameterJson) {
|
|
1759
|
-
var name = promptTemplateParameterJson.name, description = promptTemplateParameterJson.description;
|
|
1760
|
-
var parameterString = "{".concat(name, "}");
|
|
1761
|
-
if (description) {
|
|
1762
|
-
parameterString = "".concat(parameterString, " ").concat(description);
|
|
1763
|
-
}
|
|
1764
|
-
return parameterString;
|
|
1765
|
-
}
|
|
1766
|
-
/**
|
|
1767
|
-
* TODO: Escape all
|
|
1768
|
-
*/
|
|
1769
|
-
|
|
1770
|
-
/**
|
|
1771
|
-
* This error indicates that promptbook not found in the library
|
|
1772
|
-
*/
|
|
1773
|
-
var NotFoundError = /** @class */ (function (_super) {
|
|
1774
|
-
__extends(NotFoundError, _super);
|
|
1775
|
-
function NotFoundError(message) {
|
|
1776
|
-
var _this = _super.call(this, message) || this;
|
|
1777
|
-
_this.name = 'NotFoundError';
|
|
1778
|
-
Object.setPrototypeOf(_this, NotFoundError.prototype);
|
|
1779
|
-
return _this;
|
|
1780
|
-
}
|
|
1781
|
-
return NotFoundError;
|
|
1782
|
-
}(Error));
|
|
1783
|
-
|
|
1784
|
-
/**
|
|
1785
|
-
* This error indicates errors in referencing promptbooks between each other
|
|
1786
|
-
*/
|
|
1787
|
-
var ReferenceError$1 = /** @class */ (function (_super) {
|
|
1788
|
-
__extends(ReferenceError, _super);
|
|
1789
|
-
function ReferenceError(message) {
|
|
1790
|
-
var _this = _super.call(this, message) || this;
|
|
1791
|
-
_this.name = 'ReferenceError';
|
|
1792
|
-
Object.setPrototypeOf(_this, ReferenceError.prototype);
|
|
1793
|
-
return _this;
|
|
1794
|
-
}
|
|
1795
|
-
return ReferenceError;
|
|
1796
|
-
}(Error));
|
|
1797
|
-
|
|
1798
|
-
/**
|
|
1799
|
-
* Library of promptbooks that groups together promptbooks for an application.
|
|
1800
|
-
* This implementation is a very thin wrapper around the Array / Map of promptbooks.
|
|
1801
|
-
*
|
|
1802
|
-
* @private use `createCollectionFromJson` instead
|
|
1803
|
-
* @see https://github.com/webgptorg/promptbook#promptbook-collection
|
|
1804
|
-
*/
|
|
1805
|
-
var SimplePipelineCollection = /** @class */ (function () {
|
|
1806
|
-
/**
|
|
1807
|
-
* Constructs a promptbook library from promptbooks
|
|
1808
|
-
*
|
|
1809
|
-
* @param promptbooks !!!
|
|
1810
|
-
*
|
|
1811
|
-
* @private Use instead `createCollectionFromJson`
|
|
1812
|
-
* Note: During the construction logic of all promptbooks are validated
|
|
1813
|
-
* Note: It is not recommended to use this constructor directly, use `createCollectionFromJson` *(or other variant)* instead
|
|
1814
|
-
*/
|
|
1815
|
-
function SimplePipelineCollection() {
|
|
1816
|
-
var e_1, _a;
|
|
1817
|
-
var promptbooks = [];
|
|
1818
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1819
|
-
promptbooks[_i] = arguments[_i];
|
|
1820
|
-
}
|
|
1821
|
-
this.library = new Map();
|
|
1822
|
-
try {
|
|
1823
|
-
for (var promptbooks_1 = __values(promptbooks), promptbooks_1_1 = promptbooks_1.next(); !promptbooks_1_1.done; promptbooks_1_1 = promptbooks_1.next()) {
|
|
1824
|
-
var promptbook = promptbooks_1_1.value;
|
|
1825
|
-
if (promptbook.promptbookUrl === undefined) {
|
|
1826
|
-
throw new ReferenceError$1(spaceTrim("\n Promptbook with name \"".concat(promptbook.title, "\" does not have defined URL\n\n Note: Promptbooks without URLs are called anonymous promptbooks\n They can be used as standalone promptbooks, but they cannot be referenced by other promptbooks\n And also they cannot be used in the promptbook library\n\n ")));
|
|
1827
|
-
}
|
|
1828
|
-
validatePipeline(promptbook);
|
|
1829
|
-
// Note: [🦄]
|
|
1830
|
-
if (this.library.has(promptbook.promptbookUrl) &&
|
|
1831
|
-
pipelineJsonToString(promptbook) !== pipelineJsonToString(this.library.get(promptbook.promptbookUrl))) {
|
|
1832
|
-
throw new ReferenceError$1(spaceTrim("\n Promptbook with URL \"".concat(promptbook.promptbookUrl, "\" is already in the library\n\n Note: Promptbooks with the same URL are not allowed\n Note: Automatically check whether the promptbooks are the same BUT they are DIFFERENT\n\n ")));
|
|
1833
|
-
}
|
|
1834
|
-
this.library.set(promptbook.promptbookUrl, promptbook);
|
|
1835
|
-
}
|
|
1836
|
-
}
|
|
1837
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1838
|
-
finally {
|
|
1839
|
-
try {
|
|
1840
|
-
if (promptbooks_1_1 && !promptbooks_1_1.done && (_a = promptbooks_1.return)) _a.call(promptbooks_1);
|
|
1841
|
-
}
|
|
1842
|
-
finally { if (e_1) throw e_1.error; }
|
|
1843
|
-
}
|
|
1844
|
-
}
|
|
1845
|
-
/**
|
|
1846
|
-
* Gets all promptbooks in the library
|
|
1847
|
-
*/
|
|
1848
|
-
SimplePipelineCollection.prototype.listPipelines = function () {
|
|
1849
|
-
return Array.from(this.library.keys());
|
|
1850
|
-
};
|
|
1851
|
-
/**
|
|
1852
|
-
* Gets promptbook by its URL
|
|
1853
|
-
*
|
|
1854
|
-
* Note: This is not a direct fetching from the URL, but a lookup in the library
|
|
1855
|
-
*/
|
|
1856
|
-
SimplePipelineCollection.prototype.getPipelineByUrl = function (url) {
|
|
1857
|
-
var _this = this;
|
|
1858
|
-
var promptbook = this.library.get(url);
|
|
1859
|
-
if (!promptbook) {
|
|
1860
|
-
if (this.listPipelines().length === 0) {
|
|
1861
|
-
throw new NotFoundError(spaceTrim("\n Promptbook with url \"".concat(url, "\" not found\n\n No promptbooks available\n ")));
|
|
1862
|
-
}
|
|
1863
|
-
throw new NotFoundError(spaceTrim(function (block) { return "\n Promptbook with url \"".concat(url, "\" not found\n\n Available promptbooks:\n ").concat(block(_this.listPipelines()
|
|
1864
|
-
.map(function (promptbookUrl) { return "- ".concat(promptbookUrl); })
|
|
1865
|
-
.join('\n')), "\n\n "); }));
|
|
1866
|
-
}
|
|
1867
|
-
return promptbook;
|
|
1868
|
-
};
|
|
1869
|
-
/**
|
|
1870
|
-
* Checks whether given prompt was defined in any promptbook in the library
|
|
1871
|
-
*/
|
|
1872
|
-
SimplePipelineCollection.prototype.isResponsibleForPrompt = function (prompt) {
|
|
1873
|
-
return true;
|
|
1874
|
-
};
|
|
1875
|
-
return SimplePipelineCollection;
|
|
1876
|
-
}());
|
|
1877
|
-
|
|
1878
|
-
/**
|
|
1879
|
-
* Creates PipelineCollection from array of PipelineJson or PipelineString
|
|
1880
|
-
*
|
|
1881
|
-
* Note: Functions `libraryToJson` and `createCollectionFromJson` are complementary
|
|
1882
|
-
* Note: During the construction syntax and logic of all sources are validated
|
|
1883
|
-
*
|
|
1884
|
-
* @param promptbookSources
|
|
1885
|
-
* @returns PipelineCollection
|
|
1886
|
-
*/
|
|
1887
|
-
function createCollectionFromJson() {
|
|
1888
|
-
var promptbooks = [];
|
|
1889
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1890
|
-
promptbooks[_i] = arguments[_i];
|
|
1891
|
-
}
|
|
1892
|
-
return new (SimplePipelineCollection.bind.apply(SimplePipelineCollection, __spreadArray([void 0], __read(promptbooks), false)))();
|
|
1893
|
-
}
|
|
1894
|
-
|
|
1895
1895
|
/* tslint:disable */
|
|
1896
1896
|
function normalizeToKebabCase(sentence) {
|
|
1897
1897
|
var e_1, _a;
|
|
@@ -1949,18 +1949,18 @@ function normalizeToKebabCase(sentence) {
|
|
|
1949
1949
|
|
|
1950
1950
|
function prepareKnowledgeFromMarkdown(options) {
|
|
1951
1951
|
return __awaiter(this, void 0, void 0, function () {
|
|
1952
|
-
var content, llmTools, _a, isVerbose,
|
|
1952
|
+
var content, llmTools, _a, isVerbose, collection, prepareKnowledgeFromMarkdownPromptbook, prepareKnowledgeFromMarkdownExecutor, prepareKeywordsPromptbook, prepareKeywordsExecutor, result, outputParameters, knowledgeRaw, knowledgeTextPieces, knowledge;
|
|
1953
1953
|
var _this = this;
|
|
1954
1954
|
return __generator(this, function (_b) {
|
|
1955
1955
|
switch (_b.label) {
|
|
1956
1956
|
case 0:
|
|
1957
1957
|
content = options.content, llmTools = options.llmTools, _a = options.isVerbose, isVerbose = _a === void 0 ? false : _a;
|
|
1958
|
-
|
|
1959
|
-
return [4 /*yield*/,
|
|
1958
|
+
collection = createCollectionFromJson.apply(void 0, __spreadArray([], __read(PipelineCollection), false));
|
|
1959
|
+
return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md')];
|
|
1960
1960
|
case 1:
|
|
1961
1961
|
prepareKnowledgeFromMarkdownPromptbook = _b.sent();
|
|
1962
|
-
prepareKnowledgeFromMarkdownExecutor =
|
|
1963
|
-
|
|
1962
|
+
prepareKnowledgeFromMarkdownExecutor = createPipelineExecutor({
|
|
1963
|
+
pipeline: prepareKnowledgeFromMarkdownPromptbook,
|
|
1964
1964
|
tools: {
|
|
1965
1965
|
llm: llmTools,
|
|
1966
1966
|
script: [
|
|
@@ -1968,11 +1968,11 @@ function prepareKnowledgeFromMarkdown(options) {
|
|
|
1968
1968
|
],
|
|
1969
1969
|
},
|
|
1970
1970
|
});
|
|
1971
|
-
return [4 /*yield*/,
|
|
1971
|
+
return [4 /*yield*/, collection.getPipelineByUrl('https://promptbook.studio/promptbook/prepare-keywords.ptbk.md')];
|
|
1972
1972
|
case 2:
|
|
1973
1973
|
prepareKeywordsPromptbook = _b.sent();
|
|
1974
|
-
prepareKeywordsExecutor =
|
|
1975
|
-
|
|
1974
|
+
prepareKeywordsExecutor = createPipelineExecutor({
|
|
1975
|
+
pipeline: prepareKeywordsPromptbook,
|
|
1976
1976
|
tools: {
|
|
1977
1977
|
llm: llmTools,
|
|
1978
1978
|
script: [
|
|
@@ -1996,8 +1996,8 @@ function prepareKnowledgeFromMarkdown(options) {
|
|
|
1996
1996
|
switch (_b.label) {
|
|
1997
1997
|
case 0:
|
|
1998
1998
|
name = "piece-".concat(i);
|
|
1999
|
-
title = spaceTrim
|
|
2000
|
-
content = spaceTrim
|
|
1999
|
+
title = spaceTrim(knowledgeTextPiece.substring(0, 100));
|
|
2000
|
+
content = spaceTrim(knowledgeTextPiece);
|
|
2001
2001
|
keywords = [];
|
|
2002
2002
|
index = [];
|
|
2003
2003
|
sources = [];
|
|
@@ -2005,7 +2005,7 @@ function prepareKnowledgeFromMarkdown(options) {
|
|
|
2005
2005
|
case 1:
|
|
2006
2006
|
_b.trys.push([1, 3, , 4]);
|
|
2007
2007
|
// TODO: !!!! Summarize name and title from the content
|
|
2008
|
-
title = spaceTrim
|
|
2008
|
+
title = spaceTrim(knowledgeTextPiece.substring(0, 30));
|
|
2009
2009
|
name = normalizeToKebabCase(title);
|
|
2010
2010
|
return [4 /*yield*/, prepareKeywordsExecutor({ content: content })];
|
|
2011
2011
|
case 2:
|
|
@@ -2123,7 +2123,7 @@ function markdownToMarkdownStructure(markdown) {
|
|
|
2123
2123
|
}
|
|
2124
2124
|
if (parent_1.parent === null /* <- Note: We are in root */) {
|
|
2125
2125
|
// [🌻]
|
|
2126
|
-
throw new Error(spaceTrim("\n The file has an invalid structure.\n The markdown file must have exactly one top-level section.\n "));
|
|
2126
|
+
throw new Error(spaceTrim$1("\n The file has an invalid structure.\n The markdown file must have exactly one top-level section.\n "));
|
|
2127
2127
|
}
|
|
2128
2128
|
parent_1 = parent_1.parent;
|
|
2129
2129
|
}
|
|
@@ -2157,7 +2157,7 @@ function parsingMarkdownStructureToMarkdownStructure(parsingMarkdownStructure) {
|
|
|
2157
2157
|
return {
|
|
2158
2158
|
level: level,
|
|
2159
2159
|
title: title,
|
|
2160
|
-
content: spaceTrim(contentLines.join('\n')),
|
|
2160
|
+
content: spaceTrim$1(contentLines.join('\n')),
|
|
2161
2161
|
sections: sections.map(parsingMarkdownStructureToMarkdownStructure),
|
|
2162
2162
|
};
|
|
2163
2163
|
}
|
|
@@ -2289,7 +2289,7 @@ function extractOneBlockFromMarkdown(markdown) {
|
|
|
2289
2289
|
* @returns {string} The input string with all comments removed.
|
|
2290
2290
|
*/
|
|
2291
2291
|
function removeContentComments(content) {
|
|
2292
|
-
return spaceTrim(content.replace(/<!--(.*?)-->/gs, ''));
|
|
2292
|
+
return spaceTrim$1(content.replace(/<!--(.*?)-->/gs, ''));
|
|
2293
2293
|
}
|
|
2294
2294
|
|
|
2295
2295
|
/**
|
|
@@ -2398,7 +2398,7 @@ function extractVariables(script) {
|
|
|
2398
2398
|
if (!(error instanceof Error)) {
|
|
2399
2399
|
throw error;
|
|
2400
2400
|
}
|
|
2401
|
-
throw new SyntaxError(spaceTrim(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.name), ": ").concat(block(error.message), "\n "); }));
|
|
2401
|
+
throw new SyntaxError(spaceTrim$1(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.name), ": ").concat(block(error.message), "\n "); }));
|
|
2402
2402
|
}
|
|
2403
2403
|
return variables;
|
|
2404
2404
|
}
|
|
@@ -2649,33 +2649,36 @@ function parseCommand(listItem) {
|
|
|
2649
2649
|
.map(function (part) { return part.trim(); })
|
|
2650
2650
|
.filter(function (item) { return item !== ''; })
|
|
2651
2651
|
.filter(function (item) { return !/^PTBK$/i.test(item); })
|
|
2652
|
+
.filter(function (item) { return !/^PIPELINE$/i.test(item); })
|
|
2652
2653
|
.filter(function (item) { return !/^PROMPTBOOK$/i.test(item); })
|
|
2653
2654
|
.map(removeMarkdownFormatting);
|
|
2654
2655
|
if (type.startsWith('URL') ||
|
|
2655
2656
|
type.startsWith('PTBK_URL') ||
|
|
2656
2657
|
type.startsWith('PTBKURL') ||
|
|
2658
|
+
type.startsWith('PIPELINE_URL') ||
|
|
2659
|
+
type.startsWith('PIPELINEURL') ||
|
|
2657
2660
|
type.startsWith('PROMPTBOOK_URL') ||
|
|
2658
2661
|
type.startsWith('PROMPTBOOKURL') ||
|
|
2659
2662
|
type.startsWith('HTTPS')) {
|
|
2660
2663
|
if (!(listItemParts.length === 2 || (listItemParts.length === 1 && type.startsWith('HTTPS')))) {
|
|
2661
|
-
throw new SyntaxError(spaceTrim("\n Invalid
|
|
2664
|
+
throw new SyntaxError(spaceTrim$1("\n Invalid PIPELINE_URL command:\n\n - ".concat(listItem, "\n ")));
|
|
2662
2665
|
}
|
|
2663
|
-
var
|
|
2664
|
-
var
|
|
2665
|
-
if (
|
|
2666
|
-
throw new SyntaxError(spaceTrim("\n Invalid
|
|
2666
|
+
var pipelineUrlString = listItemParts.pop();
|
|
2667
|
+
var pipelineUrl = new URL(pipelineUrlString);
|
|
2668
|
+
if (pipelineUrl.protocol !== 'https:') {
|
|
2669
|
+
throw new SyntaxError(spaceTrim$1("\n Invalid PIPELINE_URL command:\n\n - ".concat(listItem, "\n\n Protocol must be HTTPS\n ")));
|
|
2667
2670
|
}
|
|
2668
|
-
if (
|
|
2669
|
-
throw new SyntaxError(spaceTrim("\n Invalid
|
|
2671
|
+
if (pipelineUrl.hash !== '') {
|
|
2672
|
+
throw new SyntaxError(spaceTrim$1("\n Invalid PIPELINE_URL command:\n\n - ".concat(listItem, "\n\n URL must not contain hash\n Hash is used for identification of the prompt template in the pipeline\n ")));
|
|
2670
2673
|
}
|
|
2671
2674
|
return {
|
|
2672
|
-
type: '
|
|
2673
|
-
|
|
2675
|
+
type: 'PIPELINE_URL',
|
|
2676
|
+
pipelineUrl: pipelineUrl,
|
|
2674
2677
|
};
|
|
2675
2678
|
}
|
|
2676
2679
|
else if (type.startsWith('PROMPTBOOK_VERSION') || type.startsWith('PTBK_VERSION')) {
|
|
2677
2680
|
if (listItemParts.length !== 2) {
|
|
2678
|
-
throw new SyntaxError(spaceTrim("\n Invalid PROMPTBOOK_VERSION command:\n\n - ".concat(listItem, "\n ")));
|
|
2681
|
+
throw new SyntaxError(spaceTrim$1("\n Invalid PROMPTBOOK_VERSION command:\n\n - ".concat(listItem, "\n ")));
|
|
2679
2682
|
}
|
|
2680
2683
|
var promptbookVersion = listItemParts.pop();
|
|
2681
2684
|
// TODO: Validate version
|
|
@@ -2690,7 +2693,7 @@ function parseCommand(listItem) {
|
|
|
2690
2693
|
type.startsWith('SIMPLE_TEMPLATE')) {
|
|
2691
2694
|
var executionTypes = ExecutionTypes.filter(function (executionType) { return type.includes(executionType); });
|
|
2692
2695
|
if (executionTypes.length !== 1) {
|
|
2693
|
-
throw new SyntaxError(spaceTrim(function (block) { return "\n Unknown execution type in command:\n\n - ".concat(listItem, "\n\n Supported execution types are:\n ").concat(block(ExecutionTypes.join(', ')), "\n "); }));
|
|
2696
|
+
throw new SyntaxError(spaceTrim$1(function (block) { return "\n Unknown execution type in command:\n\n - ".concat(listItem, "\n\n Supported execution types are:\n ").concat(block(ExecutionTypes.join(', ')), "\n "); }));
|
|
2694
2697
|
}
|
|
2695
2698
|
return {
|
|
2696
2699
|
type: 'EXECUTE',
|
|
@@ -2715,7 +2718,7 @@ function parseCommand(listItem) {
|
|
|
2715
2718
|
};
|
|
2716
2719
|
}
|
|
2717
2720
|
else {
|
|
2718
|
-
throw new SyntaxError(spaceTrim(function (block) { return "\n Unknown model variant in command:\n\n - ".concat(listItem, "\n\n Supported variants are:\n ").concat(block(['CHAT', 'COMPLETION'].join(', ')), "\n "); }));
|
|
2721
|
+
throw new SyntaxError(spaceTrim$1(function (block) { return "\n Unknown model variant in command:\n\n - ".concat(listItem, "\n\n Supported variants are:\n ").concat(block(['CHAT', 'COMPLETION'].join(', ')), "\n "); }));
|
|
2719
2722
|
}
|
|
2720
2723
|
}
|
|
2721
2724
|
if (type.startsWith('MODEL_NAME')) {
|
|
@@ -2726,7 +2729,7 @@ function parseCommand(listItem) {
|
|
|
2726
2729
|
};
|
|
2727
2730
|
}
|
|
2728
2731
|
else {
|
|
2729
|
-
throw new SyntaxError(spaceTrim(function (block) { return "\n Unknown model key in command:\n\n - ".concat(listItem, "\n\n Supported model keys are:\n ").concat(block(['variant', 'name'].join(', ')), "\n\n Example:\n\n - MODEL VARIANT Chat\n - MODEL NAME gpt-4\n "); }));
|
|
2732
|
+
throw new SyntaxError(spaceTrim$1(function (block) { return "\n Unknown model key in command:\n\n - ".concat(listItem, "\n\n Supported model keys are:\n ").concat(block(['variant', 'name'].join(', ')), "\n\n Example:\n\n - MODEL VARIANT Chat\n - MODEL NAME gpt-4\n "); }));
|
|
2730
2733
|
}
|
|
2731
2734
|
}
|
|
2732
2735
|
else if (type.startsWith('PARAM') ||
|
|
@@ -2736,12 +2739,12 @@ function parseCommand(listItem) {
|
|
|
2736
2739
|
listItem.startsWith('> {') /* <- Note: This is a bit hack to parse return parameters defined at the end of each section */) {
|
|
2737
2740
|
var parametersMatch = listItem.match(/\{(?<parameterName>[a-z0-9_]+)\}[^\S\r\n]*(?<parameterDescription>.*)$/im);
|
|
2738
2741
|
if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
|
|
2739
|
-
throw new SyntaxError(spaceTrim("\n Invalid parameter in command:\n\n - ".concat(listItem, "\n ")));
|
|
2742
|
+
throw new SyntaxError(spaceTrim$1("\n Invalid parameter in command:\n\n - ".concat(listItem, "\n ")));
|
|
2740
2743
|
}
|
|
2741
2744
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2742
2745
|
var _b = parametersMatch.groups, parameterName = _b.parameterName, parameterDescription = _b.parameterDescription;
|
|
2743
2746
|
if (parameterDescription && parameterDescription.match(/\{(?<parameterName>[a-z0-9_]+)\}/im)) {
|
|
2744
|
-
throw new SyntaxError(spaceTrim("\n Parameter {".concat(parameterName, "} can not contain another parameter in description:\n\n - ").concat(listItem, "\n ")));
|
|
2747
|
+
throw new SyntaxError(spaceTrim$1("\n Parameter {".concat(parameterName, "} can not contain another parameter in description:\n\n - ").concat(listItem, "\n ")));
|
|
2745
2748
|
}
|
|
2746
2749
|
var isInput = type.startsWith('INPUT');
|
|
2747
2750
|
var isOutput = type.startsWith('OUTPUT');
|
|
@@ -2759,11 +2762,11 @@ function parseCommand(listItem) {
|
|
|
2759
2762
|
}
|
|
2760
2763
|
else if (type.startsWith('JOKER')) {
|
|
2761
2764
|
if (listItemParts.length !== 2) {
|
|
2762
|
-
throw new SyntaxError(spaceTrim("\n Invalid JOKER command:\n\n - ".concat(listItem, "\n ")));
|
|
2765
|
+
throw new SyntaxError(spaceTrim$1("\n Invalid JOKER command:\n\n - ".concat(listItem, "\n ")));
|
|
2763
2766
|
}
|
|
2764
2767
|
var parametersMatch = (listItemParts.pop() || '').match(/^\{(?<parameterName>[a-z0-9_]+)\}$/im);
|
|
2765
2768
|
if (!parametersMatch || !parametersMatch.groups || !parametersMatch.groups.parameterName) {
|
|
2766
|
-
throw new SyntaxError(spaceTrim("\n Invalid parameter in command:\n\n - ".concat(listItem, "\n ")));
|
|
2769
|
+
throw new SyntaxError(spaceTrim$1("\n Invalid parameter in command:\n\n - ".concat(listItem, "\n ")));
|
|
2767
2770
|
}
|
|
2768
2771
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2769
2772
|
var parameterName = parametersMatch.groups.parameterName;
|
|
@@ -2774,7 +2777,7 @@ function parseCommand(listItem) {
|
|
|
2774
2777
|
}
|
|
2775
2778
|
else if (type.startsWith('POSTPROCESS') || type.startsWith('POST_PROCESS')) {
|
|
2776
2779
|
if (listItemParts.length !== 2) {
|
|
2777
|
-
throw new SyntaxError(spaceTrim("\n Invalid POSTPROCESSING command:\n\n - ".concat(listItem, "\n ")));
|
|
2780
|
+
throw new SyntaxError(spaceTrim$1("\n Invalid POSTPROCESSING command:\n\n - ".concat(listItem, "\n ")));
|
|
2778
2781
|
}
|
|
2779
2782
|
var functionName = listItemParts.pop();
|
|
2780
2783
|
return {
|
|
@@ -2854,7 +2857,7 @@ function parseCommand(listItem) {
|
|
|
2854
2857
|
if (!(error instanceof Error)) {
|
|
2855
2858
|
throw error;
|
|
2856
2859
|
}
|
|
2857
|
-
throw new SyntaxError(spaceTrim("\n Invalid EXPECT command; ".concat(error.message, ":\n\n - ").concat(listItem, "\n ")));
|
|
2860
|
+
throw new SyntaxError(spaceTrim$1("\n Invalid EXPECT command; ".concat(error.message, ":\n\n - ").concat(listItem, "\n ")));
|
|
2858
2861
|
}
|
|
2859
2862
|
/*
|
|
2860
2863
|
} else if (type.startsWith('__________________')) {
|
|
@@ -2862,7 +2865,7 @@ function parseCommand(listItem) {
|
|
|
2862
2865
|
*/
|
|
2863
2866
|
}
|
|
2864
2867
|
else {
|
|
2865
|
-
throw new SyntaxError(spaceTrim("\n Unknown command:\n\n - ".concat(listItem, "\n\n Supported commands are:\n -
|
|
2868
|
+
throw new SyntaxError(spaceTrim$1("\n Unknown command:\n\n - ".concat(listItem, "\n\n Supported commands are:\n - PIPELINE_URL <url>\n - PROMPTBOOK_VERSION <version>\n - EXECUTE PROMPT TEMPLATE\n - EXECUTE SIMPLE TEMPLATE\n - SIMPLE TEMPLATE\n - EXECUTE SCRIPT\n - EXECUTE PROMPT_DIALOG'\n - PROMPT_DIALOG'\n - MODEL NAME <name>\n - MODEL VARIANT <\"Chat\"|\"Completion\">\n - INPUT PARAM {<name>} <description>\n - OUTPUT PARAM {<name>} <description>\n - POSTPROCESS `{functionName}`\n - JOKER {<name>}\n - EXPECT JSON\n - EXPECT <\"Exactly\"|\"Min\"|\"Max\"> <number> <\"Chars\"|\"Words\"|\"Sentences\"|\"Paragraphs\"|\"Pages\">\n\n ")));
|
|
2866
2869
|
}
|
|
2867
2870
|
}
|
|
2868
2871
|
|
|
@@ -2911,7 +2914,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
2911
2914
|
var pipelineJson = {
|
|
2912
2915
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2913
2916
|
title: undefined /* <- Note: Putting here placeholder to keep `title` on top at final JSON */,
|
|
2914
|
-
|
|
2917
|
+
pipelineUrl: undefined /* <- Note: Putting here placeholder to keep `pipelineUrl` on top at final JSON */,
|
|
2915
2918
|
promptbookVersion: PROMPTBOOK_VERSION,
|
|
2916
2919
|
description: undefined /* <- Note: Putting here placeholder to keep `description` on top at final JSON */,
|
|
2917
2920
|
parameters: [],
|
|
@@ -2932,7 +2935,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
2932
2935
|
existingParameter.description &&
|
|
2933
2936
|
existingParameter.description !== parameterDescription &&
|
|
2934
2937
|
parameterDescription) {
|
|
2935
|
-
throw new SyntaxError(spaceTrim(function (block) { return "\n Parameter {".concat(parameterName, "} is defined multiple times with different description.\n\n First definition:\n ").concat(block(existingParameter.description || '[undefined]'), "\n\n Second definition:\n ").concat(block(parameterDescription || '[undefined]'), "\n "); }));
|
|
2938
|
+
throw new SyntaxError(spaceTrim$1(function (block) { return "\n Parameter {".concat(parameterName, "} is defined multiple times with different description.\n\n First definition:\n ").concat(block(existingParameter.description || '[undefined]'), "\n\n Second definition:\n ").concat(block(parameterDescription || '[undefined]'), "\n "); }));
|
|
2936
2939
|
}
|
|
2937
2940
|
if (existingParameter) {
|
|
2938
2941
|
if (parameterDescription) {
|
|
@@ -2953,7 +2956,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
2953
2956
|
var markdownStructure = markdownToMarkdownStructure(pipelineString);
|
|
2954
2957
|
var markdownStructureDeepness = countMarkdownStructureDeepness(markdownStructure);
|
|
2955
2958
|
if (markdownStructureDeepness !== 2) {
|
|
2956
|
-
throw new SyntaxError(spaceTrim("\n Invalid markdown structure.\n The markdown must have exactly 2 levels of headings (one top-level section and one section for each template).\n Now it has ".concat(markdownStructureDeepness, " levels of headings.\n ")));
|
|
2959
|
+
throw new SyntaxError(spaceTrim$1("\n Invalid markdown structure.\n The markdown must have exactly 2 levels of headings (one top-level section and one section for each template).\n Now it has ".concat(markdownStructureDeepness, " levels of headings.\n ")));
|
|
2957
2960
|
}
|
|
2958
2961
|
pipelineJson.title = markdownStructure.title;
|
|
2959
2962
|
// TODO: [1] DRY description
|
|
@@ -2962,7 +2965,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
2962
2965
|
description = description.split(/^```.*^```/gms).join('');
|
|
2963
2966
|
//Note: Remove lists and return statement
|
|
2964
2967
|
description = description.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
2965
|
-
description = spaceTrim(description);
|
|
2968
|
+
description = spaceTrim$1(description);
|
|
2966
2969
|
if (description === '') {
|
|
2967
2970
|
description = undefined;
|
|
2968
2971
|
}
|
|
@@ -2974,8 +2977,8 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
2974
2977
|
var listItem = listItems_1_1.value;
|
|
2975
2978
|
var command = parseCommand(listItem);
|
|
2976
2979
|
switch (command.type) {
|
|
2977
|
-
case '
|
|
2978
|
-
pipelineJson.
|
|
2980
|
+
case 'PIPELINE_URL':
|
|
2981
|
+
pipelineJson.pipelineUrl = command.pipelineUrl.href;
|
|
2979
2982
|
break;
|
|
2980
2983
|
case 'PROMPTBOOK_VERSION':
|
|
2981
2984
|
pipelineJson.promptbookVersion = command.promptbookVersion;
|
|
@@ -3077,13 +3080,13 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
3077
3080
|
throw new SyntaxError('You must specify the language of the script in the prompt template');
|
|
3078
3081
|
}
|
|
3079
3082
|
else if (!SUPPORTED_SCRIPT_LANGUAGES.includes(language)) {
|
|
3080
|
-
throw new SyntaxError(spaceTrim(function (block) { return "\n Script language ".concat(language, " is not supported.\n\n Supported languages are:\n ").concat(block(SUPPORTED_SCRIPT_LANGUAGES.join(', ')), "\n\n "); }));
|
|
3083
|
+
throw new SyntaxError(spaceTrim$1(function (block) { return "\n Script language ".concat(language, " is not supported.\n\n Supported languages are:\n ").concat(block(SUPPORTED_SCRIPT_LANGUAGES.join(', ')), "\n\n "); }));
|
|
3081
3084
|
}
|
|
3082
3085
|
}
|
|
3083
3086
|
var lastLine = section.content.split('\n').pop();
|
|
3084
3087
|
var match = /^->\s*\{(?<resultingParamName>[a-z0-9_]+)\}/im.exec(lastLine);
|
|
3085
3088
|
if (!match || match.groups === undefined || match.groups.resultingParamName === undefined) {
|
|
3086
|
-
throw new SyntaxError(spaceTrim(function (block) { return "\n Invalid template - each section must end with \"-> {...}\"\n\n Invalid section:\n ".concat(block(
|
|
3089
|
+
throw new SyntaxError(spaceTrim$1(function (block) { return "\n Invalid template - each section must end with \"-> {...}\"\n\n Invalid section:\n ".concat(block(
|
|
3087
3090
|
// TODO: Show code of invalid sections each time + DRY
|
|
3088
3091
|
section.content
|
|
3089
3092
|
.split('\n')
|
|
@@ -3097,7 +3100,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
3097
3100
|
description_1 = description_1.split(/^```.*^```/gms).join('');
|
|
3098
3101
|
//Note: Remove lists and return statement
|
|
3099
3102
|
description_1 = description_1.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
|
|
3100
|
-
description_1 = spaceTrim(description_1);
|
|
3103
|
+
description_1 = spaceTrim$1(description_1);
|
|
3101
3104
|
if (description_1 === '') {
|
|
3102
3105
|
description_1 = undefined;
|
|
3103
3106
|
}
|
|
@@ -3201,7 +3204,7 @@ function pipelineStringToJson(pipelineString, options) {
|
|
|
3201
3204
|
*/
|
|
3202
3205
|
|
|
3203
3206
|
/**
|
|
3204
|
-
* This error indicates that the
|
|
3207
|
+
* This error indicates that the pipeline collection cannot be propperly loaded
|
|
3205
3208
|
*/
|
|
3206
3209
|
var CollectionError = /** @class */ (function (_super) {
|
|
3207
3210
|
__extends(CollectionError, _super);
|
|
@@ -3237,7 +3240,7 @@ new Function("\n try {\n if (typeof WorkerGlobalScope !== 'undefined'
|
|
|
3237
3240
|
* `createCollectionFromUrl` or `createCollectionFromDirectory`
|
|
3238
3241
|
* Consider using those functions instead of this one
|
|
3239
3242
|
*
|
|
3240
|
-
* Note: The function does NOT return promise it returns the
|
|
3243
|
+
* Note: The function does NOT return promise it returns the collection directly which waits for the sources to be resolved
|
|
3241
3244
|
* when error occurs in given promise or factory function, it is thrown during `listPipelines` or `getPipelineByUrl` call
|
|
3242
3245
|
*
|
|
3243
3246
|
* Note: Consider using `createCollectionFromDirectory` or `createCollectionFromUrl`
|
|
@@ -3247,7 +3250,7 @@ new Function("\n try {\n if (typeof WorkerGlobalScope !== 'undefined'
|
|
|
3247
3250
|
* @deprecated Do not use, it will became internal tool for other constructor functions
|
|
3248
3251
|
*/
|
|
3249
3252
|
function createCollectionFromPromise(promptbookSourcesPromiseOrFactory) {
|
|
3250
|
-
var
|
|
3253
|
+
var collection;
|
|
3251
3254
|
function forSources() {
|
|
3252
3255
|
return __awaiter(this, void 0, void 0, function () {
|
|
3253
3256
|
var promptbookSources;
|
|
@@ -3261,7 +3264,7 @@ function createCollectionFromPromise(promptbookSourcesPromiseOrFactory) {
|
|
|
3261
3264
|
return [4 /*yield*/, promptbookSourcesPromiseOrFactory];
|
|
3262
3265
|
case 1:
|
|
3263
3266
|
promptbookSources = _a.sent();
|
|
3264
|
-
|
|
3267
|
+
collection = createCollectionFromJson.apply(void 0, __spreadArray([], __read(promptbookSources), false));
|
|
3265
3268
|
return [2 /*return*/];
|
|
3266
3269
|
}
|
|
3267
3270
|
});
|
|
@@ -3274,7 +3277,7 @@ function createCollectionFromPromise(promptbookSourcesPromiseOrFactory) {
|
|
|
3274
3277
|
case 0: return [4 /*yield*/, forSources()];
|
|
3275
3278
|
case 1:
|
|
3276
3279
|
_a.sent();
|
|
3277
|
-
return [2 /*return*/, /* not await */
|
|
3280
|
+
return [2 /*return*/, /* not await */ collection.listPipelines()];
|
|
3278
3281
|
}
|
|
3279
3282
|
});
|
|
3280
3283
|
});
|
|
@@ -3286,7 +3289,7 @@ function createCollectionFromPromise(promptbookSourcesPromiseOrFactory) {
|
|
|
3286
3289
|
case 0: return [4 /*yield*/, forSources()];
|
|
3287
3290
|
case 1:
|
|
3288
3291
|
_a.sent();
|
|
3289
|
-
return [2 /*return*/, /* not await */
|
|
3292
|
+
return [2 /*return*/, /* not await */ collection.getPipelineByUrl(url)];
|
|
3290
3293
|
}
|
|
3291
3294
|
});
|
|
3292
3295
|
});
|
|
@@ -3298,7 +3301,7 @@ function createCollectionFromPromise(promptbookSourcesPromiseOrFactory) {
|
|
|
3298
3301
|
case 0: return [4 /*yield*/, forSources()];
|
|
3299
3302
|
case 1:
|
|
3300
3303
|
_a.sent();
|
|
3301
|
-
return [2 /*return*/, /* not await */
|
|
3304
|
+
return [2 /*return*/, /* not await */ collection.isResponsibleForPrompt(prompt)];
|
|
3302
3305
|
}
|
|
3303
3306
|
});
|
|
3304
3307
|
});
|
|
@@ -3316,12 +3319,12 @@ function createCollectionFromPromise(promptbookSourcesPromiseOrFactory) {
|
|
|
3316
3319
|
* Note: Works only in Node.js environment because it reads the file system
|
|
3317
3320
|
*
|
|
3318
3321
|
* @param path - path to the directory with promptbooks
|
|
3319
|
-
* @param options - Misc options for the
|
|
3322
|
+
* @param options - Misc options for the collection
|
|
3320
3323
|
* @returns PipelineCollection
|
|
3321
3324
|
*/
|
|
3322
3325
|
function createCollectionFromDirectory(path, options) {
|
|
3323
3326
|
return __awaiter(this, void 0, void 0, function () {
|
|
3324
|
-
var makedLibraryFilePath, makedLibraryFileExists, _a, _b, isRecursive, _c, isVerbose, _d, isLazyLoaded, _e, isCrashOnError,
|
|
3327
|
+
var makedLibraryFilePath, makedLibraryFileExists, _a, _b, isRecursive, _c, isVerbose, _d, isLazyLoaded, _e, isCrashOnError, collection;
|
|
3325
3328
|
var _this = this;
|
|
3326
3329
|
return __generator(this, function (_f) {
|
|
3327
3330
|
switch (_f.label) {
|
|
@@ -3329,28 +3332,28 @@ function createCollectionFromDirectory(path, options) {
|
|
|
3329
3332
|
if (!isRunningInNode()) {
|
|
3330
3333
|
throw new Error('Function `createCollectionFromDirectory` can only be run in Node.js environment because it reads the file system.');
|
|
3331
3334
|
}
|
|
3332
|
-
makedLibraryFilePath = join(path, "".concat(
|
|
3335
|
+
makedLibraryFilePath = join(path, "".concat(PIPELINE_COLLECTION_BASE_FILENAME, ".json"));
|
|
3333
3336
|
return [4 /*yield*/, access(makedLibraryFilePath, constants.R_OK)
|
|
3334
3337
|
.then(function () { return true; })
|
|
3335
3338
|
.catch(function () { return false; })];
|
|
3336
3339
|
case 1:
|
|
3337
3340
|
makedLibraryFileExists = _f.sent();
|
|
3338
3341
|
if (!makedLibraryFileExists) {
|
|
3339
|
-
console.info(colors.yellow("Tip: Prebuild your
|
|
3342
|
+
console.info(colors.yellow("Tip: Prebuild your pipeline collection (file with supposed prebuild ".concat(makedLibraryFilePath, " not found) with CLI util \"promptbook make\" to speed up the collection creation.")));
|
|
3340
3343
|
}
|
|
3341
3344
|
else {
|
|
3342
|
-
colors.green("(In future, not implemented yet) Using your prebuild
|
|
3345
|
+
colors.green("(In future, not implemented yet) Using your prebuild pipeline collection ".concat(makedLibraryFilePath));
|
|
3343
3346
|
// TODO: !! Implement;
|
|
3344
3347
|
}
|
|
3345
3348
|
_a = options || {}, _b = _a.isRecursive, isRecursive = _b === void 0 ? true : _b, _c = _a.isVerbose, isVerbose = _c === void 0 ? false : _c, _d = _a.isLazyLoaded, isLazyLoaded = _d === void 0 ? false : _d, _e = _a.isCrashOnError, isCrashOnError = _e === void 0 ? true : _e;
|
|
3346
|
-
|
|
3349
|
+
collection = createCollectionFromPromise(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
3347
3350
|
var fileNames, promptbooks, _loop_1, fileNames_1, fileNames_1_1, fileName, e_1_1;
|
|
3348
3351
|
var e_1, _a;
|
|
3349
3352
|
return __generator(this, function (_b) {
|
|
3350
3353
|
switch (_b.label) {
|
|
3351
3354
|
case 0:
|
|
3352
3355
|
if (isVerbose) {
|
|
3353
|
-
console.info("Creating
|
|
3356
|
+
console.info("Creating pipeline collection from path ".concat(path.split('\\').join('/')));
|
|
3354
3357
|
}
|
|
3355
3358
|
return [4 /*yield*/, listAllFiles(path, isRecursive)];
|
|
3356
3359
|
case 1:
|
|
@@ -3390,7 +3393,7 @@ function createCollectionFromDirectory(path, options) {
|
|
|
3390
3393
|
case 6:
|
|
3391
3394
|
// ---
|
|
3392
3395
|
if (promptbook !== null) {
|
|
3393
|
-
if (!promptbook.
|
|
3396
|
+
if (!promptbook.pipelineUrl) {
|
|
3394
3397
|
if (isVerbose) {
|
|
3395
3398
|
console.info("Not loading ".concat(fileName.split('\\').join('/'), " - missing URL"));
|
|
3396
3399
|
}
|
|
@@ -3414,7 +3417,7 @@ function createCollectionFromDirectory(path, options) {
|
|
|
3414
3417
|
if (!(error_1 instanceof Error)) {
|
|
3415
3418
|
throw error_1;
|
|
3416
3419
|
}
|
|
3417
|
-
wrappedErrorMessage = spaceTrim
|
|
3420
|
+
wrappedErrorMessage = spaceTrim(function (block) { return "\n Error during loading pipeline from file ".concat(fileName.split('\\').join('/'), ":\n\n ").concat(block(error_1.message), "\n\n "); });
|
|
3418
3421
|
if (isCrashOnError) {
|
|
3419
3422
|
throw new CollectionError(wrappedErrorMessage);
|
|
3420
3423
|
}
|
|
@@ -3455,11 +3458,11 @@ function createCollectionFromDirectory(path, options) {
|
|
|
3455
3458
|
});
|
|
3456
3459
|
}); });
|
|
3457
3460
|
if (!(isLazyLoaded === false)) return [3 /*break*/, 3];
|
|
3458
|
-
return [4 /*yield*/,
|
|
3461
|
+
return [4 /*yield*/, collection.listPipelines()];
|
|
3459
3462
|
case 2:
|
|
3460
3463
|
_f.sent();
|
|
3461
3464
|
_f.label = 3;
|
|
3462
|
-
case 3: return [2 /*return*/,
|
|
3465
|
+
case 3: return [2 /*return*/, collection];
|
|
3463
3466
|
}
|
|
3464
3467
|
});
|
|
3465
3468
|
});
|