@promptbook/openai 0.81.0-5 → 0.81.0-7

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.
@@ -18,6 +18,11 @@ export declare const HIGH_LEVEL_ABSTRACTIONS: readonly [{
18
18
  readonly knowledgePieces: import("../_packages/types.index").KnowledgePiecePreparedJson[];
19
19
  readonly personas: (import("../_packages/types.index").PersonaJson | import("../_packages/types.index").PersonaPreparedJson)[];
20
20
  readonly preparations: import("../_packages/types.index").PreparationJson[];
21
+ readonly sources: readonly {
22
+ type: "BOOK";
23
+ path: string | null;
24
+ content: import("../pipeline/PipelineString").PipelineString;
25
+ }[];
21
26
  readonly formfactorName?: "CHATBOT" | "GENERATOR" | "GENERIC" | "EXPERIMENTAL_MATCHER" | "SHEETS" | "TRANSLATOR" | undefined;
22
27
  }>): void;
23
28
  }, {
@@ -35,6 +40,11 @@ export declare const HIGH_LEVEL_ABSTRACTIONS: readonly [{
35
40
  readonly knowledgePieces: import("../_packages/types.index").KnowledgePiecePreparedJson[];
36
41
  readonly personas: (import("../_packages/types.index").PersonaJson | import("../_packages/types.index").PersonaPreparedJson)[];
37
42
  readonly preparations: import("../_packages/types.index").PreparationJson[];
43
+ readonly sources: readonly {
44
+ type: "BOOK";
45
+ path: string | null;
46
+ content: import("../pipeline/PipelineString").PipelineString;
47
+ }[];
38
48
  readonly formfactorName?: "CHATBOT" | "GENERATOR" | "GENERIC" | "EXPERIMENTAL_MATCHER" | "SHEETS" | "TRANSLATOR" | undefined;
39
49
  }>): void;
40
50
  }];
@@ -0,0 +1,12 @@
1
+ import type { string_formfactor_name } from '../../formfactors/_common/string_formfactor_name';
2
+ import type { PipelineJson } from '../../pipeline/PipelineJson/PipelineJson';
3
+ /**
4
+ * Get template for new book
5
+ *
6
+ * @public exported from `@promptbook/templates`
7
+ */
8
+ export declare function getBookTemplate(formfactorName: string_formfactor_name): Promise<PipelineJson | null>;
9
+ /**
10
+ * TODO: [🧠] Which is the best place for this function
11
+ * TODO: !!!!!! `book string template notation
12
+ */
@@ -0,0 +1,10 @@
1
+ import type { PipelineCollection } from '../../collection/PipelineCollection';
2
+ /**
3
+ * Get pipeline collection for Untitled Promptbook project
4
+ *
5
+ * ⚠️ WARNING: This code has been generated by `@promptbook/cli` so that any manual changes will be overwritten
6
+ *
7
+ * @generated
8
+ * @returns {PipelineCollection} Library of promptbooks for Untitled Promptbook project
9
+ */
10
+ export declare function getTemplatesPipelineCollection(): PipelineCollection;
@@ -3,7 +3,9 @@ import type { ModelRequirements } from '../../types/ModelRequirements';
3
3
  import type { string_filename } from '../../types/typeAliases';
4
4
  import type { string_markdown_text } from '../../types/typeAliases';
5
5
  import type { string_pipeline_url } from '../../types/typeAliases';
6
+ import type { string_relative_filename } from '../../types/typeAliases';
6
7
  import type { string_semantic_version } from '../../types/typeAliases';
8
+ import type { PipelineString } from '../PipelineString';
7
9
  import type { KnowledgePiecePreparedJson } from './KnowledgePieceJson';
8
10
  import type { KnowledgeSourceJson } from './KnowledgeSourceJson';
9
11
  import type { KnowledgeSourcePreparedJson } from './KnowledgeSourceJson';
@@ -91,6 +93,14 @@ export type PipelineJson = {
91
93
  * @see https://github.com/webgptorg/promptbook/discussions/78
92
94
  */
93
95
  readonly preparations: Array<PreparationJson>;
96
+ /**
97
+ * Backup of the original book source
98
+ */
99
+ readonly sources: ReadonlyArray<{
100
+ type: 'BOOK';
101
+ path: string_relative_filename | null;
102
+ content: PipelineString;
103
+ }>;
94
104
  };
95
105
  /**
96
106
  * TODO: [🛳] Default PERSONA for the pipeline `defaultPersonaName` (same as `defaultModelRequirements`)
@@ -1,8 +1,6 @@
1
1
  import type { ErrorJson } from '../../../errors/utils/ErrorJson';
2
2
  import type { PipelineJson } from '../../../pipeline/PipelineJson/PipelineJson';
3
3
  import type { string_date_iso8601 } from '../../../types/typeAliases';
4
- import type { string_pipeline_url } from '../../../types/typeAliases';
5
- import type { PipelineString } from '../../../pipeline/PipelineString';
6
4
  /**
7
5
  * Represents a single pipeline in PromptbookStudio
8
6
  *
@@ -22,19 +20,6 @@ export type PipelineEditableSerialized = PipelineJson & {
22
20
  * When was the pipeline last modified
23
21
  */
