@promptbook/utils 0.72.0-0 → 0.72.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 +5 -6
- package/esm/index.es.js +153 -114
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/cli.index.d.ts +4 -0
- package/esm/typings/src/_packages/core.index.d.ts +11 -1
- package/esm/typings/src/_packages/openai.index.d.ts +4 -0
- package/esm/typings/src/_packages/types.index.d.ts +12 -0
- package/esm/typings/src/_packages/utils.index.d.ts +4 -4
- package/esm/typings/src/commands/FOREACH/ForeachCommand.d.ts +3 -2
- package/esm/typings/src/commands/FOREACH/ForeachJson.d.ts +23 -0
- package/esm/typings/src/commands/FOREACH/foreachCommandParser.d.ts +1 -1
- package/esm/typings/src/commands/_common/types/CommandParser.d.ts +16 -1
- package/esm/typings/src/config.d.ts +14 -1
- package/esm/typings/src/conversion/prettify/renderPipelineMermaidOptions.d.ts +3 -0
- package/esm/typings/src/conversion/utils/extractParameterNamesFromTemplate.d.ts +2 -1
- package/esm/typings/src/conversion/validation/validatePipeline.d.ts +5 -0
- package/esm/typings/src/execution/PipelineExecutorResult.d.ts +9 -8
- package/esm/typings/src/execution/createPipelineExecutor/$OngoingTemplateResult.d.ts +45 -0
- package/esm/typings/src/execution/createPipelineExecutor/00-CreatePipelineExecutorOptions.d.ts +20 -0
- package/esm/typings/src/execution/createPipelineExecutor/00-CreatePipelineExecutorSettings.d.ts +40 -0
- package/esm/typings/src/execution/createPipelineExecutor/00-createPipelineExecutor.d.ts +10 -0
- package/esm/typings/src/execution/createPipelineExecutor/10-executePipeline.d.ts +55 -0
- package/esm/typings/src/execution/createPipelineExecutor/20-executeTemplate.d.ts +62 -0
- package/esm/typings/src/execution/createPipelineExecutor/30-executeFormatCells.d.ts +19 -0
- package/esm/typings/src/execution/createPipelineExecutor/40-executeAttempts.d.ts +74 -0
- package/esm/typings/src/execution/createPipelineExecutor/filterJustOutputParameters.d.ts +34 -0
- package/esm/typings/src/execution/createPipelineExecutor/getContextForTemplate.d.ts +10 -0
- package/esm/typings/src/execution/createPipelineExecutor/getKnowledgeForTemplate.d.ts +27 -0
- package/esm/typings/src/execution/createPipelineExecutor/getReservedParametersForTemplate.d.ts +30 -0
- package/esm/typings/src/execution/createPipelineExecutor/getSamplesForTemplate.d.ts +10 -0
- 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 +30 -0
- package/esm/typings/src/formats/csv/{ListFormatDefinition.d.ts → CsvFormatDefinition.d.ts} +6 -3
- 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/llm-providers/openai/OpenAiAssistantExecutionTools.d.ts +1 -1
- package/esm/typings/src/llm-providers/openai/OpenAiAssistantExecutionToolsOptions.d.ts +1 -1
- package/esm/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +9 -0
- package/esm/typings/src/llm-providers/openai/createOpenAiAssistantExecutionTools.d.ts +15 -0
- package/esm/typings/src/llm-providers/openai/register-configuration.d.ts +9 -0
- package/esm/typings/src/llm-providers/openai/register-constructor.d.ts +9 -0
- package/esm/typings/src/types/PipelineJson/ParameterJson.d.ts +1 -0
- package/esm/typings/src/types/PipelineJson/TemplateJsonCommon.d.ts +5 -0
- package/esm/typings/src/types/execution-report/ExecutionReportJson.d.ts +3 -0
- 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/validators/parameterName/validateParameterName.d.ts +10 -0
- package/esm/typings/src/utils/validators/parameterName/validateParameterName.test.d.ts +1 -0
- package/package.json +16 -12
- package/umd/index.umd.js +153 -114
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/execution/createPipelineExecutor.d.ts +0 -72
- 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/umd/index.umd.js
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
/**
|
|
13
13
|
* The version of the Promptbook library
|
|
14
14
|
*/
|
|
15
|
-
var PROMPTBOOK_VERSION = '0.
|
|
15
|
+
var PROMPTBOOK_VERSION = '0.72.0-0';
|
|
16
16
|
// TODO:[main] !!!! List here all the versions and annotate + put into script
|
|
17
17
|
|
|
18
18
|
/*! *****************************************************************************
|
|
@@ -633,6 +633,9 @@
|
|
|
633
633
|
return promptbookMermaid;
|
|
634
634
|
}
|
|
635
635
|
/**
|
|
636
|
+
* TODO: !!!!! FOREACH in mermaid graph
|
|
637
|
+
* TODO: !!!!! Knowledge in mermaid graph
|
|
638
|
+
* TODO: !!!!! Personas in mermaid graph
|
|
636
639
|
* TODO: Maybe use some Mermaid package instead of string templating
|
|
637
640
|
* TODO: [🕌] When more than 2 functionalities, split into separate functions
|
|
638
641
|
*/
|
|
@@ -742,52 +745,72 @@
|
|
|
742
745
|
* @public exported from `@promptbook/utils`
|
|
743
746
|
*/
|
|
744
747
|
function extractParameterNamesFromTemplate(template) {
|
|
745
|
-
var e_1, _a, e_2, _b, e_3, _c;
|
|
746
|
-
var title = template.title, description = template.description, templateType = template.templateType, content = template.content, preparedContent = template.preparedContent, jokerParameterNames = template.jokerParameterNames;
|
|
748
|
+
var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
|
|
749
|
+
var title = template.title, description = template.description, templateType = template.templateType, content = template.content, preparedContent = template.preparedContent, jokerParameterNames = template.jokerParameterNames, foreach = template.foreach;
|
|
747
750
|
var parameterNames = new Set();
|
|
748
751
|
try {
|
|
749
|
-
for (var
|
|
750
|
-
var parameterName =
|
|
752
|
+
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()) {
|
|
753
|
+
var parameterName = _f.value;
|
|
751
754
|
parameterNames.add(parameterName);
|
|
752
755
|
}
|
|
753
756
|
}
|
|
754
757
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
755
758
|
finally {
|
|
756
759
|
try {
|
|
757
|
-
if (
|
|
760
|
+
if (_f && !_f.done && (_a = _e.return)) _a.call(_e);
|
|
758
761
|
}
|
|
759
762
|
finally { if (e_1) throw e_1.error; }
|
|
760
763
|
}
|
|
761
764
|
if (templateType === 'SCRIPT_TEMPLATE') {
|
|
762
765
|
try {
|
|
763
|
-
for (var
|
|
764
|
-
var parameterName =
|
|
766
|
+
for (var _g = __values(extractVariables(content)), _h = _g.next(); !_h.done; _h = _g.next()) {
|
|
767
|
+
var parameterName = _h.value;
|
|
765
768
|
parameterNames.add(parameterName);
|
|
766
769
|
}
|
|
767
770
|
}
|
|
768
771
|
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
769
772
|
finally {
|
|
770
773
|
try {
|
|
771
|
-
if (
|
|
774
|
+
if (_h && !_h.done && (_b = _g.return)) _b.call(_g);
|
|
772
775
|
}
|
|
773
776
|
finally { if (e_2) throw e_2.error; }
|
|
774
777
|
}
|
|
775
778
|
}
|
|
776
779
|
try {
|
|
777
|
-
for (var
|
|
778
|
-
var jokerName =
|
|
780
|
+
for (var _j = __values(jokerParameterNames || []), _k = _j.next(); !_k.done; _k = _j.next()) {
|
|
781
|
+
var jokerName = _k.value;
|
|
779
782
|
parameterNames.add(jokerName);
|
|
780
783
|
}
|
|
781
784
|
}
|
|
782
785
|
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
783
786
|
finally {
|
|
784
787
|
try {
|
|
785
|
-
if (
|
|
788
|
+
if (_k && !_k.done && (_c = _j.return)) _c.call(_j);
|
|
786
789
|
}
|
|
787
790
|
finally { if (e_3) throw e_3.error; }
|
|
788
791
|
}
|
|
789
792
|
parameterNames.delete('content');
|
|
790
793
|
// <- Note {websiteContent} is used in `preparedContent`
|
|
794
|
+
// Note: [🍭] Fixing dependent subparameterName from FOREACH command
|
|
795
|
+
if (foreach !== undefined) {
|
|
796
|
+
try {
|
|
797
|
+
for (var _l = __values(foreach.subparameterNames), _m = _l.next(); !_m.done; _m = _l.next()) {
|
|
798
|
+
var subparameterName = _m.value;
|
|
799
|
+
if (parameterNames.has(subparameterName)) {
|
|
800
|
+
parameterNames.delete(subparameterName);
|
|
801
|
+
parameterNames.add(foreach.parameterName);
|
|
802
|
+
// <- TODO: [🚎] Warn/logic error when `subparameterName` not used
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
807
|
+
finally {
|
|
808
|
+
try {
|
|
809
|
+
if (_m && !_m.done && (_d = _l.return)) _d.call(_l);
|
|
810
|
+
}
|
|
811
|
+
finally { if (e_4) throw e_4.error; }
|
|
812
|
+
}
|
|
813
|
+
}
|
|
791
814
|
return parameterNames;
|
|
792
815
|
}
|
|
793
816
|
/**
|
|
@@ -1272,6 +1295,9 @@
|
|
|
1272
1295
|
LINES: countLines,
|
|
1273
1296
|
PAGES: countPages,
|
|
1274
1297
|
};
|
|
1298
|
+
/**
|
|
1299
|
+
* TODO: [🧠][🤠] This should be probbably as part of `TextFormatDefinition`
|
|
1300
|
+
*/
|
|
1275
1301
|
|
|
1276
1302
|
/**
|
|
1277
1303
|
* Makes first letter of a string uppercase
|
|
@@ -1526,108 +1552,6 @@
|
|
|
1526
1552
|
return true;
|
|
1527
1553
|
}
|
|
1528
1554
|
|
|
1529
|
-
/**
|
|
1530
|
-
* Function parseNumber will parse number from string
|
|
1531
|
-
*
|
|
1532
|
-
* Unlike Number.parseInt, Number.parseFloat it will never ever result in NaN
|
|
1533
|
-
* Note: it also works only with decimal numbers
|
|
1534
|
-
*
|
|
1535
|
-
* @returns parsed number
|
|
1536
|
-
* @throws {ParseError} if the value is not a number
|
|
1537
|
-
*
|
|
1538
|
-
* @public exported from `@promptbook/utils`
|
|
1539
|
-
*/
|
|
1540
|
-
function parseNumber(value) {
|
|
1541
|
-
var originalValue = value;
|
|
1542
|
-
if (typeof value === 'number') {
|
|
1543
|
-
value = value.toString(); // <- TODO: Maybe more efficient way to do this
|
|
1544
|
-
}
|
|
1545
|
-
if (typeof value !== 'string') {
|
|
1546
|
-
return 0;
|
|
1547
|
-
}
|
|
1548
|
-
value = value.trim();
|
|
1549
|
-
if (value.startsWith('+')) {
|
|
1550
|
-
return parseNumber(value.substring(1));
|
|
1551
|
-
}
|
|
1552
|
-
if (value.startsWith('-')) {
|
|
1553
|
-
var number = parseNumber(value.substring(1));
|
|
1554
|
-
if (number === 0) {
|
|
1555
|
-
return 0; // <- Note: To prevent -0
|
|
1556
|
-
}
|
|
1557
|
-
return -number;
|
|
1558
|
-
}
|
|
1559
|
-
value = value.replace(/,/g, '.');
|
|
1560
|
-
value = value.toUpperCase();
|
|
1561
|
-
if (value === '') {
|
|
1562
|
-
return 0;
|
|
1563
|
-
}
|
|
1564
|
-
if (value === '♾' || value.startsWith('INF')) {
|
|
1565
|
-
return Infinity;
|
|
1566
|
-
}
|
|
1567
|
-
if (value.includes('/')) {
|
|
1568
|
-
var _a = __read(value.split('/'), 2), numerator_ = _a[0], denominator_ = _a[1];
|
|
1569
|
-
var numerator = parseNumber(numerator_);
|
|
1570
|
-
var denominator = parseNumber(denominator_);
|
|
1571
|
-
if (denominator === 0) {
|
|
1572
|
-
throw new ParseError("Unable to parse number from \"".concat(originalValue, "\" because denominator is zero"));
|
|
1573
|
-
}
|
|
1574
|
-
return numerator / denominator;
|
|
1575
|
-
}
|
|
1576
|
-
if (/^(NAN|NULL|NONE|UNDEFINED|ZERO|NO.*)$/.test(value)) {
|
|
1577
|
-
return 0;
|
|
1578
|
-
}
|
|
1579
|
-
if (value.includes('E')) {
|
|
1580
|
-
var _b = __read(value.split('E'), 2), significand = _b[0], exponent = _b[1];
|
|
1581
|
-
return parseNumber(significand) * Math.pow(10, parseNumber(exponent));
|
|
1582
|
-
}
|
|
1583
|
-
if (!/^[0-9.]+$/.test(value) || value.split('.').length > 2) {
|
|
1584
|
-
throw new ParseError("Unable to parse number from \"".concat(originalValue, "\""));
|
|
1585
|
-
}
|
|
1586
|
-
var num = parseFloat(value);
|
|
1587
|
-
if (isNaN(num)) {
|
|
1588
|
-
throw new ParseError("Unexpected NaN when parsing number from \"".concat(originalValue, "\""));
|
|
1589
|
-
}
|
|
1590
|
-
return num;
|
|
1591
|
-
}
|
|
1592
|
-
/**
|
|
1593
|
-
* TODO: Maybe use sth. like safe-eval in fraction/calculation case @see https://www.npmjs.com/package/safe-eval
|
|
1594
|
-
* TODO: [🧠][🌻] Maybe export through `@promptbook/markdown-utils` not `@promptbook/utils`
|
|
1595
|
-
*/
|
|
1596
|
-
|
|
1597
|
-
/**
|
|
1598
|
-
* Generates random seed
|
|
1599
|
-
*
|
|
1600
|
-
* Note: `$` is used to indicate that this function is not a pure function - it is not deterministic
|
|
1601
|
-
* Warning: This function is not cryptographically secure (it uses Math.random internally)
|
|
1602
|
-
* @public exported from `@promptbook/utils`
|
|
1603
|
-
*/
|
|
1604
|
-
function $randomSeed() {
|
|
1605
|
-
return Math.random();
|
|
1606
|
-
}
|
|
1607
|
-
|
|
1608
|
-
/**
|
|
1609
|
-
* Removes quotes from a string
|
|
1610
|
-
*
|
|
1611
|
-
* Tip: This is very usefull for post-processing of the result of the LLM model
|
|
1612
|
-
* Note: This function removes only the same quotes from the beginning and the end of the string
|
|
1613
|
-
* Note: There are two simmilar functions:
|
|
1614
|
-
* - `removeQuotes` which removes only bounding quotes
|
|
1615
|
-
* - `unwrapResult` which removes whole introduce sentence
|
|
1616
|
-
*
|
|
1617
|
-
* @param text optionally quoted text
|
|
1618
|
-
* @returns text without quotes
|
|
1619
|
-
* @public exported from `@promptbook/utils`
|
|
1620
|
-
*/
|
|
1621
|
-
function removeQuotes(text) {
|
|
1622
|
-
if (text.startsWith('"') && text.endsWith('"')) {
|
|
1623
|
-
return text.slice(1, -1);
|
|
1624
|
-
}
|
|
1625
|
-
if (text.startsWith('\'') && text.endsWith('\'')) {
|
|
1626
|
-
return text.slice(1, -1);
|
|
1627
|
-
}
|
|
1628
|
-
return text;
|
|
1629
|
-
}
|
|
1630
|
-
|
|
1631
1555
|
/**
|
|
1632
1556
|
* @@@
|
|
1633
1557
|
*
|
|
@@ -1830,6 +1754,7 @@
|
|
|
1830
1754
|
'samples',
|
|
1831
1755
|
'modelName',
|
|
1832
1756
|
'currentDate',
|
|
1757
|
+
// <- TODO: !!!!! list here all command names
|
|
1833
1758
|
// <- TODO: Add more like 'date', 'modelName',...
|
|
1834
1759
|
// <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
|
|
1835
1760
|
]);
|
|
@@ -1845,6 +1770,18 @@
|
|
|
1845
1770
|
* @private within the repository
|
|
1846
1771
|
*/
|
|
1847
1772
|
var RESERVED_PARAMETER_RESTRICTED = 'RESTRICTED-' + REPLACING_NONCE;
|
|
1773
|
+
// <- TODO: [🧜♂️]
|
|
1774
|
+
/**
|
|
1775
|
+
* @@@
|
|
1776
|
+
*
|
|
1777
|
+
* @public exported from `@promptbook/core`
|
|
1778
|
+
*/
|
|
1779
|
+
Object.freeze({
|
|
1780
|
+
delimiter: ',',
|
|
1781
|
+
quoteChar: '"',
|
|
1782
|
+
newline: '\n',
|
|
1783
|
+
skipEmptyLines: true,
|
|
1784
|
+
});
|
|
1848
1785
|
/**
|
|
1849
1786
|
* TODO: [🧠][🧜♂️] Maybe join remoteUrl and path into single value
|
|
1850
1787
|
*/
|
|
@@ -1928,6 +1865,108 @@
|
|
|
1928
1865
|
return replacedTemplate;
|
|
1929
1866
|
}
|
|
1930
1867
|
|
|
1868
|
+
/**
|
|
1869
|
+
* Function parseNumber will parse number from string
|
|
1870
|
+
*
|
|
1871
|
+
* Unlike Number.parseInt, Number.parseFloat it will never ever result in NaN
|
|
1872
|
+
* Note: it also works only with decimal numbers
|
|
1873
|
+
*
|
|
1874
|
+
* @returns parsed number
|
|
1875
|
+
* @throws {ParseError} if the value is not a number
|
|
1876
|
+
*
|
|
1877
|
+
* @public exported from `@promptbook/utils`
|
|
1878
|
+
*/
|
|
1879
|
+
function parseNumber(value) {
|
|
1880
|
+
var originalValue = value;
|
|
1881
|
+
if (typeof value === 'number') {
|
|
1882
|
+
value = value.toString(); // <- TODO: Maybe more efficient way to do this
|
|
1883
|
+
}
|
|
1884
|
+
if (typeof value !== 'string') {
|
|
1885
|
+
return 0;
|
|
1886
|
+
}
|
|
1887
|
+
value = value.trim();
|
|
1888
|
+
if (value.startsWith('+')) {
|
|
1889
|
+
return parseNumber(value.substring(1));
|
|
1890
|
+
}
|
|
1891
|
+
if (value.startsWith('-')) {
|
|
1892
|
+
var number = parseNumber(value.substring(1));
|
|
1893
|
+
if (number === 0) {
|
|
1894
|
+
return 0; // <- Note: To prevent -0
|
|
1895
|
+
}
|
|
1896
|
+
return -number;
|
|
1897
|
+
}
|
|
1898
|
+
value = value.replace(/,/g, '.');
|
|
1899
|
+
value = value.toUpperCase();
|
|
1900
|
+
if (value === '') {
|
|
1901
|
+
return 0;
|
|
1902
|
+
}
|
|
1903
|
+
if (value === '♾' || value.startsWith('INF')) {
|
|
1904
|
+
return Infinity;
|
|
1905
|
+
}
|
|
1906
|
+
if (value.includes('/')) {
|
|
1907
|
+
var _a = __read(value.split('/'), 2), numerator_ = _a[0], denominator_ = _a[1];
|
|
1908
|
+
var numerator = parseNumber(numerator_);
|
|
1909
|
+
var denominator = parseNumber(denominator_);
|
|
1910
|
+
if (denominator === 0) {
|
|
1911
|
+
throw new ParseError("Unable to parse number from \"".concat(originalValue, "\" because denominator is zero"));
|
|
1912
|
+
}
|
|
1913
|
+
return numerator / denominator;
|
|
1914
|
+
}
|
|
1915
|
+
if (/^(NAN|NULL|NONE|UNDEFINED|ZERO|NO.*)$/.test(value)) {
|
|
1916
|
+
return 0;
|
|
1917
|
+
}
|
|
1918
|
+
if (value.includes('E')) {
|
|
1919
|
+
var _b = __read(value.split('E'), 2), significand = _b[0], exponent = _b[1];
|
|
1920
|
+
return parseNumber(significand) * Math.pow(10, parseNumber(exponent));
|
|
1921
|
+
}
|
|
1922
|
+
if (!/^[0-9.]+$/.test(value) || value.split('.').length > 2) {
|
|
1923
|
+
throw new ParseError("Unable to parse number from \"".concat(originalValue, "\""));
|
|
1924
|
+
}
|
|
1925
|
+
var num = parseFloat(value);
|
|
1926
|
+
if (isNaN(num)) {
|
|
1927
|
+
throw new ParseError("Unexpected NaN when parsing number from \"".concat(originalValue, "\""));
|
|
1928
|
+
}
|
|
1929
|
+
return num;
|
|
1930
|
+
}
|
|
1931
|
+
/**
|
|
1932
|
+
* TODO: Maybe use sth. like safe-eval in fraction/calculation case @see https://www.npmjs.com/package/safe-eval
|
|
1933
|
+
* TODO: [🧠][🌻] Maybe export through `@promptbook/markdown-utils` not `@promptbook/utils`
|
|
1934
|
+
*/
|
|
1935
|
+
|
|
1936
|
+
/**
|
|
1937
|
+
* Generates random seed
|
|
1938
|
+
*
|
|
1939
|
+
* Note: `$` is used to indicate that this function is not a pure function - it is not deterministic
|
|
1940
|
+
* Warning: This function is not cryptographically secure (it uses Math.random internally)
|
|
1941
|
+
* @public exported from `@promptbook/utils`
|
|
1942
|
+
*/
|
|
1943
|
+
function $randomSeed() {
|
|
1944
|
+
return Math.random();
|
|
1945
|
+
}
|
|
1946
|
+
|
|
1947
|
+
/**
|
|
1948
|
+
* Removes quotes from a string
|
|
1949
|
+
*
|
|
1950
|
+
* Tip: This is very usefull for post-processing of the result of the LLM model
|
|
1951
|
+
* Note: This function removes only the same quotes from the beginning and the end of the string
|
|
1952
|
+
* Note: There are two simmilar functions:
|
|
1953
|
+
* - `removeQuotes` which removes only bounding quotes
|
|
1954
|
+
* - `unwrapResult` which removes whole introduce sentence
|
|
1955
|
+
*
|
|
1956
|
+
* @param text optionally quoted text
|
|
1957
|
+
* @returns text without quotes
|
|
1958
|
+
* @public exported from `@promptbook/utils`
|
|
1959
|
+
*/
|
|
1960
|
+
function removeQuotes(text) {
|
|
1961
|
+
if (text.startsWith('"') && text.endsWith('"')) {
|
|
1962
|
+
return text.slice(1, -1);
|
|
1963
|
+
}
|
|
1964
|
+
if (text.startsWith('\'') && text.endsWith('\'')) {
|
|
1965
|
+
return text.slice(1, -1);
|
|
1966
|
+
}
|
|
1967
|
+
return text;
|
|
1968
|
+
}
|
|
1969
|
+
|
|
1931
1970
|
/**
|
|
1932
1971
|
* @@@
|
|
1933
1972
|
*
|