@promptbook/remote-server 0.8.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.
Files changed (190) hide show
  1. package/README.md +5 -0
  2. package/esm/index.es.js +160 -0
  3. package/esm/index.es.js.map +1 -0
  4. package/esm/typings/_packages/core.index.d.ts +17 -0
  5. package/esm/typings/_packages/execute-javascript.index.d.ts +3 -0
  6. package/esm/typings/_packages/openai.index.d.ts +3 -0
  7. package/esm/typings/_packages/remote-client.index.d.ts +4 -0
  8. package/esm/typings/_packages/remote-server.index.d.ts +3 -0
  9. package/esm/typings/_packages/types.index.d.ts +20 -0
  10. package/esm/typings/_packages/utils.index.d.ts +6 -0
  11. package/esm/typings/_packages/wizzard.index.d.ts +2 -0
  12. package/esm/typings/classes/PromptTemplatePipeline.d.ts +68 -0
  13. package/esm/typings/classes/PromptTemplatePipelineLibrary.d.ts +55 -0
  14. package/esm/typings/config.d.ts +10 -0
  15. package/esm/typings/conversion/_importPtp.d.ts +12 -0
  16. package/esm/typings/conversion/parseCommand.d.ts +6 -0
  17. package/esm/typings/conversion/parseCommand.test.d.ts +1 -0
  18. package/esm/typings/conversion/promptTemplatePipelineStringToJson.d.ts +12 -0
  19. package/esm/typings/conversion/promptTemplatePipelineStringToJson.test.d.ts +1 -0
  20. package/esm/typings/conversion/validatePromptTemplatePipelineJson.d.ts +26 -0
  21. package/esm/typings/conversion/validatePromptTemplatePipelineJson.test.d.ts +1 -0
  22. package/esm/typings/execution/CommonExecutionToolsOptions.d.ts +6 -0
  23. package/esm/typings/execution/ExecutionTools.d.ts +25 -0
  24. package/esm/typings/execution/NaturalExecutionTools.d.ts +22 -0
  25. package/esm/typings/execution/PromptResult.d.ts +38 -0
  26. package/esm/typings/execution/PtpExecutor.d.ts +19 -0
  27. package/esm/typings/execution/ScriptExecutionTools.d.ts +34 -0
  28. package/esm/typings/execution/UserInterfaceTools.d.ts +30 -0
  29. package/esm/typings/execution/createPtpExecutor.d.ts +18 -0
  30. package/esm/typings/execution/plugins/natural-execution-tools/mocked/MockedEchoNaturalExecutionTools.d.ts +22 -0
  31. package/esm/typings/execution/plugins/natural-execution-tools/mocked/mocked-chat.test.d.ts +4 -0
  32. package/esm/typings/execution/plugins/natural-execution-tools/mocked/mocked-completion.test.d.ts +4 -0
  33. package/esm/typings/execution/plugins/natural-execution-tools/openai/OpenAiExecutionTools.d.ts +27 -0
  34. package/esm/typings/execution/plugins/natural-execution-tools/openai/OpenAiExecutionToolsOptions.d.ts +11 -0
  35. package/esm/typings/execution/plugins/natural-execution-tools/remote/RemoteNaturalExecutionTools.d.ts +35 -0
  36. package/esm/typings/execution/plugins/natural-execution-tools/remote/RemoteNaturalExecutionToolsOptions.d.ts +16 -0
  37. package/esm/typings/execution/plugins/natural-execution-tools/remote/createRemoteServer.d.ts +16 -0
  38. package/esm/typings/execution/plugins/natural-execution-tools/remote/interfaces/Ptps_Error.d.ts +3 -0
  39. package/esm/typings/execution/plugins/natural-execution-tools/remote/interfaces/Ptps_Progress.d.ts +4 -0
  40. package/esm/typings/execution/plugins/natural-execution-tools/remote/interfaces/Ptps_Request.d.ts +6 -0
  41. package/esm/typings/execution/plugins/natural-execution-tools/remote/interfaces/Ptps_Response.d.ts +4 -0
  42. package/esm/typings/execution/plugins/natural-execution-tools/remote/interfaces/RemoteServerOptions.d.ts +20 -0
  43. package/esm/typings/execution/plugins/script-execution-tools/javascript/JavascriptEvalExecutionTools.d.ts +19 -0
  44. package/esm/typings/execution/plugins/script-execution-tools/javascript/JavascriptEvalExecutionTools.test.d.ts +4 -0
  45. package/esm/typings/execution/plugins/script-execution-tools/javascript/JavascriptExecutionTools.d.ts +20 -0
  46. package/esm/typings/execution/plugins/script-execution-tools/javascript/utils/preserve.d.ts +11 -0
  47. package/esm/typings/execution/plugins/script-execution-tools/postprocessing.test.d.ts +4 -0
  48. package/esm/typings/execution/plugins/script-execution-tools/python/PythonExecutionTools.d.ts +15 -0
  49. package/esm/typings/execution/plugins/script-execution-tools/script-execution-errors.test.d.ts +1 -0
  50. package/esm/typings/execution/plugins/script-execution-tools/script-execution-tools.test.d.ts +1 -0
  51. package/esm/typings/execution/plugins/script-execution-tools/typescript/TypescriptExecutionTools.d.ts +15 -0
  52. package/esm/typings/execution/plugins/user-interface-execution-tools/callback/CallbackInterfaceTools.d.ts +14 -0
  53. package/esm/typings/execution/plugins/user-interface-execution-tools/callback/CallbackInterfaceToolsOptions.d.ts +12 -0
  54. package/esm/typings/execution/plugins/user-interface-execution-tools/simple-prompt/SimplePromptInterfaceTools.d.ts +16 -0
  55. package/esm/typings/execution/plugins/user-interface-execution-tools/user-interface-execution-tools.test.d.ts +1 -0
  56. package/esm/typings/types/Command.d.ts +65 -0
  57. package/esm/typings/types/ExecutionTypes.d.ts +13 -0
  58. package/esm/typings/types/ModelRequirements.d.ts +28 -0
  59. package/esm/typings/types/Parameters.d.ts +14 -0
  60. package/esm/typings/types/Prompt.d.ts +35 -0
  61. package/esm/typings/types/PromptTemplatePipelineJson/PromptTemplateJson.d.ts +82 -0
  62. package/esm/typings/types/PromptTemplatePipelineJson/PromptTemplateParameterJson.d.ts +23 -0
  63. package/esm/typings/types/PromptTemplatePipelineJson/PromptTemplatePipelineJson.d.ts +56 -0
  64. package/esm/typings/types/PromptTemplatePipelineString.d.ts +14 -0
  65. package/esm/typings/types/ScriptLanguage.d.ts +9 -0
  66. package/esm/typings/types/TaskProgress.d.ts +12 -0
  67. package/esm/typings/types/typeAliasEmoji.d.ts +9 -0
  68. package/esm/typings/types/typeAliases.d.ts +477 -0
  69. package/esm/typings/utils/emojis.d.ts +16 -0
  70. package/esm/typings/utils/just.d.ts +10 -0
  71. package/esm/typings/utils/markdown/extractAllListItemsFromMarkdown.d.ts +15 -0
  72. package/esm/typings/utils/markdown/extractAllListItemsFromMarkdown.test.d.ts +1 -0
  73. package/esm/typings/utils/markdown/extractBlocksFromMarkdown.d.ts +13 -0
  74. package/esm/typings/utils/markdown/extractBlocksFromMarkdown.test.d.ts +1 -0
  75. package/esm/typings/utils/markdown/extractOneBlockFromMarkdown.d.ts +16 -0
  76. package/esm/typings/utils/markdown/extractOneBlockFromMarkdown.test.d.ts +1 -0
  77. package/esm/typings/utils/markdown/removeContentComments.d.ts +8 -0
  78. package/esm/typings/utils/markdown/removeContentComments.test.d.ts +1 -0
  79. package/esm/typings/utils/markdown/removeMarkdownFormatting.d.ts +8 -0
  80. package/esm/typings/utils/markdown/removeMarkdownFormatting.test.d.ts +1 -0
  81. package/esm/typings/utils/markdown-json/MarkdownStructure.d.ts +25 -0
  82. package/esm/typings/utils/markdown-json/countMarkdownStructureDeepness.d.ts +7 -0
  83. package/esm/typings/utils/markdown-json/countMarkdownStructureDeepness.test.d.ts +1 -0
  84. package/esm/typings/utils/markdown-json/markdownToMarkdownStructure.d.ts +13 -0
  85. package/esm/typings/utils/markdown-json/markdownToMarkdownStructure.test.d.ts +1 -0
  86. package/esm/typings/utils/removeEmojis.d.ts +7 -0
  87. package/esm/typings/utils/removeEmojis.test.d.ts +1 -0
  88. package/esm/typings/utils/removeQuotes.d.ts +13 -0
  89. package/esm/typings/utils/removeQuotes.test.d.ts +1 -0
  90. package/esm/typings/utils/replaceParameters.d.ts +16 -0
  91. package/esm/typings/utils/replaceParameters.test.d.ts +1 -0
  92. package/esm/typings/utils/unwrapResult.d.ts +13 -0
  93. package/esm/typings/utils/unwrapResult.test.d.ts +1 -0
  94. package/esm/typings/wizzard/Wizzard.d.ts +1 -0
  95. package/esm/typings/wizzard/sample.d.ts +5 -0
  96. package/package.json +46 -0
  97. package/umd/index.umd.js +171 -0
  98. package/umd/index.umd.js.map +1 -0
  99. package/umd/typings/_packages/core.index.d.ts +17 -0
  100. package/umd/typings/_packages/execute-javascript.index.d.ts +3 -0
  101. package/umd/typings/_packages/openai.index.d.ts +3 -0
  102. package/umd/typings/_packages/remote-client.index.d.ts +4 -0
  103. package/umd/typings/_packages/remote-server.index.d.ts +3 -0
  104. package/umd/typings/_packages/types.index.d.ts +20 -0
  105. package/umd/typings/_packages/utils.index.d.ts +6 -0
  106. package/umd/typings/_packages/wizzard.index.d.ts +2 -0
  107. package/umd/typings/classes/PromptTemplatePipeline.d.ts +68 -0
  108. package/umd/typings/classes/PromptTemplatePipelineLibrary.d.ts +55 -0
  109. package/umd/typings/config.d.ts +10 -0
  110. package/umd/typings/conversion/_importPtp.d.ts +12 -0
  111. package/umd/typings/conversion/parseCommand.d.ts +6 -0
  112. package/umd/typings/conversion/parseCommand.test.d.ts +1 -0
  113. package/umd/typings/conversion/promptTemplatePipelineStringToJson.d.ts +12 -0
  114. package/umd/typings/conversion/promptTemplatePipelineStringToJson.test.d.ts +1 -0
  115. package/umd/typings/conversion/validatePromptTemplatePipelineJson.d.ts +26 -0
  116. package/umd/typings/conversion/validatePromptTemplatePipelineJson.test.d.ts +1 -0
  117. package/umd/typings/execution/CommonExecutionToolsOptions.d.ts +6 -0
  118. package/umd/typings/execution/ExecutionTools.d.ts +25 -0
  119. package/umd/typings/execution/NaturalExecutionTools.d.ts +22 -0
  120. package/umd/typings/execution/PromptResult.d.ts +38 -0
  121. package/umd/typings/execution/PtpExecutor.d.ts +19 -0
  122. package/umd/typings/execution/ScriptExecutionTools.d.ts +34 -0
  123. package/umd/typings/execution/UserInterfaceTools.d.ts +30 -0
  124. package/umd/typings/execution/createPtpExecutor.d.ts +18 -0
  125. package/umd/typings/execution/plugins/natural-execution-tools/mocked/MockedEchoNaturalExecutionTools.d.ts +22 -0
  126. package/umd/typings/execution/plugins/natural-execution-tools/mocked/mocked-chat.test.d.ts +4 -0
  127. package/umd/typings/execution/plugins/natural-execution-tools/mocked/mocked-completion.test.d.ts +4 -0
  128. package/umd/typings/execution/plugins/natural-execution-tools/openai/OpenAiExecutionTools.d.ts +27 -0
  129. package/umd/typings/execution/plugins/natural-execution-tools/openai/OpenAiExecutionToolsOptions.d.ts +11 -0
  130. package/umd/typings/execution/plugins/natural-execution-tools/remote/RemoteNaturalExecutionTools.d.ts +35 -0
  131. package/umd/typings/execution/plugins/natural-execution-tools/remote/RemoteNaturalExecutionToolsOptions.d.ts +16 -0
  132. package/umd/typings/execution/plugins/natural-execution-tools/remote/createRemoteServer.d.ts +16 -0
  133. package/umd/typings/execution/plugins/natural-execution-tools/remote/interfaces/Ptps_Error.d.ts +3 -0
  134. package/umd/typings/execution/plugins/natural-execution-tools/remote/interfaces/Ptps_Progress.d.ts +4 -0
  135. package/umd/typings/execution/plugins/natural-execution-tools/remote/interfaces/Ptps_Request.d.ts +6 -0
  136. package/umd/typings/execution/plugins/natural-execution-tools/remote/interfaces/Ptps_Response.d.ts +4 -0
  137. package/umd/typings/execution/plugins/natural-execution-tools/remote/interfaces/RemoteServerOptions.d.ts +20 -0
  138. package/umd/typings/execution/plugins/script-execution-tools/javascript/JavascriptEvalExecutionTools.d.ts +19 -0
  139. package/umd/typings/execution/plugins/script-execution-tools/javascript/JavascriptEvalExecutionTools.test.d.ts +4 -0
  140. package/umd/typings/execution/plugins/script-execution-tools/javascript/JavascriptExecutionTools.d.ts +20 -0
  141. package/umd/typings/execution/plugins/script-execution-tools/javascript/utils/preserve.d.ts +11 -0
  142. package/umd/typings/execution/plugins/script-execution-tools/postprocessing.test.d.ts +4 -0
  143. package/umd/typings/execution/plugins/script-execution-tools/python/PythonExecutionTools.d.ts +15 -0
  144. package/umd/typings/execution/plugins/script-execution-tools/script-execution-errors.test.d.ts +1 -0
  145. package/umd/typings/execution/plugins/script-execution-tools/script-execution-tools.test.d.ts +1 -0
  146. package/umd/typings/execution/plugins/script-execution-tools/typescript/TypescriptExecutionTools.d.ts +15 -0
  147. package/umd/typings/execution/plugins/user-interface-execution-tools/callback/CallbackInterfaceTools.d.ts +14 -0
  148. package/umd/typings/execution/plugins/user-interface-execution-tools/callback/CallbackInterfaceToolsOptions.d.ts +12 -0
  149. package/umd/typings/execution/plugins/user-interface-execution-tools/simple-prompt/SimplePromptInterfaceTools.d.ts +16 -0
  150. package/umd/typings/execution/plugins/user-interface-execution-tools/user-interface-execution-tools.test.d.ts +1 -0
  151. package/umd/typings/types/Command.d.ts +65 -0
  152. package/umd/typings/types/ExecutionTypes.d.ts +13 -0
  153. package/umd/typings/types/ModelRequirements.d.ts +28 -0
  154. package/umd/typings/types/Parameters.d.ts +14 -0
  155. package/umd/typings/types/Prompt.d.ts +35 -0
  156. package/umd/typings/types/PromptTemplatePipelineJson/PromptTemplateJson.d.ts +82 -0
  157. package/umd/typings/types/PromptTemplatePipelineJson/PromptTemplateParameterJson.d.ts +23 -0
  158. package/umd/typings/types/PromptTemplatePipelineJson/PromptTemplatePipelineJson.d.ts +56 -0
  159. package/umd/typings/types/PromptTemplatePipelineString.d.ts +14 -0
  160. package/umd/typings/types/ScriptLanguage.d.ts +9 -0
  161. package/umd/typings/types/TaskProgress.d.ts +12 -0
  162. package/umd/typings/types/typeAliasEmoji.d.ts +9 -0
  163. package/umd/typings/types/typeAliases.d.ts +477 -0
  164. package/umd/typings/utils/emojis.d.ts +16 -0
  165. package/umd/typings/utils/just.d.ts +10 -0
  166. package/umd/typings/utils/markdown/extractAllListItemsFromMarkdown.d.ts +15 -0
  167. package/umd/typings/utils/markdown/extractAllListItemsFromMarkdown.test.d.ts +1 -0
  168. package/umd/typings/utils/markdown/extractBlocksFromMarkdown.d.ts +13 -0
  169. package/umd/typings/utils/markdown/extractBlocksFromMarkdown.test.d.ts +1 -0
  170. package/umd/typings/utils/markdown/extractOneBlockFromMarkdown.d.ts +16 -0
  171. package/umd/typings/utils/markdown/extractOneBlockFromMarkdown.test.d.ts +1 -0
  172. package/umd/typings/utils/markdown/removeContentComments.d.ts +8 -0
  173. package/umd/typings/utils/markdown/removeContentComments.test.d.ts +1 -0
  174. package/umd/typings/utils/markdown/removeMarkdownFormatting.d.ts +8 -0
  175. package/umd/typings/utils/markdown/removeMarkdownFormatting.test.d.ts +1 -0
  176. package/umd/typings/utils/markdown-json/MarkdownStructure.d.ts +25 -0
  177. package/umd/typings/utils/markdown-json/countMarkdownStructureDeepness.d.ts +7 -0
  178. package/umd/typings/utils/markdown-json/countMarkdownStructureDeepness.test.d.ts +1 -0
  179. package/umd/typings/utils/markdown-json/markdownToMarkdownStructure.d.ts +13 -0
  180. package/umd/typings/utils/markdown-json/markdownToMarkdownStructure.test.d.ts +1 -0
  181. package/umd/typings/utils/removeEmojis.d.ts +7 -0
  182. package/umd/typings/utils/removeEmojis.test.d.ts +1 -0
  183. package/umd/typings/utils/removeQuotes.d.ts +13 -0
  184. package/umd/typings/utils/removeQuotes.test.d.ts +1 -0
  185. package/umd/typings/utils/replaceParameters.d.ts +16 -0
  186. package/umd/typings/utils/replaceParameters.test.d.ts +1 -0
  187. package/umd/typings/utils/unwrapResult.d.ts +13 -0
  188. package/umd/typings/utils/unwrapResult.test.d.ts +1 -0
  189. package/umd/typings/wizzard/Wizzard.d.ts +1 -0
  190. package/umd/typings/wizzard/sample.d.ts +5 -0
