@promptbook/openai 0.48.0 → 0.48.1-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/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 +1 -0
- 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/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 +1 -0
- 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/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/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
|
|
@@ -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:
|
|
@@ -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.48.0",
|
|
3
|
+
"version": "0.48.1-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.48.0"
|
|
51
|
+
"@promptbook/core": "0.48.1-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
|
|
@@ -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:
|
|
@@ -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
|