@promptbook/openai 0.52.0-9 โ†’ 0.52.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 (48) hide show
  1. package/README.md +67 -28
  2. package/esm/index.es.js +1 -1
  3. package/esm/typings/_packages/core.index.d.ts +4 -2
  4. package/esm/typings/_packages/utils.index.d.ts +2 -0
  5. package/esm/typings/errors/PromptbookLibraryError.d.ts +7 -0
  6. package/esm/typings/execution/ExecutionTools.d.ts +5 -3
  7. package/esm/typings/execution/plugins/llm-execution-tools/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +0 -1
  8. package/esm/typings/execution/plugins/llm-execution-tools/azure-openai/AzureOpenAiExecutionTools.d.ts +0 -1
  9. package/esm/typings/execution/plugins/llm-execution-tools/langtail/LangtailExecutionTools.d.ts +0 -3
  10. package/esm/typings/execution/plugins/llm-execution-tools/openai/OpenAiExecutionTools.d.ts +1 -1
  11. package/esm/typings/execution/plugins/llm-execution-tools/remote/RemoteLlmExecutionTools.d.ts +1 -1
  12. package/esm/typings/execution/plugins/llm-execution-tools/remote/startRemoteServer.d.ts +1 -0
  13. package/esm/typings/execution/utils/forEachAsync.d.ts +18 -0
  14. package/esm/typings/library/constructors/createPromptbookLibraryFromDirectory.d.ts +28 -4
  15. package/esm/typings/library/constructors/createPromptbookLibraryFromDirectory.test.d.ts +1 -0
  16. package/esm/typings/library/constructors/createPromptbookLibraryFromPromise.d.ts +2 -2
  17. package/esm/typings/library/constructors/createPromptbookLibraryFromPromise.test.d.ts +1 -0
  18. package/esm/typings/library/constructors/createPromptbookLibraryFromSources.test.d.ts +1 -0
  19. package/esm/typings/library/constructors/createPromptbookLibraryFromUrl.d.ts +22 -5
  20. package/esm/typings/library/constructors/justTestFsImport.d.ts +7 -0
  21. package/esm/typings/types/Prompt.d.ts +1 -1
  22. package/esm/typings/types/typeAliases.d.ts +2 -2
  23. package/package.json +2 -2
  24. package/umd/index.umd.js +1 -1
  25. package/umd/typings/_packages/core.index.d.ts +4 -2
  26. package/umd/typings/_packages/utils.index.d.ts +2 -0
  27. package/umd/typings/errors/PromptbookLibraryError.d.ts +7 -0
  28. package/umd/typings/execution/ExecutionTools.d.ts +5 -3
  29. package/umd/typings/execution/plugins/llm-execution-tools/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +0 -1
  30. package/umd/typings/execution/plugins/llm-execution-tools/azure-openai/AzureOpenAiExecutionTools.d.ts +0 -1
  31. package/umd/typings/execution/plugins/llm-execution-tools/langtail/LangtailExecutionTools.d.ts +0 -3
  32. package/umd/typings/execution/plugins/llm-execution-tools/openai/OpenAiExecutionTools.d.ts +1 -1
  33. package/umd/typings/execution/plugins/llm-execution-tools/remote/RemoteLlmExecutionTools.d.ts +1 -1
  34. package/umd/typings/execution/plugins/llm-execution-tools/remote/startRemoteServer.d.ts +1 -0
  35. package/umd/typings/execution/utils/forEachAsync.d.ts +18 -0
  36. package/umd/typings/library/constructors/createPromptbookLibraryFromDirectory.d.ts +28 -4
  37. package/umd/typings/library/constructors/createPromptbookLibraryFromDirectory.test.d.ts +1 -0
  38. package/umd/typings/library/constructors/createPromptbookLibraryFromPromise.d.ts +2 -2
  39. package/umd/typings/library/constructors/createPromptbookLibraryFromPromise.test.d.ts +1 -0
  40. package/umd/typings/library/constructors/createPromptbookLibraryFromSources.test.d.ts +1 -0
  41. package/umd/typings/library/constructors/createPromptbookLibraryFromUrl.d.ts +22 -5
  42. package/umd/typings/library/constructors/justTestFsImport.d.ts +7 -0
  43. package/umd/typings/types/Prompt.d.ts +1 -1
  44. package/umd/typings/types/typeAliases.d.ts +2 -2
  45. package/esm/typings/wizzard/Wizzard.d.ts +0 -4
  46. package/esm/typings/wizzard/sample.d.ts +0 -6
  47. package/umd/typings/wizzard/Wizzard.d.ts +0 -4
  48. package/umd/typings/wizzard/sample.d.ts +0 -6