24
22
  readonly updatedAt: string_date_iso8601 | null;
25
- /**
26
- * Unique identifier of the pipeline
27
- *
28
- * Note: In PromptbookStudio it is required
29
- */
30
- readonly pipelineUrl: string_pipeline_url;
31
- /**
32
- * Backup of the pipeline string
33
- *
34
- * Note: This is present ONLY if pipelineString can not be automatically converted into json (i.e. compilePipeline throws an error)
35
- * In other words, this is just a BACKUP of pipeline which will be deleted whener pipeline is valid again
36
- */
37
- readonly pipelineString: PipelineString | string | null;
38
23
  /**
39
24
  * Known errors to transfer to new PipelineEditable
40
25
  */
@@ -0,0 +1,7 @@
1
+ import type { string_parameter_value } from '../../types/typeAliases';
2
+ /**
3
+ * Format either small or big number
4
+ *
5
+ * @public exported from `@promptbook/utils`
6
+ */
7
+ export declare function numberToString(value: number): string_parameter_value;
@@ -1,12 +1,16 @@
1
- import type { Parameters } from '../../types/typeAliases';
1
+ import type { string_parameter_name } from '../../types/typeAliases';
2
2
  import type { string_template } from '../../types/typeAliases';
3
+ import type { really_unknown } from '../organization/really_unknown';
3
4
  /**
4
5
  * Replaces parameters in template with values from parameters object
5
6
  *
7
+ * Note: This function is not places strings into string,
8
+ * It's more complex and can handle this operation specifically for LLM models
9
+ *
6
10
  * @param template the template with parameters in {curly} braces
7
11
  * @param parameters the object with parameters
8
12
  * @returns the template with replaced parameters
9
13
  * @throws {PipelineExecutionError} if parameter is not defined, not closed, or not opened
10
14
  * @public exported from `@promptbook/utils`
11
15
  */
12
- export declare function templateParameters(template: string_template, parameters: Parameters): string;
16
+ export declare function templateParameters(template: string_template, parameters: Record<string_parameter_name, really_unknown>): string;
@@ -0,0 +1,17 @@
1
+ import type { string_parameter_value } from '../../types/typeAliases';
2
+ import type { really_unknown } from '../organization/really_unknown';
3
+ /**
4
+ * Function `valueToString` will convert the given value to string
5
+ * This is useful and used in the `templateParameters` function
6
+ *
7
+ * Note: This function is not just calling `toString` method
8
+ * It's more complex and can handle this conversion specifically for LLM models
9
+ * See `VALUE_STRINGS`
10
+ *
11
+ * Note: There are 2 similar functions
12
+ * - `valueToString` converts value to string for LLM models as human-readable string
13
+ * - `asSerializable` converts value to string to preserve full information to be able to convert it back
14
+ *
15
+ * @public exported from `@promptbook/utils`
16
+ */
17
+ export declare function valueToString(value: really_unknown): string_parameter_value;
@@ -6,6 +6,10 @@ import type { really_any } from '../organization/really_any';
6
6
  * For example:
7
7
  * - `Date` objects will be converted to string
8
8
  *
9
+ * Note: There are 2 similar functions
10
+ * - `valueToString` converts value to string for LLM models as human-readable string
11
+ * - `asSerializable` converts value to string to preserve full information to be able to convert it back
12
+ *
9
13
  * @private Internal helper function
10
14
  */
11
15
  export declare function asSerializable(value: really_any): really_any;
@@ -2,15 +2,22 @@ import type { string_semantic_version } from './types/typeAliases';
2
2
  /**
3
3
  * The version of the Book language
4
4
  *
5
+ * @generated
5
6
  * @see https://github.com/webgptorg/book
6
7
  */
7
8
  export declare const BOOK_LANGUAGE_VERSION: string_semantic_version;
8
9
  /**
9
10
  * The version of the Promptbook engine
10
11
  *
12
+ * @generated
11
13
  * @see https://github.com/webgptorg/promptbook
12
14
  */
13
15
  export declare const PROMPTBOOK_ENGINE_VERSION: string_promptbook_version;
16
+ /**
17
+ * @@@
18
+ *
19
+ * @generated
20
+ */
14
21
  export type string_promptbook_version = string_semantic_version;
15
22
  /**
16
23
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/openai",
3
- "version": "0.81.0-5",
3
+ "version": "0.81.0-7",
4
4
  "description": "It's time for a paradigm shift. The future of software in plain English, French or Latin",
5
5
  "--note-0": " <- [🐊]",
6
6
  "private": false,
@@ -54,7 +54,7 @@
54
54
  "module": "./esm/index.es.js",
55
55
  "typings": "./esm/typings/src/_packages/openai.index.d.ts",
56
56
  "peerDependencies": {
57
- "@promptbook/core": "0.81.0-5"
57
+ "@promptbook/core": "0.81.0-7"
58
58
  },
59
59
  "dependencies": {
60
60
  "colors": "1.4.0",
package/umd/index.umd.js CHANGED
@@ -14,15 +14,17 @@
14
14
  /**
15
15
  * The version of the Book language
16
16
  *
17
+ * @generated
17
18
  * @see https://github.com/webgptorg/book
18
19
  */
