@promptbook/openai 0.35.1 → 0.36.2

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.
Files changed (104) hide show
  1. package/README.md +1 -1
  2. package/esm/index.es.js +1 -1
  3. package/esm/typings/_packages/core.index.d.ts +8 -8
  4. package/esm/typings/_packages/remote-server.index.d.ts +2 -2
  5. package/esm/typings/_packages/types.index.d.ts +8 -8
  6. package/esm/typings/classes/PromptbookLibrary.d.ts +61 -0
  7. package/esm/typings/conversion/_importPromptbook.d.ts +12 -0
  8. package/esm/typings/conversion/promptbookStringToJson.d.ts +13 -0
  9. package/esm/typings/conversion/validatePromptbookJson.d.ts +26 -0
  10. package/{umd/typings/execution/PtpExecutor.d.ts → esm/typings/execution/PromptbookExecutor.d.ts} +5 -5
  11. package/esm/typings/execution/assertsExecutionSuccessful.d.ts +2 -2
  12. package/esm/typings/execution/createPromptbookExecutor.d.ts +40 -0
  13. package/esm/typings/execution/plugins/natural-execution-tools/mocked/joker.test.d.ts +1 -1
  14. package/esm/typings/execution/plugins/natural-execution-tools/mocked/mocked-chat.test.d.ts +1 -1
  15. package/esm/typings/execution/plugins/natural-execution-tools/mocked/mocked-completion.test.d.ts +1 -1
  16. package/esm/typings/execution/plugins/natural-execution-tools/remote/RemoteNaturalExecutionToolsOptions.d.ts +1 -1
  17. package/esm/typings/execution/plugins/natural-execution-tools/remote/interfaces/{Ptps_Error.d.ts → Promptbook_Server_Error.d.ts} +1 -1
  18. package/esm/typings/execution/plugins/natural-execution-tools/remote/interfaces/{Ptps_Progress.d.ts → Promptbook_Server_Progress.d.ts} +1 -1
  19. package/esm/typings/execution/plugins/natural-execution-tools/remote/interfaces/{Ptps_Request.d.ts → Promptbook_Server_Request.d.ts} +2 -2
  20. package/esm/typings/execution/plugins/natural-execution-tools/remote/interfaces/{Ptps_Response.d.ts → Promptbook_Server_Response.d.ts} +2 -2
  21. package/esm/typings/execution/plugins/natural-execution-tools/remote/interfaces/RemoteServerOptions.d.ts +3 -3
  22. package/{umd/typings/execution/plugins/natural-execution-tools/remote/runRemoteServer.d.ts → esm/typings/execution/plugins/natural-execution-tools/remote/startRemoteServer.d.ts} +2 -2
  23. package/esm/typings/types/Command.d.ts +12 -12
  24. package/esm/typings/types/Parameters.d.ts +3 -3
  25. package/esm/typings/types/Prompt.d.ts +5 -5
  26. package/{umd/typings/types/PromptTemplatePipelineJson → esm/typings/types/PromptbookJson}/PromptTemplateJson.d.ts +4 -4
  27. package/esm/typings/types/{PromptTemplatePipelineJson → PromptbookJson}/PromptTemplateParameterJson.d.ts +2 -2
  28. package/{umd/typings/types/PromptTemplatePipelineJson/PromptTemplatePipelineJson.d.ts → esm/typings/types/PromptbookJson/PromptbookJson.d.ts} +11 -15
  29. package/esm/typings/types/PromptbookString.d.ts +12 -0
  30. package/esm/typings/types/TaskProgress.d.ts +1 -1
  31. package/esm/typings/types/execution-report/ExecutionReportJson.d.ts +10 -10
  32. package/esm/typings/types/typeAliases.d.ts +4 -4
  33. package/esm/typings/utils/expectation-counters/countCharacters.d.ts +1 -1
  34. package/esm/typings/utils/expectation-counters/countLines.d.ts +1 -1
  35. package/esm/typings/utils/expectation-counters/countPages.d.ts +1 -1
  36. package/esm/typings/utils/expectation-counters/countParagraphs.d.ts +1 -1
  37. package/esm/typings/utils/expectation-counters/countSentences.d.ts +1 -1
  38. package/esm/typings/utils/expectation-counters/countWords.d.ts +1 -1
  39. package/esm/typings/utils/expectation-counters/index.d.ts +1 -1
  40. package/esm/typings/utils/isRunningInWhatever.d.ts +12 -0
  41. package/esm/typings/version.d.ts +1 -1
  42. package/package.json +2 -2
  43. package/umd/index.umd.js +1 -1
  44. package/umd/typings/_packages/core.index.d.ts +8 -8
  45. package/umd/typings/_packages/remote-server.index.d.ts +2 -2
  46. package/umd/typings/_packages/types.index.d.ts +8 -8
  47. package/umd/typings/classes/PromptbookLibrary.d.ts +61 -0
  48. package/umd/typings/conversion/_importPromptbook.d.ts +12 -0
  49. package/umd/typings/conversion/promptbookStringToJson.d.ts +13 -0
  50. package/umd/typings/conversion/validatePromptbookJson.d.ts +26 -0
  51. package/{esm/typings/execution/PtpExecutor.d.ts → umd/typings/execution/PromptbookExecutor.d.ts} +5 -5
  52. package/umd/typings/execution/assertsExecutionSuccessful.d.ts +2 -2
  53. package/umd/typings/execution/createPromptbookExecutor.d.ts +40 -0
  54. package/umd/typings/execution/plugins/natural-execution-tools/mocked/joker.test.d.ts +1 -1
  55. package/umd/typings/execution/plugins/natural-execution-tools/mocked/mocked-chat.test.d.ts +1 -1
  56. package/umd/typings/execution/plugins/natural-execution-tools/mocked/mocked-completion.test.d.ts +1 -1
  57. package/umd/typings/execution/plugins/natural-execution-tools/remote/RemoteNaturalExecutionToolsOptions.d.ts +1 -1
  58. package/umd/typings/execution/plugins/natural-execution-tools/remote/interfaces/{Ptps_Error.d.ts → Promptbook_Server_Error.d.ts} +1 -1
  59. package/umd/typings/execution/plugins/natural-execution-tools/remote/interfaces/{Ptps_Progress.d.ts → Promptbook_Server_Progress.d.ts} +1 -1
  60. package/umd/typings/execution/plugins/natural-execution-tools/remote/interfaces/{Ptps_Request.d.ts → Promptbook_Server_Request.d.ts} +2 -2
  61. package/umd/typings/execution/plugins/natural-execution-tools/remote/interfaces/{Ptps_Response.d.ts → Promptbook_Server_Response.d.ts} +2 -2
  62. package/umd/typings/execution/plugins/natural-execution-tools/remote/interfaces/RemoteServerOptions.d.ts +3 -3
  63. package/{esm/typings/execution/plugins/natural-execution-tools/remote/runRemoteServer.d.ts → umd/typings/execution/plugins/natural-execution-tools/remote/startRemoteServer.d.ts} +2 -2
  64. package/umd/typings/types/Command.d.ts +12 -12
  65. package/umd/typings/types/Parameters.d.ts +3 -3
  66. package/umd/typings/types/Prompt.d.ts +5 -5
  67. package/{esm/typings/types/PromptTemplatePipelineJson → umd/typings/types/PromptbookJson}/PromptTemplateJson.d.ts +4 -4
  68. package/umd/typings/types/{PromptTemplatePipelineJson → PromptbookJson}/PromptTemplateParameterJson.d.ts +2 -2
  69. package/{esm/typings/types/PromptTemplatePipelineJson/PromptTemplatePipelineJson.d.ts → umd/typings/types/PromptbookJson/PromptbookJson.d.ts} +11 -15
  70. package/umd/typings/types/PromptbookString.d.ts +12 -0
  71. package/umd/typings/types/TaskProgress.d.ts +1 -1
  72. package/umd/typings/types/execution-report/ExecutionReportJson.d.ts +10 -10
  73. package/umd/typings/types/typeAliases.d.ts +4 -4
  74. package/umd/typings/utils/expectation-counters/countCharacters.d.ts +1 -1
  75. package/umd/typings/utils/expectation-counters/countLines.d.ts +1 -1
  76. package/umd/typings/utils/expectation-counters/countPages.d.ts +1 -1
  77. package/umd/typings/utils/expectation-counters/countParagraphs.d.ts +1 -1
  78. package/umd/typings/utils/expectation-counters/countSentences.d.ts +1 -1
  79. package/umd/typings/utils/expectation-counters/countWords.d.ts +1 -1
  80. package/umd/typings/utils/expectation-counters/index.d.ts +1 -1
  81. package/umd/typings/utils/isRunningInWhatever.d.ts +12 -0
  82. package/umd/typings/version.d.ts +1 -1
  83. package/esm/typings/classes/PromptTemplatePipelineLibrary.d.ts +0 -71
  84. package/esm/typings/config.d.ts +0 -12
  85. package/esm/typings/conversion/_importPtp.d.ts +0 -12
  86. package/esm/typings/conversion/promptTemplatePipelineStringToJson.d.ts +0 -13
  87. package/esm/typings/conversion/validatePromptTemplatePipelineJson.d.ts +0 -26
  88. package/esm/typings/execution/createPtpExecutor.d.ts +0 -40
  89. package/esm/typings/types/PromptTemplatePipelineString.d.ts +0 -16
  90. package/umd/typings/classes/PromptTemplatePipelineLibrary.d.ts +0 -71
  91. package/umd/typings/config.d.ts +0 -12
  92. package/umd/typings/conversion/_importPtp.d.ts +0 -12
  93. package/umd/typings/conversion/promptTemplatePipelineStringToJson.d.ts +0 -13
  94. package/umd/typings/conversion/validatePromptTemplatePipelineJson.d.ts +0 -26
  95. package/umd/typings/execution/createPtpExecutor.d.ts +0 -40
  96. package/umd/typings/types/PromptTemplatePipelineString.d.ts +0 -16
  97. /package/esm/typings/conversion/{promptTemplatePipelineStringToJson-syntaxErrors.test.d.ts → promptbookStringToJson-syntaxErrors.test.d.ts} +0 -0
  98. /package/esm/typings/conversion/{promptTemplatePipelineStringToJson.test.d.ts → promptbookStringToJson.test.d.ts} +0 -0
  99. /package/esm/typings/conversion/{validatePromptTemplatePipelineJson-logicErrors.test.d.ts → validatePromptbookJson-logicErrors.test.d.ts} +0 -0
  100. /package/esm/typings/conversion/{validatePromptTemplatePipelineJson.test.d.ts → validatePromptbookJson.test.d.ts} +0 -0
  101. /package/umd/typings/conversion/{promptTemplatePipelineStringToJson-syntaxErrors.test.d.ts → promptbookStringToJson-syntaxErrors.test.d.ts} +0 -0
  102. /package/umd/typings/conversion/{promptTemplatePipelineStringToJson.test.d.ts → promptbookStringToJson.test.d.ts} +0 -0
  103. /package/umd/typings/conversion/{validatePromptTemplatePipelineJson-logicErrors.test.d.ts → validatePromptbookJson-logicErrors.test.d.ts} +0 -0
  104. /package/umd/typings/conversion/{validatePromptTemplatePipelineJson.test.d.ts → validatePromptbookJson.test.d.ts} +0 -0
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # 📖 Prompt template pipelines
1
+ # 📖 Promptbook
2
2
 
