@promptbook/remote-client 0.54.1 → 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.
@@ -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,11 +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 { string_markdown_text } from '../typeAliases';
7
- import type { number_positive_or_zero } from '../typeAliases';
6
+ import type { number_positive } from '../typeAliases';
8
7
  import type { string_javascript } from '../typeAliases';
9
8
  import type { string_javascript_name } from '../typeAliases';
10
9
  import type { string_markdown } from '../typeAliases';
10
+ import type { string_markdown_text } from '../typeAliases';
11
11
  import type { string_name } from '../typeAliases';
12
12
  import type { string_prompt } from '../typeAliases';
13
13
  import type { string_template } from '../typeAliases';
@@ -48,7 +48,7 @@ export type ExpectationUnit = typeof EXPECTATION_UNITS[number];
48
48
  /**
49
49
  * Amount of text measurement
50
50
  */
51
- export type ExpectationAmount = number_integer & number_positive_or_zero;
51
+ export type ExpectationAmount = number_integer & (number_positive | 0);
52
52
  /**
53
53
  * Template for simple concatenation of strings
54
54
  */
@@ -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.1",
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.1"
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,11 +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 { string_markdown_text } from '../typeAliases';
7
- import type { number_positive_or_zero } from '../typeAliases';
6
+ import type { number_positive } from '../typeAliases';
8
7
  import type { string_javascript } from '../typeAliases';
9
8
  import type { string_javascript_name } from '../typeAliases';
10
9
  import type { string_markdown } from '../typeAliases';
10
+ import type { string_markdown_text } from '../typeAliases';
11
11
  import type { string_name } from '../typeAliases';
12
12
  import type { string_prompt } from '../typeAliases';
13
13
  import type { string_template } from '../typeAliases';
@@ -48,7 +48,7 @@ export type ExpectationUnit = typeof EXPECTATION_UNITS[number];
48
48
  /**
49
49
  * Amount of text measurement
50
50
  */
51
- export type ExpectationAmount = number_integer & number_positive_or_zero;
51
+ export type ExpectationAmount = number_integer & (number_positive | 0);
52
52
  /**
53
53
  * Template for simple concatenation of strings
54
54
  */
@@ -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;