@promptbook/pdf 0.84.0-10 → 0.84.0-11

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.
@@ -8,6 +8,7 @@ import { serializeError } from '../errors/utils/serializeError';
8
8
  import { forEachAsync } from '../execution/utils/forEachAsync';
9
9
  import { isValidJsonString } from '../formats/json/utils/isValidJsonString';
10
10
  import { prompt } from '../pipeline/prompt-notation';
11
+ import { promptTemplate } from '../pipeline/prompt-notation';
11
12
  import { $getCurrentDate } from '../utils/$getCurrentDate';
12
13
  import { $isRunningInBrowser } from '../utils/environment/$isRunningInBrowser';
13
14
  import { $isRunningInJest } from '../utils/environment/$isRunningInJest';
@@ -89,6 +90,7 @@ export { serializeError };
89
90
  export { forEachAsync };
90
91
  export { isValidJsonString };
91
92
  export { prompt };
93
+ export { promptTemplate };
92
94
  export { $getCurrentDate };
93
95
  export { $isRunningInBrowser };
94
96
  export { $isRunningInJest };
@@ -2,11 +2,13 @@ import type { PipelineExecutorResult } from './PipelineExecutorResult';
2
2
  /**
3
3
  * Asserts that the execution of a Promptbook is successful
4
4
  *
5
+ * Note: If there are only warnings, the execution is still successful but the warnings are logged in the console
6
+ *
5
7
  * @param executionResult - The partial result of the Promptbook execution
6
8
  * @throws {PipelineExecutionError} If the execution is not successful or if multiple errors occurred
7
9
  * @public exported from `@promptbook/core`
8
10
  */
9
- export declare function assertsExecutionSuccessful(executionResult: Pick<PipelineExecutorResult, 'isSuccessful' | 'errors'>): void;
11
+ export declare function assertsExecutionSuccessful(executionResult: Pick<PipelineExecutorResult, 'isSuccessful' | 'errors' | 'warnings'>): void;
10
12
  /**
11
13
  * TODO: [🐚] This function should be removed OR changed OR be completely rewritten
12
14
  * TODO: [🧠] Can this return type be better typed than void
@@ -2,9 +2,10 @@ import type { PipelineString } from './PipelineString';
2
2
  /**
3
3
  * Tag function for notating a pipeline with a book\`...\ notation as template literal
4
4
  *
5
- * Note: There are 2 similar functions:
5
+ * Note: There are 3 similar functions:
6
6
  * 1) `prompt` for notating single prompt exported from `@promptbook/utils`
7
- * 1) `book` for notating and validating entire books exported from `@promptbook/utils`
7
+ * 2) `promptTemplate` alias for `prompt`
8
+ * 3) `book` for notating and validating entire books exported from `@promptbook/utils`
8
9
  *
9
10
  * @param strings @@@
10
11
  * @param values @@@
@@ -2,16 +2,29 @@ import type { string_prompt } from '../types/typeAliases';
2
2
  /**
3
3
  * Tag function for notating a prompt as template literal
4
4
  *
5
- * Note: There are 2 similar functions:
5
+ * Note: There are 3 similar functions:
6
6
  * 1) `prompt` for notating single prompt exported from `@promptbook/utils`
7
- * 1) `book` for notating and validating entire books exported from `@promptbook/utils`
7
+ * 2) `promptTemplate` alias for `prompt`
8
+ * 3) `book` for notating and validating entire books exported from `@promptbook/utils`
8
9
  *
9
- * @param strings @@@
10
- * @param values @@@
11
- * @returns the pipeline string
10
+ * @param strings
11
+ * @param values
12
+ * @returns the prompt string
12
13
  * @public exported from `@promptbook/utils`
13
14
  */
14
15
  export declare function prompt(strings: TemplateStringsArray, ...values: Array<string>): string_prompt;
16
+ /**
17
+ * Tag function for notating a prompt as template literal
18
+ *
19
+ * Note: There are 3 similar functions:
20
+ * 1) `prompt` for notating single prompt exported from `@promptbook/utils`
21
+ * 2) `promptTemplate` alias for `prompt`
22
+ * 3) `book` for notating and validating entire books exported from `@promptbook/utils`
23
+ *
24
+ * @alias prompt
25
+ * @public exported from `@promptbook/utils`
26
+ */
27
+ export declare const promptTemplate: typeof prompt;
15
28
  /**
16
29
  * TODO: [🧠][🈴] Where is the best location for this file
17
30
  * Note: [💞] Ignore a discrepancy between file name and entity name
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/pdf",
3
- "version": "0.84.0-10",
3
+ "version": "0.84.0-11",
4
4
  "description": "It's time for a paradigm shift. The future of software in plain English, French or Latin",
5
5
  "--note-0": " <- [🐊]",
6
6
  "private": false,
@@ -54,7 +54,7 @@
54
54
  "module": "./esm/index.es.js",
55
55
  "typings": "./esm/typings/src/_packages/pdf.index.d.ts",
56
56
  "peerDependencies": {
57
- "@promptbook/core": "0.84.0-10"
57
+ "@promptbook/core": "0.84.0-11"
58
58
  },
59
59
  "dependencies": {
60
60
  "crypto-js": "4.2.0",
package/umd/index.umd.js CHANGED
@@ -24,7 +24,7 @@
24
24
  * @generated
25
25
  * @see https://github.com/webgptorg/promptbook
26
26
  */
