@promptbook/core 0.61.0 → 0.62.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 +139 -17
- package/esm/index.es.js.map +1 -1
- package/esm/typings/promptbook-collection/index.d.ts +3 -3
- package/esm/typings/src/_packages/core.index.d.ts +2 -1
- package/esm/typings/src/conversion/pipelineJsonToString.d.ts +2 -1
- package/esm/typings/src/execution/createPipelineExecutor.d.ts +1 -0
- package/esm/typings/src/execution/utils/usageToHuman.d.ts +15 -0
- package/esm/typings/src/execution/utils/usageToHuman.test.d.ts +1 -0
- package/esm/typings/src/llm-providers/_common/createLlmToolsFromEnv.d.ts +4 -0
- package/esm/typings/src/llm-providers/_common/getLlmToolsForCli.d.ts +12 -2
- package/esm/typings/src/llm-providers/_common/getLlmToolsForTestingAndScriptsAndPlayground.d.ts +12 -2
- package/esm/typings/src/llm-providers/_common/utils/cache/CacheLlmToolsOptions.d.ts +7 -1
- package/esm/typings/src/llm-providers/_common/utils/cache/cacheLlmTools.d.ts +7 -4
- package/esm/typings/src/llm-providers/_common/utils/count-total-usage/LlmExecutionToolsWithTotalUsage.d.ts +15 -0
- package/{umd/typings/src/llm-providers/_common/utils/count-total-cost/countTotalCost.d.ts → esm/typings/src/llm-providers/_common/utils/count-total-usage/countTotalUsage.d.ts} +5 -2
- package/esm/typings/src/llm-providers/_common/utils/{count-total-cost/limitTotalCost.d.ts → count-total-usage/limitTotalUsage.d.ts} +8 -5
- package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +1 -0
- package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionToolsOptions.d.ts +3 -0
- package/esm/typings/src/llm-providers/anthropic-claude/playground/playground.d.ts +1 -0
- package/esm/typings/src/llm-providers/multiple/joinLlmExecutionTools.d.ts +3 -0
- package/esm/typings/src/llm-providers/openai/computeOpenaiUsage.test.d.ts +1 -0
- package/esm/typings/src/llm-providers/remote/RemoteLlmExecutionTools.d.ts +2 -1
- package/esm/typings/src/llm-providers/remote/interfaces/RemoteServerOptions.d.ts +3 -0
- package/esm/typings/src/llm-providers/remote/startRemoteServer.d.ts +1 -0
- package/esm/typings/src/prepare/preparePipeline.d.ts +0 -1
- package/esm/typings/src/types/PipelineJson/PreparationJson.d.ts +1 -1
- package/package.json +2 -2
- package/umd/index.umd.js +139 -16
- package/umd/index.umd.js.map +1 -1
- package/umd/typings/promptbook-collection/index.d.ts +3 -3
- package/umd/typings/src/_packages/core.index.d.ts +2 -1
- package/umd/typings/src/conversion/pipelineJsonToString.d.ts +2 -1
- package/umd/typings/src/execution/createPipelineExecutor.d.ts +1 -0
- package/umd/typings/src/execution/utils/usageToHuman.d.ts +15 -0
- package/umd/typings/src/execution/utils/usageToHuman.test.d.ts +1 -0
- package/umd/typings/src/llm-providers/_common/createLlmToolsFromEnv.d.ts +4 -0
- package/umd/typings/src/llm-providers/_common/getLlmToolsForCli.d.ts +12 -2
- package/umd/typings/src/llm-providers/_common/getLlmToolsForTestingAndScriptsAndPlayground.d.ts +12 -2
- package/umd/typings/src/llm-providers/_common/utils/cache/CacheLlmToolsOptions.d.ts +7 -1
- package/umd/typings/src/llm-providers/_common/utils/cache/cacheLlmTools.d.ts +7 -4
- package/umd/typings/src/llm-providers/_common/utils/count-total-usage/LlmExecutionToolsWithTotalUsage.d.ts +15 -0
- package/{esm/typings/src/llm-providers/_common/utils/count-total-cost/countTotalCost.d.ts → umd/typings/src/llm-providers/_common/utils/count-total-usage/countTotalUsage.d.ts} +5 -2
- package/umd/typings/src/llm-providers/_common/utils/{count-total-cost/limitTotalCost.d.ts → count-total-usage/limitTotalUsage.d.ts} +8 -5
- package/umd/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +1 -0
- package/umd/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionToolsOptions.d.ts +3 -0
- package/umd/typings/src/llm-providers/anthropic-claude/playground/playground.d.ts +1 -0
- package/umd/typings/src/llm-providers/multiple/joinLlmExecutionTools.d.ts +3 -0
- package/umd/typings/src/llm-providers/openai/computeOpenaiUsage.test.d.ts +1 -0
- package/umd/typings/src/llm-providers/remote/RemoteLlmExecutionTools.d.ts +2 -1
- package/umd/typings/src/llm-providers/remote/interfaces/RemoteServerOptions.d.ts +3 -0
- package/umd/typings/src/llm-providers/remote/startRemoteServer.d.ts +1 -0
- package/umd/typings/src/prepare/preparePipeline.d.ts +0 -1
- package/umd/typings/src/types/PipelineJson/PreparationJson.d.ts +1 -1
- package/esm/typings/src/llm-providers/_common/utils/count-total-cost/LlmExecutionToolsWithTotalCost.d.ts +0 -11
- package/umd/typings/src/llm-providers/_common/utils/count-total-cost/LlmExecutionToolsWithTotalCost.d.ts +0 -11
package/umd/index.umd.js
CHANGED
|
@@ -394,7 +394,8 @@
|
|
|
394
394
|
/**
|
|
395
395
|
* TODO: !!!! Implement new features and commands into `promptTemplateParameterJsonToString`
|
|
396
396
|
* TODO: [🧠] Is there a way to auto-detect missing features in pipelineJsonToString
|
|
397
|
-
* TODO:
|
|
397
|
+
* TODO: [🏛] Maybe make some markdown builder
|
|
398
|
+
* TODO: [🏛] Escape all
|
|
398
399
|
*/
|
|
399
400
|
|
|
400
401
|
/**
|
|
@@ -1524,7 +1525,7 @@
|
|
|
1524
1525
|
});
|
|
1525
1526
|
}
|
|
1526
1527
|
|
|
1527
|
-
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.
|
|
1528
|
+
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.62.0-0",parameters:[{name:"knowledgeContent",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},content:"You are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {knowledgeContent}",dependentParameterNames:["knowledgeContent"],resultingParameterName:"knowledgePieces"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.62.0-0",usage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-knowledge-from-markdown.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.ptbk.md",promptbookVersion:"0.62.0-0",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},content:"You are experienced data researcher, detect the important keywords in the document.\n\n# Rules\n\n- Write just keywords separated by comma\n\n# The document\n\nTake information from this document:\n\n> {knowledgePieceContent}",dependentParameterNames:["knowledgePieceContent"],resultingParameterName:"keywords"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.62.0-0",usage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-knowledge-keywords.ptbk.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.ptbk.md",promptbookVersion:"0.62.0-0",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},content:"You are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Title should be concise and clear\n- Write maximum 5 words for the title\n\n# The document\n\n> {knowledgePieceContent}",expectations:{words:{min:1,max:8}},dependentParameterNames:["knowledgePieceContent"],resultingParameterName:"title"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.62.0-0",usage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-knowledge-title.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.ptbk.md",promptbookVersion:"0.62.0-0",parameters:[{name:"availableModelNames",description:"List of available model names separated by comma (,)",isInput:true,isOutput:false},{name:"personaDescription",description:"Description of the persona",isInput:true,isOutput:false},{name:"modelRequirements",description:"Specific requirements for the model",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"make-model-requirements",title:"Make modelRequirements",modelRequirements:{modelVariant:"CHAT",modelName:"gpt-4-turbo"},content:"You are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Sample\n\n```json\n{\n\"modelName\": \"gpt-4o\",\n\"systemMessage\": \"You are experienced AI engineer and helpfull assistant.\",\n\"temperature\": 0.7\n}\n```\n\n## Instructions\n\n### Option `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Option `systemMessage`\n\nThe system message is used to communicate instructions or provide context to the model at the beginning of a conversation. It is displayed in a different format compared to user messages, helping the model understand its role in the conversation. The system message typically guides the model's behavior, sets the tone, or specifies desired output from the model. By utilizing the system message effectively, users can steer the model towards generating more accurate and relevant responses.\n\nFor example:\n\n> You are an experienced AI engineer and helpful assistant.\n\n> You are a friendly and knowledgeable chatbot.\n\n### Option `temperature`\n\nThe sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit.\n\nYou can pick a value between 0 and 2. For example:\n\n- `0.1`: Low temperature, extremely conservative and deterministic\n- `0.5`: Medium temperature, balanced between conservative and creative\n- `1.0`: High temperature, creative and bit random\n- `1.5`: Very high temperature, extremely creative and often chaotic and unpredictable\n- `2.0`: Maximum temperature, completely random and unpredictable, for some extreme creative use cases\n\n# The assistant\n\nTake this description of the persona:\n\n> {personaDescription}",expectFormat:"JSON",dependentParameterNames:["availableModelNames","personaDescription"],resultingParameterName:"modelRequirements"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.62.0-0",usage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-persona.ptbk.md"}];
|
|
1528
1529
|
|
|
1529
1530
|
var defaultDiacriticsRemovalMap = [
|
|
1530
1531
|
{
|
|
@@ -2294,6 +2295,9 @@
|
|
|
2294
2295
|
}
|
|
2295
2296
|
return new (MultipleLlmExecutionTools.bind.apply(MultipleLlmExecutionTools, __spreadArray([void 0], __read(llmExecutionTools), false)))();
|
|
2296
2297
|
}
|
|
2298
|
+
/**
|
|
2299
|
+
* TODO: [👷♂️] @@@ Manual about construction of llmTools
|
|
2300
|
+
*/
|
|
2297
2301
|
|
|
2298
2302
|
/**
|
|
2299
2303
|
* Determine if the pipeline is fully prepared
|
|
@@ -2529,7 +2533,7 @@
|
|
|
2529
2533
|
/**
|
|
2530
2534
|
* The version of the Promptbook library
|
|
2531
2535
|
*/
|
|
2532
|
-
var PROMPTBOOK_VERSION = '0.
|
|
2536
|
+
var PROMPTBOOK_VERSION = '0.62.0-0';
|
|
2533
2537
|
// TODO: !!!! List here all the versions and annotate + put into script
|
|
2534
2538
|
|
|
2535
2539
|
/**
|
|
@@ -3443,6 +3447,7 @@
|
|
|
3443
3447
|
}
|
|
3444
3448
|
/**
|
|
3445
3449
|
* TODO: Use isVerbose here (not only pass to `preparePipeline`)
|
|
3450
|
+
* TODO: [🧠] Use here `countTotalUsage` and put preparation and prepared pipiline to report
|
|
3446
3451
|
* TODO: [🪂] Use maxParallelCount here (not only pass to `preparePipeline`)
|
|
3447
3452
|
* TODO: [♈] Probbably move expectations from templates to parameters
|
|
3448
3453
|
* TODO: [🧠] When not meet expectations in PROMPT_DIALOG, make some way to tell the user
|
|
@@ -3651,6 +3656,86 @@
|
|
|
3651
3656
|
* [ ] One piece can have multiple sources
|
|
3652
3657
|
*/
|
|
3653
3658
|
|
|
3659
|
+
/**
|
|
3660
|
+
* Intercepts LLM tools and counts total usage of the tools
|
|
3661
|
+
*
|
|
3662
|
+
* @param llmTools LLM tools to be intercepted with usage counting
|
|
3663
|
+
* @returns LLM tools with same functionality with added total cost counting
|
|
3664
|
+
*/
|
|
3665
|
+
function countTotalUsage(llmTools) {
|
|
3666
|
+
var _this = this;
|
|
3667
|
+
var totalUsage = ZERO_USAGE;
|
|
3668
|
+
var proxyTools = {
|
|
3669
|
+
get title() {
|
|
3670
|
+
// TODO: [🧠] Maybe put here some suffix
|
|
3671
|
+
return llmTools.title;
|
|
3672
|
+
},
|
|
3673
|
+
get description() {
|
|
3674
|
+
// TODO: [🧠] Maybe put here some suffix
|
|
3675
|
+
return llmTools.description;
|
|
3676
|
+
},
|
|
3677
|
+
listModels: function () {
|
|
3678
|
+
return /* not await */ llmTools.listModels();
|
|
3679
|
+
},
|
|
3680
|
+
getTotalUsage: function () {
|
|
3681
|
+
// <- Note: [🥫] Not using getter `get totalUsage` but `getTotalUsage` to allow this object to be proxied
|
|
3682
|
+
return totalUsage;
|
|
3683
|
+
},
|
|
3684
|
+
};
|
|
3685
|
+
if (llmTools.callChatModel !== undefined) {
|
|
3686
|
+
proxyTools.callChatModel = function (prompt) { return __awaiter(_this, void 0, void 0, function () {
|
|
3687
|
+
var promptResult;
|
|
3688
|
+
return __generator(this, function (_a) {
|
|
3689
|
+
switch (_a.label) {
|
|
3690
|
+
case 0: return [4 /*yield*/, llmTools.callChatModel(prompt)];
|
|
3691
|
+
case 1:
|
|
3692
|
+
promptResult = _a.sent();
|
|
3693
|
+
totalUsage = addUsage(totalUsage, promptResult.usage);
|
|
3694
|
+
return [2 /*return*/, promptResult];
|
|
3695
|
+
}
|
|
3696
|
+
});
|
|
3697
|
+
}); };
|
|
3698
|
+
}
|
|
3699
|
+
if (llmTools.callCompletionModel !== undefined) {
|
|
3700
|
+
proxyTools.callCompletionModel = function (prompt) { return __awaiter(_this, void 0, void 0, function () {
|
|
3701
|
+
var promptResult;
|
|
3702
|
+
return __generator(this, function (_a) {
|
|
3703
|
+
switch (_a.label) {
|
|
3704
|
+
case 0: return [4 /*yield*/, llmTools.callCompletionModel(prompt)];
|
|
3705
|
+
case 1:
|
|
3706
|
+
promptResult = _a.sent();
|
|
3707
|
+
totalUsage = addUsage(totalUsage, promptResult.usage);
|
|
3708
|
+
return [2 /*return*/, promptResult];
|
|
3709
|
+
}
|
|
3710
|
+
});
|
|
3711
|
+
}); };
|
|
3712
|
+
}
|
|
3713
|
+
if (llmTools.callEmbeddingModel !== undefined) {
|
|
3714
|
+
proxyTools.callEmbeddingModel = function (prompt) { return __awaiter(_this, void 0, void 0, function () {
|
|
3715
|
+
var promptResult;
|
|
3716
|
+
return __generator(this, function (_a) {
|
|
3717
|
+
switch (_a.label) {
|
|
3718
|
+
case 0: return [4 /*yield*/, llmTools.callEmbeddingModel(prompt)];
|
|
3719
|
+
case 1:
|
|
3720
|
+
promptResult = _a.sent();
|
|
3721
|
+
totalUsage = addUsage(totalUsage, promptResult.usage);
|
|
3722
|
+
return [2 /*return*/, promptResult];
|
|
3723
|
+
}
|
|
3724
|
+
});
|
|
3725
|
+
}); };
|
|
3726
|
+
}
|
|
3727
|
+
// <- Note: [🤖]
|
|
3728
|
+
return proxyTools;
|
|
3729
|
+
}
|
|
3730
|
+
/**
|
|
3731
|
+
* TODO: [🔼] !!! Export via `@promptbookcore/`
|
|
3732
|
+
* TODO: [🧠][💸] Maybe make some common abstraction `interceptLlmTools` and use here (or use javascript Proxy?)
|
|
3733
|
+
* TODO: [🧠] Is there some meaningfull way how to test this util
|
|
3734
|
+
* TODO: [🧠][🌯] Maybe a way how to hide ability to `get totalUsage`
|
|
3735
|
+
* > const [llmToolsWithUsage,getUsage] = countTotalUsage(llmTools);
|
|
3736
|
+
* TODO: [👷♂️] @@@ Manual about construction of llmTools
|
|
3737
|
+
*/
|
|
3738
|
+
|
|
3654
3739
|
/**
|
|
3655
3740
|
* Prepares the persona for the pipeline
|
|
3656
3741
|
*
|
|
@@ -3774,23 +3859,24 @@
|
|
|
3774
3859
|
*/
|
|
3775
3860
|
function preparePipeline(pipeline, options) {
|
|
3776
3861
|
return __awaiter(this, void 0, void 0, function () {
|
|
3777
|
-
var _a, maxParallelCount, parameters, promptTemplates,
|
|
3862
|
+
var llmTools, _a, maxParallelCount, _b, isVerbose, parameters, promptTemplates,
|
|
3778
3863
|
/*
|
|
3779
3864
|
<- TODO: [🧠][0] `promptbookVersion` */
|
|
3780
3865
|
knowledgeSources /*
|
|
3781
3866
|
<- TODO: [🧊] `knowledgePieces` */, personas /*
|
|
3782
|
-
<- TODO: [🧊] `preparations` */, currentPreparation, preparations, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared, promptTemplatesPrepared /* TODO: parameters: parametersPrepared*/;
|
|
3867
|
+
<- TODO: [🧊] `preparations` */, llmToolsWithUsage, currentPreparation, preparations, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared, promptTemplatesPrepared /* TODO: parameters: parametersPrepared*/;
|
|
3783
3868
|
var _this = this;
|
|
3784
|
-
return __generator(this, function (
|
|
3785
|
-
switch (
|
|
3869
|
+
return __generator(this, function (_c) {
|
|
3870
|
+
switch (_c.label) {
|
|
3786
3871
|
case 0:
|
|
3787
|
-
_a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a;
|
|
3872
|
+
llmTools = options.llmTools, _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a, _b = options.isVerbose, isVerbose = _b === void 0 ? false : _b;
|
|
3788
3873
|
parameters = pipeline.parameters, promptTemplates = pipeline.promptTemplates, knowledgeSources = pipeline.knowledgeSources, personas = pipeline.personas;
|
|
3874
|
+
llmToolsWithUsage = countTotalUsage(llmTools);
|
|
3789
3875
|
currentPreparation = {
|
|
3790
3876
|
id: 1,
|
|
3791
3877
|
// TODO: [🍥]> date: $currentDate(),
|
|
3792
3878
|
promptbookVersion: PROMPTBOOK_VERSION,
|
|
3793
|
-
|
|
3879
|
+
usage: ZERO_USAGE,
|
|
3794
3880
|
};
|
|
3795
3881
|
preparations = [
|
|
3796
3882
|
// ...preparations
|
|
@@ -3802,7 +3888,11 @@
|
|
|
3802
3888
|
var modelRequirements, preparedPersona;
|
|
3803
3889
|
return __generator(this, function (_a) {
|
|
3804
3890
|
switch (_a.label) {
|
|
3805
|
-
case 0: return [4 /*yield*/, preparePersona(persona.description,
|
|
3891
|
+
case 0: return [4 /*yield*/, preparePersona(persona.description, {
|
|
3892
|
+
llmTools: llmToolsWithUsage,
|
|
3893
|
+
maxParallelCount: maxParallelCount /* <- TODO: [🪂] */,
|
|
3894
|
+
isVerbose: isVerbose,
|
|
3895
|
+
})];
|
|
3806
3896
|
case 1:
|
|
3807
3897
|
modelRequirements = _a.sent();
|
|
3808
3898
|
preparedPersona = __assign(__assign({}, persona), { modelRequirements: modelRequirements, preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] });
|
|
@@ -3812,20 +3902,30 @@
|
|
|
3812
3902
|
});
|
|
3813
3903
|
}); })];
|
|
3814
3904
|
case 1:
|
|
3815
|
-
|
|
3905
|
+
_c.sent();
|
|
3816
3906
|
knowledgeSourcesPrepared = knowledgeSources.map(function (source) { return (__assign(__assign({}, source), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
|
|
3817
|
-
return [4 /*yield*/, prepareKnowledgePieces(knowledgeSources /* <- TODO: [🧊] {knowledgeSources, knowledgePieces} */,
|
|
3907
|
+
return [4 /*yield*/, prepareKnowledgePieces(knowledgeSources /* <- TODO: [🧊] {knowledgeSources, knowledgePieces} */, {
|
|
3908
|
+
llmTools: llmToolsWithUsage,
|
|
3909
|
+
maxParallelCount: maxParallelCount /* <- TODO: [🪂] */,
|
|
3910
|
+
isVerbose: isVerbose,
|
|
3911
|
+
})];
|
|
3818
3912
|
case 2:
|
|
3819
|
-
partialknowledgePiecesPrepared =
|
|
3913
|
+
partialknowledgePiecesPrepared = _c.sent();
|
|
3820
3914
|
knowledgePiecesPrepared = partialknowledgePiecesPrepared.map(function (piece) { return (__assign(__assign({}, piece), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
|
|
3821
3915
|
return [4 /*yield*/, prepareTemplates({
|
|
3822
3916
|
parameters: parameters,
|
|
3823
3917
|
promptTemplates: promptTemplates,
|
|
3824
3918
|
knowledgePiecesCount: knowledgePiecesPrepared.length,
|
|
3825
|
-
},
|
|
3919
|
+
}, {
|
|
3920
|
+
llmTools: llmToolsWithUsage,
|
|
3921
|
+
maxParallelCount: maxParallelCount /* <- TODO: [🪂] */,
|
|
3922
|
+
isVerbose: isVerbose,
|
|
3923
|
+
})];
|
|
3826
3924
|
case 3:
|
|
3827
|
-
promptTemplatesPrepared = (
|
|
3925
|
+
promptTemplatesPrepared = (_c.sent()).promptTemplatesPrepared;
|
|
3828
3926
|
// ----- /Templates preparation -----
|
|
3927
|
+
// Note: Count total usage
|
|
3928
|
+
currentPreparation.usage = llmToolsWithUsage.getTotalUsage();
|
|
3829
3929
|
return [2 /*return*/, __assign(__assign({}, pipeline), { promptTemplates: promptTemplatesPrepared, knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, personas: preparedPersonas, preparations: preparations })];
|
|
3830
3930
|
}
|
|
3831
3931
|
});
|
|
@@ -3836,7 +3936,6 @@
|
|
|
3836
3936
|
* TODO: Write tests for `preparePipeline`
|
|
3837
3937
|
* TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
|
|
3838
3938
|
* TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
|
|
3839
|
-
* TODO: [🎐] !!!!! Use here countTotalUsage
|
|
3840
3939
|
* TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
3841
3940
|
*/
|
|
3842
3941
|
|
|
@@ -6036,6 +6135,29 @@
|
|
|
6036
6135
|
return uncertainNumber;
|
|
6037
6136
|
}
|
|
6038
6137
|
|
|
6138
|
+
/**
|
|
6139
|
+
* Function `usageToHuman` will take usage and convert it to human readable report
|
|
6140
|
+
*/
|
|
6141
|
+
function usageToHuman(usage) {
|
|
6142
|
+
var report = 'Usage:';
|
|
6143
|
+
var uncertainNumberToHuman = function (_a) {
|
|
6144
|
+
var value = _a.value, isUncertain = _a.isUncertain;
|
|
6145
|
+
return "".concat(isUncertain ? 'approximately ' : '').concat(Math.round(value * 100) / 100);
|
|
6146
|
+
};
|
|
6147
|
+
report += '\n' + "- Cost ".concat(uncertainNumberToHuman(usage.price), " USD");
|
|
6148
|
+
report += '\n' + "- Saved ".concat(uncertainNumberToHuman(usageToWorktime(usage)), " hours of human time");
|
|
6149
|
+
return spaceTrim__default["default"](report);
|
|
6150
|
+
}
|
|
6151
|
+
/**
|
|
6152
|
+
* TODO: Use "$1" not "1 USD"
|
|
6153
|
+
* TODO: Use markdown formatting like "Cost approximately **$1**"
|
|
6154
|
+
* TODO: Report in minutes, seconds, days NOT 0.1 hours
|
|
6155
|
+
* TODO: [🧠] Maybe make from `uncertainNumberToHuman` separate exported utility
|
|
6156
|
+
* TODO: When negligible usage, report "Negligible" or just don't report it
|
|
6157
|
+
* TODO: [🧠] Maybe use "~" instead of "approximately"
|
|
6158
|
+
* TODO: [🏛] Maybe make some markdown builder
|
|
6159
|
+
*/
|
|
6160
|
+
|
|
6039
6161
|
/**
|
|
6040
6162
|
* Delagates the user interaction to a async callback function
|
|
6041
6163
|
* You need to provide your own implementation of this callback function and its bind to UI.
|
|
@@ -6450,6 +6572,7 @@
|
|
|
6450
6572
|
exports.prettifyPipelineString = prettifyPipelineString;
|
|
6451
6573
|
exports.stringifyPipelineJson = stringifyPipelineJson;
|
|
6452
6574
|
exports.unpreparePipeline = unpreparePipeline;
|
|
6575
|
+
exports.usageToHuman = usageToHuman;
|
|
6453
6576
|
exports.usageToWorktime = usageToWorktime;
|
|
6454
6577
|
exports.validatePipeline = validatePipeline;
|
|
6455
6578
|
|