@promptbook/remote-client 0.54.0 → 0.55.0-0

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.
Files changed (26) hide show
  1. package/README.md +1 -1
  2. package/esm/typings/_packages/core.index.d.ts +2 -1
  3. package/esm/typings/_packages/types.index.d.ts +2 -2
  4. package/esm/typings/execution/PromptResult.d.ts +43 -18
  5. package/esm/typings/execution/addPromptResultUsage.d.ts +7 -0
  6. package/esm/typings/execution/addPromptResultUsage.test.d.ts +1 -0
  7. package/esm/typings/execution/computeUsageCounts.d.ts +10 -0
  8. package/esm/typings/execution/plugins/llm-execution-tools/openai/computeOpenaiUsage.d.ts +5 -1
  9. package/esm/typings/types/PromptbookJson/PromptTemplateJson.d.ts +4 -3
  10. package/esm/typings/types/PromptbookJson/PromptTemplateParameterJson.d.ts +2 -1
  11. package/esm/typings/types/PromptbookJson/PromptbookJson.d.ts +3 -2
  12. package/esm/typings/types/execution-report/ExecutionReportJson.d.ts +2 -1
  13. package/esm/typings/types/typeAliases.d.ts +1 -3
  14. package/package.json +2 -2
  15. package/umd/typings/_packages/core.index.d.ts +2 -1
  16. package/umd/typings/_packages/types.index.d.ts +2 -2
  17. package/umd/typings/execution/PromptResult.d.ts +43 -18
  18. package/umd/typings/execution/addPromptResultUsage.d.ts +7 -0
  19. package/umd/typings/execution/addPromptResultUsage.test.d.ts +1 -0
  20. package/umd/typings/execution/computeUsageCounts.d.ts +10 -0
  21. package/umd/typings/execution/plugins/llm-execution-tools/openai/computeOpenaiUsage.d.ts +5 -1
  22. package/umd/typings/types/PromptbookJson/PromptTemplateJson.d.ts +4 -3
  23. package/umd/typings/types/PromptbookJson/PromptTemplateParameterJson.d.ts +2 -1
  24. package/umd/typings/types/PromptbookJson/PromptbookJson.d.ts +3 -2
  25. package/umd/typings/types/execution-report/ExecutionReportJson.d.ts +2 -1
  26. package/umd/typings/types/typeAliases.d.ts +1 -3