3
3
  Library to supercharge your use of large language models
4
4
 
package/esm/index.es.js CHANGED
@@ -93,7 +93,7 @@ function computeOpenaiUsage(rawResponse) {
93
93
  completion: 0.002,
94
94
  },
95
95
  'gpt-4-0613': {
96
- // TODO: !!! Not sure if this is correct
96
+ // TODO: Not sure if this is correct
97
97
  prompt: 0.01,
98
98
  completion: 0.03,
99
99
  },
@@ -1,16 +1,16 @@
1
- import { PromptTemplatePipelineLibrary } from '../classes/PromptTemplatePipelineLibrary';
2
- import { PTBK_VERSION } from '../version';
3
- import { promptTemplatePipelineStringToJson } from '../conversion/promptTemplatePipelineStringToJson';
4
- import { validatePromptTemplatePipelineJson } from '../conversion/validatePromptTemplatePipelineJson';
5
- import { createPtpExecutor } from '../execution/createPtpExecutor';
1
+ import { PromptbookLibrary } from '../classes/PromptbookLibrary';
2
+ import { promptbookStringToJson } from '../conversion/promptbookStringToJson';
3
+ import { validatePromptbookJson } from '../conversion/validatePromptbookJson';
4
+ import { createPromptbookExecutor } from '../execution/createPromptbookExecutor';
6
5
  import { MockedEchoNaturalExecutionTools } from '../execution/plugins/natural-execution-tools/mocked/MockedEchoNaturalExecutionTools';