27
- var PROMPTBOOK_ENGINE_VERSION = '0.84.0-9';
27
+ var PROMPTBOOK_ENGINE_VERSION = '0.84.0-10';
28
28
  /**
29
29
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
30
30
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -941,24 +941,18 @@
941
941
  var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.book.md",formfactorName:"GENERIC",parameters:[{name:"knowledgeContent",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",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}",resultingParameterName:"knowledgePieces",dependentParameterNames:["knowledgeContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Knowledge from Markdown\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.book.md`\n- INPUT PARAMETER `{knowledgeContent}` Markdown document content\n- OUTPUT PARAMETER `{knowledgePieces}` The knowledge JSON object\n\n## Knowledge\n\n<!-- TODO: [🍆] -FORMAT JSON -->\n\n```markdown\nYou 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}\n```\n\n`-> {knowledgePieces}`\n"}],sourceFile:"./books/prepare-knowledge-from-markdown.book.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.book.md",formfactorName:"GENERIC",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",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}",resultingParameterName:"keywords",dependentParameterNames:["knowledgePieceContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Keywords\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-knowledge-keywords.book.md`\n- INPUT PARAMETER `{knowledgePieceContent}` The content\n- OUTPUT PARAMETER `{keywords}` Keywords separated by comma\n\n## Knowledge\n\n<!-- TODO: [🍆] -FORMAT JSON -->\n\n```markdown\nYou 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}\n```\n\n`-> {keywords}`\n"}],sourceFile:"./books/prepare-knowledge-keywords.book.md"},{title:"Prepare Knowledge-piece Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.book.md",formfactorName:"GENERIC",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",content:"You are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Write maximum 5 words for the title\n\n# The document\n\n> {knowledgePieceContent}",resultingParameterName:"title",expectations:{words:{min:1,max:8}},dependentParameterNames:["knowledgePieceContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Knowledge-piece Title\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-knowledge-title.book.md`\n- INPUT PARAMETER `{knowledgePieceContent}` The content\n- OUTPUT PARAMETER `{title}` The title of the document\n\n## Knowledge\n\n- EXPECT MIN 1 WORD\n- EXPECT MAX 8 WORDS\n\n```markdown\nYou are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Write maximum 5 words for the title\n\n# The document\n\n> {knowledgePieceContent}\n```\n\n`-> {title}`\n"}],sourceFile:"./books/prepare-knowledge-title.book.md"},{title:"Prepare Persona",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.book.md",formfactorName:"GENERIC",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}],tasks:[{taskType:"PROMPT_TASK",name:"make-model-requirements",title:"Make modelRequirements",content:"You are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Example\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- Your output format is JSON object\n- Write just the JSON object, no other text should be present\n- It contains the following keys:\n - `modelName`: The name of the model to use\n - `systemMessage`: The system message to provide context to the model\n - `temperature`: The sampling temperature to use\n\n### Key `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Key `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### Key `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}",resultingParameterName:"modelRequirements",format:"JSON",dependentParameterNames:["availableModelNames","personaDescription"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Persona\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-persona.book.md`\n- INPUT PARAMETER `{availableModelNames}` List of available model names separated by comma (,)\n- INPUT PARAMETER `{personaDescription}` Description of the persona\n- OUTPUT PARAMETER `{modelRequirements}` Specific requirements for the model\n\n## Make modelRequirements\n\n- FORMAT JSON\n\n```markdown\nYou are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Example\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- Your output format is JSON object\n- Write just the JSON object, no other text should be present\n- It contains the following keys:\n - `modelName`: The name of the model to use\n - `systemMessage`: The system message to provide context to the model\n - `temperature`: The sampling temperature to use\n\n### Key `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Key `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### Key `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}\n```\n\n`-> {modelRequirements}`\n"}],sourceFile:"./books/prepare-persona.book.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-title.book.md",formfactorName:"GENERIC",parameters:[{name:"book",description:"The book to prepare the title for",isInput:true,isOutput:false},{name:"title",description:"Best title for the book",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"make-title",title:"Make title",content:"Make best title for given text which describes the workflow:\n\n## Rules\n\n- Write just title, nothing else\n- Title should be concise and clear - Write maximum ideally 2 words, maximum 5 words\n- Title starts with emoticon\n- Title should not mention the input and output of the workflow but the main purpose of the workflow\n _For example, not \"✍ Convert Knowledge-piece to title\" but \"✍ Title\"_\n\n## The workflow\n\n> {book}",resultingParameterName:"title",expectations:{words:{min:1,max:8},lines:{min:1,max:1}},dependentParameterNames:["book"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Title\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-title.book.md`\n- INPUT PARAMETER `{book}` The book to prepare the title for\n- OUTPUT PARAMETER `{title}` Best title for the book\n\n## Make title\n\n- EXPECT MIN 1 Word\n- EXPECT MAX 8 Words\n- EXPECT EXACTLY 1 Line\n\n```markdown\nMake best title for given text which describes the workflow:\n\n## Rules\n\n- Write just title, nothing else\n- Title should be concise and clear - Write maximum ideally 2 words, maximum 5 words\n- Title starts with emoticon\n- Title should not mention the input and output of the workflow but the main purpose of the workflow\n _For example, not \"✍ Convert Knowledge-piece to title\" but \"✍ Title\"_\n\n## The workflow\n\n> {book}\n```\n\n`-> {title}`\n"}],sourceFile:"./books/prepare-title.book.md"}];
942
942
 
943
943
  /**
944
- * Function isValidJsonString will tell you if the string is valid JSON or not
944
+ * Checks if value is valid email
945
945
  *
946
946
  * @public exported from `@promptbook/utils`
947
947
  */