@@ -0,0 +1,22 @@
1
+ import { Prompt } from '../types/Prompt';
2
+ import { PromptChatResult, PromptCompletionResult } from './PromptResult';
3
+ /**
4
+ * Vontainer for all the tools needed to execute prompts to large language models like GPT-4
5
+ * On its interface it exposes common methods for prompt execution.
6
+ * Inside (in constructor) it calls OpenAI, Azure, GPU, proxy, cache, logging,...
7
+ *
8
+ * @see https://github.com/webgptorg/promptbook#natural-execution-tools
9
+ */
10
+ export interface NaturalExecutionTools {
11
+ /**
12
+ * Use a chat model
13
+ */
14
+ gptChat(prompt: Prompt): Promise<PromptChatResult>;
15
+ /**
16
+ * Use a completion model
17
+ */
18
+ gptComplete(prompt: Prompt): Promise<PromptCompletionResult>;
19
+ }
20
+ /**
21
+ * TODO: [🧠] Should or should not there be a word "GPT" in both gptComplete and gptChat
22
+ */
@@ -0,0 +1,38 @@
1
+ import { string_model_name } from '.././types/typeAliases';
2
+ /**
3
+ * Prompt result is the simplest concept of execution.
4
+ * It is the result of executing one prompt _(NOT a template)_.
5
+ *
6
+ * @see https://github.com/webgptorg/promptbook#prompt-result
7
+ */
8
+ export type PromptResult = PromptCompletionResult | PromptChatResult;
9
+ /**
10
+ * Prompt completion result
11
+ * It contains only the following text NOT the whole completion
12
+ */
13
+ export type PromptCompletionResult = PromptCommonResult;
14
+ /**
15
+ * Prompt chat result
16
+ */
17
+ export interface PromptChatResult extends PromptCommonResult {
18
+ }
19
+ export interface PromptCommonResult {
20
+ /**
21
+ * Exact text response from the model
22
+ */
23
+ readonly content: string;
24
+ /**
25
+ * Name of the model used to generate the response
26
+ */
27
+ readonly model: string_model_name;
28
+ /**
29
+ * Raw response from the model
30
+ */
31
+ readonly rawResponse: object;
32
+ }
33
+ /**
34
+ * TODO: [🧠] Should here be link to the prompt?
35
+ * TODO: [🧠] Maybe type raw properly - not onject but OpenAI.result.whatever
36
+ * TODO: [🧠] Maybe remove redundant raw.choices.text
37
+ * TODO: Log raw even if prompt failed - log the raw error
38
+ */
@@ -0,0 +1,19 @@
1
+ import { Promisable } from 'type-fest';
2
+ import { string_name } from '.././types/typeAliases';
3
+ import { TaskProgress } from '../types/TaskProgress';
4
+ /**
5
+ * 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)_.
6
+ * Executor is made by combining execution tools and prompt template pipeline library.
7
+ *
8
+ * It can be done in two ways:
9
+ * - From `PromptTemplatePipelineLibrary.getExecutor` method
10
+ * - `createPtpExecutor` utility function
11
+ *
12
+ * @see https://github.com/webgptorg/promptbook#executor
13
+ */
14
+ export interface PtpExecutor {
15
+ (inputParameters: Record<string_name, string>, onProgress: (taskProgress: TaskProgress) => Promisable<void>): Promise<Record<string_name, string>>;
16
+ }
17
+ /**
18
+ * TODO: [🧠] Should this file be in /execution or /types folder?
19
+ */
@@ -0,0 +1,34 @@
1
+ import { string_name, string_script } from '.././types/typeAliases';
2
+ import { ScriptLanguage } from '../types/ScriptLanguage';
3
+ /**
4
+ * Represents all the tools needed to execute scripts
5
+ *
6
+ * @see https://github.com/webgptorg/promptbook#script-execution-tools
7
+ */
8
+ export interface ScriptExecutionTools {
9
+ execute(options: ScriptExecutionToolsExecuteOptions): Promise<string>;
10
+ }
11
+ /**
12
+ * Input for the script execution
13
+ */
14
+ export interface ScriptExecutionToolsExecuteOptions {
15
+ /**
16
+ * Language of the script
17
+ */
18
+ scriptLanguage: ScriptLanguage;
19
+ /**
20
+ * Parameters for the script
21
+ * Theese parameters are passed to the script as variables
22
+ * For example: { "name": "John" } => const name = "John";
23
+ */
24
+ parameters: Record<string_name, string>;
25
+ /**
26
+ * The content of the script to execute
27
+ * - It can be a single statement
28
+ * - It can be multiple statements separated by semicolon and return
29
+ * - It can be a function (but you need to call it)
30
+ * - It can be IIFE (immediately invoked function expression)
31
+ * - It can use the parameters as variables and functions from global scope
32
+ */
33
+ script: string_script;
34
+ }
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Represents all the tools needed to interact with the user.
3
+ *
4
+ * @see https://github.com/webgptorg/promptbook#user-interface-tools
5
+ */
6
+ export interface UserInterfaceTools {
7
+ /**
8
+ * Asks the user to answer a free-text (multiline) question
9
+ *
10
+ * @param options the question to ask
11
+ * @returns the answer from the user
12
+ */
13
+ promptDialog(options: UserInterfaceToolsPromptDialogOptions): Promise<string>;
14
+ }
15
+ export interface UserInterfaceToolsPromptDialogOptions {
16
+ /**
17
+ * Prompt message
18
+ *
19
+ * Note: This is not a prompt to language model but a prompt to the user
20
+ */
21
+ prompt: string;
22
+ /**
23
+ * Default value for the input/textarea
24
+ */
25
+ defaultValue: string | null;
26
+ /**
27
+ * Placeholder for the input/textarea
28
+ */
29
+ placeholder?: string;
30
+ }
@@ -0,0 +1,18 @@
1
+ import { PromptTemplatePipeline } from '../classes/PromptTemplatePipeline';
2
+ import { ExecutionTools } from './ExecutionTools';
3
+ import { PtpExecutor } from './PtpExecutor';
4
+ interface CreatePtpExecutorOptions {
5
+ readonly ptp: PromptTemplatePipeline;
6
+ readonly tools: ExecutionTools;
7
+ }
8
+ /**
9
+ * Creates executor function from prompt template pipeline and execution tools.
10
+ *
11
+ * Note: Consider using getExecutor method of the library instead of using this function
12
+ */
13
+ export declare function createPtpExecutor(options: CreatePtpExecutorOptions): PtpExecutor;
14
+ export {};
15
+ /**
16
+ * TODO: [👧] Strongly type the executors to avoid need of remove nullables whtn noUncheckedIndexedAccess in tsconfig.json
17
+ * Note: CreatePtpExecutorOptions are just connected to PtpExecutor so do not extract to types folder
18
+ */
@@ -0,0 +1,22 @@
1
+ import { Prompt } from '../../../../types/Prompt';
2
+ import { CommonExecutionToolsOptions } from '../../../CommonExecutionToolsOptions';
3
+ import { NaturalExecutionTools } from '../../../NaturalExecutionTools';
4
+ import { PromptChatResult, PromptCompletionResult } from '../../../PromptResult';
5
+ /**
6
+ * Mocked execution Tools for just echoing the requests for testing purposes.
7
+ */
8
+ export declare class MockedEchoNaturalExecutionTools implements NaturalExecutionTools {
9
+ private readonly options;
10
+ constructor(options: CommonExecutionToolsOptions);
11
+ /**
12
+ * Mocks chat model
13
+ */
14
+ gptChat(prompt: Prompt): Promise<PromptChatResult>;
15
+ /**
16
+ * Mocks completion model
17
+ */
18
+ gptComplete(prompt: Prompt): Promise<PromptCompletionResult>;
19
+ }
20
+ /**
21
+ * TODO: Allow in spaceTrim: nesting with > ${block(prompt.request)}
22
+ */
@@ -0,0 +1,4 @@
1
+ export {};
2
+ /**
3
+ * TODO: [🧠] What should be name of this test "MockedEchoExecutionTools.test.ts" or "createPtpExecutor.test.ts"
4
+ */
@@ -0,0 +1,4 @@
1
+ export {};
2
+ /**
3
+ * TODO: [🧠] What should be name of this test "MockedEchoExecutionTools.test.ts" or "createPtpExecutor.test.ts"
4
+ */
@@ -0,0 +1,27 @@
1
+ import { Prompt } from '../../../../types/Prompt';
2
+ import { NaturalExecutionTools } from '../../../NaturalExecutionTools';
3
+ import { PromptChatResult, PromptCompletionResult } from '../../../PromptResult';
4
+ import { OpenAiExecutionToolsOptions } from './OpenAiExecutionToolsOptions';
5
+ /**
6
+ * Execution Tools for calling OpenAI API.
7
+ */
8
+ export declare class OpenAiExecutionTools implements NaturalExecutionTools {
9
+ private readonly options;
10
+ /**
11
+ * OpenAI API client.
12
+ */
13
+ private readonly openai;
14
+ constructor(options: OpenAiExecutionToolsOptions);
15
+ /**
16
+ * Calls OpenAI API to use a chat model.
17
+ */
18
+ gptChat(prompt: Prompt): Promise<PromptChatResult>;
19
+ /**
20
+ * Calls OpenAI API to use a complete model.
21
+ */
22
+ gptComplete(prompt: Prompt): Promise<PromptCompletionResult>;
23
+ }
24
+ /**
25
+ * TODO: Maybe Create some common util for gptChat and gptComplete
26
+ * TODO: Maybe make custom OpenaiError
27
+ */
@@ -0,0 +1,11 @@
1
+ import { string_token } from '../../../.././types/typeAliases';
2
+ import { CommonExecutionToolsOptions } from '../../../CommonExecutionToolsOptions';
3
+ /**
4
+ * Options for OpenAiExecutionTools
5
+ */
6
+ export interface OpenAiExecutionToolsOptions extends CommonExecutionToolsOptions {
7
+ /**
8
+ * OpenAI API key
9
+ */
10
+ openAiApiKey: string_token;
11
+ }
@@ -0,0 +1,35 @@
1
+ import { Prompt } from '../../../../types/Prompt';
2
+ import { NaturalExecutionTools } from '../../../NaturalExecutionTools';
3
+ import { PromptChatResult, PromptCompletionResult } from '../../../PromptResult';
4
+ import { RemoteNaturalExecutionToolsOptions } from './RemoteNaturalExecutionToolsOptions';
5
+ /**
6
+ * Remote server is a proxy server that uses its execution tools internally and exposes the executor interface externally.
7
+ *
8
+ * You can simply use `RemoteExecutionTools` on client-side javascript and connect to your remote server.
9
+ * This is useful to make all logic on browser side but not expose your API keys or no need to use customer's GPU.
10
+ *
11
+ * @see https://github.com/webgptorg/promptbook#remote-server
12
+ */
13
+ export declare class RemoteNaturalExecutionTools implements NaturalExecutionTools {
14
+ private readonly options;
15
+ constructor(options: RemoteNaturalExecutionToolsOptions);
16
+ /**
17
+ * Creates a connection to the remote proxy server.
18
+ */
19
+ private makeConnection;
20
+ /**
21
+ * Calls remote proxy server to use a chat model.
22
+ */
23
+ gptChat(prompt: Prompt): Promise<PromptChatResult>;
24
+ /**
25
+ * Calls remote proxy server to use a completion model.
26
+ */
27
+ gptComplete(prompt: Prompt): Promise<PromptCompletionResult>;
28
+ /**
29
+ * Calls remote proxy server to use both completion or chat model.
30
+ */
31
+ private gptCommon;
32
+ }
33
+ /**
34
+ * TODO: [🤹‍♂️] RemoteNaturalExecutionTools should extend Destroyable and implement IDestroyable
35
+ */
@@ -0,0 +1,16 @@
1
+ import { uuid } from '../../../.././types/typeAliases';
2
+ import { CommonExecutionToolsOptions } from '../../../CommonExecutionToolsOptions';
3
+ /**
4
+ * Options for RemoteNaturalExecutionTools
5
+ */
6
+ export interface RemoteNaturalExecutionToolsOptions extends CommonExecutionToolsOptions {
7
+ /**
8
+ * URL of the remote PTP server
9
+ * On this server will be connected to the socket.io server
10
+ */
11
+ readonly remoteUrl: URL;
12
+ /**
13
+ * Your client ID
14
+ */
15
+ readonly clientId: uuid;
16
+ }
@@ -0,0 +1,16 @@
1
+ import { RemoteServerOptions } from './interfaces/RemoteServerOptions';
2
+ /**
3
+ * Remote server is a proxy server that uses its execution tools internally and exposes the executor interface externally.
4
+ *
5
+ * You can simply use `RemoteExecutionTools` on client-side javascript and connect to your remote server.
6
+ * This is useful to make all logic on browser side but not expose your API keys or no need to use customer's GPU.
7
+ *
8
+ * @see https://github.com/webgptorg/promptbook#remote-server
9
+ */
10
+ export declare function createRemoteServer(options: RemoteServerOptions): void;
11
+ /**
12
+ * TODO: Handle progress - support streaming
13
+ * TODO: [🤹‍♂️] Do not hang up immediately but wait until client closes OR timeout
14
+ * TODO: [🤹‍♂️] Timeout on chat to free up resources
15
+ * TODO: [🃏] Pass here some security token to prevent DDoS
16
+ */
@@ -0,0 +1,3 @@
1
+ export interface Ptps_Error {
2
+ readonly errorMessage: string;
3
+ }
@@ -0,0 +1,4 @@
1
+ import { TaskProgress } from '../../../../../types/TaskProgress';
2
+ export interface Ptps_Progress {
3
+ readonly taskProgress: TaskProgress;
4
+ }
@@ -0,0 +1,6 @@
1
+ import { uuid } from '../../../../.././types/typeAliases';
2
+ import { Prompt } from '../../../../../types/Prompt';
3
+ export interface Ptps_Request {
4
+ readonly clientId: uuid;
5
+ readonly prompt: Prompt;
6
+ }
@@ -0,0 +1,4 @@
1
+ import { PromptResult } from '../../../../../execution/PromptResult';
2
+ export interface Ptps_Response {
3
+ promptResult: PromptResult;
4
+ }
@@ -0,0 +1,20 @@
1
+ import { PromptTemplatePipelineLibrary } from '../../../../../classes/PromptTemplatePipelineLibrary';
2
+ import { uuid } from '../../../../../types/typeAliases';
3
+ import { CommonExecutionToolsOptions } from '../../../../CommonExecutionToolsOptions';
4
+ import { NaturalExecutionTools } from '../../../../NaturalExecutionTools';
5
+ export interface RemoteServerOptions extends CommonExecutionToolsOptions {
6
+ /**
7
+ * Port on which the server will listen
8
+ */
9
+ readonly port: number;
10
+ /**
11
+ * Prompt template pipeline library to use
12
+ *
13
+ * This is used to checkl validity of the prompt to prevent DDoS
14
+ */
15
+ readonly ptpLibrary: PromptTemplatePipelineLibrary;
16
+ /**
17
+ * Creates natural execution tools for each client
18
+ */
19
+ createNaturalExecutionTools(clientId: uuid): NaturalExecutionTools;
20
+ }
@@ -0,0 +1,19 @@
1
+ import { CommonExecutionToolsOptions } from '../../../CommonExecutionToolsOptions';
2
+ import { ScriptExecutionTools, ScriptExecutionToolsExecuteOptions } from '../../../ScriptExecutionTools';
3
+ /**
4
+ * ScriptExecutionTools for JavaScript implemented via eval
5
+ *
6
+ * Warning: It is used for testing and mocking
7
+ * **NOT intended to use in the production** due to its unsafe nature, use `JavascriptExecutionTools` instead.
8
+ */
9
+ export declare class JavascriptEvalExecutionTools implements ScriptExecutionTools {
10
+ private readonly options;
11
+ constructor(options: CommonExecutionToolsOptions);
12
+ /**
13
+ * Executes a JavaScript
14
+ */
15
+ execute(options: ScriptExecutionToolsExecuteOptions): Promise<string>;
16
+ }
17
+ /**
18
+ * TODO: Put predefined functions (like removeQuotes, spaceTrim, etc.) into annotation OR pass into constructor
19
+ */
@@ -0,0 +1,4 @@
1
+ export {};
2
+ /**
3
+ * TODO: !! Make shared test between JavascriptEvalExecutionTools and JavascriptExecutionTools to test the same functionality when implemented via vm2
4
+ */
@@ -0,0 +1,20 @@
1
+ import { CommonExecutionToolsOptions } from '../../../CommonExecutionToolsOptions';
2
+ import { ScriptExecutionTools, ScriptExecutionToolsExecuteOptions } from '../../../ScriptExecutionTools';
3
+ /**
4
+ * ScriptExecutionTools for JavaScript implemented via vm2
5
+ *
6
+ * Warning: This is not implemented yet
7
+ */
8
+ export declare class JavascriptExecutionTools implements ScriptExecutionTools {
9
+ private readonly options;
10
+ constructor(options: CommonExecutionToolsOptions);
11
+ /**
12
+ * Executes a JavaScript
13
+ */
14
+ execute(options: ScriptExecutionToolsExecuteOptions): Promise<string>;
15
+ }
16
+ /**
17
+ * TODO: !! Pass isVerbose to constructor and use it
18
+ * TODO: !! Probbably make some common util createStatementToEvaluate
19
+ * TODO: !! Implement via vm2
20
+ */
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Does nothing, but preserves the function in the bundle
3
+ * Compiler is tricked into thinking the function is used
4
+ *
5
+ * @param value any function to preserve
6
+ * @returns nothing
7
+ */
8
+ export declare function preserve(func: (...params: Array<any>) => unknown): void;
9
+ /**
10
+ * TODO: !! [1] This maybe does memory leak
11
+ */
@@ -0,0 +1,4 @@
1
+ export {};
2
+ /**
3
+ * TODO: What is the ideal folder for this test?
4
+ */
@@ -0,0 +1,15 @@
1
+ import { CommonExecutionToolsOptions } from '../../../CommonExecutionToolsOptions';
2
+ import { ScriptExecutionTools, ScriptExecutionToolsExecuteOptions } from '../../../ScriptExecutionTools';
3
+ /**
4
+ * ScriptExecutionTools for Python
5
+ *
6
+ * Warning: This is not implemented yet
7
+ */
8
+ export declare class PythonExecutionTools implements ScriptExecutionTools {
9
+ private readonly options;
10
+ constructor(options: CommonExecutionToolsOptions);
11
+ /**
12
+ * Executes a Python
13
+ */
14
+ execute(options: ScriptExecutionToolsExecuteOptions): Promise<string>;
15
+ }
@@ -0,0 +1,15 @@
1
+ import { CommonExecutionToolsOptions } from '../../../CommonExecutionToolsOptions';
2
+ import { ScriptExecutionTools, ScriptExecutionToolsExecuteOptions } from '../../../ScriptExecutionTools';
3
+ /**
4
+ * ScriptExecutionTools for TypeScript
5
+ *
6
+ * Warning: This is not implemented yet
7
+ */
8
+ export declare class TypescriptExecutionTools implements ScriptExecutionTools {
9
+ private readonly options;
10
+ constructor(options: CommonExecutionToolsOptions);
11
+ /**
12
+ * Executes a TypeScript
13
+ */
14
+ execute(options: ScriptExecutionToolsExecuteOptions): Promise<string>;
15
+ }
@@ -0,0 +1,14 @@
1
+ import { UserInterfaceTools, UserInterfaceToolsPromptDialogOptions } from '../../../UserInterfaceTools';
2
+ import { CallbackInterfaceToolsOptions } from './CallbackInterfaceToolsOptions';
3
+ /**
4
+ * Delagates the user interaction to a async callback function
5
+ * You need to provide your own implementation of this callback function and its bind to UI.
6
+ */
7
+ export declare class CallbackInterfaceTools implements UserInterfaceTools {
8
+ private readonly options;
9
+ constructor(options: CallbackInterfaceToolsOptions);
10
+ /**
11
+ * Trigger the custom callback function
12
+ */
13
+ promptDialog(options: UserInterfaceToolsPromptDialogOptions): Promise<string>;
14
+ }
@@ -0,0 +1,12 @@
1
+ import { Promisable } from 'type-fest';
2
+ import { CommonExecutionToolsOptions } from '../../../CommonExecutionToolsOptions';
3
+ import { UserInterfaceToolsPromptDialogOptions } from '../../../UserInterfaceTools';
4
+ /**
5
+ * Options for CallbackInterfaceTools
6
+ */
7
+ export interface CallbackInterfaceToolsOptions extends CommonExecutionToolsOptions {
8
+ /**
9
+ * The callback function to be called when promptDialog is called
10
+ */
11
+ callback(prompt: UserInterfaceToolsPromptDialogOptions): Promisable<string>;
12
+ }
@@ -0,0 +1,16 @@
1
+ import { CommonExecutionToolsOptions } from '../../../CommonExecutionToolsOptions';
2
+ import { UserInterfaceTools, UserInterfaceToolsPromptDialogOptions } from '../../../UserInterfaceTools';
3
+ /**
4
+ * Wrapper around `window.prompt` synchronous function that interacts with the user via browser prompt
5
+ *
6
+ * Warning: It is used for testing and mocking
7
+ * **NOT intended to use in the production** due to its synchronous nature.
8
+ */
9
+ export declare class SimplePromptInterfaceTools implements UserInterfaceTools {
10
+ private readonly options;
11
+ constructor(options: CommonExecutionToolsOptions);
12
+ /**
13
+ * Trigger window.prompt dialog
14
+ */
15
+ promptDialog(options: UserInterfaceToolsPromptDialogOptions): Promise<string>;
16
+ }
@@ -0,0 +1,65 @@
1
+ import { string_markdown_text, string_name, string_version } from '.././types/typeAliases';
2
+ import { ExecutionType } from './ExecutionTypes';
3
+ import { ModelRequirements } from './ModelRequirements';
4
+ /**
5
+ * Command is one piece of the prompt template which adds some logic to the prompt template or the whole pipeline.
6
+ * It is parsed from the markdown from ul/ol items - one command per one item.
7
+ */
8
+ export type Command = PtpUrlCommand | PtpVersionCommand | ExecuteCommand | UseCommand | ParameterCommand | PostprocessCommand;
9
+ /**
10
+ * PtpVersion command tells which version is .ptp file using
11
+ *
12
+ * - It is used for backward compatibility
13
+ * - It is defined per whole .ptp file in the header
14
+ */
15
+ export interface PtpUrlCommand {
16
+ readonly type: 'PTP_URL';
17
+ readonly ptpUrl: URL;
18
+ }
19
+ /**
20
+ * PtpVersion command tells which version is .ptp file using
21
+ *
22
+ * - It is used for backward compatibility
23
+ * - It is defined per whole .ptp file in the header
24
+ */
25
+ export interface PtpVersionCommand {
26
+ readonly type: 'PTP_VERSION';
27
+ readonly ptpVersion: string_version;
28
+ }
29
+ /**
30
+ * Execute command tells how to execute the section
31
+ * It can be either prompt template, script or simple template etc.
32
+ */
33
+ export interface ExecuteCommand {
34
+ readonly type: 'EXECUTE';
35
+ readonly executionType: ExecutionType;
36
+ }
37
+ /**
38
+ * Use command tells which model and modelRequirements to use for the prompt template. execution
39
+ */
40
+ export interface UseCommand {
41
+ readonly type: 'USE';
42
+ readonly key: keyof ModelRequirements;
43
+ readonly value: any;
44
+ }
45
+ /**
46
+ * Parameter command describes one parameter of the prompt template
47
+ *
48
+ * - It can tell if it is input or output parameter
49
+ * - It can have description
50
+ * - In description it can have simple formatting BUT not markdown structure or reference to other parameters
51
+ */
52
+ export interface ParameterCommand {
53
+ readonly type: 'PARAMETER';
54
+ readonly isInputParameter: boolean;
55
+ readonly parameterName: string_name;
56
+ readonly parameterDescription: string_markdown_text | null;
57
+ }
58
+ /**
59
+ * Postprocess command describes which function to use for postprocessing
60
+ * This will be created as separate execute script block bellow
61
+ */
62
+ export interface PostprocessCommand {
63
+ readonly type: 'POSTPROCESS';
64
+ readonly functionName: string_name;
65
+ }
@@ -0,0 +1,13 @@
1
+ import { TupleToUnion } from 'type-fest';
2
+ /**
3
+ * Execution type describes the way how the block is executed
4
+ *
5
+ * @see https://github.com/webgptorg/promptbook#execution-type
6
+ */
7
+ export type ExecutionType = TupleToUnion<typeof ExecutionTypes>;
8
+ /**
9
+ * Execution type describes the way how the block is executed
10
+ *
11
+ * @see https://github.com/webgptorg/promptbook#execution-type
12
+ */
13
+ export declare const ExecutionTypes: readonly ["PROMPT_TEMPLATE", "SIMPLE_TEMPLATE", "SCRIPT", "PROMPT_DIALOG"];
@@ -0,0 +1,28 @@
1
+ export declare const MODEL_VARIANTS: readonly ["COMPLETION", "CHAT"];
2
+ /**
3
+ * Model variant describes the very general type of the model
4
+ *
5
+ * There are two variants:
6
+ * - **COMPLETION** - model that takes prompt and writes the rest of the text
7
+ * - **CHAT** - model that takes prompt and previous messages and returns response
8
+ */
9
+ export type ModelVariant = (typeof MODEL_VARIANTS)[number];
10
+ /**
11
+ * Abstract way to specify the LLM. It does not specify the LLM with concrete version itself, only the requirements for the LLM.
12
+ *
13
+ * @see https://github.com/webgptorg/promptbook#model-requirements
14
+ */
15
+ export interface ModelRequirements {
16
+ /**
17
+ * Model variant describes the very general type of the model
18
+ *
19
+ * There are two variants:
20
+ * - **COMPLETION** - model that takes prompt and writes the rest of the text
21
+ * - **CHAT** - model that takes prompt and previous messages and returns response
22
+ */
23
+ readonly variant: ModelVariant;
24
+ }
25
+ /**
26
+ * TODO: Maybe figure out better word than "variant"
27
+ * TODO: Add here more requirement options like max context size, max tokens, etc.
28
+ */
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Parameters of the prompt template (pipeline)
3
+ *
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.
8
+ *
9
+ * @see https://github.com/webgptorg/promptbook#parameters
10
+ */
11
+ export type Parameters = object;
12
+ /**
13
+ * TODO: Constrain type to Simple key-value object, only string keys and string values and no index signature + only camelCase keys and spaceTrimmed values
14
+ */