@promptbook/utils 0.47.0 โ 0.48.0-1
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 +12 -1
- package/esm/index.es.js +33 -23
- package/esm/index.es.js.map +1 -1
- package/esm/typings/_packages/core.index.d.ts +2 -1
- package/esm/typings/_packages/utils.index.d.ts +2 -1
- package/esm/typings/conversion/prettify/prettifyPromptbookStringCli.d.ts +1 -1
- package/esm/typings/conversion/promptbookJsonToString.d.ts +8 -0
- package/esm/typings/conversion/utils/titleToName.d.ts +4 -0
- package/esm/typings/conversion/utils/titleToName.test.d.ts +1 -0
- package/esm/typings/execution/ExecutionTools.d.ts +1 -1
- package/esm/typings/execution/LlmExecutionTools.d.ts +1 -0
- package/esm/typings/execution/plugins/llm-execution-tools/langtail/LangtailExecutionTools.d.ts +1 -1
- package/esm/typings/execution/plugins/llm-execution-tools/openai/OpenAiExecutionTools.d.ts +1 -1
- package/esm/typings/execution/plugins/llm-execution-tools/openai/computeOpenaiUsage.d.ts +4 -1
- package/esm/typings/execution/plugins/llm-execution-tools/remote/RemoteLlmExecutionTools.d.ts +1 -0
- package/esm/typings/library/SimplePromptbookLibrary.d.ts +2 -1
- package/esm/typings/library/constructors/createPromptbookLibraryFromDirectory.d.ts +10 -1
- package/esm/typings/library/constructors/createPromptbookLibraryFromPromise.d.ts +20 -1
- package/esm/typings/library/constructors/createPromptbookLibraryFromSources.d.ts +5 -6
- package/esm/typings/library/constructors/createPromptbookLibraryFromUrl.d.ts +13 -0
- package/esm/typings/library/constructors/createPromptbookSublibrary.d.ts +10 -1
- package/esm/typings/utils/markdown/extractOneBlockFromMarkdown.d.ts +1 -1
- package/package.json +1 -1
- package/umd/index.umd.js +33 -22
- package/umd/index.umd.js.map +1 -1
- package/umd/typings/_packages/core.index.d.ts +2 -1
- package/umd/typings/_packages/utils.index.d.ts +2 -1
- package/umd/typings/conversion/prettify/prettifyPromptbookStringCli.d.ts +1 -1
- package/umd/typings/conversion/promptbookJsonToString.d.ts +8 -0
- package/umd/typings/conversion/utils/titleToName.d.ts +4 -0
- package/umd/typings/conversion/utils/titleToName.test.d.ts +1 -0
- package/umd/typings/execution/ExecutionTools.d.ts +1 -1
- package/umd/typings/execution/LlmExecutionTools.d.ts +1 -0
- package/umd/typings/execution/plugins/llm-execution-tools/langtail/LangtailExecutionTools.d.ts +1 -1
- package/umd/typings/execution/plugins/llm-execution-tools/openai/OpenAiExecutionTools.d.ts +1 -1
- package/umd/typings/execution/plugins/llm-execution-tools/openai/computeOpenaiUsage.d.ts +4 -1
- package/umd/typings/execution/plugins/llm-execution-tools/remote/RemoteLlmExecutionTools.d.ts +1 -0
- package/umd/typings/library/SimplePromptbookLibrary.d.ts +2 -1
- package/umd/typings/library/constructors/createPromptbookLibraryFromDirectory.d.ts +10 -1
- package/umd/typings/library/constructors/createPromptbookLibraryFromPromise.d.ts +20 -1
- package/umd/typings/library/constructors/createPromptbookLibraryFromSources.d.ts +5 -6
- package/umd/typings/library/constructors/createPromptbookLibraryFromUrl.d.ts +13 -0
- package/umd/typings/library/constructors/createPromptbookSublibrary.d.ts +10 -1
- package/umd/typings/utils/markdown/extractOneBlockFromMarkdown.d.ts +1 -1
- package/esm/typings/library/constructors/createPromptbookLibraryFromList.d.ts +0 -5
- package/umd/typings/library/constructors/createPromptbookLibraryFromList.d.ts +0 -5
|
@@ -27,7 +27,7 @@ export declare class OpenAiExecutionTools implements LlmExecutionTools {
|
|
|
27
27
|
gptComplete(prompt: Prompt): Promise<PromptCompletionResult>;
|
|
28
28
|
}
|
|
29
29
|
/**
|
|
30
|
-
|
|
30
|
+
* TODO: [๐][โ] Allow to list compatible models with each variant
|
|
31
31
|
* TODO: Maybe Create some common util for gptChat and gptComplete
|
|
32
32
|
* TODO: Maybe make custom OpenaiError
|
|
33
33
|
*/
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import type OpenAI from 'openai';
|
|
2
2
|
import type { PromptResult } from '../../../PromptResult';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Computes the usage of the OpenAI API based on the response from OpenAI
|
|
5
5
|
*
|
|
6
6
|
* @throws {PromptbookExecutionError} If the usage is not defined in the response from OpenAI
|
|
7
7
|
*/
|
|
8
8
|
export declare function computeOpenaiUsage(rawResponse: Pick<OpenAI.Chat.Completions.ChatCompletion | OpenAI.Completions.Completion, 'model' | 'usage'>): PromptResult['usage'];
|
|
9
|
+
/**
|
|
10
|
+
* TODO: [๐] Make better
|
|
11
|
+
*/
|
package/esm/typings/execution/plugins/llm-execution-tools/remote/RemoteLlmExecutionTools.d.ts
CHANGED
|
@@ -31,5 +31,6 @@ export declare class RemoteLlmExecutionTools implements LlmExecutionTools {
|
|
|
31
31
|
private gptCommon;
|
|
32
32
|
}
|
|
33
33
|
/**
|
|
34
|
+
* TODO: [๐][โ] Allow to list compatible models with each variant
|
|
34
35
|
* TODO: [๐คนโโ๏ธ] RemoteLlmExecutionTools should extend Destroyable and implement IDestroyable
|
|
35
36
|
*/
|
|
@@ -10,7 +10,8 @@ import { PromptbookLibrary } from './PromptbookLibrary';
|
|
|
10
10
|
*/
|
|
11
11
|
export declare class SimplePromptbookLibrary implements PromptbookLibrary {
|
|
12
12
|
private library;
|
|
13
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Constructs a promptbook library from promptbooks
|
|
14
15
|
*
|
|
15
16
|
* @param promptbooks !!!
|
|
16
17
|
*
|
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import { PromptbookLibrary } from '../PromptbookLibrary';
|
|
2
|
+
/**
|
|
3
|
+
* Constructs Promptbook from given directory
|
|
4
|
+
*
|
|
5
|
+
* Note: Works only in Node.js environment because it reads the file system
|
|
6
|
+
* Note: The function does NOT return promise it returns the library directly which dynamically loads promptbooks when needed
|
|
7
|
+
* SO during the construction syntax and logic sources IS NOT validated
|
|
8
|
+
*
|
|
9
|
+
* @returns PromptbookLibrary
|
|
10
|
+
*/
|
|
2
11
|
export declare function createPromptbookLibraryFromDirectory(): PromptbookLibrary;
|
|
3
12
|
/***
|
|
4
|
-
* TODO: !!!
|
|
13
|
+
* TODO: [๐][๐ฏ] !!! Add to README and samples + maybe make `@promptbook/library` package
|
|
5
14
|
*/
|
|
@@ -1,7 +1,26 @@
|
|
|
1
1
|
import type { PromptbookJson } from '../../types/PromptbookJson/PromptbookJson';
|
|
2
2
|
import { PromptbookString } from '../../types/PromptbookString';
|
|
3
3
|
import { PromptbookLibrary } from '../PromptbookLibrary';
|
|
4
|
+
/**
|
|
5
|
+
* Constructs Promptbook from async sources
|
|
6
|
+
* It can be one of the following:
|
|
7
|
+
* - Promise of array of PromptbookJson or PromptbookString
|
|
8
|
+
* - Factory function that returns Promise of array of PromptbookJson or PromptbookString
|
|
9
|
+
*
|
|
10
|
+
* Note: This is useful as internal tool for other constructor functions like
|
|
11
|
+
* `createPromptbookLibraryFromUrl` or `createPromptbookLibraryFromDirectory`
|
|
12
|
+
* Consider using those functions instead of this one
|
|
13
|
+
*
|
|
14
|
+
* Note: The function does NOT return promise it returns the library directly which waits for the sources to be resolved
|
|
15
|
+
* when error occurs in given promise or factory function, it is thrown during `listPromptbooks` or `getPromptbookByUrl` call
|
|
16
|
+
*
|
|
17
|
+
*
|
|
18
|
+
* @param promptbookSourcesPromiseOrFactory
|
|
19
|
+
* @returns PromptbookLibrary
|
|
20
|
+
*
|
|
21
|
+
* @deprecated Consider using `createPromptbookLibraryFromUrl` or `createPromptbookLibraryFromDirectory`
|
|
22
|
+
*/
|
|
4
23
|
export declare function createPromptbookLibraryFromPromise(promptbookSourcesPromiseOrFactory: Promise<Array<PromptbookJson | PromptbookString>> | (() => Promise<Array<PromptbookJson | PromptbookString>>)): PromptbookLibrary;
|
|
5
24
|
/***
|
|
6
|
-
* TODO: !!!
|
|
25
|
+
* TODO: [๐][๐ฏ] !!! Add to README and samples + maybe make `@promptbook/library` package
|
|
7
26
|
*/
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import { PromptbookJson, PromptbookString } from '../../_packages/types.index';
|
|
2
2
|
import { SimplePromptbookLibrary } from '../SimplePromptbookLibrary';
|
|
3
|
-
export declare function createPromptbookLibraryFromSources(...promptbookSources: Array<PromptbookJson | PromptbookString>): SimplePromptbookLibrary;
|
|
4
3
|
/**
|
|
5
|
-
*
|
|
4
|
+
* Creates PromptbookLibrary from array of PromptbookJson or PromptbookString
|
|
6
5
|
*
|
|
6
|
+
* Note: You can combine `PromptbookString` (`.ptbk.md`) with `PromptbookJson` BUT it is not recommended
|
|
7
7
|
* Note: During the construction syntax and logic of all sources are validated
|
|
8
|
-
* Note: You can combine .ptbk.md and .ptbk.json files BUT it is not recommended
|
|
9
8
|
*
|
|
10
|
-
* @param promptbookSources
|
|
11
|
-
* @param settings settings for creating executor functions
|
|
9
|
+
* @param promptbookSources
|
|
12
10
|
* @returns PromptbookLibrary
|
|
13
11
|
*/
|
|
12
|
+
export declare function createPromptbookLibraryFromSources(...promptbookSources: Array<PromptbookJson | PromptbookString>): SimplePromptbookLibrary;
|
|
14
13
|
/***
|
|
15
|
-
* TODO: !!!
|
|
14
|
+
* TODO: [๐][๐ฏ] !!! Add to README and samples + maybe make `@promptbook/library` package
|
|
16
15
|
*/
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { PromptbookLibrary } from '../PromptbookLibrary';
|
|
2
|
+
/**
|
|
3
|
+
* Constructs Promptbook from remote Promptbase URL
|
|
4
|
+
*
|
|
5
|
+
* Note: The function does NOT return promise it returns the library directly which dynamically loads promptbooks when needed
|
|
6
|
+
* SO during the construction syntax and logic sources IS NOT validated
|
|
7
|
+
*
|
|
8
|
+
* @returns PromptbookLibrary
|
|
9
|
+
*/
|
|
10
|
+
export declare function createPromptbookLibraryFromUrl(): PromptbookLibrary;
|
|
11
|
+
/***
|
|
12
|
+
* TODO: [๐][๐ฏ] !!! Add to README and samples + maybe make `@promptbook/library` package
|
|
13
|
+
*/
|
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import type { string_promptbook_url } from '../../types/typeAliases';
|
|
2
2
|
import { PromptbookLibrary } from '../PromptbookLibrary';
|
|
3
|
+
/**
|
|
4
|
+
* Creates PromptbookLibrary as a subset of another PromptbookLibrary
|
|
5
|
+
*
|
|
6
|
+
* Note: You can use any type of library as a parent library - local, remote, etc.
|
|
7
|
+
* Note: This is just a thin wrapper / proxy around the parent library
|
|
8
|
+
*
|
|
9
|
+
* @param promptbookSources
|
|
10
|
+
* @returns PromptbookLibrary
|
|
11
|
+
*/
|
|
3
12
|
export declare function createPromptbookSublibrary(library: PromptbookLibrary, predicate: (url: string_promptbook_url) => boolean): PromptbookLibrary;
|
|
4
13
|
/***
|
|
5
|
-
* TODO: !!!
|
|
14
|
+
* TODO: [๐][๐ฏ] !!! Add to README and samples + maybe make `@promptbook/library` package
|
|
6
15
|
*/
|
|
@@ -15,5 +15,5 @@ import { CodeBlock } from './extractAllBlocksFromMarkdown';
|
|
|
15
15
|
*/
|
|
16
16
|
export declare function extractOneBlockFromMarkdown(markdown: string_markdown): CodeBlock;
|
|
17
17
|
/***
|
|
18
|
-
* TODO: [๐ป] !!! Decide of this is internal util, external util OR validator/postprocessor
|
|
18
|
+
* TODO: [๐][๐ป] !!! Decide of this is internal util, external util OR validator/postprocessor
|
|
19
19
|
*/
|
package/package.json
CHANGED
package/umd/index.umd.js
CHANGED
|
@@ -392,7 +392,7 @@
|
|
|
392
392
|
return codeBlocks[0];
|
|
393
393
|
}
|
|
394
394
|
/***
|
|
395
|
-
* TODO: [๐ป] !!! Decide of this is internal util, external util OR validator/postprocessor
|
|
395
|
+
* TODO: [๐][๐ป] !!! Decide of this is internal util, external util OR validator/postprocessor
|
|
396
396
|
*/
|
|
397
397
|
|
|
398
398
|
/**
|
|
@@ -408,7 +408,7 @@
|
|
|
408
408
|
/**
|
|
409
409
|
* The version of the Promptbook library
|
|
410
410
|
*/
|
|
411
|
-
var PROMPTBOOK_VERSION = '0.
|
|
411
|
+
var PROMPTBOOK_VERSION = '0.48.0-0';
|
|
412
412
|
|
|
413
413
|
/**
|
|
414
414
|
* Parses the given script and returns the list of all used variables that are not defined in the script
|
|
@@ -809,6 +809,31 @@
|
|
|
809
809
|
}
|
|
810
810
|
}
|
|
811
811
|
|
|
812
|
+
/**
|
|
813
|
+
* Removes emojis from a string and fix whitespaces
|
|
814
|
+
*
|
|
815
|
+
* @param text with emojis
|
|
816
|
+
* @returns text without emojis
|
|
817
|
+
*/
|
|
818
|
+
function removeEmojis(text) {
|
|
819
|
+
// Replace emojis (and also ZWJ sequence) with hyphens
|
|
820
|
+
text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
|
|
821
|
+
text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
|
|
822
|
+
text = text.replace(/(\p{Extended_Pictographic})(\u{200D}\p{Extended_Pictographic})*/gu, '$1');
|
|
823
|
+
text = text.replace(/\p{Extended_Pictographic}/gu, '');
|
|
824
|
+
return text;
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
/**
|
|
828
|
+
* Function normalizes title to name which can be used as identifier
|
|
829
|
+
*/
|
|
830
|
+
function titleToName(value) {
|
|
831
|
+
value = removeEmojis(value);
|
|
832
|
+
value = normalizeToKebabCase(value);
|
|
833
|
+
// TODO: [๐ง ] Maybe warn or add some padding to short name which are not good identifiers
|
|
834
|
+
return value;
|
|
835
|
+
}
|
|
836
|
+
|
|
812
837
|
/**
|
|
813
838
|
* Parse promptbook from string format to JSON format
|
|
814
839
|
*
|
|
@@ -1049,7 +1074,7 @@
|
|
|
1049
1074
|
}
|
|
1050
1075
|
dependentParameterNames = __spreadArray([], __read(new Set(dependentParameterNames)), false);
|
|
1051
1076
|
promptbookJson.promptTemplates.push({
|
|
1052
|
-
name:
|
|
1077
|
+
name: titleToName(section.title),
|
|
1053
1078
|
title: section.title,
|
|
1054
1079
|
description: description_1,
|
|
1055
1080
|
dependentParameterNames: dependentParameterNames,
|
|
@@ -1157,7 +1182,7 @@
|
|
|
1157
1182
|
if (!template) {
|
|
1158
1183
|
throw new Error("Could not find template for {".concat(parameterName, "}"));
|
|
1159
1184
|
}
|
|
1160
|
-
return 'template' +
|
|
1185
|
+
return normalizeTo_camelCase('template-' + titleToName(template.title));
|
|
1161
1186
|
};
|
|
1162
1187
|
var promptbookMermaid = spacetrim.spaceTrim(function (block) { return "\n\n %% \uD83D\uDD2E Tip: Open this on GitHub or in the VSCode website to see the Mermaid graph visually\n\n flowchart LR\n subgraph \"".concat(promptbookJson.title, "\"\n\n direction TB\n\n input((Input)):::input\n ").concat(block(promptbookJson.promptTemplates
|
|
1163
1188
|
.flatMap(function (_a) {
|
|
@@ -1178,6 +1203,7 @@
|
|
|
1178
1203
|
return "".concat(parameterNameToTemplateName(name), "--\"{").concat(name, "}\"-->output");
|
|
1179
1204
|
})
|
|
1180
1205
|
.join('\n')), "\n output((Output)):::output\n\n classDef input color: grey;\n classDef output color: grey;\n\n end;\n\n "); });
|
|
1206
|
+
// TODO: !!!!! Allow to put link callback into `renderPromptbookMermaid`
|
|
1181
1207
|
return promptbookMermaid;
|
|
1182
1208
|
}
|
|
1183
1209
|
/**
|
|
@@ -1541,11 +1567,10 @@
|
|
|
1541
1567
|
var letters = defaultDiacriticsRemovalMap[i].letters;
|
|
1542
1568
|
// tslint:disable-next-line: prefer-for-of
|
|
1543
1569
|
for (var j = 0; j < letters.length; j++) {
|
|
1544
|
-
DIACRITIC_VARIANTS_LETTERS[letters[j]] =
|
|
1545
|
-
defaultDiacriticsRemovalMap[i].base;
|
|
1570
|
+
DIACRITIC_VARIANTS_LETTERS[letters[j]] = defaultDiacriticsRemovalMap[i].base;
|
|
1546
1571
|
}
|
|
1547
1572
|
}
|
|
1548
|
-
// <- TODO:
|
|
1573
|
+
// <- TODO: [๐] Put to maker function to save execution time if not needed
|
|
1549
1574
|
/*
|
|
1550
1575
|
@see https://stackoverflow.com/questions/990904/remove-accents-diacritics-in-a-string-in-javascript
|
|
1551
1576
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
@@ -1762,21 +1787,6 @@
|
|
|
1762
1787
|
return value;
|
|
1763
1788
|
}
|
|
1764
1789
|
|
|
1765
|
-
/**
|
|
1766
|
-
* Removes emojis from a string and fix whitespaces
|
|
1767
|
-
*
|
|
1768
|
-
* @param text with emojis
|
|
1769
|
-
* @returns text without emojis
|
|
1770
|
-
*/
|
|
1771
|
-
function removeEmojis(text) {
|
|
1772
|
-
// Replace emojis (and also ZWJ sequence) with hyphens
|
|
1773
|
-
text = text.replace(/(\p{Extended_Pictographic})\p{Modifier_Symbol}/gu, '$1');
|
|
1774
|
-
text = text.replace(/(\p{Extended_Pictographic})[\u{FE00}-\u{FE0F}]/gu, '$1');
|
|
1775
|
-
text = text.replace(/(\p{Extended_Pictographic})(\u{200D}\p{Extended_Pictographic})*/gu, '$1');
|
|
1776
|
-
text = text.replace(/\p{Extended_Pictographic}/gu, '');
|
|
1777
|
-
return text;
|
|
1778
|
-
}
|
|
1779
|
-
|
|
1780
1790
|
/**
|
|
1781
1791
|
* Create a markdown table from a 2D array of strings
|
|
1782
1792
|
*
|
|
@@ -2584,6 +2594,7 @@
|
|
|
2584
2594
|
exports.replaceParameters = replaceParameters;
|
|
2585
2595
|
exports.searchKeywords = searchKeywords;
|
|
2586
2596
|
exports.splitIntoSentences = splitIntoSentences;
|
|
2597
|
+
exports.titleToName = titleToName;
|
|
2587
2598
|
exports.trimCodeBlock = trimCodeBlock;
|
|
2588
2599
|
exports.trimEndOfCodeBlock = trimEndOfCodeBlock;
|
|
2589
2600
|
exports.unwrapResult = unwrapResult;
|