@promptbook/core 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.
- package/README.md +1 -1
- package/esm/index.es.js +135 -31
- package/esm/index.es.js.map +1 -1
- package/esm/typings/_packages/core.index.d.ts +2 -1
- package/esm/typings/_packages/types.index.d.ts +2 -2
- package/esm/typings/execution/PromptResult.d.ts +43 -18
- package/esm/typings/execution/addPromptResultUsage.d.ts +7 -0
- package/esm/typings/execution/addPromptResultUsage.test.d.ts +1 -0
- package/esm/typings/execution/computeUsageCounts.d.ts +10 -0
- package/esm/typings/execution/plugins/llm-execution-tools/openai/computeOpenaiUsage.d.ts +5 -1
- package/esm/typings/types/PromptbookJson/PromptTemplateJson.d.ts +4 -3
- package/esm/typings/types/PromptbookJson/PromptTemplateParameterJson.d.ts +2 -1
- package/esm/typings/types/PromptbookJson/PromptbookJson.d.ts +3 -2
- package/esm/typings/types/execution-report/ExecutionReportJson.d.ts +2 -1
- package/esm/typings/types/typeAliases.d.ts +1 -3
- package/package.json +1 -1
- package/umd/index.umd.js +135 -30
- package/umd/index.umd.js.map +1 -1
- package/umd/typings/_packages/core.index.d.ts +2 -1
- package/umd/typings/_packages/types.index.d.ts +2 -2
- package/umd/typings/execution/PromptResult.d.ts +43 -18
- package/umd/typings/execution/addPromptResultUsage.d.ts +7 -0
- package/umd/typings/execution/addPromptResultUsage.test.d.ts +1 -0
- package/umd/typings/execution/computeUsageCounts.d.ts +10 -0
- package/umd/typings/execution/plugins/llm-execution-tools/openai/computeOpenaiUsage.d.ts +5 -1
- package/umd/typings/types/PromptbookJson/PromptTemplateJson.d.ts +4 -3
- package/umd/typings/types/PromptbookJson/PromptTemplateParameterJson.d.ts +2 -1
- package/umd/typings/types/PromptbookJson/PromptbookJson.d.ts +3 -2
- package/umd/typings/types/execution-report/ExecutionReportJson.d.ts +2 -1
- package/umd/typings/types/typeAliases.d.ts +1 -3
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
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 @@
|
|
|
1
|
+
export {};
|
|
@@ -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(
|
|
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 {
|
|
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 &
|
|
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?:
|
|
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?:
|
|
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:
|
|
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?:
|
|
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?:
|
|
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 &
|
|
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
package/umd/index.umd.js
CHANGED
|
@@ -454,7 +454,7 @@
|
|
|
454
454
|
/**
|
|
455
455
|
* The version of the Promptbook library
|
|
456
456
|
*/
|
|
457
|
-
var PROMPTBOOK_VERSION = '0.
|
|
457
|
+
var PROMPTBOOK_VERSION = '0.54.1';
|
|
458
458
|
|
|
459
459
|
/**
|
|
460
460
|
* Parses the template and returns the list of all parameter names
|
|
@@ -1777,7 +1777,7 @@
|
|
|
1777
1777
|
* @returns Promptbook in string format (.ptbk.md)
|
|
1778
1778
|
*/
|
|
1779
1779
|
function promptbookJsonToString(promptbookJson) {
|
|
1780
|
-
var e_1, _a, e_2, _b, e_3, _c, e_4, _d, e_5, _e;
|
|
1780
|
+
var e_1, _a, e_2, _b, e_3, _c, e_4, _d, e_5, _e, e_6, _f;
|
|
1781
1781
|
var title = promptbookJson.title, promptbookUrl = promptbookJson.promptbookUrl, promptbookVersion = promptbookJson.promptbookVersion, description = promptbookJson.description, parameters = promptbookJson.parameters, promptTemplates = promptbookJson.promptTemplates;
|
|
1782
1782
|
var promptbookString = "# ".concat(title);
|
|
1783
1783
|
if (description) {
|
|
@@ -1792,24 +1792,37 @@
|
|
|
1792
1792
|
commands.push("PROMPTBOOK VERSION ".concat(promptbookVersion));
|
|
1793
1793
|
promptbookString = prettifyMarkdown(promptbookString);
|
|
1794
1794
|
try {
|
|
1795
|
-
for (var
|
|
1796
|
-
var
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
else if (isOutput) {
|
|
1802
|
-
commands.push("OUTPUT PARAMETER ".concat(promptTemplateParameterJsonToString(parameter)));
|
|
1803
|
-
}
|
|
1795
|
+
for (var _g = __values(parameters.filter(function (_a) {
|
|
1796
|
+
var isInput = _a.isInput;
|
|
1797
|
+
return isInput;
|
|
1798
|
+
})), _h = _g.next(); !_h.done; _h = _g.next()) {
|
|
1799
|
+
var parameter = _h.value;
|
|
1800
|
+
commands.push("INPUT PARAMETER ".concat(promptTemplateParameterJsonToString(parameter)));
|
|
1804
1801
|
}
|
|
1805
1802
|
}
|
|
1806
1803
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1807
1804
|
finally {
|
|
1808
1805
|
try {
|
|
1809
|
-
if (
|
|
1806
|
+
if (_h && !_h.done && (_a = _g.return)) _a.call(_g);
|
|
1810
1807
|
}
|
|
1811
1808
|
finally { if (e_1) throw e_1.error; }
|
|
1812
1809
|
}
|
|
1810
|
+
try {
|
|
1811
|
+
for (var _j = __values(parameters.filter(function (_a) {
|
|
1812
|
+
var isOutput = _a.isOutput;
|
|
1813
|
+
return isOutput;
|
|
1814
|
+
})), _k = _j.next(); !_k.done; _k = _j.next()) {
|
|
1815
|
+
var parameter = _k.value;
|
|
1816
|
+
commands.push("OUTPUT PARAMETER ".concat(promptTemplateParameterJsonToString(parameter)));
|
|
1817
|
+
}
|
|
1818
|
+
}
|
|
1819
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
1820
|
+
finally {
|
|
1821
|
+
try {
|
|
1822
|
+
if (_k && !_k.done && (_b = _j.return)) _b.call(_j);
|
|
1823
|
+
}
|
|
1824
|
+
finally { if (e_2) throw e_2.error; }
|
|
1825
|
+
}
|
|
1813
1826
|
promptbookString += '\n\n';
|
|
1814
1827
|
promptbookString += commands.map(function (command) { return "- ".concat(command); }).join('\n');
|
|
1815
1828
|
try {
|
|
@@ -1859,38 +1872,38 @@
|
|
|
1859
1872
|
}
|
|
1860
1873
|
if (jokers) {
|
|
1861
1874
|
try {
|
|
1862
|
-
for (var jokers_1 = (
|
|
1875
|
+
for (var jokers_1 = (e_4 = void 0, __values(jokers)), jokers_1_1 = jokers_1.next(); !jokers_1_1.done; jokers_1_1 = jokers_1.next()) {
|
|
1863
1876
|
var joker = jokers_1_1.value;
|
|
1864
1877
|
commands_1.push("JOKER {".concat(joker, "}"));
|
|
1865
1878
|
}
|
|
1866
1879
|
}
|
|
1867
|
-
catch (
|
|
1880
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
1868
1881
|
finally {
|
|
1869
1882
|
try {
|
|
1870
|
-
if (jokers_1_1 && !jokers_1_1.done && (
|
|
1883
|
+
if (jokers_1_1 && !jokers_1_1.done && (_d = jokers_1.return)) _d.call(jokers_1);
|
|
1871
1884
|
}
|
|
1872
|
-
finally { if (
|
|
1885
|
+
finally { if (e_4) throw e_4.error; }
|
|
1873
1886
|
}
|
|
1874
1887
|
} /* not else */
|
|
1875
1888
|
if (postprocessing) {
|
|
1876
1889
|
try {
|
|
1877
|
-
for (var postprocessing_1 = (
|
|
1890
|
+
for (var postprocessing_1 = (e_5 = void 0, __values(postprocessing)), postprocessing_1_1 = postprocessing_1.next(); !postprocessing_1_1.done; postprocessing_1_1 = postprocessing_1.next()) {
|
|
1878
1891
|
var postprocessingFunctionName = postprocessing_1_1.value;
|
|
1879
1892
|
commands_1.push("POSTPROCESSING `".concat(postprocessingFunctionName, "`"));
|
|
1880
1893
|
}
|
|
1881
1894
|
}
|
|
1882
|
-
catch (
|
|
1895
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
1883
1896
|
finally {
|
|
1884
1897
|
try {
|
|
1885
|
-
if (postprocessing_1_1 && !postprocessing_1_1.done && (
|
|
1898
|
+
if (postprocessing_1_1 && !postprocessing_1_1.done && (_e = postprocessing_1.return)) _e.call(postprocessing_1);
|
|
1886
1899
|
}
|
|
1887
|
-
finally { if (
|
|
1900
|
+
finally { if (e_5) throw e_5.error; }
|
|
1888
1901
|
}
|
|
1889
1902
|
} /* not else */
|
|
1890
1903
|
if (expectations) {
|
|
1891
1904
|
try {
|
|
1892
|
-
for (var
|
|
1893
|
-
var
|
|
1905
|
+
for (var _l = (e_6 = void 0, __values(Object.entries(expectations))), _m = _l.next(); !_m.done; _m = _l.next()) {
|
|
1906
|
+
var _o = __read(_m.value, 2), unit = _o[0], _p = _o[1], min = _p.min, max = _p.max;
|
|
1894
1907
|
if (min === max) {
|
|
1895
1908
|
commands_1.push("EXPECT EXACTLY ".concat(min, " ").concat(capitalize(unit + (min > 1 ? 's' : ''))));
|
|
1896
1909
|
}
|
|
@@ -1904,12 +1917,12 @@
|
|
|
1904
1917
|
}
|
|
1905
1918
|
}
|
|
1906
1919
|
}
|
|
1907
|
-
catch (
|
|
1920
|
+
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
1908
1921
|
finally {
|
|
1909
1922
|
try {
|
|
1910
|
-
if (
|
|
1923
|
+
if (_m && !_m.done && (_f = _l.return)) _f.call(_l);
|
|
1911
1924
|
}
|
|
1912
|
-
finally { if (
|
|
1925
|
+
finally { if (e_6) throw e_6.error; }
|
|
1913
1926
|
}
|
|
1914
1927
|
} /* not else */
|
|
1915
1928
|
if (expectFormat) {
|
|
@@ -1932,12 +1945,12 @@
|
|
|
1932
1945
|
promptbookString += "`-> {".concat(resultingParameterName, "}`"); // <- TODO: !!! If the parameter here has description, add it and use promptTemplateParameterJsonToString
|
|
1933
1946
|
}
|
|
1934
1947
|
}
|
|
1935
|
-
catch (
|
|
1948
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
1936
1949
|
finally {
|
|
1937
1950
|
try {
|
|
1938
|
-
if (promptTemplates_1_1 && !promptTemplates_1_1.done && (
|
|
1951
|
+
if (promptTemplates_1_1 && !promptTemplates_1_1.done && (_c = promptTemplates_1.return)) _c.call(promptTemplates_1);
|
|
1939
1952
|
}
|
|
1940
|
-
finally { if (
|
|
1953
|
+
finally { if (e_3) throw e_3.error; }
|
|
1941
1954
|
}
|
|
1942
1955
|
return promptbookString;
|
|
1943
1956
|
}
|
|
@@ -2271,6 +2284,97 @@
|
|
|
2271
2284
|
return TemplateError;
|
|
2272
2285
|
}(Error));
|
|
2273
2286
|
|
|
2287
|
+
/**
|
|
2288
|
+
* Function addPromptResultUsage will add multiple usages into one
|
|
2289
|
+
*
|
|
2290
|
+
* Note: If you provide 0 values, it returns void usage
|
|
2291
|
+
*/
|
|
2292
|
+
function addPromptResultUsage() {
|
|
2293
|
+
var usageItems = [];
|
|
2294
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2295
|
+
usageItems[_i] = arguments[_i];
|
|
2296
|
+
}
|
|
2297
|
+
var initialStructure = {
|
|
2298
|
+
price: { value: 0 },
|
|
2299
|
+
input: {
|
|
2300
|
+
tokensCount: { value: 0 },
|
|
2301
|
+
charactersCount: { value: 0 },
|
|
2302
|
+
wordsCount: { value: 0 },
|
|
2303
|
+
sentencesCount: { value: 0 },
|
|
2304
|
+
linesCount: { value: 0 },
|
|
2305
|
+
paragraphsCount: { value: 0 },
|
|
2306
|
+
pagesCount: { value: 0 },
|
|
2307
|
+
},
|
|
2308
|
+
output: {
|
|
2309
|
+
tokensCount: { value: 0 },
|
|
2310
|
+
charactersCount: { value: 0 },
|
|
2311
|
+
wordsCount: { value: 0 },
|
|
2312
|
+
sentencesCount: { value: 0 },
|
|
2313
|
+
linesCount: { value: 0 },
|
|
2314
|
+
paragraphsCount: { value: 0 },
|
|
2315
|
+
pagesCount: { value: 0 },
|
|
2316
|
+
},
|
|
2317
|
+
};
|
|
2318
|
+
return usageItems.reduce(function (acc, item) {
|
|
2319
|
+
var e_1, _a, e_2, _b;
|
|
2320
|
+
var _c;
|
|
2321
|
+
acc.price.value += ((_c = item.price) === null || _c === void 0 ? void 0 : _c.value) || 0;
|
|
2322
|
+
try {
|
|
2323
|
+
for (var _d = __values(Object.keys(acc.input)), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
2324
|
+
var key = _e.value;
|
|
2325
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2326
|
+
//@ts-ignore
|
|
2327
|
+
if (item.input[key]) {
|
|
2328
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2329
|
+
//@ts-ignore
|
|
2330
|
+
acc.input[key].value += item.input[key].value || 0;
|
|
2331
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2332
|
+
//@ts-ignore
|
|
2333
|
+
if (item.input[key].isUncertain) {
|
|
2334
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2335
|
+
//@ts-ignore
|
|
2336
|
+
acc.input[key].isUncertain = true;
|
|
2337
|
+
}
|
|
2338
|
+
}
|
|
2339
|
+
}
|
|
2340
|
+
}
|
|
2341
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2342
|
+
finally {
|
|
2343
|
+
try {
|
|
2344
|
+
if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
|
|
2345
|
+
}
|
|
2346
|
+
finally { if (e_1) throw e_1.error; }
|
|
2347
|
+
}
|
|
2348
|
+
try {
|
|
2349
|
+
for (var _f = __values(Object.keys(acc.output)), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
2350
|
+
var key = _g.value;
|
|
2351
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2352
|
+
//@ts-ignore
|
|
2353
|
+
if (item.output[key]) {
|
|
2354
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2355
|
+
//@ts-ignore
|
|
2356
|
+
acc.output[key].value += item.output[key].value || 0;
|
|
2357
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2358
|
+
//@ts-ignore
|
|
2359
|
+
if (item.output[key].isUncertain) {
|
|
2360
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2361
|
+
//@ts-ignore
|
|
2362
|
+
acc.output[key].isUncertain = true;
|
|
2363
|
+
}
|
|
2364
|
+
}
|
|
2365
|
+
}
|
|
2366
|
+
}
|
|
2367
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
2368
|
+
finally {
|
|
2369
|
+
try {
|
|
2370
|
+
if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
|
|
2371
|
+
}
|
|
2372
|
+
finally { if (e_2) throw e_2.error; }
|
|
2373
|
+
}
|
|
2374
|
+
return acc;
|
|
2375
|
+
}, initialStructure);
|
|
2376
|
+
}
|
|
2377
|
+
|
|
2274
2378
|
/**
|
|
2275
2379
|
* Asserts that the execution of a promptnook is successful
|
|
2276
2380
|
*
|
|
@@ -3997,13 +4101,13 @@
|
|
|
3997
4101
|
return ({
|
|
3998
4102
|
title: promptExecution.prompt.title,
|
|
3999
4103
|
from: 0,
|
|
4000
|
-
to: ((_b = (_a = promptExecution.result) === null || _a === void 0 ? void 0 : _a.usage) === null || _b === void 0 ? void 0 : _b.price) * (1 + taxRate),
|
|
4104
|
+
to: (((_b = (_a = promptExecution.result) === null || _a === void 0 ? void 0 : _a.usage) === null || _b === void 0 ? void 0 : _b.price.value) || 0) /* uncertainNumber */ * (1 + taxRate),
|
|
4001
4105
|
});
|
|
4002
4106
|
});
|
|
4003
4107
|
var duration = moment__default["default"].duration(completedAt.diff(startedAt));
|
|
4004
4108
|
var llmDuration = moment__default["default"].duration(countWorkingDuration(timingItems) * 1000);
|
|
4005
4109
|
var executionsWithKnownCost = executionReportJson.promptExecutions.filter(function (promptExecution) { var _a, _b; return (((_b = (_a = promptExecution.result) === null || _a === void 0 ? void 0 : _a.usage) === null || _b === void 0 ? void 0 : _b.price) || 'UNKNOWN') !== 'UNKNOWN'; });
|
|
4006
|
-
var cost = executionsWithKnownCost.reduce(function (cost, promptExecution) { return cost + (promptExecution.result.usage.price || 0); }, 0);
|
|
4110
|
+
var cost = executionsWithKnownCost.reduce(function (cost, promptExecution) { return cost + ((promptExecution.result.usage.price.value /* uncertainNumber */) || 0); }, 0);
|
|
4007
4111
|
headerList.push("STARTED AT ".concat(moment__default["default"](startedAt).format("YYYY-MM-DD HH:mm:ss")));
|
|
4008
4112
|
headerList.push("COMPLETED AT ".concat(moment__default["default"](completedAt).format("YYYY-MM-DD HH:mm:ss")));
|
|
4009
4113
|
headerList.push("TOTAL DURATION ".concat(duration.humanize(MOMENT_ARG_THRESHOLDS)));
|
|
@@ -4132,6 +4236,7 @@
|
|
|
4132
4236
|
exports.SimplePromptbookLibrary = SimplePromptbookLibrary;
|
|
4133
4237
|
exports.TemplateError = TemplateError;
|
|
4134
4238
|
exports.UnexpectedError = UnexpectedError;
|
|
4239
|
+
exports.addPromptResultUsage = addPromptResultUsage;
|
|
4135
4240
|
exports.assertsExecutionSuccessful = assertsExecutionSuccessful;
|
|
4136
4241
|
exports.checkExpectations = checkExpectations;
|
|
4137
4242
|
exports.createPromptbookExecutor = createPromptbookExecutor;
|