@promptbook/openai 0.52.0-2 → 0.52.0-25
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.
- package/README.md +56 -6
- package/esm/typings/_packages/core.index.d.ts +16 -6
- package/esm/typings/_packages/utils.index.d.ts +3 -8
- package/esm/typings/execution/ExecutionTools.d.ts +5 -3
- package/esm/typings/execution/plugins/llm-execution-tools/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +1 -0
- package/esm/typings/execution/plugins/llm-execution-tools/azure-openai/AzureOpenAiExecutionTools.d.ts +4 -0
- package/esm/typings/execution/plugins/llm-execution-tools/multiple/MultipleLlmExecutionTools.d.ts +35 -0
- package/esm/typings/execution/plugins/llm-execution-tools/multiple/MultipleLlmExecutionToolsOptions.d.ts +23 -0
- package/esm/typings/execution/plugins/llm-execution-tools/multiple/playground/playground.d.ts +2 -0
- package/esm/typings/execution/plugins/script-execution-tools/javascript/JavascriptEvalExecutionTools.d.ts +1 -1
- package/esm/typings/execution/plugins/script-execution-tools/javascript/JavascriptExecutionTools.d.ts +4 -17
- package/esm/typings/library/constructors/createPromptbookLibraryFromDirectory.d.ts +36 -4
- package/esm/typings/library/constructors/createPromptbookLibraryFromDirectory.test.d.ts +1 -0
- package/esm/typings/library/constructors/createPromptbookLibraryFromPromise.d.ts +2 -2
- package/esm/typings/library/constructors/createPromptbookLibraryFromPromise.test.d.ts +1 -0
- package/esm/typings/library/constructors/createPromptbookLibraryFromSources.test.d.ts +1 -0
- package/esm/typings/library/constructors/createPromptbookLibraryFromUrl.d.ts +21 -5
- package/esm/typings/library/constructors/justTestFsImport.d.ts +7 -0
- package/esm/typings/types/Prompt.d.ts +1 -1
- package/esm/typings/types/typeAliases.d.ts +2 -2
- package/package.json +2 -2
- package/umd/typings/_packages/core.index.d.ts +16 -6
- package/umd/typings/_packages/utils.index.d.ts +3 -8
- package/umd/typings/execution/ExecutionTools.d.ts +5 -3
- package/umd/typings/execution/plugins/llm-execution-tools/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +1 -0
- package/umd/typings/execution/plugins/llm-execution-tools/azure-openai/AzureOpenAiExecutionTools.d.ts +4 -0
- package/umd/typings/execution/plugins/llm-execution-tools/multiple/MultipleLlmExecutionTools.d.ts +35 -0
- package/umd/typings/execution/plugins/llm-execution-tools/multiple/MultipleLlmExecutionToolsOptions.d.ts +23 -0
- package/umd/typings/execution/plugins/llm-execution-tools/multiple/playground/playground.d.ts +2 -0
- package/umd/typings/execution/plugins/script-execution-tools/javascript/JavascriptEvalExecutionTools.d.ts +1 -1
- package/umd/typings/execution/plugins/script-execution-tools/javascript/JavascriptExecutionTools.d.ts +4 -17
- package/umd/typings/library/constructors/createPromptbookLibraryFromDirectory.d.ts +36 -4
- package/umd/typings/library/constructors/createPromptbookLibraryFromDirectory.test.d.ts +1 -0
- package/umd/typings/library/constructors/createPromptbookLibraryFromPromise.d.ts +2 -2
- package/umd/typings/library/constructors/createPromptbookLibraryFromPromise.test.d.ts +1 -0
- package/umd/typings/library/constructors/createPromptbookLibraryFromSources.test.d.ts +1 -0
- package/umd/typings/library/constructors/createPromptbookLibraryFromUrl.d.ts +21 -5
- package/umd/typings/library/constructors/justTestFsImport.d.ts +7 -0
- package/umd/typings/types/Prompt.d.ts +1 -1
- package/umd/typings/types/typeAliases.d.ts +2 -2
- package/esm/typings/_packages/wizzard.index.d.ts +0 -5
- package/esm/typings/wizzard/Wizzard.d.ts +0 -4
- package/esm/typings/wizzard/sample.d.ts +0 -6
- package/umd/typings/_packages/wizzard.index.d.ts +0 -5
- package/umd/typings/wizzard/Wizzard.d.ts +0 -4
- package/umd/typings/wizzard/sample.d.ts +0 -6
package/README.md
CHANGED
|
@@ -34,7 +34,56 @@ Wrapper around [OpenAI's SDK](https://www.npmjs.com/package/openai) to make it e
|
|
|
34
34
|
|
|
35
35
|
|
|
36
36
|
|
|
37
|
+
## Usage
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
import {
|
|
41
|
+
createPromptbookExecutor,
|
|
42
|
+
createPromptbookLibraryFromDirectory,
|
|
43
|
+
assertsExecutionSuccessful,
|
|
44
|
+
} from '@promptbook/core';
|
|
45
|
+
import { JavascriptExecutionTools } from '@promptbook/execute-javascript';
|
|
46
|
+
import { OpenAiExecutionTools } from '@promptbook/openai';
|
|
47
|
+
|
|
48
|
+
// Create whole Promptbook library
|
|
49
|
+
const library = await createPromptbookLibraryFromDirectory('./promptbook-library');
|
|
50
|
+
|
|
51
|
+
// Get one Promptbook
|
|
52
|
+
const promptbook = library.getPromptbookByUrl(`https://promptbook.studio/my-library/write-article.ptbk.md`);
|
|
53
|
+
|
|
54
|
+
// Prepare tools
|
|
55
|
+
const tools = {
|
|
56
|
+
llm: new OpenAiExecutionTools({
|
|
57
|
+
apiKey: process.env.OPENAI_API_KEY,
|
|
58
|
+
}),
|
|
59
|
+
script: [new JavascriptExecutionTools()],
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
// Create executor - the function that will execute the Promptbook
|
|
63
|
+
const promptbookExecutor = createPromptbookExecutor({ promptbook, tools });
|
|
64
|
+
|
|
65
|
+
// Prepare input parameters
|
|
66
|
+
const inputParameters = { word: 'cat' };
|
|
67
|
+
|
|
68
|
+
// 🚀 Execute the Promptbook
|
|
69
|
+
const result = await promptbookExecutor(inputParameters);
|
|
70
|
+
|
|
71
|
+
// Fail if the execution was not successful
|
|
72
|
+
assertsExecutionSuccessful(result);
|
|
73
|
+
|
|
74
|
+
// Handle the result
|
|
75
|
+
const { isSuccessful, errors, outputParameters, executionReport } = result;
|
|
76
|
+
console.info(outputParameters);
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
## Other models
|
|
37
82
|
|
|
83
|
+
See the other models available in the Promptbook package:
|
|
84
|
+
|
|
85
|
+
- [Azure OpenAI](https://www.npmjs.com/package/@promptbook/azure-openai)
|
|
86
|
+
- [Anthropic Claude](https://www.npmjs.com/package/@promptbook/anthropic-claude)
|
|
38
87
|
|
|
39
88
|
|
|
40
89
|
---
|
|
@@ -96,7 +145,7 @@ File `write-website-content.ptbk.md`:
|
|
|
96
145
|
>
|
|
97
146
|
> Instructions for creating web page content.
|
|
98
147
|
>
|
|
99
|
-
> - PROMPTBOOK URL https://promptbook.webgpt.com/en/write-website-content.ptbk.md
|
|
148
|
+
> - PROMPTBOOK URL https://promptbook.webgpt.com/en/write-website-content.ptbk.md
|
|
100
149
|
> - PROMPTBOOK VERSION 0.0.1
|
|
101
150
|
> - INPUT PARAM `{rawTitle}` Automatically suggested a site name or empty text
|
|
102
151
|
> - INPUT PARAM `{rawAssigment}` Automatically generated site entry from image recognition
|
|
@@ -493,9 +542,10 @@ Internally it calls OpenAI, Azure, GPU, proxy, cache, logging,...
|
|
|
493
542
|
- _(Not implemented yet)_ `BardExecutionTools`
|
|
494
543
|
- _(Not implemented yet)_ `LamaExecutionTools`
|
|
495
544
|
- _(Not implemented yet)_ `GpuExecutionTools`
|
|
496
|
-
- And a special case are `
|
|
497
|
-
-
|
|
498
|
-
- The
|
|
545
|
+
- And a special case are `MultipleLlmExecutionTools` that combines multiple execution tools together and tries to execute the prompt on the best one.
|
|
546
|
+
- Another special case are `RemoteLlmExecutionTools` that connect to a remote server and run one of the above execution tools on that server.
|
|
547
|
+
- The another special case is `MockedEchoLlmExecutionTools` that is used for testing and mocking.
|
|
548
|
+
- The another special case is `LogLlmExecutionToolsWrapper` that is technically also an execution tools but it is more proxy wrapper around other execution tools that logs all calls to execution tools.
|
|
499
549
|
|
|
500
550
|
#### Script Execution Tools
|
|
501
551
|
|
|
@@ -554,8 +604,6 @@ _Note: LLMs work with tokens, not characters, but in Promptbooks we want to use
|
|
|
554
604
|
```markdown
|
|
555
605
|
# ✨ Sample: Expectations
|
|
556
606
|
|
|
557
|
-
- PROMPTBOOK URL https://promptbook.example.com/samples/postprocessing-2.ptbk.md@v1
|
|
558
|
-
- PROMPTBOOK VERSION 1.0.0
|
|
559
607
|
- INPUT PARAMETER {yourName} Name of the hero
|
|
560
608
|
|
|
561
609
|
## 💬 Question
|
|
@@ -594,6 +642,8 @@ Execution report is a simple object or markdown that contains information about
|
|
|
594
642
|
|
|
595
643
|
|
|
596
644
|
|
|
645
|
+
|
|
646
|
+
|
|
597
647
|
### Remote server
|
|
598
648
|
|
|
599
649
|
Remote server is a proxy server that uses its execution tools internally and exposes the executor interface externally.
|
|
@@ -1,19 +1,29 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { prettifyPromptbookString } from '../conversion/prettify/prettifyPromptbookString';
|
|
2
2
|
import { promptbookJsonToString } from '../conversion/promptbookJsonToString';
|
|
3
|
+
import { promptbookStringToJson } from '../conversion/promptbookStringToJson';
|
|
3
4
|
import { validatePromptbookJson } from '../conversion/validation/validatePromptbookJson';
|
|
5
|
+
import { assertsExecutionSuccessful } from '../execution/assertsExecutionSuccessful';
|
|
4
6
|
import { createPromptbookExecutor } from '../execution/createPromptbookExecutor';
|
|
7
|
+
import { MultipleLlmExecutionTools } from '../execution/plugins/llm-execution-tools/multiple/MultipleLlmExecutionTools';
|
|
5
8
|
import { CallbackInterfaceTools } from '../execution/plugins/user-interface-execution-tools/callback/CallbackInterfaceTools';
|
|
6
9
|
import { CallbackInterfaceToolsOptions } from '../execution/plugins/user-interface-execution-tools/callback/CallbackInterfaceToolsOptions';
|
|
7
10
|
import { SimplePromptInterfaceTools } from '../execution/plugins/user-interface-execution-tools/simple-prompt/SimplePromptInterfaceTools';
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
11
|
+
import { checkExpectations, isPassingExpectations } from '../execution/utils/checkExpectations';
|
|
12
|
+
import { createPromptbookLibraryFromDirectory } from '../library/constructors/createPromptbookLibraryFromDirectory';
|
|
10
13
|
import { createPromptbookLibraryFromSources } from '../library/constructors/createPromptbookLibraryFromSources';
|
|
14
|
+
import { createPromptbookLibraryFromUrl } from '../library/constructors/createPromptbookLibraryFromUrl';
|
|
11
15
|
import { createPromptbookSublibrary } from '../library/constructors/createPromptbookSublibrary';
|
|
16
|
+
import { justTestFsImport } from '../library/constructors/justTestFsImport';
|
|
17
|
+
import { SimplePromptbookLibrary } from '../library/SimplePromptbookLibrary';
|
|
18
|
+
import { executionReportJsonToString } from '../types/execution-report/executionReportJsonToString';
|
|
19
|
+
import { ExecutionReportStringOptions, ExecutionReportStringOptionsDefaults } from '../types/execution-report/ExecutionReportStringOptions';
|
|
12
20
|
import { ExecutionTypes } from '../types/ExecutionTypes';
|
|
13
21
|
import { PROMPTBOOK_VERSION } from '../version';
|
|
22
|
+
export { justTestFsImport };
|
|
14
23
|
export { ExecutionTypes, PROMPTBOOK_VERSION };
|
|
15
|
-
export {
|
|
24
|
+
export { assertsExecutionSuccessful, checkExpectations, executionReportJsonToString, ExecutionReportStringOptions, ExecutionReportStringOptionsDefaults, isPassingExpectations, prettifyPromptbookString, };
|
|
25
|
+
export { createPromptbookLibraryFromDirectory, createPromptbookLibraryFromSources, createPromptbookLibraryFromUrl, createPromptbookSublibrary, SimplePromptbookLibrary, };
|
|
16
26
|
export { SimplePromptInterfaceTools };
|
|
17
|
-
export {
|
|
18
|
-
export { createPromptbookExecutor };
|
|
27
|
+
export { promptbookJsonToString, promptbookStringToJson, validatePromptbookJson };
|
|
28
|
+
export { createPromptbookExecutor, MultipleLlmExecutionTools };
|
|
19
29
|
export { CallbackInterfaceTools, CallbackInterfaceToolsOptions };
|
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
import { spaceTrim } from 'spacetrim';
|
|
2
|
-
import { prettifyPromptbookString } from '../conversion/prettify/prettifyPromptbookString';
|
|
3
2
|
import { renderPromptbookMermaid } from '../conversion/prettify/renderPromptbookMermaid';
|
|
4
3
|
import { extractParametersFromPromptTemplate } from '../conversion/utils/extractParametersFromPromptTemplate';
|
|
5
4
|
import { extractVariables } from '../conversion/utils/extractVariables';
|
|
6
5
|
import { parseNumber } from '../conversion/utils/parseNumber';
|
|
7
6
|
import { renameParameter } from '../conversion/utils/renameParameter';
|
|
8
7
|
import { titleToName } from '../conversion/utils/titleToName';
|
|
9
|
-
import { assertsExecutionSuccessful } from '../execution/assertsExecutionSuccessful';
|
|
10
|
-
import { checkExpectations, isPassingExpectations } from '../execution/utils/checkExpectations';
|
|
11
8
|
import { replaceParameters } from '../execution/utils/replaceParameters';
|
|
12
|
-
import { executionReportJsonToString } from '../types/execution-report/executionReportJsonToString';
|
|
13
|
-
import { ExecutionReportStringOptions, ExecutionReportStringOptionsDefaults } from '../types/execution-report/ExecutionReportStringOptions';
|
|
14
9
|
import { CountUtils } from '../utils/expectation-counters';
|
|
15
10
|
import { countCharacters } from '../utils/expectation-counters/countCharacters';
|
|
16
11
|
import { countLines } from '../utils/expectation-counters/countLines';
|
|
@@ -51,10 +46,10 @@ import { union } from '../utils/sets/union';
|
|
|
51
46
|
import { trimCodeBlock } from '../utils/trimCodeBlock';
|
|
52
47
|
import { trimEndOfCodeBlock } from '../utils/trimEndOfCodeBlock';
|
|
53
48
|
import { unwrapResult } from '../utils/unwrapResult';
|
|
54
|
-
export {
|
|
49
|
+
export { extractAllBlocksFromMarkdown, // <- [🌻]
|
|
55
50
|
extractAllListItemsFromMarkdown, extractBlock, // <- [🌻]
|
|
56
|
-
extractOneBlockFromMarkdown, extractParameters, extractVariables,
|
|
57
|
-
|
|
51
|
+
extractOneBlockFromMarkdown, extractParameters, extractVariables, isValidJsonString, parseNumber, // <- [🌻]
|
|
52
|
+
removeContentComments, removeEmojis, removeMarkdownFormatting, removeQuotes, replaceParameters, spaceTrim, trimCodeBlock, trimEndOfCodeBlock, unwrapResult, };
|
|
58
53
|
export { countCharacters, countLines, countPages, countParagraphs, countSentences, CountUtils, countWords };
|
|
59
54
|
export { splitIntoSentences };
|
|
60
55
|
export declare const normalizeTo: {
|
|
@@ -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
|
-
*/
|
|
@@ -35,6 +35,7 @@ export declare class AnthropicClaudeExecutionTools implements LlmExecutionTools
|
|
|
35
35
|
listModels(): Array<AvailableModel>;
|
|
36
36
|
}
|
|
37
37
|
/**
|
|
38
|
+
* TODO: [🧠] Maybe handle errors via transformAnthropicError (like transformAzureError)
|
|
38
39
|
* TODO: [🍓][♐] Allow to list compatible models with each variant
|
|
39
40
|
* TODO: Maybe Create some common util for gptChat and gptComplete
|
|
40
41
|
* TODO: Maybe make custom OpenaiError
|
|
@@ -25,6 +25,10 @@ export declare class AzureOpenAiExecutionTools implements LlmExecutionTools {
|
|
|
25
25
|
* Calls Azure OpenAI API to use a complete model.
|
|
26
26
|
*/
|
|
27
27
|
gptComplete(prompt: Pick<Prompt, 'content' | 'modelRequirements'>): Promise<PromptCompletionResult>;
|
|
28
|
+
/**
|
|
29
|
+
* Changes Azure error (which is not propper Error but object) to propper Error
|
|
30
|
+
*/
|
|
31
|
+
private transformAzureError;
|
|
28
32
|
/**
|
|
29
33
|
* List all available Azure OpenAI models that can be used
|
|
30
34
|
*/
|
package/esm/typings/execution/plugins/llm-execution-tools/multiple/MultipleLlmExecutionTools.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { Prompt } from '../../../../types/Prompt';
|
|
2
|
+
import type { AvailableModel, LlmExecutionTools } from '../../../LlmExecutionTools';
|
|
3
|
+
import type { PromptChatResult, PromptCompletionResult } from '../../../PromptResult';
|
|
4
|
+
/**
|
|
5
|
+
* Multiple LLM Execution Tools is a proxy server that uses multiple execution tools internally and exposes the executor interface externally.
|
|
6
|
+
*
|
|
7
|
+
* @see https://github.com/webgptorg/promptbook#multiple-server
|
|
8
|
+
*/
|
|
9
|
+
export declare class MultipleLlmExecutionTools implements LlmExecutionTools {
|
|
10
|
+
/**
|
|
11
|
+
* Array of execution tools in order of priority
|
|
12
|
+
*/
|
|
13
|
+
private llmExecutionTools;
|
|
14
|
+
/**
|
|
15
|
+
* Gets array of execution tools in order of priority
|
|
16
|
+
*/
|
|
17
|
+
constructor(...llmExecutionTools: Array<LlmExecutionTools>);
|
|
18
|
+
/**
|
|
19
|
+
* Calls the best available chat model
|
|
20
|
+
*/
|
|
21
|
+
gptChat(prompt: Prompt): Promise<PromptChatResult>;
|
|
22
|
+
/**
|
|
23
|
+
* Calls the best available completion model
|
|
24
|
+
*/
|
|
25
|
+
gptComplete(prompt: Prompt): Promise<PromptCompletionResult>;
|
|
26
|
+
/**
|
|
27
|
+
* Calls the best available model
|
|
28
|
+
*/
|
|
29
|
+
private gptCommon;
|
|
30
|
+
/**
|
|
31
|
+
* List all available models that can be used
|
|
32
|
+
* This liost is a combination of all available models from all execution tools
|
|
33
|
+
*/
|
|
34
|
+
listModels(): Promise<Array<AvailableModel>>;
|
|
35
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { client_id, string_uri } from '../../../../types/typeAliases';
|
|
2
|
+
import type { CommonExecutionToolsOptions } from '../../../CommonExecutionToolsOptions';
|
|
3
|
+
/**
|
|
4
|
+
* Options for MultipleLlmExecutionTools
|
|
5
|
+
*/
|
|
6
|
+
export type MultipleLlmExecutionToolsOptions = CommonExecutionToolsOptions & {
|
|
7
|
+
/**
|
|
8
|
+
* URL of the multiple PROMPTBOOK server
|
|
9
|
+
* On this server will be connected to the socket.io server
|
|
10
|
+
*/
|
|
11
|
+
readonly multipleUrl: URL;
|
|
12
|
+
/**
|
|
13
|
+
* Path for the Socket.io server to listen
|
|
14
|
+
*
|
|
15
|
+
* @default '/socket.io'
|
|
16
|
+
* @example '/promptbook/socket.io'
|
|
17
|
+
*/
|
|
18
|
+
readonly path: string_uri;
|
|
19
|
+
/**
|
|
20
|
+
* Your client ID
|
|
21
|
+
*/
|
|
22
|
+
readonly clientId: client_id;
|
|
23
|
+
};
|
|
@@ -8,7 +8,7 @@ import { JavascriptExecutionToolsOptions } from './JavascriptExecutionToolsOptio
|
|
|
8
8
|
*/
|
|
9
9
|
export declare class JavascriptEvalExecutionTools implements ScriptExecutionTools {
|
|
10
10
|
private readonly options;
|
|
11
|
-
constructor(options
|
|
11
|
+
constructor(options?: JavascriptExecutionToolsOptions);
|
|
12
12
|
/**
|
|
13
13
|
* Executes a JavaScript
|
|
14
14
|
*/
|
|
@@ -1,20 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { JavascriptExecutionToolsOptions } from './JavascriptExecutionToolsOptions';
|
|
1
|
+
import { JavascriptEvalExecutionTools } from './JavascriptEvalExecutionTools';
|
|
3
2
|
/**
|
|
4
|
-
*
|
|
3
|
+
* Placeholder for better implementation of JavascriptExecutionTools - some propper sandboxing
|
|
5
4
|
*
|
|
6
|
-
*
|
|
7
|
-
*/
|
|
8
|
-
export declare class JavascriptExecutionTools implements ScriptExecutionTools {
|
|
9
|
-
private readonly options;
|
|
10
|
-
constructor(options: JavascriptExecutionToolsOptions);
|
|
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
|
|
5
|
+
* @alias JavascriptExecutionTools
|
|
20
6
|
*/
|
|
7
|
+
export declare const JavascriptExecutionTools: typeof JavascriptEvalExecutionTools;
|
|
@@ -1,14 +1,46 @@
|
|
|
1
|
+
import { string_folder_path } from '../../types/typeAliases';
|
|
1
2
|
import { PromptbookLibrary } from '../PromptbookLibrary';
|
|
3
|
+
/**
|
|
4
|
+
* Options for `createPromptbookLibraryFromDirectory` function
|
|
5
|
+
*/
|
|
6
|
+
type CreatePromptbookLibraryFromDirectoryOptions = {
|
|
7
|
+
/**
|
|
8
|
+
* If true, the directory is searched recursively for promptbooks
|
|
9
|
+
*
|
|
10
|
+
* @default true
|
|
11
|
+
*/
|
|
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
|
+
};
|
|
2
26
|
/**
|
|
3
27
|
* Constructs Promptbook from given directory
|
|
4
28
|
*
|
|
5
29
|
* Note: Works only in Node.js environment because it reads the file system
|
|
6
|
-
* Note: The function does NOT return promise it returns the library directly which dynamically loads promptbooks when needed
|
|
7
|
-
* SO during the construction syntax and logic sources IS NOT validated
|
|
8
30
|
*
|
|
31
|
+
* @param path - path to the directory with promptbooks
|
|
32
|
+
* @param options - Misc options for the library
|
|
9
33
|
* @returns PromptbookLibrary
|
|
10
34
|
*/
|
|
11
|
-
export declare function createPromptbookLibraryFromDirectory(): PromptbookLibrary
|
|
35
|
+
export declare function createPromptbookLibraryFromDirectory(path: string_folder_path, options?: CreatePromptbookLibraryFromDirectoryOptions): Promise<PromptbookLibrary>;
|
|
36
|
+
export {};
|
|
12
37
|
/***
|
|
13
|
-
* TODO: [
|
|
38
|
+
* TODO: [🧠] Maybe do not do hacks like [1] and just create package @promptbook/node
|
|
39
|
+
* [🍓][🚯] maybe make `@promptbook/library` package
|
|
40
|
+
* TODO: Fix the dynamic import issue in Webpack (! Not working !)
|
|
41
|
+
* > ./node_modules/@promptbook/core/esm/index.es.js
|
|
42
|
+
* > Critical dependency: the request of a dependency is an expression
|
|
43
|
+
*
|
|
44
|
+
* Note: [1] Using require(just('fs/promises')) to allow
|
|
45
|
+
* the `@promptbook/core` work for both Node.js and browser environments
|
|
14
46
|
*/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -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
|
/***
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,13 +1,29 @@
|
|
|
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
|
/***
|
|
12
28
|
* TODO: [🍓][🚯] !!! Add to README and samples + maybe make `@promptbook/library` package
|
|
13
29
|
*/
|
|
@@ -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
|
|
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
|
|
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
|
|
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-
|
|
3
|
+
"version": "0.52.0-25",
|
|
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-
|
|
51
|
+
"@promptbook/core": "0.52.0-25"
|
|
52
52
|
},
|
|
53
53
|
"main": "./umd/index.umd.js",
|
|
54
54
|
"module": "./esm/index.es.js",
|
|
@@ -1,19 +1,29 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { prettifyPromptbookString } from '../conversion/prettify/prettifyPromptbookString';
|
|
2
2
|
import { promptbookJsonToString } from '../conversion/promptbookJsonToString';
|
|
3
|
+
import { promptbookStringToJson } from '../conversion/promptbookStringToJson';
|
|
3
4
|
import { validatePromptbookJson } from '../conversion/validation/validatePromptbookJson';
|
|
5
|
+
import { assertsExecutionSuccessful } from '../execution/assertsExecutionSuccessful';
|
|
4
6
|
import { createPromptbookExecutor } from '../execution/createPromptbookExecutor';
|
|
7
|
+
import { MultipleLlmExecutionTools } from '../execution/plugins/llm-execution-tools/multiple/MultipleLlmExecutionTools';
|
|
5
8
|
import { CallbackInterfaceTools } from '../execution/plugins/user-interface-execution-tools/callback/CallbackInterfaceTools';
|
|
6
9
|
import { CallbackInterfaceToolsOptions } from '../execution/plugins/user-interface-execution-tools/callback/CallbackInterfaceToolsOptions';
|
|
7
10
|
import { SimplePromptInterfaceTools } from '../execution/plugins/user-interface-execution-tools/simple-prompt/SimplePromptInterfaceTools';
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
11
|
+
import { checkExpectations, isPassingExpectations } from '../execution/utils/checkExpectations';
|
|
12
|
+
import { createPromptbookLibraryFromDirectory } from '../library/constructors/createPromptbookLibraryFromDirectory';
|
|
10
13
|
import { createPromptbookLibraryFromSources } from '../library/constructors/createPromptbookLibraryFromSources';
|
|
14
|
+
import { createPromptbookLibraryFromUrl } from '../library/constructors/createPromptbookLibraryFromUrl';
|
|
11
15
|
import { createPromptbookSublibrary } from '../library/constructors/createPromptbookSublibrary';
|
|
16
|
+
import { justTestFsImport } from '../library/constructors/justTestFsImport';
|
|
17
|
+
import { SimplePromptbookLibrary } from '../library/SimplePromptbookLibrary';
|
|
18
|
+
import { executionReportJsonToString } from '../types/execution-report/executionReportJsonToString';
|
|
19
|
+
import { ExecutionReportStringOptions, ExecutionReportStringOptionsDefaults } from '../types/execution-report/ExecutionReportStringOptions';
|
|
12
20
|
import { ExecutionTypes } from '../types/ExecutionTypes';
|
|
13
21
|
import { PROMPTBOOK_VERSION } from '../version';
|
|
22
|
+
export { justTestFsImport };
|
|
14
23
|
export { ExecutionTypes, PROMPTBOOK_VERSION };
|
|
15
|
-
export {
|
|
24
|
+
export { assertsExecutionSuccessful, checkExpectations, executionReportJsonToString, ExecutionReportStringOptions, ExecutionReportStringOptionsDefaults, isPassingExpectations, prettifyPromptbookString, };
|
|
25
|
+
export { createPromptbookLibraryFromDirectory, createPromptbookLibraryFromSources, createPromptbookLibraryFromUrl, createPromptbookSublibrary, SimplePromptbookLibrary, };
|
|
16
26
|
export { SimplePromptInterfaceTools };
|
|
17
|
-
export {
|
|
18
|
-
export { createPromptbookExecutor };
|
|
27
|
+
export { promptbookJsonToString, promptbookStringToJson, validatePromptbookJson };
|
|
28
|
+
export { createPromptbookExecutor, MultipleLlmExecutionTools };
|
|
19
29
|
export { CallbackInterfaceTools, CallbackInterfaceToolsOptions };
|
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
import { spaceTrim } from 'spacetrim';
|
|
2
|
-
import { prettifyPromptbookString } from '../conversion/prettify/prettifyPromptbookString';
|
|
3
2
|
import { renderPromptbookMermaid } from '../conversion/prettify/renderPromptbookMermaid';
|
|
4
3
|
import { extractParametersFromPromptTemplate } from '../conversion/utils/extractParametersFromPromptTemplate';
|
|
5
4
|
import { extractVariables } from '../conversion/utils/extractVariables';
|
|
6
5
|
import { parseNumber } from '../conversion/utils/parseNumber';
|
|
7
6
|
import { renameParameter } from '../conversion/utils/renameParameter';
|
|
8
7
|
import { titleToName } from '../conversion/utils/titleToName';
|
|
9
|
-
import { assertsExecutionSuccessful } from '../execution/assertsExecutionSuccessful';
|
|
10
|
-
import { checkExpectations, isPassingExpectations } from '../execution/utils/checkExpectations';
|
|
11
8
|
import { replaceParameters } from '../execution/utils/replaceParameters';
|
|
12
|
-
import { executionReportJsonToString } from '../types/execution-report/executionReportJsonToString';
|
|
13
|
-
import { ExecutionReportStringOptions, ExecutionReportStringOptionsDefaults } from '../types/execution-report/ExecutionReportStringOptions';
|
|
14
9
|
import { CountUtils } from '../utils/expectation-counters';
|
|
15
10
|
import { countCharacters } from '../utils/expectation-counters/countCharacters';
|
|
16
11
|
import { countLines } from '../utils/expectation-counters/countLines';
|
|
@@ -51,10 +46,10 @@ import { union } from '../utils/sets/union';
|
|
|
51
46
|
import { trimCodeBlock } from '../utils/trimCodeBlock';
|
|
52
47
|
import { trimEndOfCodeBlock } from '../utils/trimEndOfCodeBlock';
|
|
53
48
|
import { unwrapResult } from '../utils/unwrapResult';
|
|
54
|
-
export {
|
|
49
|
+
export { extractAllBlocksFromMarkdown, // <- [🌻]
|
|
55
50
|
extractAllListItemsFromMarkdown, extractBlock, // <- [🌻]
|
|
56
|
-
extractOneBlockFromMarkdown, extractParameters, extractVariables,
|
|
57
|
-
|
|
51
|
+
extractOneBlockFromMarkdown, extractParameters, extractVariables, isValidJsonString, parseNumber, // <- [🌻]
|
|
52
|
+
removeContentComments, removeEmojis, removeMarkdownFormatting, removeQuotes, replaceParameters, spaceTrim, trimCodeBlock, trimEndOfCodeBlock, unwrapResult, };
|
|
58
53
|
export { countCharacters, countLines, countPages, countParagraphs, countSentences, CountUtils, countWords };
|
|
59
54
|
export { splitIntoSentences };
|
|
60
55
|
export declare const normalizeTo: {
|
|
@@ -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
|
-
*/
|
|
@@ -35,6 +35,7 @@ export declare class AnthropicClaudeExecutionTools implements LlmExecutionTools
|
|
|
35
35
|
listModels(): Array<AvailableModel>;
|
|
36
36
|
}
|
|
37
37
|
/**
|
|
38
|
+
* TODO: [🧠] Maybe handle errors via transformAnthropicError (like transformAzureError)
|
|
38
39
|
* TODO: [🍓][♐] Allow to list compatible models with each variant
|
|
39
40
|
* TODO: Maybe Create some common util for gptChat and gptComplete
|
|
40
41
|
* TODO: Maybe make custom OpenaiError
|
|
@@ -25,6 +25,10 @@ export declare class AzureOpenAiExecutionTools implements LlmExecutionTools {
|
|
|
25
25
|
* Calls Azure OpenAI API to use a complete model.
|
|
26
26
|
*/
|
|
27
27
|
gptComplete(prompt: Pick<Prompt, 'content' | 'modelRequirements'>): Promise<PromptCompletionResult>;
|
|
28
|
+
/**
|
|
29
|
+
* Changes Azure error (which is not propper Error but object) to propper Error
|
|
30
|
+
*/
|
|
31
|
+
private transformAzureError;
|
|
28
32
|
/**
|
|
29
33
|
* List all available Azure OpenAI models that can be used
|
|
30
34
|
*/
|
package/umd/typings/execution/plugins/llm-execution-tools/multiple/MultipleLlmExecutionTools.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { Prompt } from '../../../../types/Prompt';
|
|
2
|
+
import type { AvailableModel, LlmExecutionTools } from '../../../LlmExecutionTools';
|
|
3
|
+
import type { PromptChatResult, PromptCompletionResult } from '../../../PromptResult';
|
|
4
|
+
/**
|
|
5
|
+
* Multiple LLM Execution Tools is a proxy server that uses multiple execution tools internally and exposes the executor interface externally.
|
|
6
|
+
*
|
|
7
|
+
* @see https://github.com/webgptorg/promptbook#multiple-server
|
|
8
|
+
*/
|
|
9
|
+
export declare class MultipleLlmExecutionTools implements LlmExecutionTools {
|
|
10
|
+
/**
|
|
11
|
+
* Array of execution tools in order of priority
|
|
12
|
+
*/
|
|
13
|
+
private llmExecutionTools;
|
|
14
|
+
/**
|
|
15
|
+
* Gets array of execution tools in order of priority
|
|
16
|
+
*/
|
|
17
|
+
constructor(...llmExecutionTools: Array<LlmExecutionTools>);
|
|
18
|
+
/**
|
|
19
|
+
* Calls the best available chat model
|
|
20
|
+
*/
|
|
21
|
+
gptChat(prompt: Prompt): Promise<PromptChatResult>;
|
|
22
|
+
/**
|
|
23
|
+
* Calls the best available completion model
|
|
24
|
+
*/
|
|
25
|
+
gptComplete(prompt: Prompt): Promise<PromptCompletionResult>;
|
|
26
|
+
/**
|
|
27
|
+
* Calls the best available model
|
|
28
|
+
*/
|
|
29
|
+
private gptCommon;
|
|
30
|
+
/**
|
|
31
|
+
* List all available models that can be used
|
|
32
|
+
* This liost is a combination of all available models from all execution tools
|
|
33
|
+
*/
|
|
34
|
+
listModels(): Promise<Array<AvailableModel>>;
|
|
35
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { client_id, string_uri } from '../../../../types/typeAliases';
|
|
2
|
+
import type { CommonExecutionToolsOptions } from '../../../CommonExecutionToolsOptions';
|
|
3
|
+
/**
|
|
4
|
+
* Options for MultipleLlmExecutionTools
|
|
5
|
+
*/
|
|
6
|
+
export type MultipleLlmExecutionToolsOptions = CommonExecutionToolsOptions & {
|
|
7
|
+
/**
|
|
8
|
+
* URL of the multiple PROMPTBOOK server
|
|
9
|
+
* On this server will be connected to the socket.io server
|
|
10
|
+
*/
|
|
11
|
+
readonly multipleUrl: URL;
|
|
12
|
+
/**
|
|
13
|
+
* Path for the Socket.io server to listen
|
|
14
|
+
*
|
|
15
|
+
* @default '/socket.io'
|
|
16
|
+
* @example '/promptbook/socket.io'
|
|
17
|
+
*/
|
|
18
|
+
readonly path: string_uri;
|
|
19
|
+
/**
|
|
20
|
+
* Your client ID
|
|
21
|
+
*/
|
|
22
|
+
readonly clientId: client_id;
|
|
23
|
+
};
|
|
@@ -8,7 +8,7 @@ import { JavascriptExecutionToolsOptions } from './JavascriptExecutionToolsOptio
|
|
|
8
8
|
*/
|
|
9
9
|
export declare class JavascriptEvalExecutionTools implements ScriptExecutionTools {
|
|
10
10
|
private readonly options;
|
|
11
|
-
constructor(options
|
|
11
|
+
constructor(options?: JavascriptExecutionToolsOptions);
|
|
12
12
|
/**
|
|
13
13
|
* Executes a JavaScript
|
|
14
14
|
*/
|
|
@@ -1,20 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { JavascriptExecutionToolsOptions } from './JavascriptExecutionToolsOptions';
|
|
1
|
+
import { JavascriptEvalExecutionTools } from './JavascriptEvalExecutionTools';
|
|
3
2
|
/**
|
|
4
|
-
*
|
|
3
|
+
* Placeholder for better implementation of JavascriptExecutionTools - some propper sandboxing
|
|
5
4
|
*
|
|
6
|
-
*
|
|
7
|
-
*/
|
|
8
|
-
export declare class JavascriptExecutionTools implements ScriptExecutionTools {
|
|
9
|
-
private readonly options;
|
|
10
|
-
constructor(options: JavascriptExecutionToolsOptions);
|
|
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
|
|
5
|
+
* @alias JavascriptExecutionTools
|
|
20
6
|
*/
|
|
7
|
+
export declare const JavascriptExecutionTools: typeof JavascriptEvalExecutionTools;
|
|
@@ -1,14 +1,46 @@
|
|
|
1
|
+
import { string_folder_path } from '../../types/typeAliases';
|
|
1
2
|
import { PromptbookLibrary } from '../PromptbookLibrary';
|
|
3
|
+
/**
|
|
4
|
+
* Options for `createPromptbookLibraryFromDirectory` function
|
|
5
|
+
*/
|
|
6
|
+
type CreatePromptbookLibraryFromDirectoryOptions = {
|
|
7
|
+
/**
|
|
8
|
+
* If true, the directory is searched recursively for promptbooks
|
|
9
|
+
*
|
|
10
|
+
* @default true
|
|
11
|
+
*/
|
|
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
|
+
};
|
|
2
26
|
/**
|
|
3
27
|
* Constructs Promptbook from given directory
|
|
4
28
|
*
|
|
5
29
|
* Note: Works only in Node.js environment because it reads the file system
|
|
6
|
-
* Note: The function does NOT return promise it returns the library directly which dynamically loads promptbooks when needed
|
|
7
|
-
* SO during the construction syntax and logic sources IS NOT validated
|
|
8
30
|
*
|
|
31
|
+
* @param path - path to the directory with promptbooks
|
|
32
|
+
* @param options - Misc options for the library
|
|
9
33
|
* @returns PromptbookLibrary
|
|
10
34
|
*/
|
|
11
|
-
export declare function createPromptbookLibraryFromDirectory(): PromptbookLibrary
|
|
35
|
+
export declare function createPromptbookLibraryFromDirectory(path: string_folder_path, options?: CreatePromptbookLibraryFromDirectoryOptions): Promise<PromptbookLibrary>;
|
|
36
|
+
export {};
|
|
12
37
|
/***
|
|
13
|
-
* TODO: [
|
|
38
|
+
* TODO: [🧠] Maybe do not do hacks like [1] and just create package @promptbook/node
|
|
39
|
+
* [🍓][🚯] maybe make `@promptbook/library` package
|
|
40
|
+
* TODO: Fix the dynamic import issue in Webpack (! Not working !)
|
|
41
|
+
* > ./node_modules/@promptbook/core/esm/index.es.js
|
|
42
|
+
* > Critical dependency: the request of a dependency is an expression
|
|
43
|
+
*
|
|
44
|
+
* Note: [1] Using require(just('fs/promises')) to allow
|
|
45
|
+
* the `@promptbook/core` work for both Node.js and browser environments
|
|
14
46
|
*/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -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
|
/***
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,13 +1,29 @@
|
|
|
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
|
/***
|
|
12
28
|
* TODO: [🍓][🚯] !!! Add to README and samples + maybe make `@promptbook/library` package
|
|
13
29
|
*/
|
|
@@ -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
|
|
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
|
|
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
|
|
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
|
/**
|