@promptbook/core 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/index.es.js +64 -60
- package/esm/index.es.js.map +1 -1
- package/esm/typings/_packages/core.index.d.ts +2 -2
- package/esm/typings/_packages/types.index.d.ts +2 -2
- package/esm/typings/classes/PromptTemplatePipeline.d.ts +9 -9
- package/esm/typings/classes/PromptTemplatePipelineLibrary.d.ts +5 -4
- package/esm/typings/config.d.ts +1 -1
- package/esm/typings/conversion/_importPtp.d.ts +2 -2
- package/esm/typings/conversion/validatePromptTemplatePipelineJson.d.ts +1 -1
- package/esm/typings/execution/plugins/natural-execution-tools/remote/interfaces/RemoteServerOptions.d.ts +1 -1
- package/esm/typings/types/Command.d.ts +7 -7
- package/esm/typings/types/Prompt.d.ts +4 -4
- package/esm/typings/types/PromptTemplatePipelineJson/PromptTemplateJson.d.ts +1 -1
- package/esm/typings/types/PromptTemplatePipelineJson/PromptTemplatePipelineJson.d.ts +7 -7
- package/esm/typings/types/PromptTemplatePipelineString.d.ts +2 -2
- package/esm/typings/types/typeAliases.d.ts +4 -4
- package/package.json +1 -1
- package/umd/index.umd.js +65 -61
- package/umd/index.umd.js.map +1 -1
- package/umd/typings/_packages/core.index.d.ts +2 -2
- package/umd/typings/_packages/types.index.d.ts +2 -2
- package/umd/typings/classes/PromptTemplatePipeline.d.ts +9 -9
- package/umd/typings/classes/PromptTemplatePipelineLibrary.d.ts +5 -4
- package/umd/typings/config.d.ts +1 -1
- package/umd/typings/conversion/_importPtp.d.ts +2 -2
- package/umd/typings/conversion/validatePromptTemplatePipelineJson.d.ts +1 -1
- package/umd/typings/execution/plugins/natural-execution-tools/remote/interfaces/RemoteServerOptions.d.ts +1 -1
- package/umd/typings/types/Command.d.ts +7 -7
- package/umd/typings/types/Prompt.d.ts +4 -4
- package/umd/typings/types/PromptTemplatePipelineJson/PromptTemplateJson.d.ts +1 -1
- package/umd/typings/types/PromptTemplatePipelineJson/PromptTemplatePipelineJson.d.ts +7 -7
- package/umd/typings/types/PromptTemplatePipelineString.d.ts +2 -2
- package/umd/typings/types/typeAliases.d.ts +4 -4
|
@@ -8,14 +8,14 @@ import { PromptTemplatePipelineString } from '../types/PromptTemplatePipelineStr
|
|
|
8
8
|
* It represents a series of prompt templates chained together to form a pipeline / one big prompt template with input and result parameters.
|
|
9
9
|
*
|
|
10
10
|
* It can have 3 formats:
|
|
11
|
-
* - **.
|
|
12
|
-
* - **JSON** format, parsed from the .
|
|
11
|
+
* - **.ptbk.md file** in custom markdown format described above
|
|
12
|
+
* - **JSON** format, parsed from the .ptbk.md file
|
|
13
13
|
* - _(this)_ **Object** which is created from JSON format and bound with tools around (but not the execution logic)
|
|
14
14
|
*
|
|
15
15
|
* @see https://github.com/webgptorg/promptbook#prompt-template-pipeline
|
|
16
16
|
*/
|
|
17
17
|
export declare class PromptTemplatePipeline {
|
|
18
|
-
readonly
|
|
18
|
+
readonly ptbkUrl: URL | null;
|
|
19
19
|
readonly parameters: Record<string_name, PromptTemplateParameterJson>;
|
|
20
20
|
readonly promptTemplates: Array<PromptTemplateJson>;
|
|
21
21
|
/**
|
|
@@ -23,28 +23,28 @@ export declare class PromptTemplatePipeline {
|
|
|
23
23
|
*
|
|
24
24
|
* Note: During the construction syntax and logic of source is validated
|
|
25
25
|
*
|
|
26
|
-
* @param source content of .
|
|
26
|
+
* @param source content of .ptbk.md or .ptbk.json file
|
|
27
27
|
* @returns PromptTemplatePipeline
|
|
28
28
|
*/
|
|
29
|
-
static fromSource(
|
|
29
|
+
static fromSource(ptbkSource: PromptTemplatePipelineString | PromptTemplatePipelineJson): PromptTemplatePipeline;
|
|
30
30
|
/**
|
|
31
31
|
* Constructs PromptTemplatePipeline from markdown source
|
|
32
32
|
*
|
|
33
33
|
* Note: During the construction syntax and logic of source is validated
|
|
34
34
|
*
|
|
35
|
-
* @param
|
|
35
|
+
* @param ptbkString content of .ptbk.md file
|
|
36
36
|
* @returns PromptTemplatePipeline
|
|
37
37
|
*/
|
|
38
|
-
static fromString(
|
|
38
|
+
static fromString(ptbkString: PromptTemplatePipelineString): PromptTemplatePipeline;
|
|
39
39
|
/**
|
|
40
40
|
* Constructs PromptTemplatePipeline from JSON source
|
|
41
41
|
*
|
|
42
42
|
* Note: During the construction the source is logic validated
|
|
43
43
|
*
|
|
44
|
-
* @param
|
|
44
|
+
* @param ptbkjson content of .ptbk.json file parsed into JSON
|
|
45
45
|
* @returns PromptTemplatePipeline
|
|
46
46
|
*/
|
|
47
|
-
static fromJson(
|
|
47
|
+
static fromJson(ptbkjson: PromptTemplatePipelineJson): PromptTemplatePipeline;
|
|
48
48
|
private constructor();
|
|
49
49
|
/**
|
|
50
50
|
* Returns the first prompt template in the pipeline
|
|
@@ -20,12 +20,12 @@ export declare class PromptTemplatePipelineLibrary {
|
|
|
20
20
|
* Constructs PromptTemplatePipeline from any sources
|
|
21
21
|
*
|
|
22
22
|
* Note: During the construction syntax and logic of all sources are validated
|
|
23
|
-
* Note: You can combine .
|
|
23
|
+
* Note: You can combine .ptbk.md and .ptbk.json files BUT it is not recommended
|
|
24
24
|
*
|
|
25
|
-
* @param
|
|
25
|
+
* @param ptbkSources contents of .ptbk.md or .ptbk.json files
|
|
26
26
|
* @returns PromptTemplatePipelineLibrary
|
|
27
27
|
*/
|
|
28
|
-
static fromSources(
|
|
28
|
+
static fromSources(ptbkSources: Record<string_name, PromptTemplatePipelineJson | PromptTemplatePipelineString>): PromptTemplatePipelineLibrary;
|
|
29
29
|
private constructor();
|
|
30
30
|
/**
|
|
31
31
|
* Gets prompt template pipeline by name
|
|
@@ -41,13 +41,14 @@ export declare class PromptTemplatePipelineLibrary {
|
|
|
41
41
|
createExecutor(name: string_name, tools: ExecutionTools): PtpExecutor;
|
|
42
42
|
}
|
|
43
43
|
/**
|
|
44
|
+
* TODO: !!! This should be renamed to Promptbook
|
|
44
45
|
* TODO: !! [👐][🧠] Split of PromptTemplatePipeline,PromptTemplatePipelineLibrary between interface and class
|
|
45
46
|
* TODO: !! [👐] Make promptTemplatePipelines private WHEN split between interface and class
|
|
46
47
|
* TODO: [🧠] Maybe isPromptInLibrary should be separate utility function
|
|
47
48
|
* TODO: [🧠] Maybe createExecutor should be separate utility function
|
|
48
49
|
* TODO: Static method fromDirectory
|
|
49
50
|
* TODO: [🤜] Add generic type for entry and result parameters
|
|
50
|
-
* TODO: [🧠] Is it better to
|
|
51
|
+
* TODO: [🧠] Is it better to ptbkLibrary.executePtp('writeXyz',{...}) OR ptbkLibrary.createExecutor('writeXyz')({...}) OR createExecutor(ptbkLibrary.getPtp('writeXyz'))
|
|
51
52
|
* TODO: [🧠] Formarly (before commit 62229afce7668a5b85077cc18becf798b583bf8d) there were two classes PromptTemplatePipelineLibrary+PtpLibraryExecutor (maybe it was better?)
|
|
52
53
|
* TODO: [🧠] Is it better to pass tools into getExecutor or into constructor
|
|
53
54
|
* Maybe it is not a good idea to cache executors when they are can be created with different tools
|
package/esm/typings/config.d.ts
CHANGED
|
@@ -8,5 +8,5 @@ import { PromptTemplatePipelineString } from '../types/PromptTemplatePipelineStr
|
|
|
8
8
|
*
|
|
9
9
|
* @private
|
|
10
10
|
*/
|
|
11
|
-
export declare function importPtp(path: `${string}.
|
|
12
|
-
export declare function importPtp(path: `${string}.
|
|
11
|
+
export declare function importPtp(path: `${string}.ptbk.md`): PromptTemplatePipelineString;
|
|
12
|
+
export declare function importPtp(path: `${string}.ptbk.json`): PromptTemplatePipelineJson;
|
|
@@ -14,7 +14,7 @@ import { PromptTemplatePipelineJson } from '../types/PromptTemplatePipelineJson/
|
|
|
14
14
|
*/
|
|
15
15
|
export declare function validatePromptTemplatePipelineJson(ptp: PromptTemplatePipelineJson): void;
|
|
16
16
|
/**
|
|
17
|
-
* TODO: [🧠] Work with
|
|
17
|
+
* TODO: [🧠] Work with ptbkVersion
|
|
18
18
|
* TODO: Use here some json-schema, Zod or something similar and change it to:
|
|
19
19
|
* > /**
|
|
20
20
|
* > * Validates PromptTemplatePipelineJson if it is logically valid.
|
|
@@ -12,7 +12,7 @@ export interface RemoteServerOptions extends CommonExecutionToolsOptions {
|
|
|
12
12
|
*
|
|
13
13
|
* This is used to checkl validity of the prompt to prevent DDoS
|
|
14
14
|
*/
|
|
15
|
-
readonly
|
|
15
|
+
readonly ptbkLibrary: PromptTemplatePipelineLibrary;
|
|
16
16
|
/**
|
|
17
17
|
* Creates natural execution tools for each client
|
|
18
18
|
*/
|
|
@@ -5,16 +5,16 @@ import { ModelRequirements } from './ModelRequirements';
|
|
|
5
5
|
* Command is one piece of the prompt template which adds some logic to the prompt template or the whole pipeline.
|
|
6
6
|
* It is parsed from the markdown from ul/ol items - one command per one item.
|
|
7
7
|
*/
|
|
8
|
-
export type Command =
|
|
8
|
+
export type Command = PtbkUrlCommand | PtbkVersionCommand | ExecuteCommand | UseCommand | ParameterCommand | PostprocessCommand;
|
|
9
9
|
/**
|
|
10
10
|
* PtpVersion command tells which version is .ptp file using
|
|
11
11
|
*
|
|
12
12
|
* - It is used for backward compatibility
|
|
13
13
|
* - It is defined per whole .ptp file in the header
|
|
14
14
|
*/
|
|
15
|
-
export interface
|
|
16
|
-
readonly type: '
|
|
17
|
-
readonly
|
|
15
|
+
export interface PtbkUrlCommand {
|
|
16
|
+
readonly type: 'PTBK_URL';
|
|
17
|
+
readonly ptbkUrl: URL;
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
20
|
* PtpVersion command tells which version is .ptp file using
|
|
@@ -22,9 +22,9 @@ export interface PtpUrlCommand {
|
|
|
22
22
|
* - It is used for backward compatibility
|
|
23
23
|
* - It is defined per whole .ptp file in the header
|
|
24
24
|
*/
|
|
25
|
-
export interface
|
|
26
|
-
readonly type: '
|
|
27
|
-
readonly
|
|
25
|
+
export interface PtbkVersionCommand {
|
|
26
|
+
readonly type: 'PTBK_VERSION';
|
|
27
|
+
readonly ptbkVersion: string_version;
|
|
28
28
|
}
|
|
29
29
|
/**
|
|
30
30
|
* Execute command tells how to execute the section
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { string_name, string_prompt,
|
|
1
|
+
import { string_name, string_prompt, string_ptbk_url_with_hashtemplate } from '.././types/typeAliases';
|
|
2
2
|
import { ModelRequirements } from './ModelRequirements';
|
|
3
3
|
/**
|
|
4
4
|
* Prompt in a text along with model requirements, but without any execution or templating logic.
|
|
@@ -20,13 +20,13 @@ export interface Prompt {
|
|
|
20
20
|
/**
|
|
21
21
|
* Unique identifier of the prompt template pipeline with specific template name as hash
|
|
22
22
|
*
|
|
23
|
-
* @example https://
|
|
23
|
+
* @example https://ptbk.webgpt.com/cs/write-website-content.ptbk.md@v2.4.15#keywords
|
|
24
24
|
*/
|
|
25
|
-
readonly
|
|
25
|
+
readonly ptbkUrl: string_ptbk_url_with_hashtemplate;
|
|
26
26
|
/**
|
|
27
27
|
* Parameters used in the prompt
|
|
28
28
|
*
|
|
29
|
-
* Note: This is redundant (same information is in
|
|
29
|
+
* Note: This is redundant (same information is in ptbkUrl+content) but useful for logging and debugging
|
|
30
30
|
*/
|
|
31
31
|
readonly parameters: Record<string_name, string>;
|
|
32
32
|
}
|
|
@@ -49,7 +49,7 @@ interface PromptTemplateJsonCommon {
|
|
|
49
49
|
* Name of the template
|
|
50
50
|
* - It must be unique across the pipeline
|
|
51
51
|
* - It should start uppercase and contain letters and numbers
|
|
52
|
-
* - The
|
|
52
|
+
* - The ptbkUrl together with hash and name are used to identify the prompt template in the pipeline
|
|
53
53
|
*/
|
|
54
54
|
readonly name: string_name;
|
|
55
55
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { string_ptbk_url, string_version } from '../.././types/typeAliases';
|
|
2
2
|
import { PromptTemplateJson } from './PromptTemplateJson';
|
|
3
3
|
import { PromptTemplateParameterJson } from './PromptTemplateParameterJson';
|
|
4
4
|
/**
|
|
@@ -6,8 +6,8 @@ import { PromptTemplateParameterJson } from './PromptTemplateParameterJson';
|
|
|
6
6
|
* It represents a series of prompt templates chained together to form a pipeline / one big prompt template with input and result parameters.
|
|
7
7
|
*
|
|
8
8
|
* It can have 3 formats:
|
|
9
|
-
* - **.
|
|
10
|
-
* - _(this)_ **JSON** format, parsed from the .
|
|
9
|
+
* - **.ptbk.md file** in custom markdown format described above
|
|
10
|
+
* - _(this)_ **JSON** format, parsed from the .ptbk.md file
|
|
11
11
|
* - **Object** which is created from JSON format and bound with tools around (but not the execution logic)
|
|
12
12
|
*
|
|
13
13
|
* @see https://github.com/webgptorg/promptbook#prompt-template-pipeline
|
|
@@ -19,19 +19,19 @@ export interface PromptTemplatePipelineJson {
|
|
|
19
19
|
* Note: It must be unique across all prompt template pipelines
|
|
20
20
|
* Note: It must use HTTPs URL
|
|
21
21
|
* Tip: You can do versioning in the URL
|
|
22
|
-
* For example: https://
|
|
22
|
+
* For example: https://ptbk.webgpt.com/cs/write-website-content.ptbk.md@1.0.0
|
|
23
23
|
* Warning: Do not hash part of the URL, hash part is used for identification of the prompt template in the pipeline
|
|
24
24
|
*/
|
|
25
|
-
readonly
|
|
25
|
+
readonly ptbkUrl?: string_ptbk_url;
|
|
26
26
|
/**
|
|
27
27
|
* Title of the prompt template pipeline
|
|
28
28
|
* -It can use simple markdown formatting like **bold**, *italic*, [link](https://example.com), ... BUT not code blocks and structure
|
|
29
29
|
*/
|
|
30
30
|
readonly title: string;
|
|
31
31
|
/**
|
|
32
|
-
* Version of the .
|
|
32
|
+
* Version of the .ptbk.json file
|
|
33
33
|
*/
|
|
34
|
-
readonly
|
|
34
|
+
readonly ptbkVersion: string_version;
|
|
35
35
|
/**
|
|
36
36
|
* Description of the prompt template pipeline
|
|
37
37
|
* It can use multiple paragraphs of simple markdown formatting like **bold**, *italic*, [link](https://example.com), ... BUT not code blocks and structure
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
* It represents a series of prompt templates chained together to form a pipeline / one big prompt template with input and result parameters.
|
|
4
4
|
*
|
|
5
5
|
* It can have 3 formats:
|
|
6
|
-
* - _(this)_ **.
|
|
7
|
-
* - **JSON** format, parsed from the .
|
|
6
|
+
* - _(this)_ **.ptbk.md file** in custom markdown format described above
|
|
7
|
+
* - **JSON** format, parsed from the .ptbk.md file
|
|
8
8
|
* - **Object** which is created from JSON format and bound with tools around (but not the execution logic)
|
|
9
9
|
*
|
|
10
10
|
* @see https://github.com/webgptorg/promptbook#prompt-template-pipeline
|
|
@@ -191,15 +191,15 @@ export type string_url = string;
|
|
|
191
191
|
/**
|
|
192
192
|
* Semantic helper
|
|
193
193
|
*
|
|
194
|
-
* For example `"https://
|
|
194
|
+
* For example `"https://ptbk.webgpt.com/cs/write-website-content.ptbk.md@v2.4.15"`
|
|
195
195
|
*/
|
|
196
|
-
export type
|
|
196
|
+
export type string_ptbk_url = string;
|
|
197
197
|
/**
|
|
198
198
|
* Semantic helper
|
|
199
199
|
*
|
|
200
|
-
* For example `"https://
|
|
200
|
+
* For example `"https://ptbk.webgpt.com/cs/write-website-content.ptbk.md@v2.4.15#keywords"`
|
|
201
201
|
*/
|
|
202
|
-
export type
|
|
202
|
+
export type string_ptbk_url_with_hashtemplate = string;
|
|
203
203
|
/**
|
|
204
204
|
* Semantic helper
|
|
205
205
|
*
|
package/package.json
CHANGED
package/umd/index.umd.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
2
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('n12'), require('spacetrim')) :
|
|
3
3
|
typeof define === 'function' && define.amd ? define(['exports', 'n12', 'spacetrim'], factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-core"] = {}, global.n12, global.spaceTrim));
|
|
5
5
|
})(this, (function (exports, n12, spaceTrim) { 'use strict';
|
|
6
6
|
|
|
7
7
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
@@ -104,7 +104,7 @@
|
|
|
104
104
|
/**
|
|
105
105
|
* The version of the PTP
|
|
106
106
|
*/
|
|
107
|
-
var
|
|
107
|
+
var PTBK_VERSION = '0.1.0';
|
|
108
108
|
/**
|
|
109
109
|
* Default model requirements for the pipeline
|
|
110
110
|
*/
|
|
@@ -379,34 +379,37 @@
|
|
|
379
379
|
.split(' ')
|
|
380
380
|
.map(function (part) { return part.trim(); })
|
|
381
381
|
.filter(function (item) { return item !== ''; })
|
|
382
|
-
.filter(function (item) { return !/^
|
|
382
|
+
.filter(function (item) { return !/^PTBK$/i.test(item); })
|
|
383
383
|
.map(removeMarkdownFormatting);
|
|
384
|
-
if (type.startsWith('URL') ||
|
|
384
|
+
if (type.startsWith('URL') ||
|
|
385
|
+
type.startsWith('PTBK_URL') ||
|
|
386
|
+
type.startsWith('PTBKURL') ||
|
|
387
|
+
type.startsWith('HTTPS')) {
|
|
385
388
|
if (!(listItemParts.length === 2 || (listItemParts.length === 1 && type.startsWith('HTTPS')))) {
|
|
386
|
-
throw new Error(spaceTrim__default["default"]("\n Invalid
|
|
389
|
+
throw new Error(spaceTrim__default["default"]("\n Invalid PTBK_URL command:\n\n - ".concat(listItem, "\n ")));
|
|
387
390
|
}
|
|
388
|
-
var
|
|
389
|
-
var
|
|
390
|
-
if (
|
|
391
|
-
throw new Error(spaceTrim__default["default"]("\n Invalid
|
|
391
|
+
var ptbkUrlString = listItemParts.pop();
|
|
392
|
+
var ptbkUrl = new URL(ptbkUrlString);
|
|
393
|
+
if (ptbkUrl.protocol !== 'https:') {
|
|
394
|
+
throw new Error(spaceTrim__default["default"]("\n Invalid PTBK_URL command:\n\n - ".concat(listItem, "\n\n Protocol must be HTTPS\n ")));
|
|
392
395
|
}
|
|
393
|
-
if (
|
|
394
|
-
throw new Error(spaceTrim__default["default"]("\n Invalid
|
|
396
|
+
if (ptbkUrl.hash !== '') {
|
|
397
|
+
throw new Error(spaceTrim__default["default"]("\n Invalid PTBK_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 ")));
|
|
395
398
|
}
|
|
396
399
|
return {
|
|
397
|
-
type: '
|
|
398
|
-
|
|
400
|
+
type: 'PTBK_URL',
|
|
401
|
+
ptbkUrl: ptbkUrl,
|
|
399
402
|
};
|
|
400
403
|
}
|
|
401
|
-
else if (type.startsWith('
|
|
404
|
+
else if (type.startsWith('PTBK_VERSION')) {
|
|
402
405
|
if (listItemParts.length !== 2) {
|
|
403
|
-
throw new Error(spaceTrim__default["default"]("\n Invalid
|
|
406
|
+
throw new Error(spaceTrim__default["default"]("\n Invalid PTBK_VERSION command:\n\n - ".concat(listItem, "\n ")));
|
|
404
407
|
}
|
|
405
|
-
var
|
|
408
|
+
var ptbkVersion = listItemParts.pop();
|
|
406
409
|
// TODO: Validate version
|
|
407
410
|
return {
|
|
408
|
-
type: '
|
|
409
|
-
|
|
411
|
+
type: 'PTBK_VERSION',
|
|
412
|
+
ptbkVersion: ptbkVersion,
|
|
410
413
|
};
|
|
411
414
|
}
|
|
412
415
|
else if (type.startsWith('EXECUTE') ||
|
|
@@ -475,7 +478,7 @@
|
|
|
475
478
|
};
|
|
476
479
|
}
|
|
477
480
|
else {
|
|
478
|
-
throw new Error(spaceTrim__default["default"]("\n Unknown command:\n\n - ".concat(listItem, "\n\n Supported commands are:\n - Execute\n - Use\n - Parameter\n - Input parameter\n - Output parameter\n -
|
|
481
|
+
throw new Error(spaceTrim__default["default"]("\n Unknown command:\n\n - ".concat(listItem, "\n\n Supported commands are:\n - Execute\n - Use\n - Parameter\n - Input parameter\n - Output parameter\n - PTBK Version\n ")));
|
|
479
482
|
}
|
|
480
483
|
}
|
|
481
484
|
|
|
@@ -486,11 +489,11 @@
|
|
|
486
489
|
*/
|
|
487
490
|
function promptTemplatePipelineStringToJson(promptTemplatePipelineString) {
|
|
488
491
|
var e_1, _a, e_2, _b;
|
|
489
|
-
var
|
|
492
|
+
var ptbJson = {
|
|
490
493
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
491
494
|
title: undefined /* <- Note: Putting here placeholder to keep `title` on top at final JSON */,
|
|
492
|
-
|
|
493
|
-
|
|
495
|
+
ptbkUrl: undefined /* <- Note: Putting here placeholder to keep `ptbkUrl` on top at final JSON */,
|
|
496
|
+
ptbkVersion: PTBK_VERSION,
|
|
494
497
|
description: undefined /* <- Note: Putting here placeholder to keep `description` on top at final JSON */,
|
|
495
498
|
parameters: [],
|
|
496
499
|
promptTemplates: [],
|
|
@@ -504,7 +507,7 @@
|
|
|
504
507
|
///Note: 2️⃣ Function for adding parameters
|
|
505
508
|
var addParam = function (parameterCommand) {
|
|
506
509
|
var parameterName = parameterCommand.parameterName, parameterDescription = parameterCommand.parameterDescription, isInputParameter = parameterCommand.isInputParameter;
|
|
507
|
-
var existingParameter =
|
|
510
|
+
var existingParameter = ptbJson.parameters.find(function (parameter) { return parameter.name === parameterName; });
|
|
508
511
|
if (existingParameter &&
|
|
509
512
|
existingParameter.description &&
|
|
510
513
|
existingParameter.description !== parameterDescription &&
|
|
@@ -517,7 +520,7 @@
|
|
|
517
520
|
}
|
|
518
521
|
}
|
|
519
522
|
else {
|
|
520
|
-
|
|
523
|
+
ptbJson.parameters.push({
|
|
521
524
|
name: parameterName,
|
|
522
525
|
description: parameterDescription || undefined,
|
|
523
526
|
isInput: isInputParameter,
|
|
@@ -531,7 +534,7 @@
|
|
|
531
534
|
if (markdownStructureDeepness !== 2) {
|
|
532
535
|
throw new Error(spaceTrim__default["default"]("\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 ")));
|
|
533
536
|
}
|
|
534
|
-
|
|
537
|
+
ptbJson.title = markdownStructure.title;
|
|
535
538
|
// TODO: [1] DRY description
|
|
536
539
|
var description = markdownStructure.content;
|
|
537
540
|
// Note: Remove codeblocks
|
|
@@ -542,7 +545,7 @@
|
|
|
542
545
|
if (description === '') {
|
|
543
546
|
description = undefined;
|
|
544
547
|
}
|
|
545
|
-
|
|
548
|
+
ptbJson.description = description;
|
|
546
549
|
var defaultModelRequirements = __assign({}, DEFAULT_MODEL_REQUIREMENTS);
|
|
547
550
|
var listItems = extractAllListItemsFromMarkdown(markdownStructure.content);
|
|
548
551
|
try {
|
|
@@ -550,11 +553,11 @@
|
|
|
550
553
|
var listItem = listItems_1_1.value;
|
|
551
554
|
var command = parseCommand(listItem);
|
|
552
555
|
switch (command.type) {
|
|
553
|
-
case '
|
|
554
|
-
|
|
556
|
+
case 'PTBK_URL':
|
|
557
|
+
ptbJson.ptbkUrl = command.ptbkUrl.href;
|
|
555
558
|
break;
|
|
556
|
-
case '
|
|
557
|
-
|
|
559
|
+
case 'PTBK_VERSION':
|
|
560
|
+
ptbJson.ptbkVersion = command.ptbkVersion;
|
|
558
561
|
break;
|
|
559
562
|
case 'USE':
|
|
560
563
|
defaultModelRequirements[command.key] = command.value;
|
|
@@ -649,7 +652,7 @@
|
|
|
649
652
|
var parameterName = postprocessingCommands.length <= i
|
|
650
653
|
? resultingParameterName
|
|
651
654
|
: n12.normalizeTo_camelCase("".concat(resultingParameterName, " before ").concat(postprocessingCommands[i].functionName));
|
|
652
|
-
var isParameterDefined =
|
|
655
|
+
var isParameterDefined = ptbJson.parameters.some(function (parameter) { return parameter.name === parameterName; });
|
|
653
656
|
if (!isParameterDefined) {
|
|
654
657
|
var parameterDescription = "*(".concat(n12.capitalize(section.title), " postprocessing ").concat(i + 1, "/").concat(postprocessingCommands.length, ")* {").concat(resultingParameterName, "} before `").concat(postprocessingCommands[i].functionName, "`");
|
|
655
658
|
addParam({
|
|
@@ -661,7 +664,7 @@
|
|
|
661
664
|
}
|
|
662
665
|
return parameterName;
|
|
663
666
|
};
|
|
664
|
-
|
|
667
|
+
ptbJson.promptTemplates.push({
|
|
665
668
|
name: n12.normalizeTo_PascalCase(section.title),
|
|
666
669
|
title: section.title,
|
|
667
670
|
description: description_1,
|
|
@@ -677,7 +680,7 @@
|
|
|
677
680
|
return [functionName, i];
|
|
678
681
|
}))), _j = _h.next(); !_j.done; _j = _h.next()) {
|
|
679
682
|
var _k = __read(_j.value, 2), functionName = _k[0], i = _k[1];
|
|
680
|
-
|
|
683
|
+
ptbJson.promptTemplates.push({
|
|
681
684
|
name: n12.normalizeTo_PascalCase(section.title + ' Postprocessing ' + i),
|
|
682
685
|
title: "(".concat(i + 1, "/").concat(postprocessingCommands.length, ") ").concat(section.title, " postprocessing"),
|
|
683
686
|
description: "Postprocessing of section ".concat(section.title, " finally with resulting parameter {").concat(resultingParameterName, "}"),
|
|
@@ -710,7 +713,7 @@
|
|
|
710
713
|
finally { if (e_2) throw e_2.error; }
|
|
711
714
|
}
|
|
712
715
|
// =============================================================
|
|
713
|
-
return
|
|
716
|
+
return ptbJson;
|
|
714
717
|
}
|
|
715
718
|
/**
|
|
716
719
|
* TODO: Report here line/column of error
|
|
@@ -773,7 +776,7 @@
|
|
|
773
776
|
}
|
|
774
777
|
}
|
|
775
778
|
/**
|
|
776
|
-
* TODO: [🧠] Work with
|
|
779
|
+
* TODO: [🧠] Work with ptbkVersion
|
|
777
780
|
* TODO: Use here some json-schema, Zod or something similar and change it to:
|
|
778
781
|
* > /**
|
|
779
782
|
* > * Validates PromptTemplatePipelineJson if it is logically valid.
|
|
@@ -789,15 +792,15 @@
|
|
|
789
792
|
* It represents a series of prompt templates chained together to form a pipeline / one big prompt template with input and result parameters.
|
|
790
793
|
*
|
|
791
794
|
* It can have 3 formats:
|
|
792
|
-
* - **.
|
|
793
|
-
* - **JSON** format, parsed from the .
|
|
795
|
+
* - **.ptbk.md file** in custom markdown format described above
|
|
796
|
+
* - **JSON** format, parsed from the .ptbk.md file
|
|
794
797
|
* - _(this)_ **Object** which is created from JSON format and bound with tools around (but not the execution logic)
|
|
795
798
|
*
|
|
796
799
|
* @see https://github.com/webgptorg/promptbook#prompt-template-pipeline
|
|
797
800
|
*/
|
|
798
801
|
var PromptTemplatePipeline = /** @class */ (function () {
|
|
799
|
-
function PromptTemplatePipeline(
|
|
800
|
-
this.
|
|
802
|
+
function PromptTemplatePipeline(ptbkUrl, parameters, promptTemplates) {
|
|
803
|
+
this.ptbkUrl = ptbkUrl;
|
|
801
804
|
this.parameters = parameters;
|
|
802
805
|
this.promptTemplates = promptTemplates;
|
|
803
806
|
if (promptTemplates.length === 0) {
|
|
@@ -809,15 +812,15 @@
|
|
|
809
812
|
*
|
|
810
813
|
* Note: During the construction syntax and logic of source is validated
|
|
811
814
|
*
|
|
812
|
-
* @param source content of .
|
|
815
|
+
* @param source content of .ptbk.md or .ptbk.json file
|
|
813
816
|
* @returns PromptTemplatePipeline
|
|
814
817
|
*/
|
|
815
|
-
PromptTemplatePipeline.fromSource = function (
|
|
816
|
-
if (typeof
|
|
817
|
-
return PromptTemplatePipeline.fromString(
|
|
818
|
+
PromptTemplatePipeline.fromSource = function (ptbkSource) {
|
|
819
|
+
if (typeof ptbkSource === 'string') {
|
|
820
|
+
return PromptTemplatePipeline.fromString(ptbkSource);
|
|
818
821
|
}
|
|
819
822
|
else {
|
|
820
|
-
return PromptTemplatePipeline.fromJson(
|
|
823
|
+
return PromptTemplatePipeline.fromJson(ptbkSource);
|
|
821
824
|
}
|
|
822
825
|
};
|
|
823
826
|
/**
|
|
@@ -825,24 +828,24 @@
|
|
|
825
828
|
*
|
|
826
829
|
* Note: During the construction syntax and logic of source is validated
|
|
827
830
|
*
|
|
828
|
-
* @param
|
|
831
|
+
* @param ptbkString content of .ptbk.md file
|
|
829
832
|
* @returns PromptTemplatePipeline
|
|
830
833
|
*/
|
|
831
|
-
PromptTemplatePipeline.fromString = function (
|
|
832
|
-
var
|
|
833
|
-
return PromptTemplatePipeline.fromJson(
|
|
834
|
+
PromptTemplatePipeline.fromString = function (ptbkString) {
|
|
835
|
+
var ptbkjson = promptTemplatePipelineStringToJson(ptbkString);
|
|
836
|
+
return PromptTemplatePipeline.fromJson(ptbkjson);
|
|
834
837
|
};
|
|
835
838
|
/**
|
|
836
839
|
* Constructs PromptTemplatePipeline from JSON source
|
|
837
840
|
*
|
|
838
841
|
* Note: During the construction the source is logic validated
|
|
839
842
|
*
|
|
840
|
-
* @param
|
|
843
|
+
* @param ptbkjson content of .ptbk.json file parsed into JSON
|
|
841
844
|
* @returns PromptTemplatePipeline
|
|
842
845
|
*/
|
|
843
|
-
PromptTemplatePipeline.fromJson = function (
|
|
844
|
-
validatePromptTemplatePipelineJson(
|
|
845
|
-
return new PromptTemplatePipeline(
|
|
846
|
+
PromptTemplatePipeline.fromJson = function (ptbkjson) {
|
|
847
|
+
validatePromptTemplatePipelineJson(ptbkjson);
|
|
848
|
+
return new PromptTemplatePipeline(ptbkjson.ptbkUrl ? new URL(ptbkjson.ptbkUrl) : null, Object.fromEntries(ptbkjson.parameters.map(function (parameter) { return [parameter.name, parameter]; })), ptbkjson.promptTemplates);
|
|
846
849
|
};
|
|
847
850
|
Object.defineProperty(PromptTemplatePipeline.prototype, "entryPromptTemplate", {
|
|
848
851
|
/**
|
|
@@ -1078,8 +1081,8 @@
|
|
|
1078
1081
|
return [3 /*break*/, 25];
|
|
1079
1082
|
case 4:
|
|
1080
1083
|
prompt_1 = {
|
|
1081
|
-
|
|
1082
|
-
? ptp.
|
|
1084
|
+
ptbkUrl: "".concat(ptp.ptbkUrl
|
|
1085
|
+
? ptp.ptbkUrl.href
|
|
1083
1086
|
: 'anonymous' /* <- [🧠] How to deal with anonymous PTPs, do here some auto-url like SHA-256 based ad-hoc identifier? */, "#").concat(currentTemplate.name),
|
|
1084
1087
|
parameters: parametersToPass,
|
|
1085
1088
|
content: replaceParameters(currentTemplate.content, parametersToPass),
|
|
@@ -1169,7 +1172,7 @@
|
|
|
1169
1172
|
case 22: return [4 /*yield*/, tools.userInterface.promptDialog({
|
|
1170
1173
|
prompt: replaceParameters(currentTemplate.description || '', parametersToPass),
|
|
1171
1174
|
defaultValue: replaceParameters(currentTemplate.content, parametersToPass),
|
|
1172
|
-
// TODO: [🧠] !! Figure out how to define placeholder in .
|
|
1175
|
+
// TODO: [🧠] !! Figure out how to define placeholder in .ptbk.md file
|
|
1173
1176
|
placeholder: undefined,
|
|
1174
1177
|
})];
|
|
1175
1178
|
case 23:
|
|
@@ -1230,16 +1233,16 @@
|
|
|
1230
1233
|
* Constructs PromptTemplatePipeline from any sources
|
|
1231
1234
|
*
|
|
1232
1235
|
* Note: During the construction syntax and logic of all sources are validated
|
|
1233
|
-
* Note: You can combine .
|
|
1236
|
+
* Note: You can combine .ptbk.md and .ptbk.json files BUT it is not recommended
|
|
1234
1237
|
*
|
|
1235
|
-
* @param
|
|
1238
|
+
* @param ptbkSources contents of .ptbk.md or .ptbk.json files
|
|
1236
1239
|
* @returns PromptTemplatePipelineLibrary
|
|
1237
1240
|
*/
|
|
1238
|
-
PromptTemplatePipelineLibrary.fromSources = function (
|
|
1241
|
+
PromptTemplatePipelineLibrary.fromSources = function (ptbkSources) {
|
|
1239
1242
|
var e_1, _a;
|
|
1240
1243
|
var promptTemplatePipelines = {};
|
|
1241
1244
|
try {
|
|
1242
|
-
for (var _b = __values(Object.entries(
|
|
1245
|
+
for (var _b = __values(Object.entries(ptbkSources)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1243
1246
|
var _d = __read(_c.value, 2), name_1 = _d[0], source = _d[1];
|
|
1244
1247
|
promptTemplatePipelines[name_1] = PromptTemplatePipeline.fromSource(source);
|
|
1245
1248
|
}
|
|
@@ -1279,13 +1282,14 @@
|
|
|
1279
1282
|
return PromptTemplatePipelineLibrary;
|
|
1280
1283
|
}());
|
|
1281
1284
|
/**
|
|
1285
|
+
* TODO: !!! This should be renamed to Promptbook
|
|
1282
1286
|
* TODO: !! [👐][🧠] Split of PromptTemplatePipeline,PromptTemplatePipelineLibrary between interface and class
|
|
1283
1287
|
* TODO: !! [👐] Make promptTemplatePipelines private WHEN split between interface and class
|
|
1284
1288
|
* TODO: [🧠] Maybe isPromptInLibrary should be separate utility function
|
|
1285
1289
|
* TODO: [🧠] Maybe createExecutor should be separate utility function
|
|
1286
1290
|
* TODO: Static method fromDirectory
|
|
1287
1291
|
* TODO: [🤜] Add generic type for entry and result parameters
|
|
1288
|
-
* TODO: [🧠] Is it better to
|
|
1292
|
+
* TODO: [🧠] Is it better to ptbkLibrary.executePtp('writeXyz',{...}) OR ptbkLibrary.createExecutor('writeXyz')({...}) OR createExecutor(ptbkLibrary.getPtp('writeXyz'))
|
|
1289
1293
|
* TODO: [🧠] Formarly (before commit 62229afce7668a5b85077cc18becf798b583bf8d) there were two classes PromptTemplatePipelineLibrary+PtpLibraryExecutor (maybe it was better?)
|
|
1290
1294
|
* TODO: [🧠] Is it better to pass tools into getExecutor or into constructor
|
|
1291
1295
|
* Maybe it is not a good idea to cache executors when they are can be created with different tools
|
|
@@ -1409,7 +1413,7 @@
|
|
|
1409
1413
|
exports.CallbackInterfaceTools = CallbackInterfaceTools;
|
|
1410
1414
|
exports.ExecutionTypes = ExecutionTypes;
|
|
1411
1415
|
exports.MockedEchoNaturalExecutionTools = MockedEchoNaturalExecutionTools;
|
|
1412
|
-
exports.
|
|
1416
|
+
exports.PTBK_VERSION = PTBK_VERSION;
|
|
1413
1417
|
exports.PromptTemplatePipeline = PromptTemplatePipeline;
|
|
1414
1418
|
exports.PromptTemplatePipelineLibrary = PromptTemplatePipelineLibrary;
|
|
1415
1419
|
exports.SimplePromptInterfaceTools = SimplePromptInterfaceTools;
|