7
6
  import { CallbackInterfaceTools } from '../execution/plugins/user-interface-execution-tools/callback/CallbackInterfaceTools';
8
7
  import { CallbackInterfaceToolsOptions } from '../execution/plugins/user-interface-execution-tools/callback/CallbackInterfaceToolsOptions';
9
8
  import { SimplePromptInterfaceTools } from '../execution/plugins/user-interface-execution-tools/simple-prompt/SimplePromptInterfaceTools';
10
9
  import { ExecutionTypes } from '../types/ExecutionTypes';
11
- export { ExecutionTypes, PTBK_VERSION, PromptTemplatePipelineLibrary };
10
+ import { PROMPTBOOK_VERSION } from '../version';
11
+ export { ExecutionTypes, PROMPTBOOK_VERSION, PromptbookLibrary };
12
12
  export { SimplePromptInterfaceTools };
13
- export { promptTemplatePipelineStringToJson, validatePromptTemplatePipelineJson };
13
+ export { promptbookStringToJson, validatePromptbookJson };
14
14
  export { MockedEchoNaturalExecutionTools };
15
- export { createPtpExecutor };
15
+ export { createPromptbookExecutor };
16
16
  export { CallbackInterfaceTools, CallbackInterfaceToolsOptions };
@@ -1,3 +1,3 @@
1
1
  import { RemoteServerOptions } from '../execution/plugins/natural-execution-tools/remote/interfaces/RemoteServerOptions';
2
- import { runRemoteServer } from '../execution/plugins/natural-execution-tools/remote/runRemoteServer';
3
- export { RemoteServerOptions, runRemoteServer };
2
+ import { startRemoteServer } from '../execution/plugins/natural-execution-tools/remote/startRemoteServer';
3
+ export { RemoteServerOptions, startRemoteServer };
@@ -2,24 +2,24 @@ import type { CommonExecutionToolsOptions } from '../execution/CommonExecutionTo
2
2
  import type { ExecutionTools } from '../execution/ExecutionTools';
3
3
  import type { NaturalExecutionTools } from '../execution/NaturalExecutionTools';
4
4
  import type { PromptChatResult, PromptCommonResult, PromptCompletionResult, PromptResult } from '../execution/PromptResult';
5
- import type { PtpExecutor } from '../execution/PtpExecutor';
5
+ import type { PromptbookExecutor } from '../execution/PromptbookExecutor';
6
6
  import type { ScriptExecutionTools, ScriptExecutionToolsExecuteOptions } from '../execution/ScriptExecutionTools';
7
7
  import type { UserInterfaceTools, UserInterfaceToolsPromptDialogOptions } from '../execution/UserInterfaceTools';
8
8
  import type { ExecutionType } from '../types/ExecutionTypes';
9
9
  import type { ModelRequirements, ModelVariant } from '../types/ModelRequirements';
10
10
  import type { Parameters } from '../types/Parameters';
11
11
  import type { Prompt } from '../types/Prompt';
12
- import type { EXPECTATION_UNITS, ExpectationAmount, ExpectationUnit, PromptTemplateJson } from '../types/PromptTemplatePipelineJson/PromptTemplateJson';
13
- import type { PromptTemplateParameterJson } from '../types/PromptTemplatePipelineJson/PromptTemplateParameterJson';
14
- import type { PromptTemplatePipelineJson } from '../types/PromptTemplatePipelineJson/PromptTemplatePipelineJson';
15
- import type { PromptTemplatePipelineString } from '../types/PromptTemplatePipelineString';
12
+ import type { EXPECTATION_UNITS, ExpectationAmount, ExpectationUnit, PromptTemplateJson } from '../types/PromptbookJson/PromptTemplateJson';
13
+ import type { PromptTemplateParameterJson } from '../types/PromptbookJson/PromptTemplateParameterJson';
14
+ import type { PromptbookJson } from '../types/PromptbookJson/PromptbookJson';
15
+ import type { PromptbookString } from '../types/PromptbookString';
16
16
  import type { ScriptLanguage } from '../types/ScriptLanguage';
17
17
  import type { TaskProgress } from '../types/TaskProgress';
18
18
  import type { ExecutionReportJson } from '../types/execution-report/ExecutionReportJson';
19
19
  import type { string_char_emoji } from '../types/typeAliasEmoji';
20
- import type { ILicense, IPersonProfile, IRepository, client_id, number_bytes, number_days, number_gigabytes, number_hours, number_integer, number_kilobytes, number_likeness, number_megabytes, number_miliseconds, number_minutes, number_months, number_negative, number_percent, number_positive, number_seconds, number_terabytes, number_weeks, number_years, string_attribute, string_attribute_value_scope, string_business_category_name, string_char, string_chat_prompt, string_color, string_completion_prompt, string_css, string_css_class, string_css_property, string_css_selector, string_css_value, string_data_url, string_domain, string_email, string_file_absolute_path, string_file_extension, string_file_path, string_file_relative_path, string_filename, string_folder_absolute_path, string_folder_path, string_folder_relative_path, string_host, string_hostname, string_href, string_html, string_javascript, string_javascript_name, string_license, string_license_token, string_markdown, string_markdown_text, string_mime_type, string_mime_type_with_wildcard, string_model_name, string_name, string_page, string_password, string_person_fullname, string_person_profile, string_pgp_key, string_prompt, string_protocol, string_ptbk_url, string_ptbk_url_with_hashtemplate, string_script, string_sha256, string_ssh_key, string_svg, string_tdl, string_template, string_text_prompt, string_title, string_token, string_translate_language, string_translate_name, string_translate_name_not_normalized, string_uri, string_uri_part, string_uriid, string_url, string_url_image, string_version, string_version_dependency, string_xml } from '../types/typeAliases';
20
+ import type { client_id, string_char, string_chat_prompt, string_completion_prompt, string_data_url, string_domain, string_email, string_file_absolute_path, string_file_extension, string_file_path, string_file_relative_path, string_filename, string_folder_absolute_path, string_folder_path, string_folder_relative_path, string_host, string_hostname, string_href, string_html, string_javascript, string_javascript_name, string_license, string_markdown, string_markdown_text, string_mime_type, string_mime_type_with_wildcard, string_model_name, string_name, string_person_fullname, string_prompt, string_promptbook_url, string_promptbook_url_with_hashtemplate, string_script, string_sha256, string_tdl, string_template, string_text_prompt, string_title, string_token, string_translate_language, string_uri, string_uri_part, string_url, string_url_image, string_version } from '../types/typeAliases';
21
21
  import { FromtoItems } from '../utils/FromtoItems';
