@promptbook/cli 0.66.0-0 → 0.66.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 CHANGED
@@ -20,7 +20,7 @@ import glob from 'glob-promise';
20
20
  /**
21
21
  * The version of the Promptbook library
22
22
  */
23
- var PROMPTBOOK_VERSION = '0.65.0';
23
+ var PROMPTBOOK_VERSION = '0.66.0-0';
24
24
  // TODO: !!!! List here all the versions and annotate + put into script
25
25
 
26
26
  /*! *****************************************************************************
@@ -303,6 +303,9 @@ var RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE;
303
303
  * @private within the repository
304
304
  */
305
305
  var RESERVED_PARAMETER_RESTRICTED = 'RESTRICTED-' + REPLACING_NONCE;
306
+ /**
307
+ * TODO: [🧠][🧜‍♂️] Maybe join remoteUrl and path into single value
308
+ */
306
309
 
307
310
  /**
308
311
  * Initializes `about` command for Promptbook CLI utilities
@@ -832,7 +835,7 @@ function forEachAsync(array, options, callbackfunction) {
832
835
  });
833
836
  }
834
837
 
835
- var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.65.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:[],sourceFile:"./promptbook-collection/prepare-knowledge-from-markdown.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.ptbk.md",promptbookVersion:"0.65.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:[],sourceFile:"./promptbook-collection/prepare-knowledge-keywords.ptbk.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.ptbk.md",promptbookVersion:"0.65.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:[],sourceFile:"./promptbook-collection/prepare-knowledge-title.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.ptbk.md",promptbookVersion:"0.65.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:[],sourceFile:"./promptbook-collection/prepare-persona.ptbk.md"}];
838
+ var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.66.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:[],sourceFile:"./promptbook-collection/prepare-knowledge-from-markdown.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.ptbk.md",promptbookVersion:"0.66.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:[],sourceFile:"./promptbook-collection/prepare-knowledge-keywords.ptbk.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.ptbk.md",promptbookVersion:"0.66.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:[],sourceFile:"./promptbook-collection/prepare-knowledge-title.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.ptbk.md",promptbookVersion:"0.66.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:[],sourceFile:"./promptbook-collection/prepare-persona.ptbk.md"}];
836
839
 
837
840
  /**
838
841
  * This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
@@ -6806,6 +6809,15 @@ var ANTHROPIC_CLAUDE_MODELS = [
6806
6809
  * TODO: [🎰] Some mechanism to auto-update available models
6807
6810
  */
6808
6811
 
6812
+ /**
6813
+ * Get current date in ISO 8601 format
6814
+ *
6815
+ * @private internal utility
6816
+ */
6817
+ function getCurrentIsoDate() {
6818
+ return new Date().toISOString();
6819
+ }
6820
+
6809
6821
  /**
6810
6822
  * Helper of usage compute
6811
6823
  *
@@ -6840,13 +6852,42 @@ function uncertainNumber(value) {
6840
6852
  }
6841
6853
 
6842
6854
  /**
6843
- * Get current date in ISO 8601 format
6855
+ * Computes the usage of the Anthropic Claude API based on the response from Anthropic Claude
6844
6856
  *
6845
- * @private internal utility
6857
+ * @param promptContent The content of the prompt
6858
+ * @param resultContent The content of the result (for embedding prompts or failed prompts pass empty string)
6859
+ * @param rawResponse The raw response from Anthropic Claude API
6860
+ * @throws {PipelineExecutionError} If the usage is not defined in the response from Anthropic Claude
6861
+ * @private internal utility of `AnthropicClaudeExecutionTools`
6846
6862
  */