948
- function isValidJsonString(value /* <- [👨‍⚖️] */) {
949
- try {
950
- JSON.parse(value);
951
- return true;
948
+ function isValidEmail(email) {
949
+ if (typeof email !== 'string') {
950
+ return false;
952
951
  }
953
- catch (error) {
954
- if (!(error instanceof Error)) {
955
- throw error;
956
- }
957
- if (error.message.includes('Unexpected token')) {
958
- return false;
959
- }
952
+ if (email.split('\n').length > 1) {
960
953
  return false;
961
954
  }
955
+ return /^.+@.+\..+$/.test(email);
962
956
  }
963
957
 
964
958
  /**
@@ -980,6 +974,27 @@
980
974
  * TODO: Maybe split `ParseError` and `ApplyError`
981
975
  */
982
976
 
977
+ /**
978
+ * Function isValidJsonString will tell you if the string is valid JSON or not
979
+ *
980
+ * @public exported from `@promptbook/utils`
981
+ */
982
+ function isValidJsonString(value /* <- [👨‍⚖️] */) {
983
+ try {
984
+ JSON.parse(value);
985
+ return true;
986
+ }
987
+ catch (error) {
988
+ if (!(error instanceof Error)) {
989
+ throw error;
990
+ }
991
+ if (error.message.includes('Unexpected token')) {
992
+ return false;
993
+ }
994
+ return false;
995
+ }
996
+ }
997
+
983
998
  /**
984
999
  * Function `validatePipelineString` will validate the if the string is a valid pipeline string
985
1000
  * It does not check if the string is fully logically correct, but if it is a string that can be a pipeline string or the string looks completely different.
@@ -993,6 +1008,15 @@
993
1008
  if (isValidJsonString(pipelineString)) {
994
1009
  throw new ParseError('Expected a book, but got a JSON string');
995
1010
  }
1011
+ else if (isValidUrl(pipelineString)) {
1012
+ throw new ParseError("Expected a book, but got just the URL \"".concat(pipelineString, "\""));
1013
+ }
1014
+ else if (isValidFilePath(pipelineString)) {
1015
+ throw new ParseError("Expected a book, but got just the file path \"".concat(pipelineString, "\""));
1016
+ }
1017
+ else if (isValidEmail(pipelineString)) {
1018
+ throw new ParseError("Expected a book, but got just the email \"".concat(pipelineString, "\""));
1019
+ }
996
1020
  // <- TODO: Implement the validation + add tests when the pipeline logic considered as invalid
997
1021
  return pipelineString;
998
1022
  }
@@ -2374,12 +2398,28 @@
2374
2398
  /**
2375
2399
  * Asserts that the execution of a Promptbook is successful
2376
2400
  *
2401
+ * Note: If there are only warnings, the execution is still successful but the warnings are logged in the console
2402
+ *
2377
2403
  * @param executionResult - The partial result of the Promptbook execution
2378
2404
  * @throws {PipelineExecutionError} If the execution is not successful or if multiple errors occurred
2379
2405
  * @public exported from `@promptbook/core`
2380
2406
  */
2381
2407
  function assertsExecutionSuccessful(executionResult) {
2382
- var isSuccessful = executionResult.isSuccessful, errors = executionResult.errors;
2408
+ var e_1, _a;
2409
+ var isSuccessful = executionResult.isSuccessful, errors = executionResult.errors, warnings = executionResult.warnings;
2410
+ try {
2411
+ for (var warnings_1 = __values(warnings), warnings_1_1 = warnings_1.next(); !warnings_1_1.done; warnings_1_1 = warnings_1.next()) {
2412
+ var warning = warnings_1_1.value;
2413
+ console.warn(warning.message);
2414
+ }
2415
+ }
2416
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
2417
+ finally {
2418
+ try {
2419
+ if (warnings_1_1 && !warnings_1_1.done && (_a = warnings_1.return)) _a.call(warnings_1);
2420
+ }
2421
+ finally { if (e_1) throw e_1.error; }
2422
+ }
2383
2423
  if (isSuccessful === true) {
2384
2424
  return;
2385
2425
  }