22
- export { CommonExecutionToolsOptions, EXPECTATION_UNITS, ExecutionReportJson, ExecutionTools, ExecutionType, ExpectationAmount, ExpectationUnit, FromtoItems, ILicense, IPersonProfile, IRepository, ModelRequirements, ModelVariant, NaturalExecutionTools, Parameters, Prompt, PromptChatResult, PromptCommonResult, PromptCompletionResult, PromptResult, PromptTemplateJson, PromptTemplateParameterJson, PromptTemplatePipelineJson, PromptTemplatePipelineString, PtpExecutor, ScriptExecutionTools, ScriptExecutionToolsExecuteOptions, ScriptLanguage, TaskProgress, UserInterfaceTools, UserInterfaceToolsPromptDialogOptions, client_id, number_bytes, number_days, number_gigabytes, number_hours, number_integer, number_kilobytes, number_likeness, number_megabytes, number_miliseconds, number_minutes, number_months, number_negative, number_percent, number_positive, number_seconds, number_terabytes, number_weeks, number_years, string_attribute, string_attribute_value_scope, string_business_category_name, string_char, string_char_emoji, string_chat_prompt, string_color, string_completion_prompt, string_css, string_css_class, string_css_property, string_css_selector, string_css_value, string_data_url, string_domain, string_email, string_file_absolute_path, string_file_extension, string_file_path, string_file_relative_path, string_filename, string_folder_absolute_path, string_folder_path, string_folder_relative_path, string_host, string_hostname, string_href, string_html, string_javascript, string_javascript_name, string_license, string_license_token, string_markdown, string_markdown_text, string_mime_type, string_mime_type_with_wildcard, string_model_name, string_name, string_page, string_password, string_person_fullname, string_person_profile, string_pgp_key, string_prompt, string_protocol, string_ptbk_url, string_ptbk_url_with_hashtemplate, string_script, string_sha256, string_ssh_key, string_svg, string_tdl, string_template, string_text_prompt, string_title, string_token, string_translate_language, string_translate_name, string_translate_name_not_normalized, string_uri, string_uri_part, string_uriid, string_url, string_url_image, string_version, string_version_dependency, string_xml, };
22
+ export { CommonExecutionToolsOptions, EXPECTATION_UNITS, ExecutionReportJson, ExecutionTools, ExecutionType, ExpectationAmount, ExpectationUnit, FromtoItems, ModelRequirements, ModelVariant, NaturalExecutionTools, Parameters, Prompt, PromptChatResult, PromptCommonResult, PromptCompletionResult, PromptResult, PromptTemplateJson, PromptTemplateParameterJson, PromptbookExecutor, PromptbookJson, PromptbookString, ScriptExecutionTools, ScriptExecutionToolsExecuteOptions, ScriptLanguage, TaskProgress, UserInterfaceTools, UserInterfaceToolsPromptDialogOptions, client_id, string_char, string_char_emoji, string_chat_prompt, string_completion_prompt, string_data_url, string_domain, string_email, string_file_absolute_path, string_file_extension, string_file_path, string_file_relative_path, string_filename, string_folder_absolute_path, string_folder_path, string_folder_relative_path, string_host, string_hostname, string_href, string_html, string_javascript, string_javascript_name, string_license, string_markdown, string_markdown_text, string_mime_type, string_mime_type_with_wildcard, string_model_name, string_name, string_person_fullname, string_prompt, string_promptbook_url, string_promptbook_url_with_hashtemplate, string_script, string_sha256, string_tdl, string_template, string_text_prompt, string_title, string_token, string_translate_language, string_uri, string_uri_part, string_url, string_url_image, string_version, };
23
23
  /**
24
- * TODO: !!! Filter out all the types that are not used in the library
24
+ * TODO: Delete type aliases that are not exported here
25
25
  */
