@promptbook/openai 0.48.0 → 0.49.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.
- package/README.md +1 -5
- package/esm/index.es.js +1 -1
- package/esm/typings/_packages/utils.index.d.ts +2 -1
- package/esm/typings/conversion/prettify/renderPromptbookMermaid.d.ts +15 -2
- package/esm/typings/conversion/promptbookJsonToString.d.ts +7 -3
- package/esm/typings/conversion/utils/renameParameter.d.ts +25 -0
- package/esm/typings/conversion/validation/_importPromptbook.d.ts +1 -0
- package/esm/typings/conversion/validation/validatePromptbookJson.d.ts +3 -2
- package/esm/typings/types/PromptbookJson/PromptTemplateJson.d.ts +2 -2
- package/esm/typings/utils/markdown/prettifyMarkdown.d.ts +2 -2
- package/package.json +2 -2
- package/umd/index.umd.js +1 -1
- package/umd/typings/_packages/utils.index.d.ts +2 -1
- package/umd/typings/conversion/prettify/renderPromptbookMermaid.d.ts +15 -2
- package/umd/typings/conversion/promptbookJsonToString.d.ts +7 -3
- package/umd/typings/conversion/promptbookStringToJson.test.d.ts +1 -0
- package/umd/typings/conversion/utils/renameParameter.d.ts +25 -0
- package/umd/typings/conversion/utils/renameParameter.test.d.ts +1 -0
- package/umd/typings/conversion/validation/_importPromptbook.d.ts +1 -0
- package/umd/typings/conversion/validation/validatePromptbookJson.d.ts +3 -2
- package/umd/typings/types/PromptbookJson/PromptTemplateJson.d.ts +2 -2
- package/umd/typings/utils/markdown/prettifyMarkdown.d.ts +2 -2
- /package/esm/typings/conversion/{validation/promptbookStringToJson.test.d.ts → promptbookStringToJson.test.d.ts} +0 -0
- /package/{umd/typings/conversion/validation/promptbookStringToJson.test.d.ts → esm/typings/conversion/utils/renameParameter.test.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -5,12 +5,11 @@ Library to supercharge your use of large language models
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
|
|
9
8
|
[ Promptbook](https://badge.fury.io/js/promptbook.svg)](https://www.npmjs.com/package/promptbook)
|
|
10
9
|
[ Promptbook](https://packagequality.com/shield/promptbook.svg)](https://packagequality.com/#?package=promptbook)
|
|
11
10
|
[](https://snyk.io/test/github/webgptorg/promptbook)
|
|
12
11
|
[](https://github.com/webgptorg/promptbook/issues)
|
|
13
|
-
|
|
12
|
+
|
|
14
13
|
|
|
15
14
|
[](https://socket.dev/npm/package/@promptbook/openai)
|
|
16
15
|
|
|
@@ -662,9 +661,6 @@ GPTs are chat assistants that can be assigned to specific tasks and materials. B
|
|
|
662
661
|
|
|
663
662
|
|
|
664
663
|
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
664
|
### Where should I store my promptbooks?
|
|
669
665
|
|
|
670
666
|
If you use raw SDKs, you just put prompts in the sourcecode, mixed in with typescript, javascript, python or whatever programming language you use.
|
package/esm/index.es.js
CHANGED
|
@@ -141,7 +141,7 @@ function computeOpenaiUsage(rawResponse) {
|
|
|
141
141
|
completion: 0.03,
|
|
142
142
|
},
|
|
143
143
|
}[rawResponse.model];
|
|
144
|
-
// TODO:
|
|
144
|
+
// TODO: !!! Retrieve dynamically
|
|
145
145
|
var price;
|
|
146
146
|
if (pricePerThousandTokens === undefined) {
|
|
147
147
|
price = 'UNKNOWN';
|
|
@@ -2,6 +2,7 @@ import { spaceTrim } from 'spacetrim';
|
|
|
2
2
|
import { prettifyPromptbookString } from '../conversion/prettify/prettifyPromptbookString';
|
|
3
3
|
import { renderPromptbookMermaid } from '../conversion/prettify/renderPromptbookMermaid';
|
|
4
4
|
import { parseNumber } from '../conversion/utils/parseNumber';
|
|
5
|
+
import { renameParameter } from '../conversion/utils/renameParameter';
|
|
5
6
|
import { titleToName } from '../conversion/utils/titleToName';
|
|
6
7
|
import { assertsExecutionSuccessful } from '../execution/assertsExecutionSuccessful';
|
|
7
8
|
import { checkExpectations, isPassingExpectations } from '../execution/utils/checkExpectations';
|
|
@@ -58,7 +59,7 @@ export declare const normalizeTo: {
|
|
|
58
59
|
'kebab-case': typeof normalizeToKebabCase;
|
|
59
60
|
};
|
|
60
61
|
export { capitalize, decapitalize, DIACRITIC_VARIANTS_LETTERS, IKeywords, isValidKeyword, nameToUriPart, nameToUriParts, normalizeTo_camelCase, normalizeTo_PascalCase, normalizeTo_SCREAMING_CASE, normalizeTo_snake_case, normalizeToKebabCase, normalizeWhitespaces, parseKeywords, parseKeywordsFromString, removeDiacritics, searchKeywords, string_keyword, titleToName, };
|
|
61
|
-
export { renderPromptbookMermaid };
|
|
62
|
+
export { renameParameter, renderPromptbookMermaid };
|
|
62
63
|
/**
|
|
63
64
|
* TODO: [🧠] Maybe create some indipendent package like `markdown-tools` from both here exported and @private utilities
|
|
64
65
|
* Note: [🕙] It does not make sence to have simple lower / UPPER case normalization
|
|
@@ -1,10 +1,23 @@
|
|
|
1
|
-
import { PromptbookJson } from '../../_packages/types.index';
|
|
1
|
+
import type { PromptbookJson, PromptTemplateJson } from '../../_packages/types.index';
|
|
2
|
+
import type { string_href } from '../../types/typeAliases';
|
|
3
|
+
/**
|
|
4
|
+
* Addtional options for rendering Mermaid graph
|
|
5
|
+
*/
|
|
6
|
+
export type renderPromptbookMermaidOptions = {
|
|
7
|
+
/**
|
|
8
|
+
* Callback for creating from prompt template graph node
|
|
9
|
+
*/
|
|
10
|
+
linkPromptTemplate?(promptTemplate: PromptTemplateJson): {
|
|
11
|
+
href: string_href;
|
|
12
|
+
title: string;
|
|
13
|
+
} | null;
|
|
14
|
+
};
|
|
2
15
|
/**
|
|
3
16
|
* Creates a Mermaid graph based on the promptbook
|
|
4
17
|
*
|
|
5
18
|
* Note: The result is not wrapped in a Markdown code block
|
|
6
19
|
*/
|
|
7
|
-
export declare function renderPromptbookMermaid(promptbookJson: PromptbookJson): string;
|
|
20
|
+
export declare function renderPromptbookMermaid(promptbookJson: PromptbookJson, options?: renderPromptbookMermaidOptions): string;
|
|
8
21
|
/**
|
|
9
22
|
* TODO: Maybe use some Mermaid library instead of string templating
|
|
10
23
|
* TODO: [🕌] When more than 2 functionalities, split into separate functions
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import type { PromptbookJson } from '../types/PromptbookJson/PromptbookJson';
|
|
2
2
|
import type { PromptbookString } from '../types/PromptbookString';
|
|
3
|
+
/**
|
|
4
|
+
* Converts promptbook in JSON format to string format
|
|
5
|
+
*
|
|
6
|
+
* @param promptbookJson Promptbook in JSON format (.ptbk.json)
|
|
7
|
+
* @returns Promptbook in string format (.ptbk.md)
|
|
8
|
+
*/
|
|
3
9
|
export declare function promptbookJsonToString(promptbookJson: PromptbookJson): PromptbookString;
|
|
4
10
|
/**
|
|
5
|
-
* TODO:
|
|
6
|
-
* TODO: !!!!! Annotate and warn
|
|
7
|
-
* TODO: !!!!! Test + test together with promptbookStringToJson
|
|
11
|
+
* TODO: Escape all
|
|
8
12
|
*/
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { PromptbookJson } from '../../types/PromptbookJson/PromptbookJson';
|
|
2
|
+
import type { string_name } from '../../types/typeAliases';
|
|
3
|
+
type RenameParameterOptions = {
|
|
4
|
+
/**
|
|
5
|
+
* Promptbook to search and replace for parameters
|
|
6
|
+
* This promptbook is returned as copy with replaced parameters
|
|
7
|
+
*/
|
|
8
|
+
promptbook: PromptbookJson;
|
|
9
|
+
/**
|
|
10
|
+
* Original parameter name that should be replaced
|
|
11
|
+
*/
|
|
12
|
+
oldParameterName: string_name;
|
|
13
|
+
/**
|
|
14
|
+
* New parameter name that should replace the original parameter name
|
|
15
|
+
*/
|
|
16
|
+
newParameterName: string_name;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Function renameParameter will find all usable parameters for given prompt template
|
|
20
|
+
* In other words, it will find all parameters that are not used in the prompt template itseld and all its dependencies
|
|
21
|
+
*
|
|
22
|
+
* @throws {PromptbookLogicError} If the new parameter name is already used in the promptbook
|
|
23
|
+
*/
|
|
24
|
+
export declare function renameParameter(options: RenameParameterOptions): PromptbookJson;
|
|
25
|
+
export {};
|
|
@@ -6,6 +6,7 @@ import { PromptbookString } from '../../types/PromptbookString';
|
|
|
6
6
|
* Note: Using here custom import to work in jest tests
|
|
7
7
|
* Note: Using sync version is 💩 in the production code, but it's ok here in tests
|
|
8
8
|
*
|
|
9
|
+
* @param path - The path to the file relative to samples/templates directory
|
|
9
10
|
* @private
|
|
10
11
|
*/
|
|
11
12
|
export declare function importPromptbook(path: `${string}.ptbk.md`): PromptbookString;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { PromptbookJson } from '../../types/PromptbookJson/PromptbookJson';
|
|
2
2
|
/**
|
|
3
|
-
* Validates PromptbookJson if it is logically valid
|
|
3
|
+
* Validates PromptbookJson if it is logically valid
|
|
4
4
|
*
|
|
5
5
|
* It checks:
|
|
6
6
|
* - if it has correct parameters dependency
|
|
@@ -10,9 +10,10 @@ import type { PromptbookJson } from '../../types/PromptbookJson/PromptbookJson';
|
|
|
10
10
|
* - if it is meaningful
|
|
11
11
|
*
|
|
12
12
|
* @param promptbook valid or invalid PromptbookJson
|
|
13
|
+
* @returns the same promptbook if it is logically valid
|
|
13
14
|
* @throws {PromptbookLogicError} on logical error in the promptbook
|
|
14
15
|
*/
|
|
15
|
-
export declare function validatePromptbookJson(promptbook: PromptbookJson):
|
|
16
|
+
export declare function validatePromptbookJson(promptbook: PromptbookJson): PromptbookJson;
|
|
16
17
|
/**
|
|
17
18
|
* TODO: [🧠] Work with promptbookVersion
|
|
18
19
|
* TODO: Use here some json-schema, Zod or something similar and change it to:
|
|
@@ -6,7 +6,7 @@ import type { number_integer, number_positive_or_zero, string_javascript, string
|
|
|
6
6
|
/**
|
|
7
7
|
* Describes one prompt template in the promptbook
|
|
8
8
|
*/
|
|
9
|
-
export type PromptTemplateJson = LlmTemplateJson | SimpleTemplateJson |
|
|
9
|
+
export type PromptTemplateJson = LlmTemplateJson | SimpleTemplateJson | ScriptJson | PromptDialogJson;
|
|
10
10
|
/**
|
|
11
11
|
* Template for prompt to LLM
|
|
12
12
|
*/
|
|
@@ -50,7 +50,7 @@ interface SimpleTemplateJson extends PromptTemplateJsonCommon {
|
|
|
50
50
|
/**
|
|
51
51
|
* Template for script execution
|
|
52
52
|
*/
|
|
53
|
-
interface
|
|
53
|
+
interface ScriptJson extends PromptTemplateJsonCommon {
|
|
54
54
|
readonly executionType: 'SCRIPT';
|
|
55
55
|
/**
|
|
56
56
|
* Language of the script
|
|
@@ -2,7 +2,7 @@ import type { string_html } from '../../types/typeAliases';
|
|
|
2
2
|
/**
|
|
3
3
|
* Prettify the html code
|
|
4
4
|
*
|
|
5
|
-
* @param
|
|
5
|
+
* @param content raw html code
|
|
6
6
|
* @returns formatted html code
|
|
7
7
|
*/
|
|
8
|
-
export declare function prettifyMarkdown(
|
|
8
|
+
export declare function prettifyMarkdown<TContent extends string_html>(content: TContent): TContent;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@promptbook/openai",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.49.0",
|
|
4
4
|
"description": "Library to supercharge your use of large language models",
|
|
5
5
|
"private": false,
|
|
6
6
|
"sideEffects": false,
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
}
|
|
49
49
|
],
|
|
50
50
|
"peerDependencies": {
|
|
51
|
-
"@promptbook/core": "0.
|
|
51
|
+
"@promptbook/core": "0.49.0"
|
|
52
52
|
},
|
|
53
53
|
"main": "./umd/index.umd.js",
|
|
54
54
|
"module": "./esm/index.es.js",
|
package/umd/index.umd.js
CHANGED
|
@@ -2,6 +2,7 @@ import { spaceTrim } from 'spacetrim';
|
|
|
2
2
|
import { prettifyPromptbookString } from '../conversion/prettify/prettifyPromptbookString';
|
|
3
3
|
import { renderPromptbookMermaid } from '../conversion/prettify/renderPromptbookMermaid';
|
|
4
4
|
import { parseNumber } from '../conversion/utils/parseNumber';
|
|
5
|
+
import { renameParameter } from '../conversion/utils/renameParameter';
|
|
5
6
|
import { titleToName } from '../conversion/utils/titleToName';
|
|
6
7
|
import { assertsExecutionSuccessful } from '../execution/assertsExecutionSuccessful';
|
|
7
8
|
import { checkExpectations, isPassingExpectations } from '../execution/utils/checkExpectations';
|
|
@@ -58,7 +59,7 @@ export declare const normalizeTo: {
|
|
|
58
59
|
'kebab-case': typeof normalizeToKebabCase;
|
|
59
60
|
};
|
|
60
61
|
export { capitalize, decapitalize, DIACRITIC_VARIANTS_LETTERS, IKeywords, isValidKeyword, nameToUriPart, nameToUriParts, normalizeTo_camelCase, normalizeTo_PascalCase, normalizeTo_SCREAMING_CASE, normalizeTo_snake_case, normalizeToKebabCase, normalizeWhitespaces, parseKeywords, parseKeywordsFromString, removeDiacritics, searchKeywords, string_keyword, titleToName, };
|
|
61
|
-
export { renderPromptbookMermaid };
|
|
62
|
+
export { renameParameter, renderPromptbookMermaid };
|
|
62
63
|
/**
|
|
63
64
|
* TODO: [🧠] Maybe create some indipendent package like `markdown-tools` from both here exported and @private utilities
|
|
64
65
|
* Note: [🕙] It does not make sence to have simple lower / UPPER case normalization
|
|
@@ -1,10 +1,23 @@
|
|
|
1
|
-
import { PromptbookJson } from '../../_packages/types.index';
|
|
1
|
+
import type { PromptbookJson, PromptTemplateJson } from '../../_packages/types.index';
|
|
2
|
+
import type { string_href } from '../../types/typeAliases';
|
|
3
|
+
/**
|
|
4
|
+
* Addtional options for rendering Mermaid graph
|
|
5
|
+
*/
|
|
6
|
+
export type renderPromptbookMermaidOptions = {
|
|
7
|
+
/**
|
|
8
|
+
* Callback for creating from prompt template graph node
|
|
9
|
+
*/
|
|
10
|
+
linkPromptTemplate?(promptTemplate: PromptTemplateJson): {
|
|
11
|
+
href: string_href;
|
|
12
|
+
title: string;
|
|
13
|
+
} | null;
|
|
14
|
+
};
|
|
2
15
|
/**
|
|
3
16
|
* Creates a Mermaid graph based on the promptbook
|
|
4
17
|
*
|
|
5
18
|
* Note: The result is not wrapped in a Markdown code block
|
|
6
19
|
*/
|
|
7
|
-
export declare function renderPromptbookMermaid(promptbookJson: PromptbookJson): string;
|
|
20
|
+
export declare function renderPromptbookMermaid(promptbookJson: PromptbookJson, options?: renderPromptbookMermaidOptions): string;
|
|
8
21
|
/**
|
|
9
22
|
* TODO: Maybe use some Mermaid library instead of string templating
|
|
10
23
|
* TODO: [🕌] When more than 2 functionalities, split into separate functions
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import type { PromptbookJson } from '../types/PromptbookJson/PromptbookJson';
|
|
2
2
|
import type { PromptbookString } from '../types/PromptbookString';
|
|
3
|
+
/**
|
|
4
|
+
* Converts promptbook in JSON format to string format
|
|
5
|
+
*
|
|
6
|
+
* @param promptbookJson Promptbook in JSON format (.ptbk.json)
|
|
7
|
+
* @returns Promptbook in string format (.ptbk.md)
|
|
8
|
+
*/
|
|
3
9
|
export declare function promptbookJsonToString(promptbookJson: PromptbookJson): PromptbookString;
|
|
4
10
|
/**
|
|
5
|
-
* TODO:
|
|
6
|
-
* TODO: !!!!! Annotate and warn
|
|
7
|
-
* TODO: !!!!! Test + test together with promptbookStringToJson
|
|
11
|
+
* TODO: Escape all
|
|
8
12
|
*/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { PromptbookJson } from '../../types/PromptbookJson/PromptbookJson';
|
|
2
|
+
import type { string_name } from '../../types/typeAliases';
|
|
3
|
+
type RenameParameterOptions = {
|
|
4
|
+
/**
|
|
5
|
+
* Promptbook to search and replace for parameters
|
|
6
|
+
* This promptbook is returned as copy with replaced parameters
|
|
7
|
+
*/
|
|
8
|
+
promptbook: PromptbookJson;
|
|
9
|
+
/**
|
|
10
|
+
* Original parameter name that should be replaced
|
|
11
|
+
*/
|
|
12
|
+
oldParameterName: string_name;
|
|
13
|
+
/**
|
|
14
|
+
* New parameter name that should replace the original parameter name
|
|
15
|
+
*/
|
|
16
|
+
newParameterName: string_name;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Function renameParameter will find all usable parameters for given prompt template
|
|
20
|
+
* In other words, it will find all parameters that are not used in the prompt template itseld and all its dependencies
|
|
21
|
+
*
|
|
22
|
+
* @throws {PromptbookLogicError} If the new parameter name is already used in the promptbook
|
|
23
|
+
*/
|
|
24
|
+
export declare function renameParameter(options: RenameParameterOptions): PromptbookJson;
|
|
25
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -6,6 +6,7 @@ import { PromptbookString } from '../../types/PromptbookString';
|
|
|
6
6
|
* Note: Using here custom import to work in jest tests
|
|
7
7
|
* Note: Using sync version is 💩 in the production code, but it's ok here in tests
|
|
8
8
|
*
|
|
9
|
+
* @param path - The path to the file relative to samples/templates directory
|
|
9
10
|
* @private
|
|
10
11
|
*/
|
|
11
12
|
export declare function importPromptbook(path: `${string}.ptbk.md`): PromptbookString;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { PromptbookJson } from '../../types/PromptbookJson/PromptbookJson';
|
|
2
2
|
/**
|
|
3
|
-
* Validates PromptbookJson if it is logically valid
|
|
3
|
+
* Validates PromptbookJson if it is logically valid
|
|
4
4
|
*
|
|
5
5
|
* It checks:
|
|
6
6
|
* - if it has correct parameters dependency
|
|
@@ -10,9 +10,10 @@ import type { PromptbookJson } from '../../types/PromptbookJson/PromptbookJson';
|
|
|
10
10
|
* - if it is meaningful
|
|
11
11
|
*
|
|
12
12
|
* @param promptbook valid or invalid PromptbookJson
|
|
13
|
+
* @returns the same promptbook if it is logically valid
|
|
13
14
|
* @throws {PromptbookLogicError} on logical error in the promptbook
|
|
14
15
|
*/
|
|
15
|
-
export declare function validatePromptbookJson(promptbook: PromptbookJson):
|
|
16
|
+
export declare function validatePromptbookJson(promptbook: PromptbookJson): PromptbookJson;
|
|
16
17
|
/**
|
|
17
18
|
* TODO: [🧠] Work with promptbookVersion
|
|
18
19
|
* TODO: Use here some json-schema, Zod or something similar and change it to:
|
|
@@ -6,7 +6,7 @@ import type { number_integer, number_positive_or_zero, string_javascript, string
|
|
|
6
6
|
/**
|
|
7
7
|
* Describes one prompt template in the promptbook
|
|
8
8
|
*/
|
|
9
|
-
export type PromptTemplateJson = LlmTemplateJson | SimpleTemplateJson |
|
|
9
|
+
export type PromptTemplateJson = LlmTemplateJson | SimpleTemplateJson | ScriptJson | PromptDialogJson;
|
|
10
10
|
/**
|
|
11
11
|
* Template for prompt to LLM
|
|
12
12
|
*/
|
|
@@ -50,7 +50,7 @@ interface SimpleTemplateJson extends PromptTemplateJsonCommon {
|
|
|
50
50
|
/**
|
|
51
51
|
* Template for script execution
|
|
52
52
|
*/
|
|
53
|
-
interface
|
|
53
|
+
interface ScriptJson extends PromptTemplateJsonCommon {
|
|
54
54
|
readonly executionType: 'SCRIPT';
|
|
55
55
|
/**
|
|
56
56
|
* Language of the script
|
|
@@ -2,7 +2,7 @@ import type { string_html } from '../../types/typeAliases';
|
|
|
2
2
|
/**
|
|
3
3
|
* Prettify the html code
|
|
4
4
|
*
|
|
5
|
-
* @param
|
|
5
|
+
* @param content raw html code
|
|
6
6
|
* @returns formatted html code
|
|
7
7
|
*/
|
|
8
|
-
export declare function prettifyMarkdown(
|
|
8
|
+
export declare function prettifyMarkdown<TContent extends string_html>(content: TContent): TContent;
|
|
File without changes
|