package/README.md CHANGED
@@ -11,7 +11,6 @@ Library to supercharge your use of large language models
11
11
  [![Issues](https://img.shields.io/github/issues/webgptorg/promptbook.svg?style=flat)](https://github.com/webgptorg/promptbook/issues)
12
12
 
13
13
 
14
- [![Socket Badge](https://socket.dev/api/badge/npm/package/@promptbook/openai)](https://socket.dev/npm/package/@promptbook/openai)
15
14
 
16
15
 
17
16
 
@@ -30,11 +29,9 @@ npm i ptbk
30
29
  npm i @promptbook/openai
31
30
  ```
32
31
 
33
- Wrapper around [OpenAI's SDK](https://www.npmjs.com/package/openai) to make it easier to use inside Promptbooks.
32
+ `@promptbook/openai` integrates [OpenAI's API](https://openai.com/) with [Promptbook](https://github.com/webgptorg/promptbook). It allows to execute Promptbooks with OpenAI GPT models.
34
33
 
35
-
36
-
37
- ## Usage
34
+ ## ๐Ÿงก Usage
38
35
 
39
36
  ```typescript
40
37
  import {
@@ -45,40 +42,91 @@ import {
45
42
  import { JavascriptExecutionTools } from '@promptbook/execute-javascript';
46
43
  import { OpenAiExecutionTools } from '@promptbook/openai';
47
44
 
48
- // Create whole Promptbook library
49
- const library = createPromptbookLibraryFromDirectory('./promptbook');
45
+ // โ–ถ Create whole Promptbook library
46
+ const library = await createPromptbookLibraryFromDirectory('./promptbook-library');
50
47
 
51
- // Get one Promptbook
52
- const promptbook = library.getPromptbookByUrl(`https://promptbook.studio/my-library/write-article.ptbk.md`);
48
+ // โ–ถ Get one Promptbook
49
+ const promptbook = await library.getPromptbookByUrl(`https://promptbook.studio/my-library/write-article.ptbk.md`);
53
50
 
54
- // Prepare tools
51
+ // โ–ถ Prepare tools
55
52
  const tools = {
56
53
  llm: new OpenAiExecutionTools({
54
+ isVerbose: true,
57
55
  apiKey: process.env.OPENAI_API_KEY,
58
56
  }),
59
57
  script: [new JavascriptExecutionTools()],
60
58
  };
61
59
 
62
- // Create executor - the function that will execute the Promptbook
60
+ // โ–ถ Create executor - the function that will execute the Promptbook
63
61
  const promptbookExecutor = createPromptbookExecutor({ promptbook, tools });
64
62
 
65
- // Prepare input parameters
63
+ // โ–ถ Prepare input parameters
66
64
  const inputParameters = { word: 'cat' };
67
65
 
68
- // ๐Ÿš€ Execute the Promptbook
66
+ // ๐Ÿš€โ–ถ Execute the Promptbook
69
67
  const result = await promptbookExecutor(inputParameters);
70
68
 
71
- // Fail if the execution was not successful
69
+ // โ–ถ Fail if the execution was not successful
72
70
  assertsExecutionSuccessful(result);
73
71
 
74
- // Handle the result
72
+ // โ–ถ Handle the result
75
73
  const { isSuccessful, errors, outputParameters, executionReport } = result;
76
74
  console.info(outputParameters);
77
75
  ```
78
76
 
77
+ ## ๐Ÿ’• Usage of multiple LLM providers
78
+
79
+ You can use multiple LLM providers in one Promptbook execution. The best model will be chosen automatically according to the prompt and the model's capabilities.
80
+
81
+ ```typescript
82
+ import {
83
+ createPromptbookExecutor,
84
+ createPromptbookLibraryFromDirectory,
85
+ assertsExecutionSuccessful,
86
+ } from '@promptbook/core';
87
+ import { JavascriptExecutionTools } from '@promptbook/execute-javascript';
88
+ import { OpenAiExecutionTools } from '@promptbook/openai';
89
+
90
+ // โ–ถ Create whole Promptbook library
91
+ const library = await createPromptbookLibraryFromDirectory('./promptbook-library');
79
92
 
93
+ // โ–ถ Get one Promptbook
94
+ const promptbook = await library.getPromptbookByUrl(`https://promptbook.studio/my-library/write-article.ptbk.md`);
80
95
 
81
- ## Other models
96
+ // โ–ถ Prepare tools
97
+ const tools = new MultipleLlmExecutionTools(
98
+ // Note: You can use multiple LLM providers in one Promptbook execution. The best model will be chosen automatically according to the prompt and the model's capabilities.
99
+ new OpenAiExecutionTools({
100
+ apiKey: process.env.OPENAI_API_KEY,
101
+ }),
102
+ new AnthropicClaudeExecutionTools({
103
+ apiKey: process.env.ANTHROPIC_CLAUDE_API_KEY,
104
+ }),
105
+ new AzureOpenAiExecutionTools({
106
+ resourceName: process.env.AZUREOPENAI_RESOURCE_NAME,
107
+ deploymentName: process.env.AZUREOPENAI_DEPLOYMENT_NAME,
108
+ apiKey: process.env.AZUREOPENAI_API_KEY,
109
+ }),
110
+ );
111
+
112
+ // โ–ถ Create executor - the function that will execute the Promptbook
113
+ const promptbookExecutor = createPromptbookExecutor({ promptbook, tools });
114
+
115
+ // โ–ถ Prepare input parameters
116
+ const inputParameters = { word: 'dog' };
117
+
118
+ // ๐Ÿš€โ–ถ Execute the Promptbook
119
+ const result = await promptbookExecutor(inputParameters);
120
+
121
+ // โ–ถ Fail if the execution was not successful
122
+ assertsExecutionSuccessful(result);
123
+
124
+ // โ–ถ Handle the result
125
+ const { isSuccessful, errors, outputParameters, executionReport } = result;
126
+ console.info(outputParameters);
127
+ ```
128
+
129
+ ## ๐Ÿ’™ Integration with other models
82
130
 
83
131
  See the other models available in the Promptbook package:
84
132
 
@@ -86,6 +134,8 @@ See the other models available in the Promptbook package:
86
134
  - [Anthropic Claude](https://www.npmjs.com/package/@promptbook/anthropic-claude)
87
135
 
88
136
 
137
+
138
+
89
139
  ---
90
140
 
91
141
  Rest of the documentation is common for **entire promptbook ecosystem**:
@@ -124,15 +174,6 @@ In any of these situations, but especially in (3), the Promptbook library can ma
124
174
  - _(Not ready yet)_ Leverage the **streaming** to make super cool UI/UX.
125
175
  - _(Not ready yet)_ **A/B testing** to determine which prompt works best for the job.
126
176
 
127
- ![WebGPT](./other/screencasts/screencast-fiabciakcmgepblmdkmemdbbkilneeeh-2023.10.26-21_46_17.gif)
128
-
129
- ## ๐Ÿง” Promptbook _(for prompt-engeneers)_
130
-
131
- **P**romp**t** **b**oo**k** markdown file (**PTBK** for short, or `.ptbk.md`) is document that describes a series of prompts that are chained together to form somewhat reciepe for transforming natural language input. Inside a PTBK you can use chat prompts, completion prompts, scripting or trigger interaction with user to ask for additional information.
132
-
133
- - Multiple promptbooks forms a library which will become a **part of your application codebase**.
134
- - Theese promptbooks are designed such as they **can be written by non-programmers**.
135
-
136
177
 
137
178
 
138
179
  ### Sample:
@@ -145,7 +186,7 @@ File `write-website-content.ptbk.md`:
145
186
  >
146
187
  > Instructions for creating web page content.
147
188
  >
148
- > - PROMPTBOOK URL https://promptbook.webgpt.com/en/write-website-content.ptbk.md@v0.1.0
189
+ > - PROMPTBOOK URL https://promptbook.webgpt.com/en/write-website-content.ptbk.md
149
190
  > - PROMPTBOOK VERSION 0.0.1
150
191
  > - INPUTโ€ฏโ€ฏPARAM `{rawTitle}` Automatically suggested a site name or empty text
151
192
  > - INPUTโ€ฏโ€ฏPARAM `{rawAssigment}` Automatically generated site entry from image recognition
@@ -604,8 +645,6 @@ _Note: LLMs work with tokens, not characters, but in Promptbooks we want to use
604
645
  ```markdown
605
646
  # โœจ Sample: Expectations
606
647
 
607
- - PROMPTBOOK URL https://promptbook.example.com/samples/postprocessing-2.ptbk.md@v1
608
- - PROMPTBOOK VERSION 1.0.0
609
648
  - INPUTโ€ฏโ€ฏPARAMETER {yourName} Name of the hero
610
649
 
611
650
  ## ๐Ÿ’ฌ Question
package/esm/index.es.js CHANGED
@@ -675,7 +675,7 @@ var OpenAiExecutionTools = /** @class */ (function () {
675
675
  return OpenAiExecutionTools;
676
676
  }());
677
677
  /**
678
- * TODO: [๐Ÿ“][โ™] Allow to list compatible models with each variant
678
+ * TODO: [๐Ÿง ][๐Ÿง™โ€โ™‚๏ธ] Maybe there can be some wizzard for thoose who want to use just OpenAI
679
679
  * TODO: Maybe Create some common util for gptChat and gptComplete
680
680
  * TODO: Maybe make custom OpenaiError
681
681
  */
@@ -10,17 +10,19 @@ import { CallbackInterfaceToolsOptions } from '../execution/plugins/user-interfa
10
10
  import { SimplePromptInterfaceTools } from '../execution/plugins/user-interface-execution-tools/simple-prompt/SimplePromptInterfaceTools';
11
11
  import { checkExpectations, isPassingExpectations } from '../execution/utils/checkExpectations';
12
12
  import { createPromptbookLibraryFromDirectory } from '../library/constructors/createPromptbookLibraryFromDirectory';
13
- import { createPromptbookLibraryFromPromise } from '../library/constructors/createPromptbookLibraryFromPromise';
14
13
  import { createPromptbookLibraryFromSources } from '../library/constructors/createPromptbookLibraryFromSources';
14
+ import { createPromptbookLibraryFromUrl } from '../library/constructors/createPromptbookLibraryFromUrl';
15
15
  import { createPromptbookSublibrary } from '../library/constructors/createPromptbookSublibrary';
16
+ import { justTestFsImport } from '../library/constructors/justTestFsImport';
16
17
  import { SimplePromptbookLibrary } from '../library/SimplePromptbookLibrary';
17
18
  import { executionReportJsonToString } from '../types/execution-report/executionReportJsonToString';
18
19
  import { ExecutionReportStringOptions, ExecutionReportStringOptionsDefaults } from '../types/execution-report/ExecutionReportStringOptions';
19
20
  import { ExecutionTypes } from '../types/ExecutionTypes';
20
21
  import { PROMPTBOOK_VERSION } from '../version';
22
+ export { justTestFsImport };
21
23
  export { ExecutionTypes, PROMPTBOOK_VERSION };
22
24
  export { assertsExecutionSuccessful, checkExpectations, executionReportJsonToString, ExecutionReportStringOptions, ExecutionReportStringOptionsDefaults, isPassingExpectations, prettifyPromptbookString, };
23
- export { createPromptbookLibraryFromDirectory, createPromptbookLibraryFromPromise, createPromptbookLibraryFromSources, createPromptbookSublibrary, SimplePromptbookLibrary, };
25
+ export { createPromptbookLibraryFromDirectory, createPromptbookLibraryFromSources, createPromptbookLibraryFromUrl, createPromptbookSublibrary, SimplePromptbookLibrary, };
24
26
  export { SimplePromptInterfaceTools };
25
27
  export { promptbookJsonToString, promptbookStringToJson, validatePromptbookJson };
26
28
  export { createPromptbookExecutor, MultipleLlmExecutionTools };
@@ -5,6 +5,7 @@ import { extractVariables } from '../conversion/utils/extractVariables';
5
5
  import { parseNumber } from '../conversion/utils/parseNumber';
6
6
  import { renameParameter } from '../conversion/utils/renameParameter';
7
7
  import { titleToName } from '../conversion/utils/titleToName';
8
+ import { forEachAsync } from '../execution/utils/forEachAsync';
8
9
  import { replaceParameters } from '../execution/utils/replaceParameters';
9
10
  import { CountUtils } from '../utils/expectation-counters';
10
11
  import { countCharacters } from '../utils/expectation-counters/countCharacters';
@@ -46,6 +47,7 @@ import { union } from '../utils/sets/union';
46
47
  import { trimCodeBlock } from '../utils/trimCodeBlock';
47
48
  import { trimEndOfCodeBlock } from '../utils/trimEndOfCodeBlock';
48
49
  import { unwrapResult } from '../utils/unwrapResult';
50
+ export { forEachAsync };
49
51
  export { extractAllBlocksFromMarkdown, // <- [๐ŸŒป]
50
52
  extractAllListItemsFromMarkdown, extractBlock, // <- [๐ŸŒป]
51
53
  extractOneBlockFromMarkdown, extractParameters, extractVariables, isValidJsonString, parseNumber, // <- [๐ŸŒป]
@@ -0,0 +1,7 @@
1
+ /**
2
+ * This error indicates that the promptbook library cannot be propperly loaded
3
+ */
4
+ export declare class PromptbookLibraryError extends Error {
5
+ readonly name = "PromptbookLibraryError";
6
+ constructor(message: string);
7
+ }
@@ -9,6 +9,9 @@ import type { UserInterfaceTools } from './UserInterfaceTools';
9
9
  export type ExecutionTools = {
10
10
  /**
11
11
  * Tools for executing prompts to large language models like GPT-4
12
+ *
13
+ * Tip: Combine multiple LLM execution tools with `MultipleLlmExecutionTools`
14
+ * @see https://github.com/webgptorg/promptbook/?tab=readme-ov-file#llm-execution-tools
12
15
  */
13
16
  llm: LlmExecutionTools;
14
17
  /**
@@ -16,15 +19,14 @@ export type ExecutionTools = {
16
19
  *
17
20
  * Note: You can pass multiple ScriptExecutionTools, they will be tried one by one until one of them supports the script
18
21
  * If none of them supports the script, an error is thrown
22
+ * @see https://github.com/webgptorg/promptbook/?tab=readme-ov-file#script-execution-tools
19
23
  */
20
24
  script: Array<ScriptExecutionTools>;
21
25
  /**
22
26
  * Tools for interacting with the user
23
27
  *
24
28
  * Note: When undefined, the user interface is disabled and promptbook which requires user interaction will fail
29
+ * @see https://github.com/webgptorg/promptbook/?tab=readme-ov-file#user-interface-tools
25
30
  */
26
31
  userInterface?: UserInterfaceTools;
27
32
  };
28
- /**
29
- * TODO: [๐Ÿ“] !!!! Allow to have more LlmExecutionTools
30
- */
@@ -36,7 +36,6 @@ export declare class AnthropicClaudeExecutionTools implements LlmExecutionTools
36
36
  }
37
37
  /**
38
38
  * TODO: [๐Ÿง ] Maybe handle errors via transformAnthropicError (like transformAzureError)
39
- * TODO: [๐Ÿ“][โ™] Allow to list compatible models with each variant
40
39
  * TODO: Maybe Create some common util for gptChat and gptComplete
41
40
  * TODO: Maybe make custom OpenaiError
42
41
  */
@@ -35,7 +35,6 @@ export declare class AzureOpenAiExecutionTools implements LlmExecutionTools {
35
35
  listModels(): Promise<Array<AvailableModel>>;
36
36
  }
37
37
  /**
38
- * TODO: [๐Ÿ“][โ™] Allow to list compatible models with each variant
39
38
  * TODO: Maybe Create some common util for gptChat and gptComplete
40
39
  * TODO: Maybe make custom AzureOpenaiError
41
40
  */
@@ -5,6 +5,3 @@ import { OpenAiExecutionTools } from '../openai/OpenAiExecutionTools';
5
5
  */
6
6
  export declare class LangtailExecutionTools extends OpenAiExecutionTools implements LlmExecutionTools {
7
7
  }
8
- /**
9
- * TODO: [๐Ÿ“][โ™] Allow to list the available prompts in Langtail
10
- */
@@ -39,7 +39,7 @@ export declare class OpenAiExecutionTools implements LlmExecutionTools {
39
39
  listModels(): Array<AvailableModel>;
40
40
  }
41
41
  /**
42
- * TODO: [๐Ÿ“][โ™] Allow to list compatible models with each variant
42
+ * TODO: [๐Ÿง ][๐Ÿง™โ€โ™‚๏ธ] Maybe there can be some wizzard for thoose who want to use just OpenAI
43
43
  * TODO: Maybe Create some common util for gptChat and gptComplete
44
44
  * TODO: Maybe make custom OpenaiError
45
45
  */
@@ -35,6 +35,6 @@ export declare class RemoteLlmExecutionTools implements LlmExecutionTools {
35
35
  listModels(): Promise<Array<AvailableModel>>;
36
36
  }
37
37
  /**
38
- * TODO: [๐Ÿ“][โ™] Allow to list compatible models with each variant
38
+ * TODO: [๐Ÿ“] Allow to list compatible models with each variant
39
39
  * TODO: [๐Ÿคนโ€โ™‚๏ธ] RemoteLlmExecutionTools should extend Destroyable and implement IDestroyable
40
40
  */
@@ -10,6 +10,7 @@ import { RemoteServerOptions } from './interfaces/RemoteServerOptions';
10
10
  */
11
11
  export declare function startRemoteServer(options: RemoteServerOptions): IDestroyable;
12
12
  /**
13
+ * TODO: [โš–] Expose the library to be able to connect to same library via createPromptbookLibraryFromUrl
13
14
  * TODO: Handle progress - support streaming
14
15
  * TODO: [๐Ÿคนโ€โ™‚๏ธ] Do not hang up immediately but wait until client closes OR timeout
15
16
  * TODO: [๐Ÿคนโ€โ™‚๏ธ] Timeout on chat to free up resources
@@ -0,0 +1,18 @@
1
+ import type { Promisable } from 'type-fest';
2
+ type ForEachAsyncOptions = {
3
+ /**
4
+ * Maximum number of tasks running in parallel
5
+ *
6
+ * @default Infinity
7
+ */
8
+ inParallelCount?: number;
9
+ };
10
+ /**
11
+ * Async version of Array.forEach
12
+ *
13
+ * @param array - Array to iterate over
14
+ * @param options - Options for the function
15
+ * @param callbackfunction - Function to call for each item
16
+ */
17
+ export declare function forEachAsync<TItem>(array: Array<TItem>, options: ForEachAsyncOptions, callbackfunction: (value: TItem, index: number, array: Array<TItem>) => Promisable<void>): Promise<void>;
18
+ export {};
@@ -10,20 +10,44 @@ type CreatePromptbookLibraryFromDirectoryOptions = {
10
10
  * @default true
11
11
  */
12
12
  isRecursive?: boolean;
13
+ /**
14
+ * If true, the library creation outputs information about each file it reads
15
+ *
16
+ * @default false
17
+ */
18
+ isVerbose?: boolean;
19
+ /**
20
+ * If true, directory will be scanned only when needed not during the construction
21
+ *
22
+ * @default false
23
+ */
24
+ isLazyLoaded?: boolean;
25
+ /**
26
+ * If true, whole library creation crashes on error in any promptbook
27
+ * If true and isLazyLoaded is true, the error is thrown on first access to the promptbook
28
+ *
29
+ * @default true
30
+ */
31
+ isCrashOnError?: boolean;
13
32
  };
14
33
  /**
15
34
  * Constructs Promptbook from given directory
16
35
  *
17
36
  * Note: Works only in Node.js environment because it reads the file system
18
- * Note: The function does NOT return promise it returns the library directly which dynamically loads promptbooks when needed
19
- * SO during the construction syntax and logic sources IS NOT validated
20
37
  *
21
38
  * @param path - path to the directory with promptbooks
22
39
  * @param options - Misc options for the library
23
40
  * @returns PromptbookLibrary
24
41
  */
25
- export declare function createPromptbookLibraryFromDirectory(path: string_folder_path, options?: CreatePromptbookLibraryFromDirectoryOptions): PromptbookLibrary;
42
+ export declare function createPromptbookLibraryFromDirectory(path: string_folder_path, options?: CreatePromptbookLibraryFromDirectoryOptions): Promise<PromptbookLibrary>;
26
43
  export {};
27
44
  /***
28
- * TODO: [๐Ÿ“][๐Ÿšฏ] !!! Add to README and samples + maybe make `@promptbook/library` package
45
+ * TODO: [๐Ÿง ] Maybe do not do hacks like [1] and just create package @promptbook/node
46
+ * [๐Ÿ“][๐Ÿšฏ] maybe make `@promptbook/library` package
47
+ * TODO: Fix the dynamic import issue in Webpack (! Not working !)
48
+ * > ./node_modules/@promptbook/core/esm/index.es.js
49
+ * > Critical dependency: the request of a dependency is an expression
50
+ *
51
+ * Note: [1] Using require(just('fs/promises')) to allow
52
+ * the `@promptbook/core` work for both Node.js and browser environments
29
53
  */
@@ -14,11 +14,11 @@ import { PromptbookLibrary } from '../PromptbookLibrary';
14
14
  * Note: The function does NOT return promise it returns the library directly which waits for the sources to be resolved
15
15
  * when error occurs in given promise or factory function, it is thrown during `listPromptbooks` or `getPromptbookByUrl` call
16
16
  *
17
+ * Note: Consider using `createPromptbookLibraryFromDirectory` or `createPromptbookLibraryFromUrl`
17
18
  *
18
19
  * @param promptbookSourcesPromiseOrFactory
19
20
  * @returns PromptbookLibrary
20
- *
21
- * @deprecated Consider using `createPromptbookLibraryFromUrl` or `createPromptbookLibraryFromDirectory`
21
+ * @private Just internal tool for other constructor functions
22
22
  */
23
23
  export declare function createPromptbookLibraryFromPromise(promptbookSourcesPromiseOrFactory: Promise<Array<PromptbookJson | PromptbookString>> | (() => Promise<Array<PromptbookJson | PromptbookString>>)): PromptbookLibrary;
24
24
  /***
@@ -1,13 +1,30 @@
1
+ import { string_url } from '../../types/typeAliases';
1
2
  import { PromptbookLibrary } from '../PromptbookLibrary';
3
+ /**
4
+ * Options for `createPromptbookLibraryFromDirectory` function
5
+ */
6
+ type CreatePromptbookLibraryFromUrlyOptions = {
7
+ /**
8
+ * If true, the library creation outputs information about each file it reads
9
+ *
10
+ * @default false
11
+ */
12
+ isVerbose?: boolean;
13
+ /**
14
+ * If true, directory will be scanned only when needed not during the construction
15
+ *
16
+ * @default false
17
+ */
18
+ isLazyLoaded?: boolean;
19
+ };
2
20
  /**
3
21
  * Constructs Promptbook from remote Promptbase URL
4
- *
5
- * Note: The function does NOT return promise it returns the library directly which dynamically loads promptbooks when needed
6
- * SO during the construction syntax and logic sources IS NOT validated
7
- *
22
+
8
23
  * @returns PromptbookLibrary
9
24
  */
10
- export declare function createPromptbookLibraryFromUrl(): PromptbookLibrary;
25
+ export declare function createPromptbookLibraryFromUrl(url: string_url | URL, options: CreatePromptbookLibraryFromUrlyOptions): Promise<PromptbookLibrary>;
26
+ export {};
11
27
  /***
28
+ * TODO: [โš–] Compatible with remote server
12
29
  * TODO: [๐Ÿ“][๐Ÿšฏ] !!! Add to README and samples + maybe make `@promptbook/library` package
13
30
  */
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Just testing imports and compatibility
3
+ */
4
+ export declare function justTestFsImport(): Promise<void>;
5
+ /**
6
+ * TODO: !!! Remove this file
7
+ */
@@ -39,7 +39,7 @@ export type Prompt = {
39
39
  /**
40
40
  * Unique identifier of the promptbook with specific template name as hash
41
41
  *
42
- * @example https://promptbook.webgpt.com/cs/write-website-content.ptbk.md@v2.4.15#keywords
42
+ * @example https://promptbook.webgpt.com/cs/write-website-content.ptbk.md#keywords
43
43
  */
44
44
  readonly promptbookUrl: string_promptbook_url_with_hashtemplate;
45
45
  /**
@@ -179,13 +179,13 @@ export type string_url = string;
179
179
  /**
180
180
  * Semantic helper
181
181
  *
182
- * For example `"https://promptbook.webgpt.com/cs/write-website-content.ptbk.md@v2.4.15"`
182
+ * For example `"https://promptbook.webgpt.com/cs/write-website-content.ptbk.md"`
183
183
  */
184
184
  export type string_promptbook_url = string;
185
185
  /**
186
186
  * Semantic helper
187
187
  *
188
- * For example `"https://promptbook.webgpt.com/cs/write-website-content.ptbk.md@v2.4.15#keywords"`
188
+ * For example `"https://promptbook.webgpt.com/cs/write-website-content.ptbk.md#keywords"`
189
189
  */
190
190
  export type string_promptbook_url_with_hashtemplate = string;
191
191
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/openai",
3
- "version": "0.52.0-9",
3
+ "version": "0.52.0",
4
4
  "description": "Library to supercharge your use of large language models",
5
5
  "private": false,
6
6
  "sideEffects": false,
@@ -48,7 +48,7 @@
48
48
  }
49
49
  ],
50
50
  "peerDependencies": {
51
- "@promptbook/core": "0.52.0-9"
51
+ "@promptbook/core": "0.52.0"
52
52
  },
53
53
  "main": "./umd/index.umd.js",
54
54
  "module": "./esm/index.es.js",
package/umd/index.umd.js CHANGED
@@ -683,7 +683,7 @@
683
683
  return OpenAiExecutionTools;
684
684
  }());
685
685
  /**
686
- * TODO: [๐Ÿ“][โ™] Allow to list compatible models with each variant
686
+ * TODO: [๐Ÿง ][๐Ÿง™โ€โ™‚๏ธ] Maybe there can be some wizzard for thoose who want to use just OpenAI
687
687
  * TODO: Maybe Create some common util for gptChat and gptComplete
688
688
  * TODO: Maybe make custom OpenaiError
689
689
  */
@@ -10,17 +10,19 @@ import { CallbackInterfaceToolsOptions } from '../execution/plugins/user-interfa
10
10
  import { SimplePromptInterfaceTools } from '../execution/plugins/user-interface-execution-tools/simple-prompt/SimplePromptInterfaceTools';
11
11
  import { checkExpectations, isPassingExpectations } from '../execution/utils/checkExpectations';
12
12
  import { createPromptbookLibraryFromDirectory } from '../library/constructors/createPromptbookLibraryFromDirectory';
13
- import { createPromptbookLibraryFromPromise } from '../library/constructors/createPromptbookLibraryFromPromise';
14
13
  import { createPromptbookLibraryFromSources } from '../library/constructors/createPromptbookLibraryFromSources';
14
+ import { createPromptbookLibraryFromUrl } from '../library/constructors/createPromptbookLibraryFromUrl';
15
15
  import { createPromptbookSublibrary } from '../library/constructors/createPromptbookSublibrary';
16
+ import { justTestFsImport } from '../library/constructors/justTestFsImport';
16
17
  import { SimplePromptbookLibrary } from '../library/SimplePromptbookLibrary';
17
18
  import { executionReportJsonToString } from '../types/execution-report/executionReportJsonToString';
18
19
  import { ExecutionReportStringOptions, ExecutionReportStringOptionsDefaults } from '../types/execution-report/ExecutionReportStringOptions';
19
20
  import { ExecutionTypes } from '../types/ExecutionTypes';
20
21
  import { PROMPTBOOK_VERSION } from '../version';
22
+ export { justTestFsImport };
21
23
  export { ExecutionTypes, PROMPTBOOK_VERSION };
22
24
  export { assertsExecutionSuccessful, checkExpectations, executionReportJsonToString, ExecutionReportStringOptions, ExecutionReportStringOptionsDefaults, isPassingExpectations, prettifyPromptbookString, };
23
- export { createPromptbookLibraryFromDirectory, createPromptbookLibraryFromPromise, createPromptbookLibraryFromSources, createPromptbookSublibrary, SimplePromptbookLibrary, };
25
+ export { createPromptbookLibraryFromDirectory, createPromptbookLibraryFromSources, createPromptbookLibraryFromUrl, createPromptbookSublibrary, SimplePromptbookLibrary, };
24
26
  export { SimplePromptInterfaceTools };
25
27
  export { promptbookJsonToString, promptbookStringToJson, validatePromptbookJson };
26
28
  export { createPromptbookExecutor, MultipleLlmExecutionTools };
@@ -5,6 +5,7 @@ import { extractVariables } from '../conversion/utils/extractVariables';
5
5
  import { parseNumber } from '../conversion/utils/parseNumber';
6
6
  import { renameParameter } from '../conversion/utils/renameParameter';
7
7
  import { titleToName } from '../conversion/utils/titleToName';
8
+ import { forEachAsync } from '../execution/utils/forEachAsync';
8
9
  import { replaceParameters } from '../execution/utils/replaceParameters';
9
10
  import { CountUtils } from '../utils/expectation-counters';
10
11
  import { countCharacters } from '../utils/expectation-counters/countCharacters';
@@ -46,6 +47,7 @@ import { union } from '../utils/sets/union';
46
47
  import { trimCodeBlock } from '../utils/trimCodeBlock';
47
48
  import { trimEndOfCodeBlock } from '../utils/trimEndOfCodeBlock';
48
49
  import { unwrapResult } from '../utils/unwrapResult';
50
+ export { forEachAsync };
49
51
  export { extractAllBlocksFromMarkdown, // <- [๐ŸŒป]
50
52
  extractAllListItemsFromMarkdown, extractBlock, // <- [๐ŸŒป]
51
53
  extractOneBlockFromMarkdown, extractParameters, extractVariables, isValidJsonString, parseNumber, // <- [๐ŸŒป]
@@ -0,0 +1,7 @@
1
+ /**
2
+ * This error indicates that the promptbook library cannot be propperly loaded
3
+ */
4
+ export declare class PromptbookLibraryError extends Error {
5
+ readonly name = "PromptbookLibraryError";
6
+ constructor(message: string);
7
+ }
@@ -9,6 +9,9 @@ import type { UserInterfaceTools } from './UserInterfaceTools';
9
9
  export type ExecutionTools = {
10
10
  /**
11
11
  * Tools for executing prompts to large language models like GPT-4
12
+ *
13
+ * Tip: Combine multiple LLM execution tools with `MultipleLlmExecutionTools`
14
+ * @see https://github.com/webgptorg/promptbook/?tab=readme-ov-file#llm-execution-tools
12
15
  */
13
16
  llm: LlmExecutionTools;
14
17
  /**
@@ -16,15 +19,14 @@ export type ExecutionTools = {
16
19
  *
17
20
  * Note: You can pass multiple ScriptExecutionTools, they will be tried one by one until one of them supports the script
18
21
  * If none of them supports the script, an error is thrown
22
+ * @see https://github.com/webgptorg/promptbook/?tab=readme-ov-file#script-execution-tools
19
23
  */
20
24
  script: Array<ScriptExecutionTools>;
21
25
  /**
22
26
  * Tools for interacting with the user
23
27
  *
24
28
  * Note: When undefined, the user interface is disabled and promptbook which requires user interaction will fail
29
+ * @see https://github.com/webgptorg/promptbook/?tab=readme-ov-file#user-interface-tools
25
30
  */
26
31
  userInterface?: UserInterfaceTools;
27
32
  };
28
- /**
29
- * TODO: [๐Ÿ“] !!!! Allow to have more LlmExecutionTools
30
- */
@@ -36,7 +36,6 @@ export declare class AnthropicClaudeExecutionTools implements LlmExecutionTools
36
36
  }
37
37
  /**
38
38
  * TODO: [๐Ÿง ] Maybe handle errors via transformAnthropicError (like transformAzureError)
39
- * TODO: [๐Ÿ“][โ™] Allow to list compatible models with each variant
40
39
  * TODO: Maybe Create some common util for gptChat and gptComplete
41
40
  * TODO: Maybe make custom OpenaiError
42
41
  */
@@ -35,7 +35,6 @@ export declare class AzureOpenAiExecutionTools implements LlmExecutionTools {
35
35
  listModels(): Promise<Array<AvailableModel>>;
36
36
  }
37
37
  /**
38
- * TODO: [๐Ÿ“][โ™] Allow to list compatible models with each variant
39
38
  * TODO: Maybe Create some common util for gptChat and gptComplete
40
39
  * TODO: Maybe make custom AzureOpenaiError
41
40
  */
@@ -5,6 +5,3 @@ import { OpenAiExecutionTools } from '../openai/OpenAiExecutionTools';
5
5
  */
6
6
  export declare class LangtailExecutionTools extends OpenAiExecutionTools implements LlmExecutionTools {
7
7
  }
8
- /**
9
- * TODO: [๐Ÿ“][โ™] Allow to list the available prompts in Langtail
10
- */
@@ -39,7 +39,7 @@ export declare class OpenAiExecutionTools implements LlmExecutionTools {
39
39
  listModels(): Array<AvailableModel>;
40
40
  }
41
41
  /**
42
- * TODO: [๐Ÿ“][โ™] Allow to list compatible models with each variant
42
+ * TODO: [๐Ÿง ][๐Ÿง™โ€โ™‚๏ธ] Maybe there can be some wizzard for thoose who want to use just OpenAI
43
43
  * TODO: Maybe Create some common util for gptChat and gptComplete
44
44
  * TODO: Maybe make custom OpenaiError
45
45
  */
@@ -35,6 +35,6 @@ export declare class RemoteLlmExecutionTools implements LlmExecutionTools {
35
35
  listModels(): Promise<Array<AvailableModel>>;
36
36
  }
37
37
  /**
38
- * TODO: [๐Ÿ“][โ™] Allow to list compatible models with each variant
38
+ * TODO: [๐Ÿ“] Allow to list compatible models with each variant
39
39
  * TODO: [๐Ÿคนโ€โ™‚๏ธ] RemoteLlmExecutionTools should extend Destroyable and implement IDestroyable
40
40
  */
@@ -10,6 +10,7 @@ import { RemoteServerOptions } from './interfaces/RemoteServerOptions';
10
10
  */
11
11
  export declare function startRemoteServer(options: RemoteServerOptions): IDestroyable;
12
12
  /**
13
+ * TODO: [โš–] Expose the library to be able to connect to same library via createPromptbookLibraryFromUrl
13
14
  * TODO: Handle progress - support streaming
14
15
  * TODO: [๐Ÿคนโ€โ™‚๏ธ] Do not hang up immediately but wait until client closes OR timeout
15
16
  * TODO: [๐Ÿคนโ€โ™‚๏ธ] Timeout on chat to free up resources
@@ -0,0 +1,18 @@
1
+ import type { Promisable } from 'type-fest';
2
+ type ForEachAsyncOptions = {
3
+ /**
4
+ * Maximum number of tasks running in parallel
5
+ *
6
+ * @default Infinity
7
+ */
8
+ inParallelCount?: number;
9
+ };
10
+ /**
11
+ * Async version of Array.forEach
12
+ *
13
+ * @param array - Array to iterate over
14
+ * @param options - Options for the function
15
+ * @param callbackfunction - Function to call for each item
16
+ */
17
+ export declare function forEachAsync<TItem>(array: Array<TItem>, options: ForEachAsyncOptions, callbackfunction: (value: TItem, index: number, array: Array<TItem>) => Promisable<void>): Promise<void>;
18
+ export {};
@@ -10,20 +10,44 @@ type CreatePromptbookLibraryFromDirectoryOptions = {
10
10
  * @default true
11
11
  */
12
12
  isRecursive?: boolean;
13
+ /**
14
+ * If true, the library creation outputs information about each file it reads
15
+ *
16
+ * @default false
17
+ */
18
+ isVerbose?: boolean;
19
+ /**
20
+ * If true, directory will be scanned only when needed not during the construction
21
+ *
22
+ * @default false
23
+ */
24
+ isLazyLoaded?: boolean;
25
+ /**
26
+ * If true, whole library creation crashes on error in any promptbook
27
+ * If true and isLazyLoaded is true, the error is thrown on first access to the promptbook
28
+ *
29
+ * @default true
30
+ */
31
+ isCrashOnError?: boolean;
13
32
  };
14
33
  /**
15
34
  * Constructs Promptbook from given directory
16
35
  *
17
36
  * Note: Works only in Node.js environment because it reads the file system
18
- * Note: The function does NOT return promise it returns the library directly which dynamically loads promptbooks when needed
19
- * SO during the construction syntax and logic sources IS NOT validated
20
37
  *
21
38
  * @param path - path to the directory with promptbooks
22
39
  * @param options - Misc options for the library
23
40
  * @returns PromptbookLibrary
24
41
  */
25
- export declare function createPromptbookLibraryFromDirectory(path: string_folder_path, options?: CreatePromptbookLibraryFromDirectoryOptions): PromptbookLibrary;
42
+ export declare function createPromptbookLibraryFromDirectory(path: string_folder_path, options?: CreatePromptbookLibraryFromDirectoryOptions): Promise<PromptbookLibrary>;
26
43
  export {};
27
44
  /***
28
- * TODO: [๐Ÿ“][๐Ÿšฏ] !!! Add to README and samples + maybe make `@promptbook/library` package
45
+ * TODO: [๐Ÿง ] Maybe do not do hacks like [1] and just create package @promptbook/node
46
+ * [๐Ÿ“][๐Ÿšฏ] maybe make `@promptbook/library` package
47
+ * TODO: Fix the dynamic import issue in Webpack (! Not working !)
48
+ * > ./node_modules/@promptbook/core/esm/index.es.js
49
+ * > Critical dependency: the request of a dependency is an expression
50
+ *
51
+ * Note: [1] Using require(just('fs/promises')) to allow
52
+ * the `@promptbook/core` work for both Node.js and browser environments
29
53
  */
@@ -14,11 +14,11 @@ import { PromptbookLibrary } from '../PromptbookLibrary';
14
14
  * Note: The function does NOT return promise it returns the library directly which waits for the sources to be resolved
15
15
  * when error occurs in given promise or factory function, it is thrown during `listPromptbooks` or `getPromptbookByUrl` call
16
16
  *
17
+ * Note: Consider using `createPromptbookLibraryFromDirectory` or `createPromptbookLibraryFromUrl`
17
18
  *
18
19
  * @param promptbookSourcesPromiseOrFactory
19
20
  * @returns PromptbookLibrary
20
- *
21
- * @deprecated Consider using `createPromptbookLibraryFromUrl` or `createPromptbookLibraryFromDirectory`
21
+ * @private Just internal tool for other constructor functions
22
22
  */
23
23
  export declare function createPromptbookLibraryFromPromise(promptbookSourcesPromiseOrFactory: Promise<Array<PromptbookJson | PromptbookString>> | (() => Promise<Array<PromptbookJson | PromptbookString>>)): PromptbookLibrary;
24
24
  /***
@@ -1,13 +1,30 @@
1
+ import { string_url } from '../../types/typeAliases';
1
2
  import { PromptbookLibrary } from '../PromptbookLibrary';
3
+ /**
4
+ * Options for `createPromptbookLibraryFromDirectory` function
5
+ */
6
+ type CreatePromptbookLibraryFromUrlyOptions = {
7
+ /**
8
+ * If true, the library creation outputs information about each file it reads
9
+ *
10
+ * @default false
11
+ */
12
+ isVerbose?: boolean;
13
+ /**
14
+ * If true, directory will be scanned only when needed not during the construction
15
+ *
16
+ * @default false
17
+ */
18
+ isLazyLoaded?: boolean;
19
+ };
2
20
  /**
3
21
  * Constructs Promptbook from remote Promptbase URL
4
- *
5
- * Note: The function does NOT return promise it returns the library directly which dynamically loads promptbooks when needed
6
- * SO during the construction syntax and logic sources IS NOT validated
7
- *
22
+
8
23
  * @returns PromptbookLibrary
9
24
  */
10
- export declare function createPromptbookLibraryFromUrl(): PromptbookLibrary;
25
+ export declare function createPromptbookLibraryFromUrl(url: string_url | URL, options: CreatePromptbookLibraryFromUrlyOptions): Promise<PromptbookLibrary>;
26
+ export {};
11
27
  /***
28
+ * TODO: [โš–] Compatible with remote server
12
29
  * TODO: [๐Ÿ“][๐Ÿšฏ] !!! Add to README and samples + maybe make `@promptbook/library` package
13
30
  */
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Just testing imports and compatibility
3
+ */
4
+ export declare function justTestFsImport(): Promise<void>;
5
+ /**
6
+ * TODO: !!! Remove this file
7
+ */
@@ -39,7 +39,7 @@ export type Prompt = {
39
39
  /**
40
40
  * Unique identifier of the promptbook with specific template name as hash
41
41
  *
42
- * @example https://promptbook.webgpt.com/cs/write-website-content.ptbk.md@v2.4.15#keywords
42
+ * @example https://promptbook.webgpt.com/cs/write-website-content.ptbk.md#keywords
43
43
  */
44
44
  readonly promptbookUrl: string_promptbook_url_with_hashtemplate;
45
45
  /**
@@ -179,13 +179,13 @@ export type string_url = string;
179
179
  /**
180
180
  * Semantic helper
181
181
  *
182
- * For example `"https://promptbook.webgpt.com/cs/write-website-content.ptbk.md@v2.4.15"`
182
+ * For example `"https://promptbook.webgpt.com/cs/write-website-content.ptbk.md"`
183
183
  */
184
184
  export type string_promptbook_url = string;
185
185
  /**
186
186
  * Semantic helper
187
187
  *
188
- * For example `"https://promptbook.webgpt.com/cs/write-website-content.ptbk.md@v2.4.15#keywords"`
188
+ * For example `"https://promptbook.webgpt.com/cs/write-website-content.ptbk.md#keywords"`
189
189
  */
190
190
  export type string_promptbook_url_with_hashtemplate = string;
191
191
  /**
@@ -1,4 +0,0 @@
1
- export declare const Wizzard: any;
2
- /**
3
- * TODO: [๐Ÿง™โ€โ™‚๏ธ]
4
- */
@@ -1,6 +0,0 @@
1
- export {};
2
- /**
3
- * TODO: [๐Ÿง™โ€โ™‚๏ธ]
4
- url, sources nebo folder
5
- * TODO: [๐Ÿง ] OpenAi apiKey vs token
6
- */
@@ -1,4 +0,0 @@
1
- export declare const Wizzard: any;
2
- /**
3
- * TODO: [๐Ÿง™โ€โ™‚๏ธ]
4
- */
@@ -1,6 +0,0 @@
1
- export {};
2
- /**
3
- * TODO: [๐Ÿง™โ€โ™‚๏ธ]
4
- url, sources nebo folder
5
- * TODO: [๐Ÿง ] OpenAi apiKey vs token
6
- */