@promptbook/openai 0.52.0-3 → 0.52.0-5
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 +49 -0
- package/esm/typings/_packages/core.index.d.ts +10 -4
- package/esm/typings/_packages/utils.index.d.ts +3 -8
- 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 +1 -1
- package/package.json +2 -2
- package/umd/typings/_packages/core.index.d.ts +10 -4
- package/umd/typings/_packages/utils.index.d.ts +3 -8
- 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 +1 -1
- package/esm/typings/_packages/wizzard.index.d.ts +0 -5
- package/umd/typings/_packages/wizzard.index.d.ts +0 -5
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 { JavascriptEvalExecutionTools } from '@promptbook/execute-javascript';
|
|
46
|
+
import { OpenAiExecutionTools } from '@promptbook/openai';
|
|
47
|
+
|
|
48
|
+
// Create whole Promptbook library
|
|
49
|
+
const library = createPromptbookLibraryFromDirectory('./promptbook');
|
|
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 JavascriptEvalExecutionTools()],
|
|
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
|
|
82
|
+
|
|
83
|
+
See the other models available in the Promptbook package:
|
|
37
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
|
---
|
|
@@ -1,20 +1,26 @@
|
|
|
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 {
|
|
11
|
+
import { checkExpectations, isPassingExpectations } from '../execution/utils/checkExpectations';
|
|
9
12
|
import { createPromptbookLibraryFromPromise } from '../library/constructors/createPromptbookLibraryFromPromise';
|
|
10
13
|
import { createPromptbookLibraryFromSources } from '../library/constructors/createPromptbookLibraryFromSources';
|
|
11
14
|
import { createPromptbookSublibrary } from '../library/constructors/createPromptbookSublibrary';
|
|
15
|
+
import { SimplePromptbookLibrary } from '../library/SimplePromptbookLibrary';
|
|
16
|
+
import { executionReportJsonToString } from '../types/execution-report/executionReportJsonToString';
|
|
17
|
+
import { ExecutionReportStringOptions, ExecutionReportStringOptionsDefaults } from '../types/execution-report/ExecutionReportStringOptions';
|
|
12
18
|
import { ExecutionTypes } from '../types/ExecutionTypes';
|
|
13
19
|
import { PROMPTBOOK_VERSION } from '../version';
|
|
14
|
-
import { MultipleLlmExecutionTools } from '../execution/plugins/llm-execution-tools/multiple/MultipleLlmExecutionTools';
|
|
15
20
|
export { ExecutionTypes, PROMPTBOOK_VERSION };
|
|
21
|
+
export { assertsExecutionSuccessful, checkExpectations, executionReportJsonToString, ExecutionReportStringOptions, ExecutionReportStringOptionsDefaults, isPassingExpectations, prettifyPromptbookString, };
|
|
16
22
|
export { createPromptbookLibraryFromPromise, createPromptbookLibraryFromSources, createPromptbookSublibrary, SimplePromptbookLibrary, };
|
|
17
23
|
export { SimplePromptInterfaceTools };
|
|
18
|
-
export {
|
|
24
|
+
export { promptbookJsonToString, promptbookStringToJson, validatePromptbookJson };
|
|
19
25
|
export { createPromptbookExecutor, MultipleLlmExecutionTools };
|
|
20
26
|
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: {
|
|
@@ -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
|
*/
|
|
@@ -7,7 +7,7 @@ import { JavascriptExecutionToolsOptions } from './JavascriptExecutionToolsOptio
|
|
|
7
7
|
*/
|
|
8
8
|
export declare class JavascriptExecutionTools implements ScriptExecutionTools {
|
|
9
9
|
private readonly options;
|
|
10
|
-
constructor(options
|
|
10
|
+
constructor(options?: JavascriptExecutionToolsOptions);
|
|
11
11
|
/**
|
|
12
12
|
* Executes a JavaScript
|
|
13
13
|
*/
|
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-5",
|
|
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-5"
|
|
52
52
|
},
|
|
53
53
|
"main": "./umd/index.umd.js",
|
|
54
54
|
"module": "./esm/index.es.js",
|
|
@@ -1,20 +1,26 @@
|
|
|
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 {
|
|
11
|
+
import { checkExpectations, isPassingExpectations } from '../execution/utils/checkExpectations';
|
|
9
12
|
import { createPromptbookLibraryFromPromise } from '../library/constructors/createPromptbookLibraryFromPromise';
|
|
10
13
|
import { createPromptbookLibraryFromSources } from '../library/constructors/createPromptbookLibraryFromSources';
|
|
11
14
|
import { createPromptbookSublibrary } from '../library/constructors/createPromptbookSublibrary';
|
|
15
|
+
import { SimplePromptbookLibrary } from '../library/SimplePromptbookLibrary';
|
|
16
|
+
import { executionReportJsonToString } from '../types/execution-report/executionReportJsonToString';
|
|
17
|
+
import { ExecutionReportStringOptions, ExecutionReportStringOptionsDefaults } from '../types/execution-report/ExecutionReportStringOptions';
|
|
12
18
|
import { ExecutionTypes } from '../types/ExecutionTypes';
|
|
13
19
|
import { PROMPTBOOK_VERSION } from '../version';
|
|
14
|
-
import { MultipleLlmExecutionTools } from '../execution/plugins/llm-execution-tools/multiple/MultipleLlmExecutionTools';
|
|
15
20
|
export { ExecutionTypes, PROMPTBOOK_VERSION };
|
|
21
|
+
export { assertsExecutionSuccessful, checkExpectations, executionReportJsonToString, ExecutionReportStringOptions, ExecutionReportStringOptionsDefaults, isPassingExpectations, prettifyPromptbookString, };
|
|
16
22
|
export { createPromptbookLibraryFromPromise, createPromptbookLibraryFromSources, createPromptbookSublibrary, SimplePromptbookLibrary, };
|
|
17
23
|
export { SimplePromptInterfaceTools };
|
|
18
|
-
export {
|
|
24
|
+
export { promptbookJsonToString, promptbookStringToJson, validatePromptbookJson };
|
|
19
25
|
export { createPromptbookExecutor, MultipleLlmExecutionTools };
|
|
20
26
|
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: {
|
|
@@ -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
|
*/
|
|
@@ -7,7 +7,7 @@ import { JavascriptExecutionToolsOptions } from './JavascriptExecutionToolsOptio
|
|
|
7
7
|
*/
|
|
8
8
|
export declare class JavascriptExecutionTools implements ScriptExecutionTools {
|
|
9
9
|
private readonly options;
|
|
10
|
-
constructor(options
|
|
10
|
+
constructor(options?: JavascriptExecutionToolsOptions);
|
|
11
11
|
/**
|
|
12
12
|
* Executes a JavaScript
|
|
13
13
|
*/
|