6847
- function getCurrentIsoDate() {
6848
- return new Date().toISOString();
6863
+ function computeAnthropicClaudeUsage(promptContent, // <- Note: Intentionally using [] to access type properties to bring jsdoc from Prompt/PromptResult to consumer
6864
+ resultContent, rawResponse) {
6865
+ var _a, _b;
6866
+ if (rawResponse.usage === undefined) {
6867
+ throw new PipelineExecutionError('The usage is not defined in the response from Anthropic Claude');
6868
+ }
6869
+ if (((_a = rawResponse.usage) === null || _a === void 0 ? void 0 : _a.input_tokens) === undefined) {
6870
+ throw new PipelineExecutionError('In Anthropic Claude response `usage.prompt_tokens` not defined');
6871
+ }
6872
+ var inputTokens = rawResponse.usage.input_tokens;
6873
+ var outputTokens = ((_b = rawResponse.usage) === null || _b === void 0 ? void 0 : _b.output_tokens) || 0;
6874
+ var modelInfo = ANTHROPIC_CLAUDE_MODELS.find(function (model) { return model.modelName === rawResponse.model; });
6875
+ var price;
6876
+ if (modelInfo === undefined || modelInfo.pricing === undefined) {
6877
+ price = uncertainNumber();
6878
+ }
6879
+ else {
6880
+ price = uncertainNumber(inputTokens * modelInfo.pricing.prompt + outputTokens * modelInfo.pricing.output);
6881
+ }
6882
+ return {
6883
+ price: price,
6884
+ input: __assign({ tokensCount: uncertainNumber(rawResponse.usage.input_tokens) }, computeUsageCounts(promptContent)),
6885
+ output: __assign({ tokensCount: uncertainNumber(outputTokens) }, computeUsageCounts(resultContent)),
6886
+ };
6849
6887
  }
6888
+ /**
6889
+ * TODO: [🤝] DRY Maybe some common abstraction between `computeOpenaiUsage` and `computeAnthropicClaudeUsage`
6890
+ */
6850
6891
 
6851
6892
  /**
6852
6893
  * Execution Tools for calling Anthropic Claude API.
@@ -6867,9 +6908,8 @@ var AnthropicClaudeExecutionTools = /** @class */ (function () {
6867
6908
  var anthropicOptions = __assign({}, options);
6868
6909
  delete anthropicOptions.isVerbose;
6869
6910
  delete anthropicOptions.isProxied;
6870
- this.client = new Anthropic(
6871
- // <- TODO: [🧱] Implement in a functional (not new Class) way
6872
- anthropicOptions);
6911
+ this.client = new Anthropic(anthropicOptions);
6912
+ // <- TODO: !!!!!! Lazy-load client
6873
6913
  }
6874
6914
  Object.defineProperty(AnthropicClaudeExecutionTools.prototype, "title", {
6875
6915
  get: function () {
@@ -6940,15 +6980,10 @@ var AnthropicClaudeExecutionTools = /** @class */ (function () {
6940
6980
  if (contentBlock.type !== 'text') {
6941
6981
  throw new PipelineExecutionError("Returned content is not \"text\" type but \"".concat(contentBlock.type, "\""));
6942
6982
  }
6943
- console.log('!!!!!! rawResponse.usage', rawResponse.usage);
6944
6983
  resultContent = contentBlock.text;
6945
6984
  // eslint-disable-next-line prefer-const
6946
6985
  complete = getCurrentIsoDate();
6947
- usage = {
6948
- price: { value: 0, isUncertain: true } /* <- TODO: [🐞] !!!!!! Compute usage */,
6949
- input: __assign({ tokensCount: uncertainNumber(rawResponse.usage.input_tokens) }, computeUsageCounts(prompt.content)),
6950
- output: __assign({ tokensCount: uncertainNumber(rawResponse.usage.output_tokens) }, computeUsageCounts(prompt.content)),
6951
- };
6986
+ usage = computeAnthropicClaudeUsage(content, '', rawResponse);
6952
6987
  return [2 /*return*/, {
6953
6988
  content: resultContent,
6954
6989
  modelName: rawResponse.model,
@@ -7473,9 +7508,8 @@ var AzureOpenAiExecutionTools = /** @class */ (function () {
7473
7508
  this.options = options;
7474
7509
  this.client = new OpenAIClient(
7475
7510
  // <- TODO: [🧱] Implement in a functional (not new Class) way
7476
- "https://".concat(options.resourceName, ".openai.azure.com/"), new AzureKeyCredential(
7477
- // <- TODO: [🧱] Implement in a functional (not new Class) way
7478
- options.apiKey));
7511
+ "https://".concat(options.resourceName, ".openai.azure.com/"), new AzureKeyCredential(options.apiKey));
7512
+ // <- TODO: !!!!!! Lazy-load client
7479
7513
  }
7480
7514
  Object.defineProperty(AzureOpenAiExecutionTools.prototype, "title", {
7481
7515
  get: function () {
@@ -7745,6 +7779,9 @@ resultContent, rawResponse) {
7745
7779
  output: __assign({ tokensCount: uncertainNumber(outputTokens) }, computeUsageCounts(resultContent)),
7746
7780
  };
7747
7781
  }
7782
+ /**
7783
+ * TODO: [🤝] DRY Maybe some common abstraction between `computeOpenaiUsage` and `computeAnthropicClaudeUsage`
7784
+ */
7748
7785
 
7749
7786
  /**
7750
7787
  * Execution Tools for calling OpenAI API.
@@ -7765,6 +7802,7 @@ var OpenAiExecutionTools = /** @class */ (function () {
7765
7802
  delete openAiOptions.isVerbose;
7766
7803
  delete openAiOptions.user;
7767
7804
  this.client = new OpenAI(__assign({}, openAiOptions));
7805
+ // <- TODO: !!!!!! Lazy-load client
7768
7806
  }
7769
7807
  Object.defineProperty(OpenAiExecutionTools.prototype, "title", {
7770
7808
  get: function () {
@@ -8066,7 +8104,7 @@ var EXECUTION_TOOLS_CLASSES = {
8066
8104
  // <- Note: [🦑] Add here new LLM provider
8067
8105
  };
8068
8106
  /**
8069
- * TODO: [🧠] Better file name than `config.ts` + maybe move to two separate files
8107
+ * TODO: !!!!!!! Make global register for this
8070
8108
  * TODO: [🧠][🎌] Adding this should be responsibility of each provider package NOT this one central place
8071
8109
  */
8072
8110