@@ -0,0 +1,61 @@
1
+ import { string_name } from '.././types/typeAliases';
2
+ import { CreatePromptbookExecutorSettings } from '../execution/createPromptbookExecutor';
3
+ import { ExecutionTools } from '../execution/ExecutionTools';
4
+ import { PromptbookExecutor } from '../execution/PromptbookExecutor';
5
+ import { Prompt } from '../types/Prompt';
6
+ import { PromptbookJson } from '../types/PromptbookJson/PromptbookJson';
7
+ import { PromptbookString } from '../types/PromptbookString';
8
+ /**
9
+ * Library of promptbooks that groups together promptbooks for an application. This is a very thin wrapper around the Array / Set of promptbooks.
10
+ *
11
+ * Promptbook library is a useful helper in execution, it can be shared between execution and consumer parts of the app and make common knowledge about promptbooks.
12
+ *
13
+ * It allows to create executor functions from promptbooks in the library.
14
+ *
15
+ * @see https://github.com/webgptorg/promptbook#prompt-template-pipeline-library
16
+ */
17
+ export declare class PromptbookLibrary {
18
+ private readonly options;
19
+ /**
20
+ * Constructs Promptbook from any sources
21
+ *
22
+ * Note: During the construction syntax and logic of all sources are validated
23
+ * Note: You can combine .ptbk.md and .ptbk.json files BUT it is not recommended
24
+ *
25
+ * @param promptbookSources contents of .ptbk.md or .ptbk.json files
26
+ * @param settings settings for creating executor functions
27
+ * @returns PromptbookLibrary
28
+ */
29
+ static fromSources(promptbookSources: Record<string_name, PromptbookJson | PromptbookString>, settings?: Partial<CreatePromptbookExecutorSettings>): PromptbookLibrary;
30
+ private constructor();
31
+ /**
32
+ * Gets all promptbooks in the library
33
+ */
34
+ get promptbookNames(): Array<string_name>;
35
+ /**
36
+ * Gets promptbook by name
37
+ */
38
+ getPromptbookByName(name: string_name): PromptbookJson;
39
+ /**
40
+ * Checks whether prompt is in the library
41
+ */
42
+ isPromptInLibrary(prompt: Prompt): boolean;
43
+ /**
44
+ * Gets executor function for given promptbook
45
+ */
46
+ createExecutor(name: string_name, tools: ExecutionTools): PromptbookExecutor;
47
+ }
48
+ /**
49
+ * TODO: [🈴] Identify promptbooks by url `promptbookUrls` + `getPromptbookByUrl`
50
+ * TODO: !! [👐][🧠] Split of Promptbook,PromptbookLibrary between interface and class
51
+ * TODO: !! [👐] Make promptbooks private WHEN split between interface and class
52
+ * TODO: [🧠] Maybe isPromptInLibrary should be separate utility function
53
+ * TODO: [🧠] Maybe createExecutor should be separate utility function
54
+ * TODO: Static method fromDirectory
55
+ * TODO: [🤜] Add generic type for entry and result parameters
56
+ * TODO: [🧠] Is it better to promptbookLibrary.executePromptbook('writeXyz',{...}) OR promptbookLibrary.createExecutor('writeXyz')({...}) OR createExecutor(promptbookLibrary.getPromptbook('writeXyz'))
57
+ * TODO: [🧠] Formarly (before commit 62229afce7668a5b85077cc18becf798b583bf8d) there were two classes PromptbookLibrary+PromptbookLibraryExecutor (maybe it was better?)
58
+ * TODO: [🧠] Is it better to pass tools into getExecutor or into constructor
59
+ * Maybe it is not a good idea to cache executors when they are can be created with different tools
60
+ * TODO: [👧] Strongly type the executors to avoid need of remove nullables whtn noUncheckedIndexedAccess in tsconfig.json
61
+ */
@@ -0,0 +1,12 @@
1
+ import { PromptbookJson } from '../types/PromptbookJson/PromptbookJson';
2
+ import { PromptbookString } from '../types/PromptbookString';
3
+ /**
4
+ * Import the text file
5
+ *
6
+ * Note: Using here custom import to work in jest tests
7
+ * Note: Using sync version is 💩 in the production code, but it's ok here in tests
8
+ *
9
+ * @private
10
+ */
11
+ export declare function importPromptbook(path: `${string}.ptbk.md`): PromptbookString;
12
+ export declare function importPromptbook(path: `${string}.ptbk.json`): PromptbookJson;
@@ -0,0 +1,13 @@
1
+ import { PromptbookJson } from '../types/PromptbookJson/PromptbookJson';
2
+ import { PromptbookString } from '../types/PromptbookString';
3
+ /**
4
+ * Parse promptbook from string format to JSON format
5
+ *
6
+ * Note: This function does not validate logic of the pipeline only the syntax
7
+ */
8
+ export declare function promptbookStringToJson(promptbookString: PromptbookString): PromptbookJson;
9
+ /**
10
+ * TODO: Report here line/column of error
11
+ * TODO: Use spaceTrim more effectively
12
+ * TODO: [🧠] Parameter flags - isInput, isOutput, isInternal
13
+ */
@@ -0,0 +1,26 @@
1
+ import type { PromptbookJson } from '../types/PromptbookJson/PromptbookJson';
2
+ /**
3
+ * Validates PromptbookJson if it is logically valid.
4
+ *
5
+ * It checks:
6
+ * - if it has correct parameters dependency
7
+ *
8
+ * It does NOT check:
9
+ * - if it is valid json
10
+ * - if it is meaningful
11
+ *
12
+ * @param promptbook valid or invalid PromptbookJson
13
+ * @throws {Error} if invalid
14
+ */
15
+ export declare function validatePromptbookJson(promptbook: PromptbookJson): void;
16
+ /**
17
+ * TODO: [🧠] Work with promptbookVersion
18
+ * TODO: Use here some json-schema, Zod or something similar and change it to:
19
+ * > /**
20
+ * > * Validates PromptbookJson if it is logically valid.
21
+ * > *
22
+ * > * It checks:
23
+ * > * - it has a valid structure
24
+ * > * - ...
25
+ * > ex port function validatePromptbookJson(promptbook: unknown): asserts promptbook is PromptbookJson {
26
+ */
@@ -1,18 +1,18 @@
1
1
  import type { Promisable } from 'type-fest';
2
- import type { string_name } from '.././types/typeAliases';
3
2
  import type { TaskProgress } from '../types/TaskProgress';
4
3
  import type { ExecutionReportJson } from '../types/execution-report/ExecutionReportJson';
4
+ import type { string_name } from '../types/typeAliases';
5
5
  /**
6
6
  * Executor is a simple async function that takes INPUT PARAMETERs and returns result parameters _(along with all intermediate parameters and INPUT PARAMETERs = it extends input object)_.
7
- * Executor is made by combining execution tools and prompt template pipeline library.
7
+ * Executor is made by combining execution tools and promptbook library.
8
8
  *
9
9
  * It can be done in two ways:
10
- * - From `PromptTemplatePipelineLibrary.getExecutor` method
11
- * - `createPtpExecutor` utility function
10
+ * - From `PromptbookLibrary.getExecutor` method
11
+ * - `createPromptbookExecutor` utility function
12
12
  *
13
13
  * @see https://github.com/webgptorg/promptbook#executor
14
14
  */
