@promptbook/core 0.61.0 → 0.62.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/esm/index.es.js +137 -16
- package/esm/index.es.js.map +1 -1
- 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 +1 -0
- package/esm/typings/src/llm-providers/_common/getLlmToolsForCli.d.ts +3 -2
- package/esm/typings/src/llm-providers/_common/getLlmToolsForTestingAndScriptsAndPlayground.d.ts +3 -2
- package/esm/typings/src/llm-providers/_common/utils/cache/CacheLlmToolsOptions.d.ts +1 -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-cost/LlmExecutionToolsWithTotalCost.d.ts → count-total-usage/LlmExecutionToolsWithTotalUsage.d.ts} +5 -2
- 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/multiple/joinLlmExecutionTools.d.ts +3 -0
- package/esm/typings/src/prepare/preparePipeline.d.ts +0 -1
- package/package.json +2 -2
- package/umd/index.umd.js +137 -15
- package/umd/index.umd.js.map +1 -1
- 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 +1 -0
- package/umd/typings/src/llm-providers/_common/getLlmToolsForCli.d.ts +3 -2
- package/umd/typings/src/llm-providers/_common/getLlmToolsForTestingAndScriptsAndPlayground.d.ts +3 -2
- package/umd/typings/src/llm-providers/_common/utils/cache/CacheLlmToolsOptions.d.ts +1 -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-cost/LlmExecutionToolsWithTotalCost.d.ts → count-total-usage/LlmExecutionToolsWithTotalUsage.d.ts} +5 -2
- 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/multiple/joinLlmExecutionTools.d.ts +3 -0
- package/umd/typings/src/prepare/preparePipeline.d.ts +0 -1
|
@@ -26,6 +26,7 @@ import { embeddingVectorToString } from '../execution/embeddingVectorToString';
|
|
|
26
26
|
import { addUsage } from '../execution/utils/addUsage';
|
|
27
27
|
import { checkExpectations, isPassingExpectations } from '../execution/utils/checkExpectations';
|
|
28
28
|
import { usageToWorktime } from '../execution/utils/usageToWorktime';
|
|
29
|
+
import { usageToHuman } from '../execution/utils/usageToHuman';
|
|
29
30
|
import { CallbackInterfaceTools } from '../knowledge/dialogs/callback/CallbackInterfaceTools';
|
|
30
31
|
import type { CallbackInterfaceToolsOptions } from '../knowledge/dialogs/callback/CallbackInterfaceToolsOptions';
|
|
31
32
|
import { SimplePromptInterfaceTools } from '../knowledge/dialogs/simple-prompt/SimplePromptInterfaceTools';
|
|
@@ -39,7 +40,7 @@ import { executionReportJsonToString } from '../types/execution-report/execution
|
|
|
39
40
|
import { PROMPTBOOK_VERSION } from '../version';
|
|
40
41
|
export { PROMPTBOOK_VERSION };
|
|
41
42
|
export { BlockTypes, RESERVED_PARAMETER_NAMES };
|
|
42
|
-
export { addUsage, assertsExecutionSuccessful, checkExpectations, embeddingVectorToString, executionReportJsonToString, ExecutionReportStringOptions, ExecutionReportStringOptionsDefaults, isPassingExpectations, prepareKnowledgeFromMarkdown, prettifyPipelineString, usageToWorktime, };
|
|
43
|
+
export { addUsage, assertsExecutionSuccessful, checkExpectations, embeddingVectorToString, executionReportJsonToString, ExecutionReportStringOptions, ExecutionReportStringOptionsDefaults, isPassingExpectations, prepareKnowledgeFromMarkdown, prettifyPipelineString, usageToWorktime, usageToHuman, };
|
|
43
44
|
export { collectionToJson, createCollectionFromJson, createCollectionFromPromise, createCollectionFromUrl, createSubcollection, };
|
|
44
45
|
export { SimplePromptInterfaceTools };
|
|
45
46
|
export { pipelineJsonToString, pipelineStringToJson, pipelineStringToJsonSync, stringifyPipelineJson, validatePipeline, };
|
|
@@ -10,5 +10,6 @@ export declare function pipelineJsonToString(pipelineJson: PipelineJson): Pipeli
|
|
|
10
10
|
/**
|
|
11
11
|
* TODO: !!!! Implement new features and commands into `promptTemplateParameterJsonToString`
|
|
12
12
|
* TODO: [🧠] Is there a way to auto-detect missing features in pipelineJsonToString
|
|
13
|
-
* TODO:
|
|
13
|
+
* TODO: [🏛] Maybe make some markdown builder
|
|
14
|
+
* TODO: [🏛] Escape all
|
|
14
15
|
*/
|
|
@@ -58,6 +58,7 @@ export declare function createPipelineExecutor(options: CreatePipelineExecutorOp
|
|
|
58
58
|
export {};
|
|
59
59
|
/**
|
|
60
60
|
* TODO: Use isVerbose here (not only pass to `preparePipeline`)
|
|
61
|
+
* TODO: [🧠] Use here `countTotalUsage` and put preparation and prepared pipiline to report
|
|
61
62
|
* TODO: [🪂] Use maxParallelCount here (not only pass to `preparePipeline`)
|
|
62
63
|
* TODO: [♈] Probbably move expectations from templates to parameters
|
|
63
64
|
* TODO: [🧠] When not meet expectations in PROMPT_DIALOG, make some way to tell the user
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { string_markdown } from '../../types/typeAliases';
|
|
2
|
+
import type { PromptResultUsage } from '../PromptResultUsage';
|
|
3
|
+
/**
|
|
4
|
+
* Function `usageToHuman` will take usage and convert it to human readable report
|
|
5
|
+
*/
|
|
6
|
+
export declare function usageToHuman(usage: PromptResultUsage): string_markdown;
|
|
7
|
+
/**
|
|
8
|
+
* TODO: Use "$1" not "1 USD"
|
|
9
|
+
* TODO: Use markdown formatting like "Cost approximately **$1**"
|
|
10
|
+
* TODO: Report in minutes, seconds, days NOT 0.1 hours
|
|
11
|
+
* TODO: [🧠] Maybe make from `uncertainNumberToHuman` separate exported utility
|
|
12
|
+
* TODO: When negligible usage, report "Negligible" or just don't report it
|
|
13
|
+
* TODO: [🧠] Maybe use "~" instead of "approximately"
|
|
14
|
+
* TODO: [🏛] Maybe make some markdown builder
|
|
15
|
+
*/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -27,4 +27,5 @@ export declare function createLlmToolsFromEnv(options?: CreateLlmToolsFromEnvOpt
|
|
|
27
27
|
* TODO: [🧠] Is there some meaningfull way how to test this util
|
|
28
28
|
* TODO: [🧠] Maybe pass env as argument
|
|
29
29
|
* Note: [🟢] This code should never be published outside of `@promptbook/node`
|
|
30
|
+
* TODO: [👷♂️] @@@ Manual about construction of llmTools
|
|
30
31
|
*/
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { LlmExecutionToolsWithTotalUsage } from './utils/count-total-usage/LlmExecutionToolsWithTotalUsage';
|
|
2
2
|
/**
|
|
3
3
|
* Returns LLM tools for CLI
|
|
4
4
|
*
|
|
5
5
|
* @private within the repository - for CLI utils
|
|
6
6
|
*/
|
|
7
|
-
export declare function getLlmToolsForCli():
|
|
7
|
+
export declare function getLlmToolsForCli(): LlmExecutionToolsWithTotalUsage;
|
|
8
8
|
/**
|
|
9
9
|
* Note: [🟡] This code should never be published outside of `@promptbook/cli`
|
|
10
|
+
* TODO: [👷♂️] @@@ Manual about construction of llmTools
|
|
10
11
|
*/
|
package/esm/typings/src/llm-providers/_common/getLlmToolsForTestingAndScriptsAndPlayground.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import type { LlmExecutionTools } from '../../execution/LlmExecutionTools';
|
|
2
1
|
import type { CreateLlmToolsFromEnvOptions } from './createLlmToolsFromEnv';
|
|
2
|
+
import type { LlmExecutionToolsWithTotalUsage } from './utils/count-total-usage/LlmExecutionToolsWithTotalUsage';
|
|
3
3
|
/**
|
|
4
4
|
* Returns LLM tools for testing purposes
|
|
5
5
|
*
|
|
6
6
|
* @private within the repository - JUST FOR TESTS, SCRIPTS AND PLAYGROUND
|
|
7
7
|
*/
|
|
8
|
-
export declare function getLlmToolsForTestingAndScriptsAndPlayground(options?: CreateLlmToolsFromEnvOptions):
|
|
8
|
+
export declare function getLlmToolsForTestingAndScriptsAndPlayground(options?: CreateLlmToolsFromEnvOptions): LlmExecutionToolsWithTotalUsage;
|
|
9
9
|
/**
|
|
10
10
|
* Note: [⚪] This should never be in any released package
|
|
11
|
+
* TODO: [👷♂️] @@@ Manual about construction of llmTools
|
|
11
12
|
*/
|
|
@@ -3,14 +3,17 @@ import type { CacheLlmToolsOptions } from './CacheLlmToolsOptions';
|
|
|
3
3
|
/**
|
|
4
4
|
* Intercepts LLM tools and counts total usage of the tools
|
|
5
5
|
*
|
|
6
|
-
*
|
|
6
|
+
* Note: It can take extended `LlmExecutionTools` and cache the
|
|
7
|
+
*
|
|
8
|
+
* @param llmTools LLM tools to be intercepted with usage counting, it can contain extra methods like `totalUsage`
|
|
7
9
|
* @returns LLM tools with same functionality with added total cost counting
|
|
8
10
|
*/
|
|
9
|
-
export declare function cacheLlmTools(llmTools:
|
|
11
|
+
export declare function cacheLlmTools<TLlmTools extends LlmExecutionTools>(llmTools: TLlmTools, options?: Partial<CacheLlmToolsOptions>): TLlmTools;
|
|
10
12
|
/**
|
|
11
13
|
* TODO: [🔼] !!! Export via `@promptbook/core`
|
|
12
|
-
* TODO: @@@ write discussion about this and storages
|
|
13
|
-
* write how to combine multiple interceptors
|
|
14
14
|
* TODO: [🧠][💸] Maybe make some common abstraction `interceptLlmTools` and use here (or use javascript Proxy?)
|
|
15
15
|
* TODO: [🧠] Is there some meaningfull way how to test this util
|
|
16
|
+
* TODO: [👷♂️] @@@ Manual about construction of llmTools
|
|
17
|
+
* @@@ write discussion about this and storages
|
|
18
|
+
* @@@ write how to combine multiple interceptors
|
|
16
19
|
*/
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import type { LlmExecutionTools } from '../../../../execution/LlmExecutionTools';
|
|
2
2
|
import type { PromptResultUsage } from '../../../../execution/PromptResultUsage';
|
|
3
3
|
/**
|
|
4
|
-
* LLM tools with option to get total
|
|
4
|
+
* LLM tools with option to get total usage of the execution
|
|
5
5
|
*/
|
|
6
|
-
export type
|
|
6
|
+
export type LlmExecutionToolsWithTotalUsage = LlmExecutionTools & {
|
|
7
7
|
/**
|
|
8
8
|
* Total cost of the execution
|
|
9
9
|
*/
|
|
10
10
|
totalUsage: PromptResultUsage;
|
|
11
11
|
};
|
|
12
|
+
/**
|
|
13
|
+
* TODO: [👷♂️] @@@ Manual about construction of llmTools
|
|
14
|
+
*/
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import type { LlmExecutionTools } from '../../../../execution/LlmExecutionTools';
|
|
2
|
-
import type {
|
|
2
|
+
import type { LlmExecutionToolsWithTotalUsage } from './LlmExecutionToolsWithTotalUsage';
|
|
3
3
|
/**
|
|
4
4
|
* Intercepts LLM tools and counts total usage of the tools
|
|
5
5
|
*
|
|
6
6
|
* @param llmTools LLM tools to be intercepted with usage counting
|
|
7
7
|
* @returns LLM tools with same functionality with added total cost counting
|
|
8
8
|
*/
|
|
9
|
-
export declare function countTotalUsage(llmTools: LlmExecutionTools):
|
|
9
|
+
export declare function countTotalUsage(llmTools: LlmExecutionTools): LlmExecutionToolsWithTotalUsage;
|
|
10
10
|
/**
|
|
11
11
|
* TODO: [🔼] !!! Export via `@promptbookcore/`
|
|
12
12
|
* TODO: [🧠][💸] Maybe make some common abstraction `interceptLlmTools` and use here (or use javascript Proxy?)
|
|
13
13
|
* TODO: [🧠] Is there some meaningfull way how to test this util
|
|
14
|
+
* TODO: [🧠][🌯] Maybe a way how to hide ability to `get totalUsage`
|
|
15
|
+
* > const [llmToolsWithUsage,getUsage] = countTotalUsage(llmTools);
|
|
16
|
+
* TODO: [👷♂️] @@@ Manual about construction of llmTools
|
|
14
17
|
*/
|
|
@@ -2,17 +2,17 @@ import type { LlmExecutionTools } from '../../../../execution/LlmExecutionTools'
|
|
|
2
2
|
import type { PromptResultUsage } from '../../../../execution/PromptResultUsage';
|
|
3
3
|
import type { PromptbookStorage } from '../../../../storage/_common/PromptbookStorage';
|
|
4
4
|
import type { TODO_any } from '../../../../utils/organization/TODO_any';
|
|
5
|
-
import type {
|
|
5
|
+
import type { LlmExecutionToolsWithTotalUsage } from './LlmExecutionToolsWithTotalUsage';
|
|
6
6
|
/**
|
|
7
|
-
* Options for `
|
|
7
|
+
* Options for `limitTotalUsage`
|
|
8
8
|
*/
|
|
9
|
-
type
|
|
9
|
+
type LimitTotalUsageOptions = {
|
|
10
10
|
/**
|
|
11
11
|
* @@@
|
|
12
12
|
*
|
|
13
13
|
* @default ZERO_USAGE
|
|
14
14
|
*/
|
|
15
|
-
|
|
15
|
+
maxTotalUsage: PromptResultUsage;
|
|
16
16
|
/**
|
|
17
17
|
* @@@
|
|
18
18
|
*
|
|
@@ -23,10 +23,13 @@ type LimitTotalCostOptions = {
|
|
|
23
23
|
/**
|
|
24
24
|
* @@@
|
|
25
25
|
*/
|
|
26
|
-
export declare function
|
|
26
|
+
export declare function limitTotalUsage(llmTools: LlmExecutionTools, options?: Partial<LimitTotalUsageOptions>): LlmExecutionToolsWithTotalUsage;
|
|
27
27
|
export {};
|
|
28
28
|
/**
|
|
29
29
|
* TODO: [🔼] !!! Export via `@promptbookcore/`
|
|
30
|
+
* TODO: Maybe internally use `countTotalUsage`
|
|
30
31
|
* TODO: [🧠][💸] Maybe make some common abstraction `interceptLlmTools` and use here (or use javascript Proxy?)
|
|
31
32
|
* TODO: [🧠] Is there some meaningfull way how to test this util
|
|
33
|
+
* TODO: [🧠][🌯] Maybe a way how to hide ability to `get totalUsage`
|
|
34
|
+
* TODO: [👷♂️] @@@ Manual about construction of llmTools
|
|
32
35
|
*/
|
|
@@ -14,3 +14,6 @@ import { MultipleLlmExecutionTools } from './MultipleLlmExecutionTools';
|
|
|
14
14
|
* Tip: You don't have to use this function directly, just pass an array of LlmExecutionTools to the `ExecutionTools`
|
|
15
15
|
*/
|
|
16
16
|
export declare function joinLlmExecutionTools(...llmExecutionTools: Array<LlmExecutionTools>): MultipleLlmExecutionTools;
|
|
17
|
+
/**
|
|
18
|
+
* TODO: [👷♂️] @@@ Manual about construction of llmTools
|
|
19
|
+
*/
|
|
@@ -12,6 +12,5 @@ export declare function preparePipeline(pipeline: PipelineJson, options: Prepare
|
|
|
12
12
|
* TODO: Write tests for `preparePipeline`
|
|
13
13
|
* TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
|
|
14
14
|
* TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
|
|
15
|
-
* TODO: [🎐] !!!!! Use here countTotalUsage
|
|
16
15
|
* TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
17
16
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@promptbook/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.62.0-0",
|
|
4
4
|
"description": "Supercharge your use of large language models",
|
|
5
5
|
"private": false,
|
|
6
6
|
"sideEffects": false,
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"moment": "2.30.1",
|
|
38
38
|
"prettier": "2.8.1",
|
|
39
|
-
"spacetrim": "0.11.
|
|
39
|
+
"spacetrim": "0.11.39"
|
|
40
40
|
},
|
|
41
41
|
"funding": [
|
|
42
42
|
{
|
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.61.0
|
|
1528
|
+
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.61.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.61.0",modelUsage:{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.61.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.61.0",modelUsage:{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.61.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.61.0",modelUsage:{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.61.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.61.0",modelUsage:{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.61.0
|
|
2536
|
+
var PROMPTBOOK_VERSION = '0.61.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,85 @@
|
|
|
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
|
+
get totalUsage() {
|
|
3681
|
+
return totalUsage;
|
|
3682
|
+
},
|
|
3683
|
+
};
|
|
3684
|
+
if (llmTools.callChatModel !== undefined) {
|
|
3685
|
+
proxyTools.callChatModel = function (prompt) { return __awaiter(_this, void 0, void 0, function () {
|
|
3686
|
+
var promptResult;
|
|
3687
|
+
return __generator(this, function (_a) {
|
|
3688
|
+
switch (_a.label) {
|
|
3689
|
+
case 0: return [4 /*yield*/, llmTools.callChatModel(prompt)];
|
|
3690
|
+
case 1:
|
|
3691
|
+
promptResult = _a.sent();
|
|
3692
|
+
totalUsage = addUsage(totalUsage, promptResult.usage);
|
|
3693
|
+
return [2 /*return*/, promptResult];
|
|
3694
|
+
}
|
|
3695
|
+
});
|
|
3696
|
+
}); };
|
|
3697
|
+
}
|
|
3698
|
+
if (llmTools.callCompletionModel !== undefined) {
|
|
3699
|
+
proxyTools.callCompletionModel = function (prompt) { return __awaiter(_this, void 0, void 0, function () {
|
|
3700
|
+
var promptResult;
|
|
3701
|
+
return __generator(this, function (_a) {
|
|
3702
|
+
switch (_a.label) {
|
|
3703
|
+
case 0: return [4 /*yield*/, llmTools.callCompletionModel(prompt)];
|
|
3704
|
+
case 1:
|
|
3705
|
+
promptResult = _a.sent();
|
|
3706
|
+
totalUsage = addUsage(totalUsage, promptResult.usage);
|
|
3707
|
+
return [2 /*return*/, promptResult];
|
|
3708
|
+
}
|
|
3709
|
+
});
|
|
3710
|
+
}); };
|
|
3711
|
+
}
|
|
3712
|
+
if (llmTools.callEmbeddingModel !== undefined) {
|
|
3713
|
+
proxyTools.callEmbeddingModel = function (prompt) { return __awaiter(_this, void 0, void 0, function () {
|
|
3714
|
+
var promptResult;
|
|
3715
|
+
return __generator(this, function (_a) {
|
|
3716
|
+
switch (_a.label) {
|
|
3717
|
+
case 0: return [4 /*yield*/, llmTools.callEmbeddingModel(prompt)];
|
|
3718
|
+
case 1:
|
|
3719
|
+
promptResult = _a.sent();
|
|
3720
|
+
totalUsage = addUsage(totalUsage, promptResult.usage);
|
|
3721
|
+
return [2 /*return*/, promptResult];
|
|
3722
|
+
}
|
|
3723
|
+
});
|
|
3724
|
+
}); };
|
|
3725
|
+
}
|
|
3726
|
+
// <- Note: [🤖]
|
|
3727
|
+
return proxyTools;
|
|
3728
|
+
}
|
|
3729
|
+
/**
|
|
3730
|
+
* TODO: [🔼] !!! Export via `@promptbookcore/`
|
|
3731
|
+
* TODO: [🧠][💸] Maybe make some common abstraction `interceptLlmTools` and use here (or use javascript Proxy?)
|
|
3732
|
+
* TODO: [🧠] Is there some meaningfull way how to test this util
|
|
3733
|
+
* TODO: [🧠][🌯] Maybe a way how to hide ability to `get totalUsage`
|
|
3734
|
+
* > const [llmToolsWithUsage,getUsage] = countTotalUsage(llmTools);
|
|
3735
|
+
* TODO: [👷♂️] @@@ Manual about construction of llmTools
|
|
3736
|
+
*/
|
|
3737
|
+
|
|
3654
3738
|
/**
|
|
3655
3739
|
* Prepares the persona for the pipeline
|
|
3656
3740
|
*
|
|
@@ -3774,18 +3858,19 @@
|
|
|
3774
3858
|
*/
|
|
3775
3859
|
function preparePipeline(pipeline, options) {
|
|
3776
3860
|
return __awaiter(this, void 0, void 0, function () {
|
|
3777
|
-
var _a, maxParallelCount, parameters, promptTemplates,
|
|
3861
|
+
var llmTools, _a, maxParallelCount, _b, isVerbose, parameters, promptTemplates,
|
|
3778
3862
|
/*
|
|
3779
3863
|
<- TODO: [🧠][0] `promptbookVersion` */
|
|
3780
3864
|
knowledgeSources /*
|
|
3781
3865
|
<- TODO: [🧊] `knowledgePieces` */, personas /*
|
|
3782
|
-
<- TODO: [🧊] `preparations` */, currentPreparation, preparations, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared, promptTemplatesPrepared /* TODO: parameters: parametersPrepared*/;
|
|
3866
|
+
<- TODO: [🧊] `preparations` */, llmToolsWithUsage, currentPreparation, preparations, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared, promptTemplatesPrepared /* TODO: parameters: parametersPrepared*/;
|
|
3783
3867
|
var _this = this;
|
|
3784
|
-
return __generator(this, function (
|
|
3785
|
-
switch (
|
|
3868
|
+
return __generator(this, function (_c) {
|
|
3869
|
+
switch (_c.label) {
|
|
3786
3870
|
case 0:
|
|
3787
|
-
_a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a;
|
|
3871
|
+
llmTools = options.llmTools, _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a, _b = options.isVerbose, isVerbose = _b === void 0 ? false : _b;
|
|
3788
3872
|
parameters = pipeline.parameters, promptTemplates = pipeline.promptTemplates, knowledgeSources = pipeline.knowledgeSources, personas = pipeline.personas;
|
|
3873
|
+
llmToolsWithUsage = countTotalUsage(llmTools);
|
|
3789
3874
|
currentPreparation = {
|
|
3790
3875
|
id: 1,
|
|
3791
3876
|
// TODO: [🍥]> date: $currentDate(),
|
|
@@ -3802,7 +3887,11 @@
|
|
|
3802
3887
|
var modelRequirements, preparedPersona;
|
|
3803
3888
|
return __generator(this, function (_a) {
|
|
3804
3889
|
switch (_a.label) {
|
|
3805
|
-
case 0: return [4 /*yield*/, preparePersona(persona.description,
|
|
3890
|
+
case 0: return [4 /*yield*/, preparePersona(persona.description, {
|
|
3891
|
+
llmTools: llmToolsWithUsage,
|
|
3892
|
+
maxParallelCount: maxParallelCount /* <- TODO: [🪂] */,
|
|
3893
|
+
isVerbose: isVerbose,
|
|
3894
|
+
})];
|
|
3806
3895
|
case 1:
|
|
3807
3896
|
modelRequirements = _a.sent();
|
|
3808
3897
|
preparedPersona = __assign(__assign({}, persona), { modelRequirements: modelRequirements, preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] });
|
|
@@ -3812,20 +3901,30 @@
|
|
|
3812
3901
|
});
|
|
3813
3902
|
}); })];
|
|
3814
3903
|
case 1:
|
|
3815
|
-
|
|
3904
|
+
_c.sent();
|
|
3816
3905
|
knowledgeSourcesPrepared = knowledgeSources.map(function (source) { return (__assign(__assign({}, source), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
|
|
3817
|
-
return [4 /*yield*/, prepareKnowledgePieces(knowledgeSources /* <- TODO: [🧊] {knowledgeSources, knowledgePieces} */,
|
|
3906
|
+
return [4 /*yield*/, prepareKnowledgePieces(knowledgeSources /* <- TODO: [🧊] {knowledgeSources, knowledgePieces} */, {
|
|
3907
|
+
llmTools: llmToolsWithUsage,
|
|
3908
|
+
maxParallelCount: maxParallelCount /* <- TODO: [🪂] */,
|
|
3909
|
+
isVerbose: isVerbose,
|
|
3910
|
+
})];
|
|
3818
3911
|
case 2:
|
|
3819
|
-
partialknowledgePiecesPrepared =
|
|
3912
|
+
partialknowledgePiecesPrepared = _c.sent();
|
|
3820
3913
|
knowledgePiecesPrepared = partialknowledgePiecesPrepared.map(function (piece) { return (__assign(__assign({}, piece), { preparationIds: [/* TODO: [🧊] -> */ currentPreparation.id] })); });
|
|
3821
3914
|
return [4 /*yield*/, prepareTemplates({
|
|
3822
3915
|
parameters: parameters,
|
|
3823
3916
|
promptTemplates: promptTemplates,
|
|
3824
3917
|
knowledgePiecesCount: knowledgePiecesPrepared.length,
|
|
3825
|
-
},
|
|
3918
|
+
}, {
|
|
3919
|
+
llmTools: llmToolsWithUsage,
|
|
3920
|
+
maxParallelCount: maxParallelCount /* <- TODO: [🪂] */,
|
|
3921
|
+
isVerbose: isVerbose,
|
|
3922
|
+
})];
|
|
3826
3923
|
case 3:
|
|
3827
|
-
promptTemplatesPrepared = (
|
|
3924
|
+
promptTemplatesPrepared = (_c.sent()).promptTemplatesPrepared;
|
|
3828
3925
|
// ----- /Templates preparation -----
|
|
3926
|
+
// Note: Count total usage
|
|
3927
|
+
currentPreparation.modelUsage = llmToolsWithUsage.totalUsage;
|
|
3829
3928
|
return [2 /*return*/, __assign(__assign({}, pipeline), { promptTemplates: promptTemplatesPrepared, knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, personas: preparedPersonas, preparations: preparations })];
|
|
3830
3929
|
}
|
|
3831
3930
|
});
|
|
@@ -3836,7 +3935,6 @@
|
|
|
3836
3935
|
* TODO: Write tests for `preparePipeline`
|
|
3837
3936
|
* TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
|
|
3838
3937
|
* TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
|
|
3839
|
-
* TODO: [🎐] !!!!! Use here countTotalUsage
|
|
3840
3938
|
* TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
|
|
3841
3939
|
*/
|
|
3842
3940
|
|
|
@@ -6036,6 +6134,29 @@
|
|
|
6036
6134
|
return uncertainNumber;
|
|
6037
6135
|
}
|
|
6038
6136
|
|
|
6137
|
+
/**
|
|
6138
|
+
* Function `usageToHuman` will take usage and convert it to human readable report
|
|
6139
|
+
*/
|
|
6140
|
+
function usageToHuman(usage) {
|
|
6141
|
+
var report = 'Usage:';
|
|
6142
|
+
var uncertainNumberToHuman = function (_a) {
|
|
6143
|
+
var value = _a.value, isUncertain = _a.isUncertain;
|
|
6144
|
+
return "".concat(isUncertain ? 'approximately ' : '').concat(Math.round(value * 100) / 100);
|
|
6145
|
+
};
|
|
6146
|
+
report += '\n' + "- Cost ".concat(uncertainNumberToHuman(usage.price), " USD");
|
|
6147
|
+
report += '\n' + "- Saved ".concat(uncertainNumberToHuman(usageToWorktime(usage)), " hours of human time");
|
|
6148
|
+
return spaceTrim__default["default"](report);
|
|
6149
|
+
}
|
|
6150
|
+
/**
|
|
6151
|
+
* TODO: Use "$1" not "1 USD"
|
|
6152
|
+
* TODO: Use markdown formatting like "Cost approximately **$1**"
|
|
6153
|
+
* TODO: Report in minutes, seconds, days NOT 0.1 hours
|
|
6154
|
+
* TODO: [🧠] Maybe make from `uncertainNumberToHuman` separate exported utility
|
|
6155
|
+
* TODO: When negligible usage, report "Negligible" or just don't report it
|
|
6156
|
+
* TODO: [🧠] Maybe use "~" instead of "approximately"
|
|
6157
|
+
* TODO: [🏛] Maybe make some markdown builder
|
|
6158
|
+
*/
|
|
6159
|
+
|
|
6039
6160
|
/**
|
|
6040
6161
|
* Delagates the user interaction to a async callback function
|
|
6041
6162
|
* You need to provide your own implementation of this callback function and its bind to UI.
|
|
@@ -6450,6 +6571,7 @@
|
|
|
6450
6571
|
exports.prettifyPipelineString = prettifyPipelineString;
|
|
6451
6572
|
exports.stringifyPipelineJson = stringifyPipelineJson;
|
|
6452
6573
|
exports.unpreparePipeline = unpreparePipeline;
|
|
6574
|
+
exports.usageToHuman = usageToHuman;
|
|
6453
6575
|
exports.usageToWorktime = usageToWorktime;
|
|
6454
6576
|
exports.validatePipeline = validatePipeline;
|
|
6455
6577
|
|