@promptbook/markdown-utils 0.81.0-8 → 0.81.0-9

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 CHANGED
@@ -22,7 +22,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
22
22
  * @generated
23
23
  * @see https://github.com/webgptorg/promptbook
24
24
  */
25
- var PROMPTBOOK_ENGINE_VERSION = '0.81.0-7';
25
+ var PROMPTBOOK_ENGINE_VERSION = '0.81.0-8';
26
26
  /**
27
27
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
28
28
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -2029,6 +2029,81 @@ function isPipelinePrepared(pipeline) {
2029
2029
  * - [♨] Are tasks prepared
2030
2030
  */
2031
2031
 
2032
+ /**
2033
+ * Format either small or big number
2034
+ *
2035
+ * @public exported from `@promptbook/utils`
2036
+ */
2037
+ function numberToString(value) {
2038
+ if (value === 0) {
2039
+ return '0';
2040
+ }
2041
+ else if (Number.isNaN(value)) {
2042
+ return VALUE_STRINGS.nan;
2043
+ }
2044
+ else if (value === Infinity) {
2045
+ return VALUE_STRINGS.infinity;
2046
+ }
2047
+ else if (value === -Infinity) {
2048
+ return VALUE_STRINGS.negativeInfinity;
2049
+ }
2050
+ for (var exponent = 0; exponent < 15; exponent++) {
2051
+ var factor = Math.pow(10, exponent);
2052
+ var valueRounded = Math.round(value * factor) / factor;
2053
+ if (Math.abs(value - valueRounded) / value < SMALL_NUMBER) {
2054
+ return valueRounded.toFixed(exponent);
2055
+ }
2056
+ }
2057
+ return value.toString();
2058
+ }
2059
+
2060
+ /**
2061
+ * Function `valueToString` will convert the given value to string
2062
+ * This is useful and used in the `templateParameters` function
2063
+ *
2064
+ * Note: This function is not just calling `toString` method
2065
+ * It's more complex and can handle this conversion specifically for LLM models
2066
+ * See `VALUE_STRINGS`
2067
+ *
2068
+ * Note: There are 2 similar functions
2069
+ * - `valueToString` converts value to string for LLM models as human-readable string
2070
+ * - `asSerializable` converts value to string to preserve full information to be able to convert it back
2071
+ *
2072
+ * @public exported from `@promptbook/utils`
2073
+ */
2074
+ function valueToString(value) {
2075
+ try {
2076
+ if (value === '') {
2077
+ return VALUE_STRINGS.empty;
2078
+ }
2079
+ else if (value === null) {
2080
+ return VALUE_STRINGS.null;
2081
+ }
2082
+ else if (value === undefined) {
2083
+ return VALUE_STRINGS.undefined;
2084
+ }
2085
+ else if (typeof value === 'string') {
2086
+ return value;
2087
+ }
2088
+ else if (typeof value === 'number') {
2089
+ return numberToString(value);
2090
+ }
2091
+ else if (value instanceof Date) {
2092
+ return value.toISOString();
2093
+ }
2094
+ else {
2095
+ return JSON.stringify(value);
2096
+ }
2097
+ }
2098
+ catch (error) {
2099
+ if (!(error instanceof Error)) {
2100
+ throw error;
2101
+ }
2102
+ console.error(error);
2103
+ return VALUE_STRINGS.unserializable;
2104
+ }
2105
+ }
2106
+
2032
2107
  /**
2033
2108
  * Serializes an error into a [🚉] JSON-serializable object
2034
2109
  *
@@ -4419,81 +4494,6 @@ function mapAvailableToExpectedParameters(options) {
4419
4494
  return mappedParameters;
4420
4495
  }
4421
4496
 
4422
- /**
4423
- * Format either small or big number
4424
- *
4425
- * @public exported from `@promptbook/utils`
4426
- */
4427
- function numberToString(value) {
4428
- if (value === 0) {
4429
- return '0';
4430
- }
4431
- else if (Number.isNaN(value)) {
4432
- return VALUE_STRINGS.nan;
4433
- }
4434
- else if (value === Infinity) {
4435
- return VALUE_STRINGS.infinity;
4436
- }
4437
- else if (value === -Infinity) {
4438
- return VALUE_STRINGS.negativeInfinity;
4439
- }
4440
- for (var exponent = 0; exponent < 15; exponent++) {
4441
- var factor = Math.pow(10, exponent);
4442
- var valueRounded = Math.round(value * factor) / factor;
4443
- if (Math.abs(value - valueRounded) / value < SMALL_NUMBER) {
4444
- return valueRounded.toFixed(exponent);
4445
- }
4446
- }
4447
- return value.toString();
4448
- }
4449
-
4450
- /**
4451
- * Function `valueToString` will convert the given value to string
4452
- * This is useful and used in the `templateParameters` function
4453
- *
4454
- * Note: This function is not just calling `toString` method
4455
- * It's more complex and can handle this conversion specifically for LLM models
4456
- * See `VALUE_STRINGS`
4457
- *
4458
- * Note: There are 2 similar functions
4459
- * - `valueToString` converts value to string for LLM models as human-readable string
4460
- * - `asSerializable` converts value to string to preserve full information to be able to convert it back
4461
- *
4462
- * @public exported from `@promptbook/utils`
4463
- */
4464
- function valueToString(value) {
4465
- try {
4466
- if (value === '') {
4467
- return VALUE_STRINGS.empty;
4468
- }
4469
- else if (value === null) {
4470
- return VALUE_STRINGS.null;
4471
- }
4472
- else if (value === undefined) {
4473
- return VALUE_STRINGS.undefined;
4474
- }
4475
- else if (typeof value === 'string') {
4476
- return value;
4477
- }
4478
- else if (typeof value === 'number') {
4479
- return numberToString(value);
4480
- }
4481
- else if (value instanceof Date) {
4482
- return value.toISOString();
4483
- }
4484
- else {
4485
- return JSON.stringify(value);
4486
- }
4487
- }
4488
- catch (error) {
4489
- if (!(error instanceof Error)) {
4490
- throw error;
4491
- }
4492
- console.error(error);
4493
- return VALUE_STRINGS.unserializable;
4494
- }
4495
- }
4496
-
4497
4497
  /**
4498
4498
  * Replaces parameters in template with values from parameters object
4499
4499
  *
@@ -5609,7 +5609,10 @@ function executePipeline(options) {
5609
5609
  finally { if (e_2) throw e_2.error; }
5610
5610
  return [7 /*endfinally*/];
5611
5611
  case 19:
5612
- parametersToPass = inputParameters;
5612
+ parametersToPass = Object.fromEntries(Object.entries(inputParameters).map(function (_a) {
5613
+ var _b = __read(_a, 2), key = _b[0], value = _b[1];
5614
+ return [key, valueToString(value)];
5615
+ }));
5613
5616
  _g.label = 20;
5614
5617
  case 20:
5615
5618
  _g.trys.push([20, 25, , 28]);