@promptbook/remote-client 0.52.0-8 → 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 +1 -13
  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/remote-client)](https://socket.dev/npm/package/@promptbook/remote-client)
15
14
 
16
15
 
17
16
 
@@ -70,15 +69,6 @@ In any of these situations, but especially in (3), the Promptbook library can ma
70
69
  - _(Not ready yet)_ Leverage the **streaming** to make super cool UI/UX.
71
70
  - _(Not ready yet)_ **A/B testing** to determine which prompt works best for the job.
72
71
 
73
- ![WebGPT](./other/screencasts/screencast-fiabciakcmgepblmdkmemdbbkilneeeh-2023.10.26-21_46_17.gif)
74
-
75
- ## 🧔 Promptbook _(for prompt-engeneers)_
76
-
77
- **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.
78
-
79
- - Multiple promptbooks forms a library which will become a **part of your application codebase**.
80
- - Theese promptbooks are designed such as they **can be written by non-programmers**.
81
-
82
72
 
83
73
 
84
74
  ### Sample:
@@ -91,7 +81,7 @@ File `write-website-content.ptbk.md`:
91
81
  >
92
82
  > Instructions for creating web page content.
93
83
  >
94
- > - PROMPTBOOK URL https://promptbook.webgpt.com/en/write-website-content.ptbk.md@v0.1.0
84
+ > - PROMPTBOOK URL https://promptbook.webgpt.com/en/write-website-content.ptbk.md
95
85
  > - PROMPTBOOK VERSION 0.0.1
96
86
  > - INPUT  PARAM `{rawTitle}` Automatically suggested a site name or empty text
97
87
  > - INPUT  PARAM `{rawAssigment}` Automatically generated site entry from image recognition
@@ -550,8 +540,6 @@ _Note: LLMs work with tokens, not characters, but in Promptbooks we want to use
550
540
  ```markdown
551
541
  # ✨ Sample: Expectations
552
542
 
553
- - PROMPTBOOK URL https://promptbook.example.com/samples/postprocessing-2.ptbk.md@v1
554
- - PROMPTBOOK VERSION 1.0.0
555
543
  - INPUT  PARAMETER {yourName} Name of the hero
556
544
 
557
545
  ## 💬 Question
package/esm/index.es.js CHANGED
@@ -149,7 +149,7 @@ var RemoteLlmExecutionTools = /** @class */ (function () {
149
149
  return RemoteLlmExecutionTools;
150
150
  }());
151
151
  /**
152
- * TODO: [🍓][♐] Allow to list compatible models with each variant
152
+ * TODO: [🍓] Allow to list compatible models with each variant
153
153
  * TODO: [🤹‍♂️] RemoteLlmExecutionTools should extend Destroyable and implement IDestroyable
154
154
  */
155
155
 
@@ -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/remote-client",
3
- "version": "0.52.0-8",
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,
@@ -47,7 +47,7 @@
47
47
  }
48
48
  ],
49
49
  "peerDependencies": {
50
- "@promptbook/core": "0.52.0-8"
50
+ "@promptbook/core": "0.52.0"
51
51
  },
52
52
  "main": "./umd/index.umd.js",
53
53
  "module": "./esm/index.es.js",
package/umd/index.umd.js CHANGED
@@ -153,7 +153,7 @@
153
153
  return RemoteLlmExecutionTools;
154
154
  }());
155
155
  /**
156
- * TODO: [🍓][♐] Allow to list compatible models with each variant
156
+ * TODO: [🍓] Allow to list compatible models with each variant
157
157
  * TODO: [🤹‍♂️] RemoteLlmExecutionTools should extend Destroyable and implement IDestroyable
158
158
  */
159
159
 
@@ -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
- */