15
- export interface PtpExecutor {
15
+ export interface PromptbookExecutor {
16
16
  (inputParameters: Record<string_name, string>, onProgress: (taskProgress: TaskProgress) => Promisable<void>): Promise<{
17
17
  /**
18
18
  * Whether the execution was successful
@@ -1,11 +1,11 @@
1
- import type { PtpExecutor } from './PtpExecutor';
1
+ import type { PromptbookExecutor } from './PromptbookExecutor';
2
2
  /**
3
3
  * Asserts that the execution of a promptnook is successful
4
4
  *
5
5
  * @param executionResult - The partial result of the promptnook execution
6
6
  * @throws Error - If the execution is not successful or if multiple errors occurred
7
7
  */
8
- export declare function assertsExecutionSuccessful(executionResult: Pick<Awaited<ReturnType<PtpExecutor>>, 'isSuccessful' | 'errors'>): void;
8
+ export declare function assertsExecutionSuccessful(executionResult: Pick<Awaited<ReturnType<PromptbookExecutor>>, 'isSuccessful' | 'errors'>): void;
9
9
  /**
10
10
  * TODO: [🧠] Can this return type be better typed than void
11
11
  */
@@ -0,0 +1,40 @@
1
+ import { PromptbookJson } from '../_packages/types.index';
2
+ import { ExecutionTools } from './ExecutionTools';
3
+ import { PromptbookExecutor } from './PromptbookExecutor';
4
+ export interface CreatePromptbookExecutorSettings {
5
+ /**
6
+ * When executor does not satisfy expectations it will be retried this amount of times
7
+ *
8
+ * @default 3
9
+ */
10
+ readonly maxExecutionAttempts: number;
11
+ }
12
+ /**
13
+ * Options for creating a promptbook executor
14
+ */
15
+ interface CreatePromptbookExecutorOptions {
16
+ /**
17
+ * The promptbook to be executed
18
+ */
19
+ readonly promptbook: PromptbookJson;
20
+ /**
21
+ * The execution tools to be used during the execution of the PROMPTBOOK
22
+ */
23
+ readonly tools: ExecutionTools;
24
+ /**
25
+ * Optional settings for the PROMPTBOOK executor
26
+ */
27
+ readonly settings?: Partial<CreatePromptbookExecutorSettings>;
28
+ }
29
+ /**
30
+ * Creates executor function from promptbook and execution tools.
31
+ *
32
+ * Note: Consider using getExecutor method of the library instead of using this function
33
+ */
34
+ export declare function createPromptbookExecutor(options: CreatePromptbookExecutorOptions): PromptbookExecutor;
35
+ export {};
36
+ /**
37
+ * TODO: [🧠] When not meet expectations in PROMPT_DIALOG, make some way to tell the user
38
+ * TODO: [👧] Strongly type the executors to avoid need of remove nullables whtn noUncheckedIndexedAccess in tsconfig.json
39
+ * Note: CreatePromptbookExecutorOptions are just connected to PromptbookExecutor so do not extract to types folder
40
+ */
@@ -1,4 +1,4 @@
1
1
  export {};
2
2
  /**
3
- * TODO: [🧠] What should be name of this test "MockedEchoExecutionTools.test.ts" or "createPtpExecutor.test.ts"
3
+ * TODO: [🧠] What should be name of this test "MockedEchoExecutionTools.test.ts" or "createPromptbookExecutor.test.ts"
4
4
  */
@@ -1,4 +1,4 @@
1
1
  export {};
2
2
  /**
3
- * TODO: [🧠] What should be name of this test "MockedEchoExecutionTools.test.ts" or "createPtpExecutor.test.ts"
3
+ * TODO: [🧠] What should be name of this test "MockedEchoExecutionTools.test.ts" or "createPromptbookExecutor.test.ts"
4
4
  */
@@ -1,4 +1,4 @@
1
1
  export {};
2
2
  /**
3
- * TODO: [🧠] What should be name of this test "MockedEchoExecutionTools.test.ts" or "createPtpExecutor.test.ts"
3
+ * TODO: [🧠] What should be name of this test "MockedEchoExecutionTools.test.ts" or "createPromptbookExecutor.test.ts"
4
4
  */
@@ -5,7 +5,7 @@ import { CommonExecutionToolsOptions } from '../../../CommonExecutionToolsOption
5
5
  */
6
6
  export interface RemoteNaturalExecutionToolsOptions extends CommonExecutionToolsOptions {
7
7
  /**
8
- * URL of the remote PTP server
8
+ * URL of the remote PROMPTBOOK server
9
9
  * On this server will be connected to the socket.io server
10
10
  */
11
11
  readonly remoteUrl: URL;
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * This is sent from server to client when error occurs and stops the process
5
5
  */
6
- export interface Ptps_Error {
6
+ export interface Promptbook_Server_Error {
7
7
  /**
8
8
  * The error message which caused the error
9
9
  */
@@ -4,7 +4,7 @@ import { TaskProgress } from '../../../../../types/TaskProgress';
4
4
  *
5
5
  * This is sent from server to client arbitrarily and may be sent multiple times
6
6
  */
7
- export interface Ptps_Progress {
7
+ export interface Promptbook_Server_Progress {
8
8
  /**
9
9
  * The progress of text generation
10
10
  */
@@ -1,11 +1,11 @@
1
- import type { client_id } from '../../../../.././types/typeAliases';
1
+ import type { client_id } from '../../../../../types/typeAliases';
2
2
  import type { Prompt } from '../../../../../types/Prompt';
3
3
  /**
4
4
  * Socket.io progress for remote text generation
5
5
  *
6
6
  * This is a request from client to server
7
7
  */
8
- export interface Ptps_Request {
8
+ export interface Promptbook_Server_Request {
9
9
  /**
10
10
  * Client responsible for the requests
11
11
  */
@@ -1,10 +1,10 @@
1
- import { PromptResult } from '../../../../../execution/PromptResult';
1
+ import { PromptResult } from '../../../../PromptResult';
2
2
  /**
3
3
  * Socket.io error for remote text generation
4
4
  *
5
5
  * This is sent from server to client when the generated text is completed
6
6
  */
7
- export interface Ptps_Response {
7
+ export interface Promptbook_Server_Response {
8
8
  /**
9
9
  * The result of the prompt
10
10
  */
@@ -1,4 +1,4 @@
1
- import type { PromptTemplatePipelineLibrary } from '../../../../../classes/PromptTemplatePipelineLibrary';
1
+ import type { PromptbookLibrary } from '../../../../../classes/PromptbookLibrary';
2
2
  import type { client_id, string_uri } from '../../../../../types/typeAliases';
3
3
  import type { CommonExecutionToolsOptions } from '../../../../CommonExecutionToolsOptions';
4
4
  import type { NaturalExecutionTools } from '../../../../NaturalExecutionTools';
@@ -15,11 +15,11 @@ export interface RemoteServerOptions extends CommonExecutionToolsOptions {
15
15
  */
16
16
  readonly path: string_uri;
17
17
  /**
18
- * Prompt template pipeline library to use
18
+ * Promptbook library to use
19
19
  *
20
20
  * This is used to checkl validity of the prompt to prevent DDoS
21
21
  */
22
- readonly ptbkLibrary: PromptTemplatePipelineLibrary;
22
+ readonly library: PromptbookLibrary;
23
23
  /**
24
24
  * Creates natural execution tools for each client
25
25
  */
@@ -1,3 +1,4 @@
1
+ import type { IDestroyable } from 'destroyable';
1
2
  import { RemoteServerOptions } from './interfaces/RemoteServerOptions';
2
3
  /**
3
4
  * Remote server is a proxy server that uses its execution tools internally and exposes the executor interface externally.
@@ -7,9 +8,8 @@ import { RemoteServerOptions } from './interfaces/RemoteServerOptions';
7
8
  *
8
9
  * @see https://github.com/webgptorg/promptbook#remote-server
9
10
  */
10
- export declare function runRemoteServer(options: RemoteServerOptions): void;
11
+ export declare function startRemoteServer(options: RemoteServerOptions): IDestroyable;
11
12
  /**
12
- * TODO: !!! This should be name runRemoteServer OR startRemoteServer and return Destroyable OR Promise<Destroyable>
13
13
  * TODO: Handle progress - support streaming
14
14
  * TODO: [🤹‍♂️] Do not hang up immediately but wait until client closes OR timeout
15
15
  * TODO: [🤹‍♂️] Timeout on chat to free up resources
@@ -1,31 +1,31 @@
1
1
  import type { string_markdown_text, string_name, string_version } from '.././types/typeAliases';
2
2
  import type { ExecutionType } from './ExecutionTypes';
3
3
  import type { ModelRequirements } from './ModelRequirements';
4
- import type { ExpectationAmount, ExpectationUnit } from './PromptTemplatePipelineJson/PromptTemplateJson';
4
+ import type { ExpectationAmount, ExpectationUnit } from './PromptbookJson/PromptTemplateJson';
5
5
  /**
6
6
  * Command is one piece of the prompt template which adds some logic to the prompt template or the whole pipeline.
7
7
  * It is parsed from the markdown from ul/ol items - one command per one item.
8
8
  */
9
- export type Command = PtbkUrlCommand | PtbkVersionCommand | ExecuteCommand | ModelCommand | JokerCommand | ParameterCommand | PostprocessCommand | ExpectCommand;
9
+ export type Command = PromptbookUrlCommand | PromptbookVersionCommand | ExecuteCommand | ModelCommand | JokerCommand | ParameterCommand | PostprocessCommand | ExpectCommand;
10
10
  /**
11
- * PtpVersion command tells which version is .ptp file using
11
+ * PromptbookVersion command tells which version is .promptbook file using
12
12
  *
13
13
  * - It is used for backward compatibility
14
- * - It is defined per whole .ptp file in the header
14
+ * - It is defined per whole .promptbook file in the header
15
15
  */
16
- export interface PtbkUrlCommand {
17
- readonly type: 'PTBK_URL';
18
- readonly ptbkUrl: URL;
16
+ export interface PromptbookUrlCommand {
17
+ readonly type: 'PROMPTBOOK_URL';
18
+ readonly promptbookUrl: URL;
19
19
  }
20
20
  /**
21
- * PtpVersion command tells which version is .ptp file using
21
+ * PromptbookVersion command tells which version is .promptbook file using
22
22
  *
23
23
  * - It is used for backward compatibility
24
- * - It is defined per whole .ptp file in the header
24
+ * - It is defined per whole .promptbook file in the header
25
25
  */
26
- export interface PtbkVersionCommand {
27
- readonly type: 'PTBK_VERSION';
28
- readonly ptbkVersion: string_version;
26
+ export interface PromptbookVersionCommand {
27
+ readonly type: 'PROMPTBOOK_VERSION';
28
+ readonly promptbookVersion: string_version;
29
29
  }
30
30
  /**
31
31
  * Execute command tells how to execute the section
@@ -2,9 +2,9 @@
2
2
  * Parameters of the prompt template (pipeline)
3
3
  *
4
4
  * There are three types of parameters:
5
- * - **INPUT PARAMETERs** are required to execute the prompt template pipeline.
6
- * - **Intermediate parameters** are used internally in the prompt template pipeline.
7
- * - **OUTPUT PARAMETERs** are not used internally in the prompt template pipeline, but are returned as the result of the prompt template pipeline execution.
5
+ * - **INPUT PARAMETERs** are required to execute the pipeline.
6
+ * - **Intermediate parameters** are used internally in the pipeline.
7
+ * - **OUTPUT PARAMETERs** are not used internally in the pipeline, but are returned as the result of the pipeline execution.
8
8
  *
9
9
  * @see https://github.com/webgptorg/promptbook#parameters
10
10
  */
@@ -1,4 +1,4 @@
1
- import type { string_name, string_prompt, string_ptbk_url_with_hashtemplate, string_title } from '.././types/typeAliases';
1
+ import type { string_name, string_prompt, string_promptbook_url_with_hashtemplate, string_title } from '.././types/typeAliases';
2
2
  import type { ModelRequirements } from './ModelRequirements';
3
3
  /**
4
4
  * Prompt in a text along with model requirements, but without any execution or templating logic.
@@ -24,15 +24,15 @@ export interface Prompt {
24
24
  */
25
25
  readonly modelRequirements: ModelRequirements;
26
26
  /**
27
- * Unique identifier of the prompt template pipeline with specific template name as hash
27
+ * Unique identifier of the promptbook with specific template name as hash
28
28
  *
29
- * @example https://ptbk.webgpt.com/cs/write-website-content.ptbk.md@v2.4.15#keywords
29
+ * @example https://promptbook.webgpt.com/cs/write-website-content.ptbk.md@v2.4.15#keywords
30
30
  */
31
- readonly ptbkUrl: string_ptbk_url_with_hashtemplate;
31
+ readonly promptbookUrl: string_promptbook_url_with_hashtemplate;
32
32
  /**
33
33
  * Parameters used in the prompt
34
34
  *
35
- * Note: This is redundant (same information is in ptbkUrl+content) but useful for logging and debugging
35
+ * Note: This is redundant (same information is in promptbookUrl+content) but useful for logging and debugging
36
36
  */
37
37
  readonly parameters: Record<string_name, string>;
38
38
  }
@@ -1,10 +1,10 @@
1
- import { number_integer, number_positive_or_zero, string_javascript, string_javascript_name, string_markdown, string_name, string_prompt, string_template } from '../.././types/typeAliases';
2
1
  import { ExpectFormatCommand } from '../Command';
3
2
  import { ExecutionType } from '../ExecutionTypes';
4
3
  import { ModelRequirements } from '../ModelRequirements';
5
4
  import { ScriptLanguage } from '../ScriptLanguage';
5
+ import { number_integer, number_positive_or_zero, string_javascript, string_javascript_name, string_markdown, string_name, string_prompt, string_template } from '../typeAliases';
6
6
  /**
7
- * Describes one prompt template in the prompt template pipeline
7
+ * Describes one prompt template in the promptbook
8
8
  */
9
9
  export type PromptTemplateJson = NaturalTemplateJson | SimpleTemplateJson | ScriptTemplateJson | PromptDialogJson;
10
10
  /**
@@ -16,7 +16,7 @@ export interface NaturalTemplateJson extends PromptTemplateJsonCommon {
16
16
  * Requirements for the model
17
17
  * - This is required only for executionType PROMPT_TEMPLATE
18
18
  */
19
- readonly modelRequirements?: ModelRequirements;
19
+ readonly modelRequirements: ModelRequirements;
20
20
  }
21
21
  /**
22
22
  * Units of text measurement
@@ -62,7 +62,7 @@ interface PromptTemplateJsonCommon {
62
62
  * Name of the template
63
63
  * - It must be unique across the pipeline
64
64
  * - It should start uppercase and contain letters and numbers
65
- * - The ptbkUrl together with hash and name are used to identify the prompt template in the pipeline
65
+ * - The promptbookUrl together with hash and name are used to identify the prompt template in the pipeline
66
66
  */
67
67
  readonly name: string_name;
68
68
  /**
@@ -1,6 +1,6 @@
1
- import { string_name } from '../.././types/typeAliases';
1
+ import { string_name } from '../typeAliases';
2
2
  /**
3
- * Describes one parameter of the prompt template pipeline
3
+ * Describes one parameter of the promptbook
4
4
  */
5
5
  export interface PromptTemplateParameterJson {
6
6
  /**
@@ -1,38 +1,34 @@
1
- import { string_ptbk_url, string_version } from '../.././types/typeAliases';
1
+ import { string_promptbook_url, string_version } from '../typeAliases';
2
2
  import { PromptTemplateJson } from './PromptTemplateJson';
3
3
  import { PromptTemplateParameterJson } from './PromptTemplateParameterJson';
4
4
  /**
5
- * Prompt template pipeline is the **core concept of this library**.
5
+ * Promptbook is the **core concept of this library**.
6
6
  * It represents a series of prompt templates chained together to form a pipeline / one big prompt template with input and result parameters.
7
7
  *
8
- * It can have 3 formats:
9
- * - **.ptbk.md file** in custom markdown format described above
10
- * - _(this)_ **JSON** format, parsed from the .ptbk.md file
11
- *
12
- * @see https://github.com/webgptorg/promptbook#prompt-template-pipeline
8
+ * @see https://github.com/webgptorg/promptbook#promptbook
13
9
  */
14
- export interface PromptTemplatePipelineJson {
10
+ export interface PromptbookJson {
15
11
  /**
16
- * Unique identifier of the prompt template pipeline
12
+ * Unique identifier of the promptbook
17
13
  *
18
- * Note: It must be unique across all prompt template pipelines
14
+ * Note: It must be unique across all promptbooks libraries
19
15
  * Note: It must use HTTPs URL
20
16
  * Tip: You can do versioning in the URL
21
- * For example: https://ptbk.webgpt.com/cs/write-website-content.ptbk.md@1.0.0
17
+ * For example: https://promptbook.webgpt.com/cs/write-website-content.ptbk.md@1.0.0
22
18
  * Warning: Do not hash part of the URL, hash part is used for identification of the prompt template in the pipeline
23
19
  */
24
- readonly ptbkUrl?: string_ptbk_url;
20
+ readonly promptbookUrl?: string_promptbook_url;
25
21
  /**
26
- * Title of the prompt template pipeline
22
+ * Title of the promptbook
27
23
  * -It can use simple markdown formatting like **bold**, *italic*, [link](https://example.com), ... BUT not code blocks and structure
28
24
  */
29
25
  readonly title: string;
30
26
  /**
31
27
  * Version of the .ptbk.json file
32
28
  */
33
- readonly ptbkVersion: string_version;
29
+ readonly promptbookVersion: string_version;
34
30
  /**
35
- * Description of the prompt template pipeline
31
+ * Description of the promptbook
36
32
  * It can use multiple paragraphs of simple markdown formatting like **bold**, *italic*, [link](https://example.com), ... BUT not code blocks and structure
37
33
  */
38
34
  readonly description?: string;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Promptbook is the **core concept of this library**.
3
+ * It represents a series of prompt templates chained together to form a pipeline / one big prompt template with input and result parameters.
4
+ *
5
+ * @see https://github.com/webgptorg/promptbook#promptbook
6
+ */
7
+ export type PromptbookString = string & {
8
+ readonly _type: 'Promptbook';
9
+ };
10
+ /**
11
+ * TODO: !! Better validation (validatePromptbookString) or remove branded type and make it just string
12
+ */
@@ -1,7 +1,7 @@
1
1
  import { ExecutionType } from './ExecutionTypes';
2
2
  import { string_markdown_text, string_name } from './typeAliases';
3
3
  /**
4
- * TaskProgress represents the progress of a PromptTemplatePipeline execution.
4
+ * TaskProgress represents the progress of a Promptbook execution.
5
5
  */
6
6
  export interface TaskProgress {
7
7
  /**