@promptbook/openai 0.66.0 → 0.67.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/esm/index.es.js +175 -14
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/core.index.d.ts +4 -4
- package/esm/typings/src/_packages/types.index.d.ts +7 -1
- package/esm/typings/src/_packages/utils.index.d.ts +14 -8
- package/esm/typings/src/commands/EXPECT/ExpectFormatCommand.d.ts +2 -0
- package/esm/typings/src/errors/{ReferenceError.d.ts → PipelineUrlError.d.ts} +2 -2
- package/esm/typings/src/errors/index.d.ts +27 -0
- package/esm/typings/src/errors/utils/ErrorJson.d.ts +20 -0
- package/esm/typings/src/errors/utils/deserializeError.d.ts +7 -0
- package/esm/typings/src/errors/utils/deserializeError.test.d.ts +1 -0
- package/esm/typings/src/errors/utils/serializeError.d.ts +7 -0
- package/esm/typings/src/errors/utils/serializeError.test.d.ts +1 -0
- package/esm/typings/src/execution/ExecutionTools.d.ts +4 -1
- package/esm/typings/src/execution/PipelineExecutor.d.ts +1 -47
- package/esm/typings/src/execution/PipelineExecutorResult.d.ts +49 -0
- package/esm/typings/src/execution/PromptResult.d.ts +4 -4
- package/esm/typings/src/execution/PromptResultUsage.d.ts +4 -0
- package/esm/typings/src/execution/UncertainNumber.d.ts +1 -0
- package/esm/typings/src/execution/assertsExecutionSuccessful.d.ts +2 -2
- package/esm/typings/src/llm-providers/_common/utils/cache/CacheItem.d.ts +0 -1
- package/esm/typings/src/llm-providers/mocked/$fakeTextToExpectations.d.ts +2 -2
- package/esm/typings/src/llm-providers/mocked/MockedFackedLlmExecutionTools.d.ts +3 -3
- package/esm/typings/src/llm-providers/remote/RemoteLlmExecutionTools.d.ts +1 -0
- package/esm/typings/src/llm-providers/remote/interfaces/PromptbookServer_Error.d.ts +2 -6
- package/esm/typings/src/llm-providers/remote/startRemoteServer.d.ts +1 -0
- package/esm/typings/src/personas/preparePersona.d.ts +1 -0
- package/esm/typings/src/prepare/isPipelinePrepared.d.ts +1 -0
- package/esm/typings/src/scripting/javascript/JavascriptExecutionToolsOptions.d.ts +2 -2
- package/esm/typings/src/storage/_common/PromptbookStorage.d.ts +1 -1
- package/esm/typings/src/types/ModelRequirements.d.ts +5 -5
- package/esm/typings/src/types/PipelineJson/Expectations.d.ts +3 -1
- package/esm/typings/src/types/PipelineJson/KnowledgePieceJson.d.ts +2 -0
- package/esm/typings/src/types/PipelineJson/KnowledgeSourceJson.d.ts +4 -0
- package/esm/typings/src/types/PipelineJson/LlmTemplateJson.d.ts +2 -0
- package/esm/typings/src/types/PipelineJson/PersonaJson.d.ts +4 -0
- package/esm/typings/src/types/PipelineJson/PipelineJson.d.ts +2 -0
- package/esm/typings/src/types/PipelineJson/PromptDialogJson.d.ts +1 -0
- package/esm/typings/src/types/PipelineJson/PromptTemplateJson.d.ts +2 -0
- package/esm/typings/src/types/PipelineJson/PromptTemplateJsonCommon.d.ts +2 -2
- package/esm/typings/src/types/PipelineJson/PromptTemplateParameterJson.d.ts +2 -0
- package/esm/typings/src/types/PipelineJson/ScriptJson.d.ts +1 -0
- package/esm/typings/src/types/PipelineJson/SimpleTemplateJson.d.ts +1 -0
- package/esm/typings/src/types/Prompt.d.ts +7 -7
- package/esm/typings/src/types/ScriptLanguage.d.ts +2 -0
- package/esm/typings/src/types/execution-report/ExecutionPromptReportJson.d.ts +24 -0
- package/esm/typings/src/types/execution-report/ExecutionReportJson.d.ts +3 -20
- package/esm/typings/src/types/typeAliases.d.ts +7 -0
- package/esm/typings/src/utils/environment/$getGlobalScope.d.ts +1 -4
- package/esm/typings/src/utils/serialization/$asDeeplyFrozenSerializableJson.d.ts +17 -0
- package/esm/typings/src/utils/{deepFreeze.d.ts → serialization/$deepFreeze.d.ts} +0 -10
- package/esm/typings/src/utils/serialization/checkSerializableAsJson.d.ts +27 -0
- package/esm/typings/src/utils/{clonePipeline.d.ts → serialization/clonePipeline.d.ts} +1 -1
- package/esm/typings/src/utils/serialization/isSerializableAsJson.d.ts +24 -0
- package/esm/typings/src/utils/serialization/isSerializableAsJson.test.d.ts +1 -0
- package/package.json +2 -2
- package/umd/index.umd.js +175 -14
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/errors/VersionMismatchError.d.ts +0 -10
- /package/esm/typings/src/utils/{deepClone.d.ts → serialization/deepClone.d.ts} +0 -0
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { BlockType } from '../../commands/BLOCK/BlockTypes';
|
|
2
2
|
import type { ExpectFormatCommand } from '../../commands/EXPECT/ExpectFormatCommand';
|
|
3
3
|
import type { string_javascript } from '../typeAliases';
|
|
4
|
-
import type { string_javascript_name } from '../typeAliases';
|
|
5
4
|
import type { string_markdown } from '../typeAliases';
|
|
6
5
|
import type { string_markdown_text } from '../typeAliases';
|
|
7
6
|
import type { string_name } from '../typeAliases';
|
|
8
7
|
import type { string_parameter_name } from '../typeAliases';
|
|
8
|
+
import type { string_postprocessing_function_name } from '../typeAliases';
|
|
9
9
|
import type { string_prompt } from '../typeAliases';
|
|
10
10
|
import type { string_template } from '../typeAliases';
|
|
11
11
|
import type { Expectations } from './Expectations';
|
|
@@ -66,7 +66,7 @@ export interface PromptTemplateJsonCommon {
|
|
|
66
66
|
*
|
|
67
67
|
* @see https://github.com/webgptorg/promptbook/discussions/31
|
|
68
68
|
*/
|
|
69
|
-
readonly postprocessingFunctionNames?: Array<
|
|
69
|
+
readonly postprocessingFunctionNames?: Array<string_postprocessing_function_name>;
|
|
70
70
|
/**
|
|
71
71
|
* Expect this amount of each unit in the answer
|
|
72
72
|
*
|
|
@@ -3,6 +3,8 @@ import type { string_parameter_name } from '../typeAliases';
|
|
|
3
3
|
import type { string_parameter_value } from '../typeAliases';
|
|
4
4
|
/**
|
|
5
5
|
* Describes one parameter of the promptbook
|
|
6
|
+
*
|
|
7
|
+
* Note: [🚉] This is fully serializable as JSON
|
|
6
8
|
*/
|
|
7
9
|
export type PromptTemplateParameterJson = {
|
|
8
10
|
/**
|
|
@@ -3,6 +3,7 @@ import type { PromptTemplateJsonCommon } from './PromptTemplateJsonCommon';
|
|
|
3
3
|
/**
|
|
4
4
|
* Template for script execution
|
|
5
5
|
*
|
|
6
|
+
* Note: [🚉] This is fully serializable as JSON
|
|
6
7
|
* @see https://github.com/webgptorg/promptbook/discussions/77
|
|
7
8
|
*/
|
|
8
9
|
export type ScriptJson = PromptTemplateJsonCommon & {
|
|
@@ -2,6 +2,7 @@ import type { PromptTemplateJsonCommon } from './PromptTemplateJsonCommon';
|
|
|
2
2
|
/**
|
|
3
3
|
* Template for simple concatenation of strings
|
|
4
4
|
*
|
|
5
|
+
* Note: [🚉] This is fully serializable as JSON
|
|
5
6
|
* @see https://github.com/webgptorg/promptbook/discussions/17
|
|
6
7
|
*/
|
|
7
8
|
export type SimpleTemplateJson = PromptTemplateJsonCommon & {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { ExpectFormatCommand } from '../commands/EXPECT/ExpectFormatCommand';
|
|
2
|
-
import type { PostprocessingFunction } from '../scripting/javascript/JavascriptExecutionToolsOptions';
|
|
3
2
|
import type { ChatModelRequirements } from './ModelRequirements';
|
|
4
3
|
import type { CompletionModelRequirements } from './ModelRequirements';
|
|
5
4
|
import type { EmbeddingModelRequirements } from './ModelRequirements';
|
|
@@ -7,20 +6,21 @@ import type { ModelRequirements } from './ModelRequirements';
|
|
|
7
6
|
import type { Expectations } from './PipelineJson/Expectations';
|
|
8
7
|
import type { Parameters } from './typeAliases';
|
|
9
8
|
import type { string_pipeline_url_with_hashtemplate } from './typeAliases';
|
|
9
|
+
import type { string_postprocessing_function_name } from './typeAliases';
|
|
10
10
|
import type { string_prompt } from './typeAliases';
|
|
11
11
|
import type { string_template } from './typeAliases';
|
|
12
12
|
import type { string_title } from './typeAliases';
|
|
13
13
|
/**
|
|
14
14
|
* Prompt in a text along with model requirements, but without any execution or templating logic.
|
|
15
15
|
*
|
|
16
|
-
* Note: [
|
|
16
|
+
* Note: [🚉] This is fully serializable as JSON
|
|
17
17
|
* @see https://github.com/webgptorg/promptbook#prompt
|
|
18
18
|
*/
|
|
19
19
|
export type Prompt = CompletionPrompt | ChatPrompt | EmbeddingPrompt;
|
|
20
20
|
/**
|
|
21
21
|
* Completion prompt
|
|
22
22
|
*
|
|
23
|
-
* Note: [
|
|
23
|
+
* Note: [🚉] This is fully serializable as JSON
|
|
24
24
|
*/
|
|
25
25
|
export type CompletionPrompt = CommonPrompt & {
|
|
26
26
|
/**
|
|
@@ -31,7 +31,7 @@ export type CompletionPrompt = CommonPrompt & {
|
|
|
31
31
|
/**
|
|
32
32
|
* Chat prompt
|
|
33
33
|
*
|
|
34
|
-
* Note: [
|
|
34
|
+
* Note: [🚉] This is fully serializable as JSON
|
|
35
35
|
*/
|
|
36
36
|
export type ChatPrompt = CommonPrompt & {
|
|
37
37
|
/**
|
|
@@ -42,7 +42,7 @@ export type ChatPrompt = CommonPrompt & {
|
|
|
42
42
|
/**
|
|
43
43
|
* Embedding prompt
|
|
44
44
|
*
|
|
45
|
-
* Note: [
|
|
45
|
+
* Note: [🚉] This is fully serializable as JSON
|
|
46
46
|
*/
|
|
47
47
|
export type EmbeddingPrompt = CommonPrompt & {
|
|
48
48
|
/**
|
|
@@ -53,7 +53,7 @@ export type EmbeddingPrompt = CommonPrompt & {
|
|
|
53
53
|
/**
|
|
54
54
|
* Common properties for all prompt results
|
|
55
55
|
*
|
|
56
|
-
* Note: This is fully serializable as JSON
|
|
56
|
+
* Note: [🚉] This is fully serializable as JSON
|
|
57
57
|
*/
|
|
58
58
|
export type CommonPrompt = {
|
|
59
59
|
/**
|
|
@@ -75,7 +75,7 @@ export type CommonPrompt = {
|
|
|
75
75
|
/**
|
|
76
76
|
* List of postprocessing steps that are executed after the prompt
|
|
77
77
|
*/
|
|
78
|
-
readonly
|
|
78
|
+
readonly postprocessingFunctionNames?: Array<string_postprocessing_function_name>;
|
|
79
79
|
/**
|
|
80
80
|
* Expectations for the answer
|
|
81
81
|
*
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ErrorJson } from '../../errors/utils/ErrorJson';
|
|
2
|
+
import type { PromptResult } from '../../execution/PromptResult';
|
|
3
|
+
import type { Prompt } from '../Prompt';
|
|
4
|
+
/**
|
|
5
|
+
* Report of single prompt execution
|
|
6
|
+
*
|
|
7
|
+
* Note: [🚉] This is fully serializable as JSON
|
|
8
|
+
*/
|
|
9
|
+
export type ExecutionPromptReportJson = {
|
|
10
|
+
/**
|
|
11
|
+
* The prompt wich was executed
|
|
12
|
+
*/
|
|
13
|
+
readonly prompt: Omit<Prompt, 'pipelineUrl'>;
|
|
14
|
+
/**
|
|
15
|
+
* Result of the prompt execution (if not failed during LLM execution)
|
|
16
|
+
*/
|
|
17
|
+
readonly result?: PromptResult;
|
|
18
|
+
/**
|
|
19
|
+
* The error which occured during LLM execution or during postprocessing or expectation checking
|
|
20
|
+
*
|
|
21
|
+
* Note: It makes sense to have both error and result defined, for example when the result not pass expectations
|
|
22
|
+
*/
|
|
23
|
+
readonly error?: ErrorJson;
|
|
24
|
+
};
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import type { PromptResult } from '../../execution/PromptResult';
|
|
2
|
-
import type { Prompt } from '../Prompt';
|
|
3
1
|
import type { string_markdown_text } from '../typeAliases';
|
|
4
2
|
import type { string_pipeline_url } from '../typeAliases';
|
|
5
3
|
import type { string_semantic_version } from '../typeAliases';
|
|
4
|
+
import type { ExecutionPromptReportJson } from './ExecutionPromptReportJson';
|
|
6
5
|
/**
|
|
7
6
|
* ExecutionReport is result of executing one promptbook
|
|
8
7
|
* It is kind of a variant of the promptbook usefull for debugging, logging and transparency for users.
|
|
@@ -11,6 +10,7 @@ import type { string_semantic_version } from '../typeAliases';
|
|
|
11
10
|
* - **.md file** created from the **JSON** format
|
|
12
11
|
* - _(this)_ **JSON** format
|
|
13
12
|
*
|
|
13
|
+
* Note: [🚉] This is fully serializable as JSON
|
|
14
14
|
* @see https://github.com/webgptorg/promptbook#execution-report
|
|
15
15
|
*/
|
|
16
16
|
export type ExecutionReportJson = {
|
|
@@ -37,22 +37,5 @@ export type ExecutionReportJson = {
|
|
|
37
37
|
/**
|
|
38
38
|
* Sequence of prompt templates in order which were executed
|
|
39
39
|
*/
|
|
40
|
-
readonly promptExecutions: Array<
|
|
41
|
-
/**
|
|
42
|
-
* The prompt wich was executed
|
|
43
|
-
*/
|
|
44
|
-
readonly prompt: Omit<Prompt, 'pipelineUrl'>;
|
|
45
|
-
/**
|
|
46
|
-
* Result of the prompt execution (if not failed during LLM execution)
|
|
47
|
-
*/
|
|
48
|
-
readonly result?: PromptResult;
|
|
49
|
-
/**
|
|
50
|
-
* The error which occured during LLM execution or during postprocessing or expectation checking
|
|
51
|
-
*
|
|
52
|
-
* Note: It makes sense to have both error and result defined, for example when the result not pass expectations
|
|
53
|
-
*/
|
|
54
|
-
readonly error?: {
|
|
55
|
-
readonly message: string;
|
|
56
|
-
};
|
|
57
|
-
}>;
|
|
40
|
+
readonly promptExecutions: Array<ExecutionPromptReportJson>;
|
|
58
41
|
};
|
|
@@ -103,6 +103,7 @@ export type string_parameter_value = string;
|
|
|
103
103
|
* - **Intermediate parameters** are used internally in the pipeline.
|
|
104
104
|
* - **OUTPUT PARAMETERs** are not used internally in the pipeline, but are returned as the result of the pipeline execution.
|
|
105
105
|
*
|
|
106
|
+
* Note: [🚉] This is fully serializable as JSON
|
|
106
107
|
* @see https://ptbk.io/parameters
|
|
107
108
|
*/
|
|
108
109
|
export type Parameters = Exclude<Record<string_parameter_name, string_parameter_value>, ReservedParameters>;
|
|
@@ -115,6 +116,8 @@ export type Parameters = Exclude<Record<string_parameter_name, string_parameter_
|
|
|
115
116
|
export type string_reserved_parameter_name = TupleToUnion<typeof RESERVED_PARAMETER_NAMES>;
|
|
116
117
|
/**
|
|
117
118
|
* @@@
|
|
119
|
+
*
|
|
120
|
+
* Note: [🚉] This is fully serializable as JSON
|
|
118
121
|
*/
|
|
119
122
|
export type ReservedParameters = Record<string_reserved_parameter_name, string_parameter_value>;
|
|
120
123
|
/**
|
|
@@ -514,6 +517,10 @@ export type string_translate_language = 'en' | 'cs';
|
|
|
514
517
|
* Semantic helper; For example "callbackName" or "renderMe"
|
|
515
518
|
*/
|
|
516
519
|
export type string_javascript_name = string;
|
|
520
|
+
/**
|
|
521
|
+
* Semantic helper; For example "unwrapResult" or "spaceTrim"
|
|
522
|
+
*/
|
|
523
|
+
export type string_postprocessing_function_name = string;
|
|
517
524
|
export type string_token = string;
|
|
518
525
|
export type string_license_token = string_token;
|
|
519
526
|
export type string_password = string;
|
|
@@ -4,9 +4,6 @@ import type { really_any } from '../organization/really_any';
|
|
|
4
4
|
*
|
|
5
5
|
* Note: `$` is used to indicate that this function is not a pure function - it access global scope
|
|
6
6
|
*
|
|
7
|
-
*
|
|
7
|
+
* @private internal function of `$Register`
|
|
8
8
|
*/
|
|
9
9
|
export declare function $getGlobalScope(): really_any;
|
|
10
|
-
/***
|
|
11
|
-
* TODO: !!!!! Make private and promptbook registry from this
|
|
12
|
-
*/
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { string_name } from '../../types/typeAliases';
|
|
2
|
+
/**
|
|
3
|
+
* @@@
|
|
4
|
+
* @@@
|
|
5
|
+
*
|
|
6
|
+
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
7
|
+
*
|
|
8
|
+
* @param name - Name of the object for debugging purposes
|
|
9
|
+
* @param objectValue - Object to be deeply frozen
|
|
10
|
+
* @returns The same object as the input, but deeply frozen
|
|
11
|
+
* @private this is in comparison to `deepFreeze` a more specific utility and maybe not very good practice to use without specific reason and considerations
|
|
12
|
+
*/
|
|
13
|
+
export declare function $asDeeplyFrozenSerializableJson<TObject>(name: string_name, objectValue: TObject): TObject;
|
|
14
|
+
/**
|
|
15
|
+
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
16
|
+
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
17
|
+
*/
|
|
@@ -9,16 +9,6 @@ import type { ReadonlyDeep } from 'type-fest';
|
|
|
9
9
|
* @public exported from `@promptbook/utils`
|
|
10
10
|
*/
|
|
11
11
|
export declare function $deepFreeze<TObject>(objectValue: TObject): ReadonlyDeep<TObject>;
|
|
12
|
-
/**
|
|
13
|
-
* @@@
|
|
14
|
-
* @@@
|
|
15
|
-
*
|
|
16
|
-
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
17
|
-
*
|
|
18
|
-
* @returns The same object as the input, but deeply frozen
|
|
19
|
-
* @private this is in comparison to `deepFreeze` a more specific utility and maybe not very good practice to use without specific reason and considerations
|
|
20
|
-
*/
|
|
21
|
-
export declare function deepFreezeWithSameType<TObject>(objectValue: TObject): TObject;
|
|
22
12
|
/**
|
|
23
13
|
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
24
14
|
*/
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { string_name } from '../../types/typeAliases';
|
|
2
|
+
/**
|
|
3
|
+
* Checks if the value is [🚉] serializable as JSON
|
|
4
|
+
* If not, throws an UnexpectedError with a rich error message and tracking
|
|
5
|
+
*
|
|
6
|
+
* - Almost all primitives are serializable BUT:
|
|
7
|
+
* - `undefined` is not serializable
|
|
8
|
+
* - `NaN` is not serializable
|
|
9
|
+
* - Objects and arrays are serializable if all their properties are serializable
|
|
10
|
+
* - Functions are not serializable
|
|
11
|
+
* - Circular references are not serializable
|
|
12
|
+
* - `Date` objects are not serializable
|
|
13
|
+
* - `Map` and `Set` objects are not serializable
|
|
14
|
+
* - `RegExp` objects are not serializable
|
|
15
|
+
* - `Error` objects are not serializable
|
|
16
|
+
* - `Symbol` objects are not serializable
|
|
17
|
+
* - And much more...
|
|
18
|
+
*
|
|
19
|
+
* @throws UnexpectedError if the value is not serializable as JSON
|
|
20
|
+
* @public exported from `@promptbook/utils`
|
|
21
|
+
*/
|
|
22
|
+
export declare function checkSerializableAsJson(name: string_name, value: unknown): void;
|
|
23
|
+
/**
|
|
24
|
+
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
25
|
+
* TODO: [🧠] !!! In-memory cache of same values to prevent multiple checks
|
|
26
|
+
* Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
|
|
27
|
+
*/
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests if the value is [🚉] serializable as JSON
|
|
3
|
+
*
|
|
4
|
+
* - Almost all primitives are serializable BUT:
|
|
5
|
+
* - `undefined` is not serializable
|
|
6
|
+
* - `NaN` is not serializable
|
|
7
|
+
* - Objects and arrays are serializable if all their properties are serializable
|
|
8
|
+
* - Functions are not serializable
|
|
9
|
+
* - Circular references are not serializable
|
|
10
|
+
* - `Date` objects are not serializable
|
|
11
|
+
* - `Map` and `Set` objects are not serializable
|
|
12
|
+
* - `RegExp` objects are not serializable
|
|
13
|
+
* - `Error` objects are not serializable
|
|
14
|
+
* - `Symbol` objects are not serializable
|
|
15
|
+
* - And much more...
|
|
16
|
+
*
|
|
17
|
+
*
|
|
18
|
+
* @public exported from `@promptbook/utils`
|
|
19
|
+
*/
|
|
20
|
+
export declare function isSerializableAsJson(value: unknown): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* TODO: [🧠] !!! In-memory cache of same values to prevent multiple checks
|
|
23
|
+
* TODO: [🧠][💺] Can be done this on type-level?
|
|
24
|
+
*/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@promptbook/openai",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.67.0-1",
|
|
4
4
|
"description": "Supercharge your use of large language models",
|
|
5
5
|
"private": false,
|
|
6
6
|
"sideEffects": false,
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"module": "./esm/index.es.js",
|
|
48
48
|
"typings": "./esm/typings/src/_packages/openai.index.d.ts",
|
|
49
49
|
"peerDependencies": {
|
|
50
|
-
"@promptbook/core": "0.
|
|
50
|
+
"@promptbook/core": "0.67.0-1"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"colors": "1.4.0",
|
package/umd/index.umd.js
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
/**
|
|
15
15
|
* The version of the Promptbook library
|
|
16
16
|
*/
|
|
17
|
-
var PROMPTBOOK_VERSION = '0.
|
|
17
|
+
var PROMPTBOOK_VERSION = '0.67.0-0';
|
|
18
18
|
// TODO: !!!! List here all the versions and annotate + put into script
|
|
19
19
|
|
|
20
20
|
/*! *****************************************************************************
|
|
@@ -136,6 +136,24 @@
|
|
|
136
136
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
137
137
|
}
|
|
138
138
|
|
|
139
|
+
/**
|
|
140
|
+
* Detects if the code is running in a browser environment in main thread (Not in a web worker)
|
|
141
|
+
*
|
|
142
|
+
* Note: `$` is used to indicate that this function is not a pure function - it looks at the global object to determine the environment
|
|
143
|
+
*
|
|
144
|
+
* @public exported from `@promptbook/utils`
|
|
145
|
+
*/
|
|
146
|
+
var $isRunningInBrowser = new Function("\n try {\n return this === window;\n } catch (e) {\n return false;\n }\n");
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Detects if the code is running in a web worker
|
|
150
|
+
*
|
|
151
|
+
* Note: `$` is used to indicate that this function is not a pure function - it looks at the global object to determine the environment
|
|
152
|
+
*
|
|
153
|
+
* @public exported from `@promptbook/utils`
|
|
154
|
+
*/
|
|
155
|
+
var $isRunningInWebWorker = new Function("\n try {\n if (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope) {\n return true;\n } else {\n return false;\n }\n } catch (e) {\n return false;\n }\n");
|
|
156
|
+
|
|
139
157
|
/**
|
|
140
158
|
* This error indicates errors during the execution of the pipeline
|
|
141
159
|
*
|
|
@@ -211,6 +229,149 @@
|
|
|
211
229
|
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
212
230
|
*/
|
|
213
231
|
|
|
232
|
+
/**
|
|
233
|
+
* Checks if the value is [🚉] serializable as JSON
|
|
234
|
+
* If not, throws an UnexpectedError with a rich error message and tracking
|
|
235
|
+
*
|
|
236
|
+
* - Almost all primitives are serializable BUT:
|
|
237
|
+
* - `undefined` is not serializable
|
|
238
|
+
* - `NaN` is not serializable
|
|
239
|
+
* - Objects and arrays are serializable if all their properties are serializable
|
|
240
|
+
* - Functions are not serializable
|
|
241
|
+
* - Circular references are not serializable
|
|
242
|
+
* - `Date` objects are not serializable
|
|
243
|
+
* - `Map` and `Set` objects are not serializable
|
|
244
|
+
* - `RegExp` objects are not serializable
|
|
245
|
+
* - `Error` objects are not serializable
|
|
246
|
+
* - `Symbol` objects are not serializable
|
|
247
|
+
* - And much more...
|
|
248
|
+
*
|
|
249
|
+
* @throws UnexpectedError if the value is not serializable as JSON
|
|
250
|
+
* @public exported from `@promptbook/utils`
|
|
251
|
+
*/
|
|
252
|
+
function checkSerializableAsJson(name, value) {
|
|
253
|
+
var e_1, _a;
|
|
254
|
+
if (value === undefined) {
|
|
255
|
+
throw new UnexpectedError("".concat(name, " is undefined"));
|
|
256
|
+
}
|
|
257
|
+
else if (value === null) {
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
else if (typeof value === 'boolean') {
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
else if (typeof value === 'number' && !isNaN(value)) {
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
else if (typeof value === 'string') {
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
else if (typeof value === 'symbol') {
|
|
270
|
+
throw new UnexpectedError("".concat(name, " is symbol"));
|
|
271
|
+
}
|
|
272
|
+
else if (typeof value === 'function') {
|
|
273
|
+
throw new UnexpectedError("".concat(name, " is function"));
|
|
274
|
+
}
|
|
275
|
+
else if (typeof value === 'object' && Array.isArray(value)) {
|
|
276
|
+
for (var i = 0; i < value.length; i++) {
|
|
277
|
+
checkSerializableAsJson("".concat(name, "[").concat(i, "]"), value[i]);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
else if (typeof value === 'object') {
|
|
281
|
+
if (value instanceof Date) {
|
|
282
|
+
throw new UnexpectedError(spaceTrim__default["default"]("\n ".concat(name, " is Date\n\n Use `string_date_iso8601` instead\n ")));
|
|
283
|
+
}
|
|
284
|
+
else if (value instanceof Map) {
|
|
285
|
+
throw new UnexpectedError("".concat(name, " is Map"));
|
|
286
|
+
}
|
|
287
|
+
else if (value instanceof Set) {
|
|
288
|
+
throw new UnexpectedError("".concat(name, " is Set"));
|
|
289
|
+
}
|
|
290
|
+
else if (value instanceof RegExp) {
|
|
291
|
+
throw new UnexpectedError("".concat(name, " is RegExp"));
|
|
292
|
+
}
|
|
293
|
+
else if (value instanceof Error) {
|
|
294
|
+
throw new UnexpectedError(spaceTrim__default["default"]("\n ".concat(name, " is unserialized Error\n\n Use function `serializeError`\n ")));
|
|
295
|
+
}
|
|
296
|
+
else {
|
|
297
|
+
try {
|
|
298
|
+
for (var _b = __values(Object.entries(value)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
299
|
+
var _d = __read(_c.value, 2), subName = _d[0], subValue = _d[1];
|
|
300
|
+
if (subValue === undefined) {
|
|
301
|
+
// Note: undefined in object is serializable - it is just omited
|
|
302
|
+
continue;
|
|
303
|
+
}
|
|
304
|
+
checkSerializableAsJson("".concat(name, ".").concat(subName), subValue);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
308
|
+
finally {
|
|
309
|
+
try {
|
|
310
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
311
|
+
}
|
|
312
|
+
finally { if (e_1) throw e_1.error; }
|
|
313
|
+
}
|
|
314
|
+
try {
|
|
315
|
+
JSON.stringify(value); // <- TODO: [0]
|
|
316
|
+
}
|
|
317
|
+
catch (error) {
|
|
318
|
+
if (!(error instanceof Error)) {
|
|
319
|
+
throw error;
|
|
320
|
+
}
|
|
321
|
+
throw new UnexpectedError(spaceTrim__default["default"](function (block) { return "\n ".concat(name, " is not serializable\n\n ").concat(block(error.toString()), "\n "); }));
|
|
322
|
+
}
|
|
323
|
+
/*
|
|
324
|
+
TODO: [0] Is there some more elegant way to check circular references?
|
|
325
|
+
const seen = new Set();
|
|
326
|
+
const stack = [{ value }];
|
|
327
|
+
while (stack.length > 0) {
|
|
328
|
+
const { value } = stack.pop()!;
|
|
329
|
+
if (typeof value === 'object' && value !== null) {
|
|
330
|
+
if (seen.has(value)) {
|
|
331
|
+
throw new UnexpectedError(`${name} has circular reference`);
|
|
332
|
+
}
|
|
333
|
+
seen.add(value);
|
|
334
|
+
if (Array.isArray(value)) {
|
|
335
|
+
stack.push(...value.map((value) => ({ value })));
|
|
336
|
+
} else {
|
|
337
|
+
stack.push(...Object.values(value).map((value) => ({ value })));
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
*/
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
else {
|
|
346
|
+
throw new UnexpectedError("".concat(name, " is unknown"));
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
351
|
+
* TODO: [🧠] !!! In-memory cache of same values to prevent multiple checks
|
|
352
|
+
* Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
|
|
353
|
+
*/
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* @@@
|
|
357
|
+
* @@@
|
|
358
|
+
*
|
|
359
|
+
* Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
|
|
360
|
+
*
|
|
361
|
+
* @param name - Name of the object for debugging purposes
|
|
362
|
+
* @param objectValue - Object to be deeply frozen
|
|
363
|
+
* @returns The same object as the input, but deeply frozen
|
|
364
|
+
* @private this is in comparison to `deepFreeze` a more specific utility and maybe not very good practice to use without specific reason and considerations
|
|
365
|
+
*/
|
|
366
|
+
function $asDeeplyFrozenSerializableJson(name, objectValue) {
|
|
367
|
+
checkSerializableAsJson(name, objectValue);
|
|
368
|
+
return $deepFreeze(objectValue);
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* TODO: [🧠][🛣] More elegant way to tracking than passing `name`
|
|
372
|
+
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
373
|
+
*/
|
|
374
|
+
|
|
214
375
|
// <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
|
|
215
376
|
/**
|
|
216
377
|
* The maximum number of iterations for a loops
|
|
@@ -229,7 +390,7 @@
|
|
|
229
390
|
*
|
|
230
391
|
* @public exported from `@promptbook/core`
|
|
231
392
|
*/
|
|
232
|
-
$
|
|
393
|
+
$asDeeplyFrozenSerializableJson('RESERVED_PARAMETER_NAMES', [
|
|
233
394
|
'content',
|
|
234
395
|
'context',
|
|
235
396
|
'knowledge',
|
|
@@ -739,7 +900,7 @@
|
|
|
739
900
|
* @see https://openai.com/api/pricing/
|
|
740
901
|
* @public exported from `@promptbook/openai`
|
|
741
902
|
*/
|
|
742
|
-
var OPENAI_MODELS = [
|
|
903
|
+
var OPENAI_MODELS = $asDeeplyFrozenSerializableJson('OPENAI_MODELS', [
|
|
743
904
|
/*/
|
|
744
905
|
{
|
|
745
906
|
modelTitle: 'dall-e-3',
|
|
@@ -1067,7 +1228,7 @@
|
|
|
1067
1228
|
},
|
|
1068
1229
|
},
|
|
1069
1230
|
/**/
|
|
1070
|
-
];
|
|
1231
|
+
]);
|
|
1071
1232
|
/**
|
|
1072
1233
|
* Note: [🤖] Add models of new variant
|
|
1073
1234
|
* TODO: [🧠] Some mechanism to propagate unsureness
|
|
@@ -1267,7 +1428,7 @@
|
|
|
1267
1428
|
if (resultContent === null) {
|
|
1268
1429
|
throw new PipelineExecutionError('No response message from OpenAI');
|
|
1269
1430
|
}
|
|
1270
|
-
return [2 /*return*/, {
|
|
1431
|
+
return [2 /*return*/, $asDeeplyFrozenSerializableJson('OpenAiExecutionTools ChatPromptResult', {
|
|
1271
1432
|
content: resultContent,
|
|
1272
1433
|
modelName: rawResponse.model || modelName,
|
|
1273
1434
|
timing: {
|
|
@@ -1279,7 +1440,7 @@
|
|
|
1279
1440
|
rawRequest: rawRequest,
|
|
1280
1441
|
rawResponse: rawResponse,
|
|
1281
1442
|
// <- [🗯]
|
|
1282
|
-
}];
|
|
1443
|
+
})];
|
|
1283
1444
|
}
|
|
1284
1445
|
});
|
|
1285
1446
|
});
|
|
@@ -1336,7 +1497,7 @@
|
|
|
1336
1497
|
// eslint-disable-next-line prefer-const
|
|
1337
1498
|
complete = getCurrentIsoDate();
|
|
1338
1499
|
usage = computeOpenAiUsage(content, resultContent || '', rawResponse);
|
|
1339
|
-
return [2 /*return*/, {
|
|
1500
|
+
return [2 /*return*/, $asDeeplyFrozenSerializableJson('OpenAiExecutionTools CompletionPromptResult', {
|
|
1340
1501
|
content: resultContent,
|
|
1341
1502
|
modelName: rawResponse.model || modelName,
|
|
1342
1503
|
timing: {
|
|
@@ -1348,7 +1509,7 @@
|
|
|
1348
1509
|
rawRequest: rawRequest,
|
|
1349
1510
|
rawResponse: rawResponse,
|
|
1350
1511
|
// <- [🗯]
|
|
1351
|
-
}];
|
|
1512
|
+
})];
|
|
1352
1513
|
}
|
|
1353
1514
|
});
|
|
1354
1515
|
});
|
|
@@ -1396,7 +1557,7 @@
|
|
|
1396
1557
|
// eslint-disable-next-line prefer-const
|
|
1397
1558
|
complete = getCurrentIsoDate();
|
|
1398
1559
|
usage = computeOpenAiUsage(content, '', rawResponse);
|
|
1399
|
-
return [2 /*return*/, {
|
|
1560
|
+
return [2 /*return*/, $asDeeplyFrozenSerializableJson('OpenAiExecutionTools EmbeddingPromptResult', {
|
|
1400
1561
|
content: resultContent,
|
|
1401
1562
|
modelName: rawResponse.model || modelName,
|
|
1402
1563
|
timing: {
|
|
@@ -1408,7 +1569,7 @@
|
|
|
1408
1569
|
rawRequest: rawRequest,
|
|
1409
1570
|
rawResponse: rawResponse,
|
|
1410
1571
|
// <- [🗯]
|
|
1411
|
-
}];
|
|
1572
|
+
})];
|
|
1412
1573
|
}
|
|
1413
1574
|
});
|
|
1414
1575
|
});
|
|
@@ -1467,6 +1628,9 @@
|
|
|
1467
1628
|
*/
|
|
1468
1629
|
var createOpenAiExecutionTools = Object.assign(function (options) {
|
|
1469
1630
|
// TODO: [🧠] !!!! If browser, auto add `dangerouslyAllowBrowser`
|
|
1631
|
+
if (($isRunningInBrowser() || $isRunningInWebWorker()) && !options.dangerouslyAllowBrowser) {
|
|
1632
|
+
options = __assign(__assign({}, options), { dangerouslyAllowBrowser: true });
|
|
1633
|
+
}
|
|
1470
1634
|
return new OpenAiExecutionTools(options);
|
|
1471
1635
|
}, {
|
|
1472
1636
|
packageName: '@promptbook/openai',
|
|
@@ -1482,14 +1646,11 @@
|
|
|
1482
1646
|
*
|
|
1483
1647
|
* Note: `$` is used to indicate that this function is not a pure function - it access global scope
|
|
1484
1648
|
*
|
|
1485
|
-
*
|
|
1649
|
+
* @private internal function of `$Register`
|
|
1486
1650
|
*/
|
|
1487
1651
|
function $getGlobalScope() {
|
|
1488
1652
|
return Function('return this')();
|
|
1489
1653
|
}
|
|
1490
|
-
/***
|
|
1491
|
-
* TODO: !!!!! Make private and promptbook registry from this
|
|
1492
|
-
*/
|
|
1493
1654
|
|
|
1494
1655
|
/**
|
|
1495
1656
|
* Register is @@@
|