package/README.md CHANGED
@@ -507,7 +507,7 @@ There are [postprocessing functions](#postprocessing-functions) that can be used
507
507
  Executor is a simple async function that takes **input parameters** and returns **output parameters**.
508
508
  It is constructed by combining execution tools and promptbook to execute together.
509
509
 
510
- ### 🃏 Jokers
510
+ ### 🃏 Jokers (conditions)
511
511
 
512
512
  Joker is a previously defined parameter that is used to bypass some parts of the pipeline.
513
513
  If the joker is present in the template, it is checked to see if it meets the requirements (without postprocessing), and if so, it is used instead of executing that prompt template. There can be multiple wildcards in a prompt template, if so they are checked in order and the first one that meets the requirements is used.
@@ -11,6 +11,7 @@ import { PromptbookReferenceError } from '../errors/PromptbookReferenceError';
11
11
  import { PromptbookSyntaxError } from '../errors/PromptbookSyntaxError';
12
12
  import { TemplateError } from '../errors/TemplateError';
13
13
  import { UnexpectedError } from '../errors/UnexpectedError';
14
+ import { addPromptResultUsage } from '../execution/addPromptResultUsage';
14
15
  import { assertsExecutionSuccessful } from '../execution/assertsExecutionSuccessful';
15
16
  import { createPromptbookExecutor } from '../execution/createPromptbookExecutor';
16
17
  import { MultipleLlmExecutionTools } from '../execution/plugins/llm-execution-tools/multiple/MultipleLlmExecutionTools';
@@ -30,7 +31,7 @@ import { ExecutionTypes } from '../types/ExecutionTypes';
30
31
  import { PROMPTBOOK_VERSION } from '../version';
31
32
  export { justTestFsImport };
32
33
  export { ExecutionTypes, PROMPTBOOK_VERSION };
33
- export { assertsExecutionSuccessful, checkExpectations, executionReportJsonToString, ExecutionReportStringOptions, ExecutionReportStringOptionsDefaults, isPassingExpectations, prettifyPromptbookString, };
34
+ export { addPromptResultUsage, assertsExecutionSuccessful, checkExpectations, executionReportJsonToString, ExecutionReportStringOptions, ExecutionReportStringOptionsDefaults, isPassingExpectations, prettifyPromptbookString, };
34
35
  export { createPromptbookLibraryFromDirectory, createPromptbookLibraryFromSources, createPromptbookLibraryFromUrl, createPromptbookSublibrary, SimplePromptbookLibrary, };
35
36
  export { SimplePromptInterfaceTools };
36
37
  export { promptbookJsonToString, promptbookStringToJson, validatePromptbookJson };
@@ -1,7 +1,7 @@
1
1
  import type { CommonExecutionToolsOptions } from '../execution/CommonExecutionToolsOptions';
2
2
  import type { ExecutionTools } from '../execution/ExecutionTools';
3
3
  import type { AvailableModel, LlmExecutionTools } from '../execution/LlmExecutionTools';
4
- import type { PromptChatResult, PromptCommonResult, PromptCompletionResult, PromptResult } from '../execution/PromptResult';
4
+ import type { PromptChatResult, PromptCommonResult, PromptCompletionResult, PromptResult, PromptResultUsage, PromptResultUsageCounts, UncertainNumber } from '../execution/PromptResult';
5
5
  import type { PromptbookExecutor } from '../execution/PromptbookExecutor';
6
6
  import type { ScriptExecutionTools, ScriptExecutionToolsExecuteOptions } from '../execution/ScriptExecutionTools';
7
7
  import type { UserInterfaceTools, UserInterfaceToolsPromptDialogOptions } from '../execution/UserInterfaceTools';
@@ -21,7 +21,7 @@ import type { ExecutionReportJson } from '../types/execution-report/ExecutionRep
21
21
  import type { string_char_emoji } from '../types/typeAliasEmoji';
22
22
  import type { client_id, string_char, string_chat_prompt, string_completion_prompt, string_data_url, string_domain, string_email, string_file_absolute_path, string_file_extension, string_file_path, string_file_relative_path, string_filename, string_folder_absolute_path, string_folder_path, string_folder_relative_path, string_host, string_hostname, string_href, string_html, string_javascript, string_javascript_name, string_license, string_markdown, string_markdown_text, string_mime_type, string_mime_type_with_wildcard, string_model_name, string_name, string_person_fullname, string_prompt, string_promptbook_url, string_promptbook_url_with_hashtemplate, string_script, string_sha256, string_tdl, string_template, string_text_prompt, string_title, string_token, string_translate_language, string_uri, string_uri_part, string_url, string_url_image, string_version } from '../types/typeAliases';
23
23
  import { FromtoItems } from '../utils/FromtoItems';
24
- export { AvailableModel, client_id, CommonExecutionToolsOptions, ExecutionReportJson, ExecutionTools, ExecutionType, EXPECTATION_UNITS, ExpectationAmount, Expectations, ExpectationUnit, FromtoItems, LlmExecutionTools, LlmTemplateJson, ModelRequirements, ModelVariant, Parameters, Prompt, PromptbookExecutor, PromptbookJson, PromptbookLibrary, PromptbookString, PromptChatResult, PromptCommonResult, PromptCompletionResult, PromptDialogJson, PromptResult, PromptTemplateJson, PromptTemplateParameterJson, ScriptExecutionTools, ScriptExecutionToolsExecuteOptions, ScriptJson, ScriptLanguage, SimpleTemplateJson, string_char, string_char_emoji, string_chat_prompt, string_completion_prompt, string_data_url, string_domain, string_email, string_file_absolute_path, string_file_extension, string_file_path, string_file_relative_path, string_filename, string_folder_absolute_path, string_folder_path, string_folder_relative_path, string_host, string_hostname, string_href, string_html, string_javascript, string_javascript_name, string_license, string_markdown, string_markdown_text, string_mime_type, string_mime_type_with_wildcard, string_model_name, string_name, string_person_fullname, string_prompt, string_promptbook_url, string_promptbook_url_with_hashtemplate, string_script, string_sha256, string_tdl, string_template, string_text_prompt, string_title, string_token, string_translate_language, string_uri, string_uri_part, string_url, string_url_image, string_version, TaskProgress, UserInterfaceTools, UserInterfaceToolsPromptDialogOptions, };
24
+ export { AvailableModel, client_id, CommonExecutionToolsOptions, ExecutionReportJson, ExecutionTools, ExecutionType, EXPECTATION_UNITS, ExpectationAmount, Expectations, ExpectationUnit, FromtoItems, LlmExecutionTools, LlmTemplateJson, ModelRequirements, ModelVariant, Parameters, Prompt, PromptbookExecutor, PromptbookJson, PromptbookLibrary, PromptbookString, PromptChatResult, PromptCommonResult, PromptCompletionResult, PromptDialogJson, PromptResult, PromptResultUsage, PromptResultUsageCounts, PromptTemplateJson, PromptTemplateParameterJson, ScriptExecutionTools, ScriptExecutionToolsExecuteOptions, ScriptJson, ScriptLanguage, SimpleTemplateJson, string_char, string_char_emoji, string_chat_prompt, string_completion_prompt, string_data_url, string_domain, string_email, string_file_absolute_path, string_file_extension, string_file_path, string_file_relative_path, string_filename, string_folder_absolute_path, string_folder_path, string_folder_relative_path, string_host, string_hostname, string_href, string_html, string_javascript, string_javascript_name, string_license, string_markdown, string_markdown_text, string_mime_type, string_mime_type_with_wildcard, string_model_name, string_name, string_person_fullname, string_prompt, string_promptbook_url, string_promptbook_url_with_hashtemplate, string_script, string_sha256, string_tdl, string_template, string_text_prompt, string_title, string_token, string_translate_language, string_uri, string_uri_part, string_url, string_url_image, string_version, TaskProgress, UncertainNumber, UserInterfaceTools, UserInterfaceToolsPromptDialogOptions, };
25
25
  /**
26
26
  * TODO: Delete type aliases (from ../types/typeAliases) that are not exported here
27
27
  */
@@ -1,5 +1,6 @@
1
- import type { number_positive_or_zero } from '../types/typeAliases';
2
- import type { number_tokens } from '../types/typeAliases';
1
+ import type { KebabCase } from 'type-fest';
2
+ import type { ExpectationUnit } from '../types/PromptbookJson/PromptTemplateJson';
3
+ import type { number_positive } from '../types/typeAliases';
3
4
  import type { number_usd } from '../types/typeAliases';
4
5
  import type { string_date_iso8601 } from '../types/typeAliases';
5
6
  import type { string_model_name } from '../types/typeAliases';
@@ -48,27 +49,51 @@ export type PromptCommonResult = {
48
49
  /**
49
50
  * Usage of the prompt execution
50
51
  */
51
- readonly usage: {
52
- /**
53
- * Cost of the execution in USD
54
- *
55
- * If the cost is unknown, the value is `'UNKNOWN'`
56
- */
57
- price: (number_positive_or_zero & number_usd) | 'UNKNOWN';
58
- /**
59
- * Number of tokens used in the input aka. `prompt_tokens`
60
- */
61
- inputTokens: number_tokens | 'UNKNOWN';
62
- /**
63
- * Number of tokens used in the output aka. `completion_tokens`
64
- */
65
- outputTokens: number_tokens | 'UNKNOWN';
66
- };
52
+ readonly usage: PromptResultUsage;
67
53
  /**
68
54
  * Raw response from the model
69
55
  */
70
56
  readonly rawResponse: object;
71
57
  };
58
+ /**
59
+ * Usage statistics for one or many prompt results
60
+ */
61
+ export type PromptResultUsage = {
62
+ /**
63
+ * Cost of the execution in USD
64
+ *
65
+ * Note: If the cost is unknown, the value 0 and isUncertain is true
66
+ */
67
+ price: UncertainNumber;
68
+ /**
69
+ * Number of whatever used in the input aka. `prompt_tokens`
70
+ */
71
+ input: PromptResultUsageCounts;
72
+ /**
73
+ * Number of tokens used in the output aka. `completion_tokens`
74
+ */
75
+ output: PromptResultUsageCounts;
76
+ };
77
+ /**
78
+ * Record of all possible measurable units
79
+ */
80
+ export type PromptResultUsageCounts = Record<`${KebabCase<'TOKENS' | ExpectationUnit>}Count`, UncertainNumber>;
81
+ /**
82
+ * Number which can be uncertain
83
+ *
84
+ * Note: If the value is completelly unknown, the value 0 and isUncertain is true
85
+ * Note: Not using NaN or null because it looses the value which is better to be uncertain then not to be at all
86
+ */
87
+ export type UncertainNumber = {
88
+ /**
89
+ * The numeric value
90
+ */
91
+ value: number_usd & (number_positive | 0);
92
+ /**
93
+ * Is the value uncertain
94
+ */
95
+ isUncertain?: true;
96
+ };
72
97
  /**
73
98
  * TODO: [🧠] Maybe timing more accurate then seconds?
74
99
  * TODO: [🧠] Should here be link to the prompt?
@@ -0,0 +1,7 @@
1
+ import type { PromptResultUsage } from './PromptResult';
2
+ /**
3
+ * Function addPromptResultUsage will add multiple usages into one
4
+ *
5
+ * Note: If you provide 0 values, it returns void usage
6
+ */
7
+ export declare function addPromptResultUsage(...usageItems: Array<PromptResultUsage>): PromptResultUsage;
@@ -0,0 +1,10 @@
1
+ import type { PromptResultUsageCounts } from './PromptResult';
2
+ /**
3
+ * Helper of usage compute
4
+ *
5
+ * @param content the content of prompt or response
6
+ * @returns part of PromptResultUsageCounts
7
+ *
8
+ * @private internal util of LlmExecutionTools
9
+ */
10
+ export declare function computeUsageCounts(content: string): Omit<PromptResultUsageCounts, 'tokensCount'>;
@@ -1,8 +1,12 @@
1
1
  import type OpenAI from 'openai';
2
+ import type { Prompt } from '../../../../types/Prompt';
2
3
  import type { PromptResult } from '../../../PromptResult';
4
+ import type { PromptResultUsage } from '../../../PromptResult';
3
5
  /**
4
6
  * Computes the usage of the OpenAI API based on the response from OpenAI
5
7
  *
6
8
  * @throws {PromptbookExecutionError} If the usage is not defined in the response from OpenAI
9
+ * @private internal util of `OpenAiExecutionTools`
7
10
  */
8
- export declare function computeOpenaiUsage(rawResponse: Pick<OpenAI.Chat.Completions.ChatCompletion | OpenAI.Completions.Completion, 'model' | 'usage'>): PromptResult['usage'];
11
+ export declare function computeOpenaiUsage(promptContent: Prompt['content'], // <- Note: Intentionally using [] to access type properties to bring jsdoc from Prompt/PromptResult to consumer
12
+ resultContent: PromptResult['content'], rawResponse: Pick<OpenAI.Chat.Completions.ChatCompletion | OpenAI.Completions.Completion, 'model' | 'usage'>): PromptResultUsage;
@@ -3,10 +3,11 @@ import type { ExecutionType } from '../ExecutionTypes';
3
3
  import type { ModelRequirements } from '../ModelRequirements';
4
4
  import type { ScriptLanguage } from '../ScriptLanguage';
5
5
  import type { number_integer } from '../typeAliases';
6
- import type { number_positive_or_zero } from '../typeAliases';
6
+ import type { number_positive } from '../typeAliases';
7
7
  import type { string_javascript } from '../typeAliases';
8
8
  import type { string_javascript_name } from '../typeAliases';
9
9
  import type { string_markdown } from '../typeAliases';
10
+ import type { string_markdown_text } from '../typeAliases';
10
11
  import type { string_name } from '../typeAliases';
11
12
  import type { string_prompt } from '../typeAliases';
12
13
  import type { string_template } from '../typeAliases';
@@ -47,7 +48,7 @@ export type ExpectationUnit = typeof EXPECTATION_UNITS[number];
47
48
  /**
48
49
  * Amount of text measurement
49
50
  */
50
- export type ExpectationAmount = number_integer & number_positive_or_zero;
51
+ export type ExpectationAmount = number_integer & (number_positive | 0);
51
52
  /**
52
53
  * Template for simple concatenation of strings
53
54
  */
@@ -92,7 +93,7 @@ interface PromptTemplateJsonCommon {
92
93
  * Description of the prompt template
93
94
  * It can use multiple paragraphs of simple markdown formatting like **bold**, *italic*, [link](https://example.com), ... BUT not code blocks and structure
94
95
  */
95
- readonly description?: string;
96
+ readonly description?: string_markdown_text;
96
97
  /**
97
98
  * List of parameter names that are used in the prompt template and must be defined before the prompt template is executed
98
99
  *
@@ -1,3 +1,4 @@
1
+ import type { string_markdown_text } from '../typeAliases';
1
2
  import type { string_name } from '../typeAliases';
2
3
  /**
3
4
  * Describes one parameter of the promptbook
@@ -21,5 +22,5 @@ export type PromptTemplateParameterJson = {
21
22
  * Description of the parameter
22
23
  * - It can use simple markdown formatting like **bold**, *italic*, [link](https://example.com), ... BUT not code blocks and structure
23
24
  */
24
- readonly description?: string;
25
+ readonly description?: string_markdown_text;
25
26
  };
@@ -1,3 +1,4 @@
1
+ import type { string_markdown_text } from '../typeAliases';
1
2
  import type { string_promptbook_url } from '../typeAliases';
2
3
  import type { string_version } from '../typeAliases';
3
4
  import type { PromptTemplateJson } from './PromptTemplateJson';
@@ -23,7 +24,7 @@ export type PromptbookJson = {
23
24
  * Title of the promptbook
24
25
  * -It can use simple markdown formatting like **bold**, *italic*, [link](https://example.com), ... BUT not code blocks and structure
25
26
  */
26
- readonly title: string;
27
+ readonly title: string_markdown_text;
27
28
  /**
28
29
  * Version of the .ptbk.json file
29
30
  */
@@ -32,7 +33,7 @@ export type PromptbookJson = {
32
33
  * Description of the promptbook
33
34
  * It can use multiple paragraphs of simple markdown formatting like **bold**, *italic*, [link](https://example.com), ... BUT not code blocks and structure
34
35
  */
35
- readonly description?: string;
36
+ readonly description?: string_markdown_text;
36
37
  /**
37
38
  * Set of variables that are used across the pipeline
38
39
  */
@@ -1,5 +1,6 @@
1
1
  import type { PromptResult } from '../../execution/PromptResult';
2
2
  import type { Prompt } from '../Prompt';
3
+ import type { string_markdown_text } from '../typeAliases';
3
4
  import type { string_promptbook_url } from '../typeAliases';
4
5
  import type { string_version } from '../typeAliases';
5
6
  /**
@@ -32,7 +33,7 @@ export type ExecutionReportJson = {
32
33
  /**
33
34
  * Description of the promptbook which was executed
34
35
  */
35
- readonly description?: string;
36
+ readonly description?: string_markdown_text;
36
37
  /**
37
38
  * Sequence of prompt templates in order which were executed
38
39
  */
@@ -393,11 +393,9 @@ export type number_usd = number;
393
393
  /**
394
394
  * Semantic helper for number of tokens
395
395
  */
396
- export type number_tokens = number_integer & number_positive_or_zero;
396
+ export type number_tokens = number_integer & (number_positive | 0);
397
397
  export type number_positive = number;
398
398
  export type number_negative = number;
399
- export type number_positive_or_zero = number;
400
- export type number_negative_or_zero = number;
401
399
  export type number_integer = number;
402
400
  /**
403
401
  * Semantic helper;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/remote-client",
3
- "version": "0.54.0",
3
+ "version": "0.55.0-0",
4
4
  "description": "Library to supercharge your use of large language models",
5
5
  "private": false,
6
6
  "sideEffects": false,
@@ -47,7 +47,7 @@
47
47
  }
48
48
  ],
49
49
  "peerDependencies": {
50
- "@promptbook/core": "0.54.0"
50
+ "@promptbook/core": "0.55.0-0"
51
51
  },
52
52
  "main": "./umd/index.umd.js",
53
53
  "module": "./esm/index.es.js",
@@ -11,6 +11,7 @@ import { PromptbookReferenceError } from '../errors/PromptbookReferenceError';
11
11
  import { PromptbookSyntaxError } from '../errors/PromptbookSyntaxError';
12
12
  import { TemplateError } from '../errors/TemplateError';
13
13
  import { UnexpectedError } from '../errors/UnexpectedError';
14
+ import { addPromptResultUsage } from '../execution/addPromptResultUsage';
14
15
  import { assertsExecutionSuccessful } from '../execution/assertsExecutionSuccessful';
15
16
  import { createPromptbookExecutor } from '../execution/createPromptbookExecutor';
16
17
  import { MultipleLlmExecutionTools } from '../execution/plugins/llm-execution-tools/multiple/MultipleLlmExecutionTools';
@@ -30,7 +31,7 @@ import { ExecutionTypes } from '../types/ExecutionTypes';
30
31
  import { PROMPTBOOK_VERSION } from '../version';
31
32
  export { justTestFsImport };
32
33
  export { ExecutionTypes, PROMPTBOOK_VERSION };
33
- export { assertsExecutionSuccessful, checkExpectations, executionReportJsonToString, ExecutionReportStringOptions, ExecutionReportStringOptionsDefaults, isPassingExpectations, prettifyPromptbookString, };
34
+ export { addPromptResultUsage, assertsExecutionSuccessful, checkExpectations, executionReportJsonToString, ExecutionReportStringOptions, ExecutionReportStringOptionsDefaults, isPassingExpectations, prettifyPromptbookString, };
34
35
  export { createPromptbookLibraryFromDirectory, createPromptbookLibraryFromSources, createPromptbookLibraryFromUrl, createPromptbookSublibrary, SimplePromptbookLibrary, };
35
36
  export { SimplePromptInterfaceTools };
36
37
  export { promptbookJsonToString, promptbookStringToJson, validatePromptbookJson };
@@ -1,7 +1,7 @@
1
1
  import type { CommonExecutionToolsOptions } from '../execution/CommonExecutionToolsOptions';
2
2
  import type { ExecutionTools } from '../execution/ExecutionTools';
3
3
  import type { AvailableModel, LlmExecutionTools } from '../execution/LlmExecutionTools';
4
- import type { PromptChatResult, PromptCommonResult, PromptCompletionResult, PromptResult } from '../execution/PromptResult';
4
+ import type { PromptChatResult, PromptCommonResult, PromptCompletionResult, PromptResult, PromptResultUsage, PromptResultUsageCounts, UncertainNumber } from '../execution/PromptResult';
5
5
  import type { PromptbookExecutor } from '../execution/PromptbookExecutor';
6
6
  import type { ScriptExecutionTools, ScriptExecutionToolsExecuteOptions } from '../execution/ScriptExecutionTools';
7
7
  import type { UserInterfaceTools, UserInterfaceToolsPromptDialogOptions } from '../execution/UserInterfaceTools';
@@ -21,7 +21,7 @@ import type { ExecutionReportJson } from '../types/execution-report/ExecutionRep
21
21
  import type { string_char_emoji } from '../types/typeAliasEmoji';
22
22
  import type { client_id, string_char, string_chat_prompt, string_completion_prompt, string_data_url, string_domain, string_email, string_file_absolute_path, string_file_extension, string_file_path, string_file_relative_path, string_filename, string_folder_absolute_path, string_folder_path, string_folder_relative_path, string_host, string_hostname, string_href, string_html, string_javascript, string_javascript_name, string_license, string_markdown, string_markdown_text, string_mime_type, string_mime_type_with_wildcard, string_model_name, string_name, string_person_fullname, string_prompt, string_promptbook_url, string_promptbook_url_with_hashtemplate, string_script, string_sha256, string_tdl, string_template, string_text_prompt, string_title, string_token, string_translate_language, string_uri, string_uri_part, string_url, string_url_image, string_version } from '../types/typeAliases';
23
23
  import { FromtoItems } from '../utils/FromtoItems';
24
- export { AvailableModel, client_id, CommonExecutionToolsOptions, ExecutionReportJson, ExecutionTools, ExecutionType, EXPECTATION_UNITS, ExpectationAmount, Expectations, ExpectationUnit, FromtoItems, LlmExecutionTools, LlmTemplateJson, ModelRequirements, ModelVariant, Parameters, Prompt, PromptbookExecutor, PromptbookJson, PromptbookLibrary, PromptbookString, PromptChatResult, PromptCommonResult, PromptCompletionResult, PromptDialogJson, PromptResult, PromptTemplateJson, PromptTemplateParameterJson, ScriptExecutionTools, ScriptExecutionToolsExecuteOptions, ScriptJson, ScriptLanguage, SimpleTemplateJson, string_char, string_char_emoji, string_chat_prompt, string_completion_prompt, string_data_url, string_domain, string_email, string_file_absolute_path, string_file_extension, string_file_path, string_file_relative_path, string_filename, string_folder_absolute_path, string_folder_path, string_folder_relative_path, string_host, string_hostname, string_href, string_html, string_javascript, string_javascript_name, string_license, string_markdown, string_markdown_text, string_mime_type, string_mime_type_with_wildcard, string_model_name, string_name, string_person_fullname, string_prompt, string_promptbook_url, string_promptbook_url_with_hashtemplate, string_script, string_sha256, string_tdl, string_template, string_text_prompt, string_title, string_token, string_translate_language, string_uri, string_uri_part, string_url, string_url_image, string_version, TaskProgress, UserInterfaceTools, UserInterfaceToolsPromptDialogOptions, };
24
+ export { AvailableModel, client_id, CommonExecutionToolsOptions, ExecutionReportJson, ExecutionTools, ExecutionType, EXPECTATION_UNITS, ExpectationAmount, Expectations, ExpectationUnit, FromtoItems, LlmExecutionTools, LlmTemplateJson, ModelRequirements, ModelVariant, Parameters, Prompt, PromptbookExecutor, PromptbookJson, PromptbookLibrary, PromptbookString, PromptChatResult, PromptCommonResult, PromptCompletionResult, PromptDialogJson, PromptResult, PromptResultUsage, PromptResultUsageCounts, PromptTemplateJson, PromptTemplateParameterJson, ScriptExecutionTools, ScriptExecutionToolsExecuteOptions, ScriptJson, ScriptLanguage, SimpleTemplateJson, string_char, string_char_emoji, string_chat_prompt, string_completion_prompt, string_data_url, string_domain, string_email, string_file_absolute_path, string_file_extension, string_file_path, string_file_relative_path, string_filename, string_folder_absolute_path, string_folder_path, string_folder_relative_path, string_host, string_hostname, string_href, string_html, string_javascript, string_javascript_name, string_license, string_markdown, string_markdown_text, string_mime_type, string_mime_type_with_wildcard, string_model_name, string_name, string_person_fullname, string_prompt, string_promptbook_url, string_promptbook_url_with_hashtemplate, string_script, string_sha256, string_tdl, string_template, string_text_prompt, string_title, string_token, string_translate_language, string_uri, string_uri_part, string_url, string_url_image, string_version, TaskProgress, UncertainNumber, UserInterfaceTools, UserInterfaceToolsPromptDialogOptions, };
25
25
  /**
26
26
  * TODO: Delete type aliases (from ../types/typeAliases) that are not exported here
27
27
  */
@@ -1,5 +1,6 @@
1
- import type { number_positive_or_zero } from '../types/typeAliases';
2
- import type { number_tokens } from '../types/typeAliases';
1
+ import type { KebabCase } from 'type-fest';
2
+ import type { ExpectationUnit } from '../types/PromptbookJson/PromptTemplateJson';
3
+ import type { number_positive } from '../types/typeAliases';
3
4
  import type { number_usd } from '../types/typeAliases';
4
5
  import type { string_date_iso8601 } from '../types/typeAliases';
5
6
  import type { string_model_name } from '../types/typeAliases';
@@ -48,27 +49,51 @@ export type PromptCommonResult = {
48
49
  /**
49
50
  * Usage of the prompt execution
50
51
  */
51
- readonly usage: {
52
- /**
53
- * Cost of the execution in USD
54
- *
55
- * If the cost is unknown, the value is `'UNKNOWN'`
56
- */
57
- price: (number_positive_or_zero & number_usd) | 'UNKNOWN';
58
- /**
59
- * Number of tokens used in the input aka. `prompt_tokens`
60
- */
61
- inputTokens: number_tokens | 'UNKNOWN';
62
- /**
63
- * Number of tokens used in the output aka. `completion_tokens`
64
- */
65
- outputTokens: number_tokens | 'UNKNOWN';
66
- };
52
+ readonly usage: PromptResultUsage;
67
53
  /**
68
54
  * Raw response from the model
69
55
  */
70
56
  readonly rawResponse: object;
71
57
  };
58
+ /**
59
+ * Usage statistics for one or many prompt results
60
+ */
61
+ export type PromptResultUsage = {
62
+ /**
63
+ * Cost of the execution in USD
64
+ *
65
+ * Note: If the cost is unknown, the value 0 and isUncertain is true
66
+ */
67
+ price: UncertainNumber;
68
+ /**
69
+ * Number of whatever used in the input aka. `prompt_tokens`
70
+ */
71
+ input: PromptResultUsageCounts;
72
+ /**
73
+ * Number of tokens used in the output aka. `completion_tokens`
74
+ */
75
+ output: PromptResultUsageCounts;
76
+ };
77
+ /**
78
+ * Record of all possible measurable units
79
+ */
80
+ export type PromptResultUsageCounts = Record<`${KebabCase<'TOKENS' | ExpectationUnit>}Count`, UncertainNumber>;
81
+ /**
82
+ * Number which can be uncertain
83
+ *
84
+ * Note: If the value is completelly unknown, the value 0 and isUncertain is true
85
+ * Note: Not using NaN or null because it looses the value which is better to be uncertain then not to be at all
86
+ */
87
+ export type UncertainNumber = {
88
+ /**
89
+ * The numeric value
90
+ */
91
+ value: number_usd & (number_positive | 0);
92
+ /**
93
+ * Is the value uncertain
94
+ */
95
+ isUncertain?: true;
96
+ };
72
97
  /**
73
98
  * TODO: [🧠] Maybe timing more accurate then seconds?
74
99
  * TODO: [🧠] Should here be link to the prompt?
@@ -0,0 +1,7 @@
1
+ import type { PromptResultUsage } from './PromptResult';
2
+ /**
3
+ * Function addPromptResultUsage will add multiple usages into one
4
+ *
5
+ * Note: If you provide 0 values, it returns void usage
6
+ */
7
+ export declare function addPromptResultUsage(...usageItems: Array<PromptResultUsage>): PromptResultUsage;
@@ -0,0 +1,10 @@
1
+ import type { PromptResultUsageCounts } from './PromptResult';
2
+ /**
3
+ * Helper of usage compute
4
+ *
5
+ * @param content the content of prompt or response
6
+ * @returns part of PromptResultUsageCounts
7
+ *
8
+ * @private internal util of LlmExecutionTools
9
+ */
10
+ export declare function computeUsageCounts(content: string): Omit<PromptResultUsageCounts, 'tokensCount'>;
@@ -1,8 +1,12 @@
1
1
  import type OpenAI from 'openai';
2
+ import type { Prompt } from '../../../../types/Prompt';
2
3
  import type { PromptResult } from '../../../PromptResult';
4
+ import type { PromptResultUsage } from '../../../PromptResult';
3
5
  /**
4
6
  * Computes the usage of the OpenAI API based on the response from OpenAI
5
7
  *
6
8
  * @throws {PromptbookExecutionError} If the usage is not defined in the response from OpenAI
9
+ * @private internal util of `OpenAiExecutionTools`
7
10
  */
8
- export declare function computeOpenaiUsage(rawResponse: Pick<OpenAI.Chat.Completions.ChatCompletion | OpenAI.Completions.Completion, 'model' | 'usage'>): PromptResult['usage'];
11
+ export declare function computeOpenaiUsage(promptContent: Prompt['content'], // <- Note: Intentionally using [] to access type properties to bring jsdoc from Prompt/PromptResult to consumer
12
+ resultContent: PromptResult['content'], rawResponse: Pick<OpenAI.Chat.Completions.ChatCompletion | OpenAI.Completions.Completion, 'model' | 'usage'>): PromptResultUsage;
@@ -3,10 +3,11 @@ import type { ExecutionType } from '../ExecutionTypes';
3
3
  import type { ModelRequirements } from '../ModelRequirements';
4
4
  import type { ScriptLanguage } from '../ScriptLanguage';
5
5
  import type { number_integer } from '../typeAliases';
6
- import type { number_positive_or_zero } from '../typeAliases';
6
+ import type { number_positive } from '../typeAliases';
7
7
  import type { string_javascript } from '../typeAliases';
8
8
  import type { string_javascript_name } from '../typeAliases';
9
9
  import type { string_markdown } from '../typeAliases';
10
+ import type { string_markdown_text } from '../typeAliases';
10
11
  import type { string_name } from '../typeAliases';
11
12
  import type { string_prompt } from '../typeAliases';
12
13
  import type { string_template } from '../typeAliases';
@@ -47,7 +48,7 @@ export type ExpectationUnit = typeof EXPECTATION_UNITS[number];
47
48
  /**
48
49
  * Amount of text measurement
49
50
  */
50
- export type ExpectationAmount = number_integer & number_positive_or_zero;
51
+ export type ExpectationAmount = number_integer & (number_positive | 0);
51
52
  /**
52
53
  * Template for simple concatenation of strings
53
54
  */
@@ -92,7 +93,7 @@ interface PromptTemplateJsonCommon {
92
93
  * Description of the prompt template
93
94
  * It can use multiple paragraphs of simple markdown formatting like **bold**, *italic*, [link](https://example.com), ... BUT not code blocks and structure
94
95
  */
95
- readonly description?: string;
96
+ readonly description?: string_markdown_text;
96
97
  /**
97
98
  * List of parameter names that are used in the prompt template and must be defined before the prompt template is executed
98
99
  *
@@ -1,3 +1,4 @@
1
+ import type { string_markdown_text } from '../typeAliases';
1
2
  import type { string_name } from '../typeAliases';
2
3
  /**
3
4
  * Describes one parameter of the promptbook
@@ -21,5 +22,5 @@ export type PromptTemplateParameterJson = {
21
22
  * Description of the parameter
22
23
  * - It can use simple markdown formatting like **bold**, *italic*, [link](https://example.com), ... BUT not code blocks and structure
23
24
  */
24
- readonly description?: string;
25
+ readonly description?: string_markdown_text;
25
26
  };
@@ -1,3 +1,4 @@
1
+ import type { string_markdown_text } from '../typeAliases';
1
2
  import type { string_promptbook_url } from '../typeAliases';
2
3
  import type { string_version } from '../typeAliases';
3
4
  import type { PromptTemplateJson } from './PromptTemplateJson';
@@ -23,7 +24,7 @@ export type PromptbookJson = {
23
24
  * Title of the promptbook
24
25
  * -It can use simple markdown formatting like **bold**, *italic*, [link](https://example.com), ... BUT not code blocks and structure
25
26
  */
26
- readonly title: string;
27
+ readonly title: string_markdown_text;
27
28
  /**
28
29
  * Version of the .ptbk.json file
29
30
  */
@@ -32,7 +33,7 @@ export type PromptbookJson = {
32
33
  * Description of the promptbook
33
34
  * It can use multiple paragraphs of simple markdown formatting like **bold**, *italic*, [link](https://example.com), ... BUT not code blocks and structure
34
35
  */
35
- readonly description?: string;
36
+ readonly description?: string_markdown_text;
36
37
  /**
37
38
  * Set of variables that are used across the pipeline
38
39
  */
@@ -1,5 +1,6 @@
1
1
  import type { PromptResult } from '../../execution/PromptResult';
2
2
  import type { Prompt } from '../Prompt';
3
+ import type { string_markdown_text } from '../typeAliases';
3
4
  import type { string_promptbook_url } from '../typeAliases';
4
5
  import type { string_version } from '../typeAliases';
5
6
  /**
@@ -32,7 +33,7 @@ export type ExecutionReportJson = {
32
33
  /**
33
34
  * Description of the promptbook which was executed
34
35
  */
35
- readonly description?: string;
36
+ readonly description?: string_markdown_text;
36
37
  /**
37
38
  * Sequence of prompt templates in order which were executed
38
39
  */
@@ -393,11 +393,9 @@ export type number_usd = number;
393
393
  /**
394
394
  * Semantic helper for number of tokens
395
395
  */
396
- export type number_tokens = number_integer & number_positive_or_zero;
396
+ export type number_tokens = number_integer & (number_positive | 0);
397
397
  export type number_positive = number;
398
398
  export type number_negative = number;
399
- export type number_positive_or_zero = number;
400
- export type number_negative_or_zero = number;
401
399
  export type number_integer = number;
402
400
  /**
403
401
  * Semantic helper;