@promptbook/utils 0.69.0-8 → 0.69.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 +4 -1
- package/esm/index.es.js +151 -124
- package/esm/index.es.js.map +1 -1
- package/esm/typings/promptbook-collection/index.d.ts +0 -3
- package/esm/typings/src/_packages/core.index.d.ts +12 -0
- package/esm/typings/src/_packages/types.index.d.ts +6 -0
- package/esm/typings/src/_packages/utils.index.d.ts +4 -4
- package/esm/typings/src/cli/cli-commands/make.d.ts +1 -1
- package/esm/typings/src/collection/constructors/createCollectionFromUrl.d.ts +1 -1
- package/esm/typings/src/commands/FOREACH/ForeachCommand.d.ts +1 -1
- package/esm/typings/src/commands/FOREACH/ForeachJson.d.ts +6 -5
- package/esm/typings/src/commands/FOREACH/foreachCommandParser.d.ts +1 -2
- package/esm/typings/src/commands/_common/types/CommandParser.d.ts +1 -1
- package/esm/typings/src/config.d.ts +11 -4
- package/esm/typings/src/conversion/pipelineStringToJsonSync.d.ts +1 -1
- package/esm/typings/src/conversion/prettify/renderPipelineMermaidOptions.d.ts +3 -3
- package/esm/typings/src/conversion/validation/validatePipeline.d.ts +6 -5
- package/esm/typings/src/errors/AbstractFormatError.d.ts +11 -0
- package/esm/typings/src/execution/PipelineExecutor.d.ts +1 -0
- package/esm/typings/src/execution/PipelineExecutorResult.d.ts +5 -6
- package/esm/typings/src/execution/createPipelineExecutor/$OngoingTemplateResult.d.ts +24 -0
- package/esm/typings/src/execution/createPipelineExecutor/00-CreatePipelineExecutorSettings.d.ts +7 -0
- package/esm/typings/src/execution/createPipelineExecutor/00-createPipelineExecutor.d.ts +3 -0
- package/esm/typings/src/execution/createPipelineExecutor/10-executePipeline.d.ts +4 -1
- package/esm/typings/src/execution/createPipelineExecutor/20-executeTemplate.d.ts +3 -0
- package/esm/typings/src/execution/createPipelineExecutor/{30-executeFormatCells.d.ts → 30-executeFormatSubvalues.d.ts} +2 -2
- package/esm/typings/src/execution/createPipelineExecutor/40-executeAttempts.d.ts +2 -8
- package/esm/typings/src/execution/embeddingVectorToString.d.ts +1 -1
- package/esm/typings/src/execution/utils/checkExpectations.d.ts +2 -0
- package/esm/typings/src/execution/utils/usageToHuman.d.ts +3 -4
- package/esm/typings/src/formats/_common/FormatDefinition.d.ts +14 -15
- package/esm/typings/src/formats/_common/FormatSubvalueDefinition.d.ts +31 -0
- package/esm/typings/src/formats/csv/{ListFormatDefinition.d.ts → CsvFormatDefinition.d.ts} +6 -3
- package/esm/typings/src/formats/csv/CsvFormatError.d.ts +10 -0
- package/esm/typings/src/formats/csv/CsvSettings.d.ts +13 -0
- package/esm/typings/src/formats/index.d.ts +1 -1
- package/esm/typings/src/formats/json/JsonFormatDefinition.d.ts +4 -3
- package/esm/typings/src/formats/text/TextFormatDefinition.d.ts +19 -0
- package/esm/typings/src/formats/xml/XmlFormatDefinition.d.ts +4 -3
- package/esm/typings/src/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.d.ts +1 -1
- package/esm/typings/src/knowledge/prepare-knowledge/pdf/prepareKnowledgeFromPdf.d.ts +1 -1
- package/esm/typings/src/llm-providers/_common/utils/cache/CacheItem.d.ts +1 -1
- package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +2 -1
- package/esm/typings/src/llm-providers/anthropic-claude/anthropic-claude-models.d.ts +1 -1
- package/esm/typings/src/llm-providers/anthropic-claude/createAnthropicClaudeExecutionTools.d.ts +2 -2
- package/esm/typings/src/llm-providers/anthropic-claude/playground/playground.d.ts +2 -2
- package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.d.ts +8 -1
- package/esm/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +2 -1
- package/esm/typings/src/llm-providers/openai/playground/playground.d.ts +1 -1
- package/esm/typings/src/personas/preparePersona.d.ts +1 -1
- package/esm/typings/src/prepare/isPipelinePrepared.d.ts +1 -1
- package/esm/typings/src/prepare/prepareTemplates.d.ts +1 -1
- package/esm/typings/src/types/PipelineJson/ParameterJson.d.ts +1 -1
- package/esm/typings/src/types/PipelineJson/PipelineJson.d.ts +1 -1
- package/esm/typings/src/types/execution-report/ExecutionReportJson.d.ts +0 -3
- package/esm/typings/src/types/execution-report/executionReportJsonToString.d.ts +2 -1
- package/esm/typings/src/types/typeAliases.d.ts +1 -1
- package/esm/typings/src/utils/expectation-counters/index.d.ts +3 -0
- package/esm/typings/src/utils/organization/{f.d.ts → empty_object.d.ts} +5 -1
- package/esm/typings/src/utils/organization/just_empty_object.d.ts +12 -0
- package/esm/typings/src/utils/{extractParameterNames.d.ts → parameters/extractParameterNames.d.ts} +2 -2
- package/esm/typings/src/utils/parameters/mapAvailableToExpectedParameters.d.ts +27 -0
- package/esm/typings/src/utils/{replaceParameters.d.ts → parameters/replaceParameters.d.ts} +2 -2
- package/esm/typings/src/utils/serialization/checkSerializableAsJson.d.ts +1 -1
- package/esm/typings/src/utils/serialization/isSerializableAsJson.d.ts +1 -1
- package/esm/typings/src/utils/validators/parameterName/validateParameterName.d.ts +10 -0
- package/package.json +16 -12
- package/umd/index.umd.js +151 -124
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/formats/list/ListFormatDefinition.d.ts +0 -16
- /package/esm/typings/src/utils/{extractParameterNames.test.d.ts → parameters/extractParameterNames.test.d.ts} +0 -0
- /package/esm/typings/src/{execution/utils/usageToHuman.test.d.ts → utils/parameters/mapAvailableToExpectedParameters.test.d.ts} +0 -0
- /package/esm/typings/src/utils/{replaceParameters.test.d.ts → parameters/replaceParameters.test.d.ts} +0 -0
- /package/esm/typings/src/{personas/preparePersona.test.d.ts → utils/validators/parameterName/validateParameterName.test.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -16,6 +16,10 @@ Supercharge your use of large language models
|
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
|
|
19
|
+
## ✨ New Features
|
|
20
|
+
|
|
21
|
+
- ✨ **Support of [OpenAI o1 model](https://openai.com/o1/)**
|
|
22
|
+
|
|
19
23
|
## 📦 Package `@promptbook/utils`
|
|
20
24
|
|
|
21
25
|
- Promptbooks are [divided into several](#-packages) packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
|
|
@@ -205,7 +209,6 @@ File `write-website-content.ptbk.md`:
|
|
|
205
209
|
> Instructions for creating web page content.
|
|
206
210
|
>
|
|
207
211
|
> - PIPELINE URL https://promptbook.studio/webgpt/write-website-content.ptbk.md
|
|
208
|
-
> - PROMPTBOOK VERSION 0.0.1
|
|
209
212
|
> - INPUT PARAM `{rawTitle}` Automatically suggested a site name or empty text
|
|
210
213
|
> - INPUT PARAM `{rawAssigment}` Automatically generated site entry from image recognition
|
|
211
214
|
> - OUTPUT PARAM `{websiteContent}` Web content
|
package/esm/index.es.js
CHANGED
|
@@ -4,8 +4,8 @@ import spaceTrim$1, { spaceTrim } from 'spacetrim';
|
|
|
4
4
|
/**
|
|
5
5
|
* The version of the Promptbook library
|
|
6
6
|
*/
|
|
7
|
-
var PROMPTBOOK_VERSION = '0.69.0
|
|
8
|
-
// TODO: !!!! List here all the versions and annotate + put into script
|
|
7
|
+
var PROMPTBOOK_VERSION = '0.69.0';
|
|
8
|
+
// TODO: [main] !!!! List here all the versions and annotate + put into script
|
|
9
9
|
|
|
10
10
|
/*! *****************************************************************************
|
|
11
11
|
Copyright (c) Microsoft Corporation.
|
|
@@ -625,9 +625,9 @@ function renderPromptbookMermaid(pipelineJson, options) {
|
|
|
625
625
|
return promptbookMermaid;
|
|
626
626
|
}
|
|
627
627
|
/**
|
|
628
|
-
* TODO:
|
|
629
|
-
* TODO:
|
|
630
|
-
* TODO:
|
|
628
|
+
* TODO: !!!!! FOREACH in mermaid graph
|
|
629
|
+
* TODO: !!!!! Knowledge in mermaid graph
|
|
630
|
+
* TODO: !!!!! Personas in mermaid graph
|
|
631
631
|
* TODO: Maybe use some Mermaid package instead of string templating
|
|
632
632
|
* TODO: [🕌] When more than 2 functionalities, split into separate functions
|
|
633
633
|
*/
|
|
@@ -737,47 +737,47 @@ function extractVariables(script) {
|
|
|
737
737
|
* @public exported from `@promptbook/utils`
|
|
738
738
|
*/
|
|
739
739
|
function extractParameterNamesFromTemplate(template) {
|
|
740
|
-
var e_1, _a, e_2, _b, e_3, _c;
|
|
740
|
+
var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
|
|
741
741
|
var title = template.title, description = template.description, templateType = template.templateType, content = template.content, preparedContent = template.preparedContent, jokerParameterNames = template.jokerParameterNames, foreach = template.foreach;
|
|
742
742
|
var parameterNames = new Set();
|
|
743
743
|
try {
|
|
744
|
-
for (var
|
|
745
|
-
var parameterName =
|
|
744
|
+
for (var _e = __values(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(extractParameterNames(title)), false), __read(extractParameterNames(description || '')), false), __read(extractParameterNames(content)), false), __read(extractParameterNames(preparedContent || '')), false)), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
745
|
+
var parameterName = _f.value;
|
|
746
746
|
parameterNames.add(parameterName);
|
|
747
747
|
}
|
|
748
748
|
}
|
|
749
749
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
750
750
|
finally {
|
|
751
751
|
try {
|
|
752
|
-
if (
|
|
752
|
+
if (_f && !_f.done && (_a = _e.return)) _a.call(_e);
|
|
753
753
|
}
|
|
754
754
|
finally { if (e_1) throw e_1.error; }
|
|
755
755
|
}
|
|
756
756
|
if (templateType === 'SCRIPT_TEMPLATE') {
|
|
757
757
|
try {
|
|
758
|
-
for (var
|
|
759
|
-
var parameterName =
|
|
758
|
+
for (var _g = __values(extractVariables(content)), _h = _g.next(); !_h.done; _h = _g.next()) {
|
|
759
|
+
var parameterName = _h.value;
|
|
760
760
|
parameterNames.add(parameterName);
|
|
761
761
|
}
|
|
762
762
|
}
|
|
763
763
|
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
764
764
|
finally {
|
|
765
765
|
try {
|
|
766
|
-
if (
|
|
766
|
+
if (_h && !_h.done && (_b = _g.return)) _b.call(_g);
|
|
767
767
|
}
|
|
768
768
|
finally { if (e_2) throw e_2.error; }
|
|
769
769
|
}
|
|
770
770
|
}
|
|
771
771
|
try {
|
|
772
|
-
for (var
|
|
773
|
-
var jokerName =
|
|
772
|
+
for (var _j = __values(jokerParameterNames || []), _k = _j.next(); !_k.done; _k = _j.next()) {
|
|
773
|
+
var jokerName = _k.value;
|
|
774
774
|
parameterNames.add(jokerName);
|
|
775
775
|
}
|
|
776
776
|
}
|
|
777
777
|
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
778
778
|
finally {
|
|
779
779
|
try {
|
|
780
|
-
if (
|
|
780
|
+
if (_k && !_k.done && (_c = _j.return)) _c.call(_j);
|
|
781
781
|
}
|
|
782
782
|
finally { if (e_3) throw e_3.error; }
|
|
783
783
|
}
|
|
@@ -785,10 +785,22 @@ function extractParameterNamesFromTemplate(template) {
|
|
|
785
785
|
// <- Note {websiteContent} is used in `preparedContent`
|
|
786
786
|
// Note: [🍭] Fixing dependent subparameterName from FOREACH command
|
|
787
787
|
if (foreach !== undefined) {
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
788
|
+
try {
|
|
789
|
+
for (var _l = __values(foreach.inputSubparameterNames), _m = _l.next(); !_m.done; _m = _l.next()) {
|
|
790
|
+
var subparameterName = _m.value;
|
|
791
|
+
if (parameterNames.has(subparameterName)) {
|
|
792
|
+
parameterNames.delete(subparameterName);
|
|
793
|
+
parameterNames.add(foreach.parameterName);
|
|
794
|
+
// <- TODO: [🚎] Warn/logic error when `subparameterName` not used
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
799
|
+
finally {
|
|
800
|
+
try {
|
|
801
|
+
if (_m && !_m.done && (_d = _l.return)) _d.call(_l);
|
|
802
|
+
}
|
|
803
|
+
finally { if (e_4) throw e_4.error; }
|
|
792
804
|
}
|
|
793
805
|
}
|
|
794
806
|
return parameterNames;
|
|
@@ -1275,6 +1287,9 @@ var CountUtils = {
|
|
|
1275
1287
|
LINES: countLines,
|
|
1276
1288
|
PAGES: countPages,
|
|
1277
1289
|
};
|
|
1290
|
+
/**
|
|
1291
|
+
* TODO: [🧠][🤠] This should be probbably as part of `TextFormatDefinition`
|
|
1292
|
+
*/
|
|
1278
1293
|
|
|
1279
1294
|
/**
|
|
1280
1295
|
* Makes first letter of a string uppercase
|
|
@@ -1529,108 +1544,6 @@ function searchKeywords(haystack, needle) {
|
|
|
1529
1544
|
return true;
|
|
1530
1545
|
}
|
|
1531
1546
|
|
|
1532
|
-
/**
|
|
1533
|
-
* Function parseNumber will parse number from string
|
|
1534
|
-
*
|
|
1535
|
-
* Unlike Number.parseInt, Number.parseFloat it will never ever result in NaN
|
|
1536
|
-
* Note: it also works only with decimal numbers
|
|
1537
|
-
*
|
|
1538
|
-
* @returns parsed number
|
|
1539
|
-
* @throws {ParseError} if the value is not a number
|
|
1540
|
-
*
|
|
1541
|
-
* @public exported from `@promptbook/utils`
|
|
1542
|
-
*/
|
|
1543
|
-
function parseNumber(value) {
|
|
1544
|
-
var originalValue = value;
|
|
1545
|
-
if (typeof value === 'number') {
|
|
1546
|
-
value = value.toString(); // <- TODO: Maybe more efficient way to do this
|
|
1547
|
-
}
|
|
1548
|
-
if (typeof value !== 'string') {
|
|
1549
|
-
return 0;
|
|
1550
|
-
}
|
|
1551
|
-
value = value.trim();
|
|
1552
|
-
if (value.startsWith('+')) {
|
|
1553
|
-
return parseNumber(value.substring(1));
|
|
1554
|
-
}
|
|
1555
|
-
if (value.startsWith('-')) {
|
|
1556
|
-
var number = parseNumber(value.substring(1));
|
|
1557
|
-
if (number === 0) {
|
|
1558
|
-
return 0; // <- Note: To prevent -0
|
|
1559
|
-
}
|
|
1560
|
-
return -number;
|
|
1561
|
-
}
|
|
1562
|
-
value = value.replace(/,/g, '.');
|
|
1563
|
-
value = value.toUpperCase();
|
|
1564
|
-
if (value === '') {
|
|
1565
|
-
return 0;
|
|
1566
|
-
}
|
|
1567
|
-
if (value === '♾' || value.startsWith('INF')) {
|
|
1568
|
-
return Infinity;
|
|
1569
|
-
}
|
|
1570
|
-
if (value.includes('/')) {
|
|
1571
|
-
var _a = __read(value.split('/'), 2), numerator_ = _a[0], denominator_ = _a[1];
|
|
1572
|
-
var numerator = parseNumber(numerator_);
|
|
1573
|
-
var denominator = parseNumber(denominator_);
|
|
1574
|
-
if (denominator === 0) {
|
|
1575
|
-
throw new ParseError("Unable to parse number from \"".concat(originalValue, "\" because denominator is zero"));
|
|
1576
|
-
}
|
|
1577
|
-
return numerator / denominator;
|
|
1578
|
-
}
|
|
1579
|
-
if (/^(NAN|NULL|NONE|UNDEFINED|ZERO|NO.*)$/.test(value)) {
|
|
1580
|
-
return 0;
|
|
1581
|
-
}
|
|
1582
|
-
if (value.includes('E')) {
|
|
1583
|
-
var _b = __read(value.split('E'), 2), significand = _b[0], exponent = _b[1];
|
|
1584
|
-
return parseNumber(significand) * Math.pow(10, parseNumber(exponent));
|
|
1585
|
-
}
|
|
1586
|
-
if (!/^[0-9.]+$/.test(value) || value.split('.').length > 2) {
|
|
1587
|
-
throw new ParseError("Unable to parse number from \"".concat(originalValue, "\""));
|
|
1588
|
-
}
|
|
1589
|
-
var num = parseFloat(value);
|
|
1590
|
-
if (isNaN(num)) {
|
|
1591
|
-
throw new ParseError("Unexpected NaN when parsing number from \"".concat(originalValue, "\""));
|
|
1592
|
-
}
|
|
1593
|
-
return num;
|
|
1594
|
-
}
|
|
1595
|
-
/**
|
|
1596
|
-
* TODO: Maybe use sth. like safe-eval in fraction/calculation case @see https://www.npmjs.com/package/safe-eval
|
|
1597
|
-
* TODO: [🧠][🌻] Maybe export through `@promptbook/markdown-utils` not `@promptbook/utils`
|
|
1598
|
-
*/
|
|
1599
|
-
|
|
1600
|
-
/**
|
|
1601
|
-
* Generates random seed
|
|
1602
|
-
*
|
|
1603
|
-
* Note: `$` is used to indicate that this function is not a pure function - it is not deterministic
|
|
1604
|
-
* Warning: This function is not cryptographically secure (it uses Math.random internally)
|
|
1605
|
-
* @public exported from `@promptbook/utils`
|
|
1606
|
-
*/
|
|
1607
|
-
function $randomSeed() {
|
|
1608
|
-
return Math.random();
|
|
1609
|
-
}
|
|
1610
|
-
|
|
1611
|
-
/**
|
|
1612
|
-
* Removes quotes from a string
|
|
1613
|
-
*
|
|
1614
|
-
* Tip: This is very usefull for post-processing of the result of the LLM model
|
|
1615
|
-
* Note: This function removes only the same quotes from the beginning and the end of the string
|
|
1616
|
-
* Note: There are two simmilar functions:
|
|
1617
|
-
* - `removeQuotes` which removes only bounding quotes
|
|
1618
|
-
* - `unwrapResult` which removes whole introduce sentence
|
|
1619
|
-
*
|
|
1620
|
-
* @param text optionally quoted text
|
|
1621
|
-
* @returns text without quotes
|
|
1622
|
-
* @public exported from `@promptbook/utils`
|
|
1623
|
-
*/
|
|
1624
|
-
function removeQuotes(text) {
|
|
1625
|
-
if (text.startsWith('"') && text.endsWith('"')) {
|
|
1626
|
-
return text.slice(1, -1);
|
|
1627
|
-
}
|
|
1628
|
-
if (text.startsWith('\'') && text.endsWith('\'')) {
|
|
1629
|
-
return text.slice(1, -1);
|
|
1630
|
-
}
|
|
1631
|
-
return text;
|
|
1632
|
-
}
|
|
1633
|
-
|
|
1634
1547
|
/**
|
|
1635
1548
|
* @@@
|
|
1636
1549
|
*
|
|
@@ -1784,7 +1697,7 @@ function checkSerializableAsJson(name, value) {
|
|
|
1784
1697
|
}
|
|
1785
1698
|
/**
|
|
1786
1699
|
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
1787
|
-
* TODO: [🧠] !!! In-memory cache of same values to prevent multiple checks
|
|
1700
|
+
* TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
|
|
1788
1701
|
* Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
|
|
1789
1702
|
*/
|
|
1790
1703
|
|
|
@@ -1849,6 +1762,18 @@ var RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE;
|
|
|
1849
1762
|
* @private within the repository
|
|
1850
1763
|
*/
|
|
1851
1764
|
var RESERVED_PARAMETER_RESTRICTED = 'RESTRICTED-' + REPLACING_NONCE;
|
|
1765
|
+
// <- TODO: [🧜♂️]
|
|
1766
|
+
/**
|
|
1767
|
+
* @@@
|
|
1768
|
+
*
|
|
1769
|
+
* @public exported from `@promptbook/core`
|
|
1770
|
+
*/
|
|
1771
|
+
Object.freeze({
|
|
1772
|
+
delimiter: ',',
|
|
1773
|
+
quoteChar: '"',
|
|
1774
|
+
newline: '\n',
|
|
1775
|
+
skipEmptyLines: true,
|
|
1776
|
+
});
|
|
1852
1777
|
/**
|
|
1853
1778
|
* TODO: [🧠][🧜♂️] Maybe join remoteUrl and path into single value
|
|
1854
1779
|
*/
|
|
@@ -1932,6 +1857,108 @@ function replaceParameters(template, parameters) {
|
|
|
1932
1857
|
return replacedTemplate;
|
|
1933
1858
|
}
|
|
1934
1859
|
|
|
1860
|
+
/**
|
|
1861
|
+
* Function parseNumber will parse number from string
|
|
1862
|
+
*
|
|
1863
|
+
* Unlike Number.parseInt, Number.parseFloat it will never ever result in NaN
|
|
1864
|
+
* Note: it also works only with decimal numbers
|
|
1865
|
+
*
|
|
1866
|
+
* @returns parsed number
|
|
1867
|
+
* @throws {ParseError} if the value is not a number
|
|
1868
|
+
*
|
|
1869
|
+
* @public exported from `@promptbook/utils`
|
|
1870
|
+
*/
|
|
1871
|
+
function parseNumber(value) {
|
|
1872
|
+
var originalValue = value;
|
|
1873
|
+
if (typeof value === 'number') {
|
|
1874
|
+
value = value.toString(); // <- TODO: Maybe more efficient way to do this
|
|
1875
|
+
}
|
|
1876
|
+
if (typeof value !== 'string') {
|
|
1877
|
+
return 0;
|
|
1878
|
+
}
|
|
1879
|
+
value = value.trim();
|
|
1880
|
+
if (value.startsWith('+')) {
|
|
1881
|
+
return parseNumber(value.substring(1));
|
|
1882
|
+
}
|
|
1883
|
+
if (value.startsWith('-')) {
|
|
1884
|
+
var number = parseNumber(value.substring(1));
|
|
1885
|
+
if (number === 0) {
|
|
1886
|
+
return 0; // <- Note: To prevent -0
|
|
1887
|
+
}
|
|
1888
|
+
return -number;
|
|
1889
|
+
}
|
|
1890
|
+
value = value.replace(/,/g, '.');
|
|
1891
|
+
value = value.toUpperCase();
|
|
1892
|
+
if (value === '') {
|
|
1893
|
+
return 0;
|
|
1894
|
+
}
|
|
1895
|
+
if (value === '♾' || value.startsWith('INF')) {
|
|
1896
|
+
return Infinity;
|
|
1897
|
+
}
|
|
1898
|
+
if (value.includes('/')) {
|
|
1899
|
+
var _a = __read(value.split('/'), 2), numerator_ = _a[0], denominator_ = _a[1];
|
|
1900
|
+
var numerator = parseNumber(numerator_);
|
|
1901
|
+
var denominator = parseNumber(denominator_);
|
|
1902
|
+
if (denominator === 0) {
|
|
1903
|
+
throw new ParseError("Unable to parse number from \"".concat(originalValue, "\" because denominator is zero"));
|
|
1904
|
+
}
|
|
1905
|
+
return numerator / denominator;
|
|
1906
|
+
}
|
|
1907
|
+
if (/^(NAN|NULL|NONE|UNDEFINED|ZERO|NO.*)$/.test(value)) {
|
|
1908
|
+
return 0;
|
|
1909
|
+
}
|
|
1910
|
+
if (value.includes('E')) {
|
|
1911
|
+
var _b = __read(value.split('E'), 2), significand = _b[0], exponent = _b[1];
|
|
1912
|
+
return parseNumber(significand) * Math.pow(10, parseNumber(exponent));
|
|
1913
|
+
}
|
|
1914
|
+
if (!/^[0-9.]+$/.test(value) || value.split('.').length > 2) {
|
|
1915
|
+
throw new ParseError("Unable to parse number from \"".concat(originalValue, "\""));
|
|
1916
|
+
}
|
|
1917
|
+
var num = parseFloat(value);
|
|
1918
|
+
if (isNaN(num)) {
|
|
1919
|
+
throw new ParseError("Unexpected NaN when parsing number from \"".concat(originalValue, "\""));
|
|
1920
|
+
}
|
|
1921
|
+
return num;
|
|
1922
|
+
}
|
|
1923
|
+
/**
|
|
1924
|
+
* TODO: Maybe use sth. like safe-eval in fraction/calculation case @see https://www.npmjs.com/package/safe-eval
|
|
1925
|
+
* TODO: [🧠][🌻] Maybe export through `@promptbook/markdown-utils` not `@promptbook/utils`
|
|
1926
|
+
*/
|
|
1927
|
+
|
|
1928
|
+
/**
|
|
1929
|
+
* Generates random seed
|
|
1930
|
+
*
|
|
1931
|
+
* Note: `$` is used to indicate that this function is not a pure function - it is not deterministic
|
|
1932
|
+
* Warning: This function is not cryptographically secure (it uses Math.random internally)
|
|
1933
|
+
* @public exported from `@promptbook/utils`
|
|
1934
|
+
*/
|
|
1935
|
+
function $randomSeed() {
|
|
1936
|
+
return Math.random();
|
|
1937
|
+
}
|
|
1938
|
+
|
|
1939
|
+
/**
|
|
1940
|
+
* Removes quotes from a string
|
|
1941
|
+
*
|
|
1942
|
+
* Tip: This is very usefull for post-processing of the result of the LLM model
|
|
1943
|
+
* Note: This function removes only the same quotes from the beginning and the end of the string
|
|
1944
|
+
* Note: There are two simmilar functions:
|
|
1945
|
+
* - `removeQuotes` which removes only bounding quotes
|
|
1946
|
+
* - `unwrapResult` which removes whole introduce sentence
|
|
1947
|
+
*
|
|
1948
|
+
* @param text optionally quoted text
|
|
1949
|
+
* @returns text without quotes
|
|
1950
|
+
* @public exported from `@promptbook/utils`
|
|
1951
|
+
*/
|
|
1952
|
+
function removeQuotes(text) {
|
|
1953
|
+
if (text.startsWith('"') && text.endsWith('"')) {
|
|
1954
|
+
return text.slice(1, -1);
|
|
1955
|
+
}
|
|
1956
|
+
if (text.startsWith('\'') && text.endsWith('\'')) {
|
|
1957
|
+
return text.slice(1, -1);
|
|
1958
|
+
}
|
|
1959
|
+
return text;
|
|
1960
|
+
}
|
|
1961
|
+
|
|
1935
1962
|
/**
|
|
1936
1963
|
* @@@
|
|
1937
1964
|
*
|
|
@@ -2013,7 +2040,7 @@ function isSerializableAsJson(value) {
|
|
|
2013
2040
|
}
|
|
2014
2041
|
}
|
|
2015
2042
|
/**
|
|
2016
|
-
* TODO: [🧠] !!! In-memory cache of same values to prevent multiple checks
|
|
2043
|
+
* TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
|
|
2017
2044
|
* TODO: [🧠][💺] Can be done this on type-level?
|
|
2018
2045
|
*/
|
|
2019
2046
|
|
|
@@ -2328,7 +2355,7 @@ function isValidPromptbookVersion(version) {
|
|
|
2328
2355
|
if ( /* version === '1.0.0' || */version === '2.0.0' || version === '3.0.0') {
|
|
2329
2356
|
return false;
|
|
2330
2357
|
}
|
|
2331
|
-
// <- TODO: !!! Check isValidPromptbookVersion against PROMPTBOOK_VERSIONS
|
|
2358
|
+
// <- TODO: [main] !!! Check isValidPromptbookVersion against PROMPTBOOK_VERSIONS
|
|
2332
2359
|
return true;
|
|
2333
2360
|
}
|
|
2334
2361
|
|