19
20
  var BOOK_LANGUAGE_VERSION = '1.0.0';
20
21
  /**
21
22
  * The version of the Promptbook engine
22
23
  *
24
+ * @generated
23
25
  * @see https://github.com/webgptorg/promptbook
24
26
  */
25
- var PROMPTBOOK_ENGINE_VERSION = '0.81.0-4';
27
+ var PROMPTBOOK_ENGINE_VERSION = '0.81.0-6';
26
28
  /**
27
29
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
28
30
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -330,6 +332,26 @@
330
332
  * @private within the repository - too low-level in comparison with other `MAX_...`
331
333
  */
332
334
  var LOOP_LIMIT = 1000;
335
+ /**
336
+ * Strings to represent various values in the context of parameter values
337
+ *
338
+ * @public exported from `@promptbook/utils`
339
+ */
340
+ var VALUE_STRINGS = {
341
+ empty: '(nothing; empty string)',
342
+ null: '(no value; null)',
343
+ undefined: '(unknown value; undefined)',
344
+ nan: '(not a number; NaN)',
345
+ infinity: '(infinity; ∞)',
346
+ negativeInfinity: '(negative infinity; -∞)',
347
+ unserializable: '(unserializable value)',
348
+ };
349
+ /**
350
+ * Small number limit
351
+ *
352
+ * @public exported from `@promptbook/utils`
353
+ */
354
+ var SMALL_NUMBER = 0.001;
333
355
  // <- TODO: [🧜‍♂️]
334
356
  /**
335
357
  * @@@
@@ -633,9 +655,87 @@
633
655
  return LimitReachedError;
634
656
  }(Error));
635
657
 
658
+ /**
659
+ * Format either small or big number
660
+ *
661
+ * @public exported from `@promptbook/utils`
662
+ */
663
+ function numberToString(value) {
664
+ if (value === 0) {
665
+ return '0';
666
+ }
667
+ else if (Number.isNaN(value)) {
668
+ return VALUE_STRINGS.nan;
669
+ }
670
+ else if (value === Infinity) {
671
+ return VALUE_STRINGS.infinity;
672
+ }
673
+ else if (value === -Infinity) {
674
+ return VALUE_STRINGS.negativeInfinity;
675
+ }
676
+ for (var exponent = 0; exponent < 15; exponent++) {
677
+ var factor = Math.pow(10, exponent);
678
+ var valueRounded = Math.round(value * factor) / factor;
679
+ if (Math.abs(value - valueRounded) / value < SMALL_NUMBER) {
680
+ return valueRounded.toFixed(exponent);
681
+ }
682
+ }
683
+ return value.toString();
684
+ }
685
+
686
+ /**
687
+ * Function `valueToString` will convert the given value to string
688
+ * This is useful and used in the `templateParameters` function
689
+ *
690
+ * Note: This function is not just calling `toString` method
691
+ * It's more complex and can handle this conversion specifically for LLM models
692
+ * See `VALUE_STRINGS`
693
+ *
694
+ * Note: There are 2 similar functions
695
+ * - `valueToString` converts value to string for LLM models as human-readable string
696
+ * - `asSerializable` converts value to string to preserve full information to be able to convert it back
697
+ *
698
+ * @public exported from `@promptbook/utils`
699
+ */
700
+ function valueToString(value) {
701
+ try {
702
+ if (value === '') {
703
+ return VALUE_STRINGS.empty;
704
+ }
705
+ else if (value === null) {
706
+ return VALUE_STRINGS.null;
707
+ }
708
+ else if (value === undefined) {
709
+ return VALUE_STRINGS.undefined;
710
+ }
711
+ else if (typeof value === 'string') {
712
+ return value;
713
+ }
714
+ else if (typeof value === 'number') {
715
+ return numberToString(value);
716
+ }
717
+ else if (value instanceof Date) {
718
+ return value.toISOString();
719
+ }
720
+ else {
721
+ return JSON.stringify(value);
722
+ }
723
+ }
724
+ catch (error) {
725
+ if (!(error instanceof Error)) {
726
+ throw error;
727
+ }
728
+ console.error(error);
729
+ return VALUE_STRINGS.unserializable;
730
+ }
731
+ }
732
+
636
733
  /**
637
734
  * Replaces parameters in template with values from parameters object
638
735
  *
736
+ * Note: This function is not places strings into string,
737
+ * It's more complex and can handle this operation specifically for LLM models
738
+ *
639
739
  * @param template the template with parameters in {curly} braces
640
740
  * @param parameters the object with parameters
641
741
  * @returns the template with replaced parameters
@@ -685,7 +785,7 @@
685
785
  if (parameterValue === undefined) {
686
786
  throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined"));
687
787
  }
688
- parameterValue = parameterValue.toString();
788
+ parameterValue = valueToString(parameterValue);
689
789
  if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
690
790
  parameterValue = parameterValue
691
791
  .split('\n')