@promptbook/openai 0.40.1-1 → 0.41.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.
@@ -15,6 +15,7 @@ import { extractAllListItemsFromMarkdown } from '../utils/markdown/extractAllLis
15
15
  import { extractOneBlockFromMarkdown } from '../utils/markdown/extractOneBlockFromMarkdown';
16
16
  import { removeContentComments } from '../utils/markdown/removeContentComments';
17
17
  import { removeMarkdownFormatting } from '../utils/markdown/removeMarkdownFormatting';
18
+ import { extractBlock } from '../utils/postprocessing/extractBlock';
18
19
  import { removeEmojis } from '../utils/removeEmojis';
19
20
  import { removeQuotes } from '../utils/removeQuotes';
20
21
  import { trimCodeBlock } from '../utils/trimCodeBlock';
@@ -23,7 +24,7 @@ import { unwrapResult } from '../utils/unwrapResult';
23
24
  export { CountUtils, ExecutionReportStringOptions, ExecutionReportStringOptionsDefaults, assertsExecutionSuccessful, countCharacters, countLines, countPages, countParagraphs, countSentences, countWords, executionReportJsonToString, extractAllBlocksFromMarkdown, // <- [🌻]
24
25
  extractAllListItemsFromMarkdown, // <- [🌻]
25
26
  extractOneBlockFromMarkdown, // <- [🌻]
26
- isValidJsonString, parseNumber, removeContentComments, removeEmojis, removeMarkdownFormatting, removeQuotes, trimCodeBlock, trimEndOfCodeBlock, unwrapResult, };
27
+ extractBlock, isValidJsonString, parseNumber, removeContentComments, removeEmojis, removeMarkdownFormatting, removeQuotes, trimCodeBlock, trimEndOfCodeBlock, unwrapResult, };
27
28
  /**
28
29
  * TODO: [🧠] Maybe create some indipendent package like `markdown-tools` from both here exported and @private utilities
29
30
  */
@@ -2,7 +2,7 @@ import { string_markdown } from '../../types/typeAliases';
2
2
  /**
3
3
  * Single code block inside markdown.
4
4
  */
5
- type CodeBlock = {
5
+ export type CodeBlock = {
6
6
  /**
7
7
  * Language of the code block OR null if the language is not specified in opening ```
8
8
  */
@@ -15,8 +15,13 @@ type CodeBlock = {
15
15
  /**
16
16
  * Extracts all code blocks from markdown.
17
17
  *
18
+ * Note: There are 3 simmilar function:
19
+ * - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
20
+ * - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
21
+ * - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
22
+ *
18
23
  * @param markdown any valid markdown
19
24
  * @returns code blocks with language and content
25
+ *
20
26
  */
21
27
  export declare function extractAllBlocksFromMarkdown(markdown: string_markdown): Array<CodeBlock>;
22
- export {};
@@ -1,17 +1,19 @@
1
1
  import { string_markdown } from '../.././types/typeAliases';
2
+ import { CodeBlock } from './extractAllBlocksFromMarkdown';
2
3
  /**
3
4
  * Extracts exactly ONE code block from markdown.
4
5
  *
5
- * Note: This function is similar to extractAllBlocksFromMarkdown but it validates that there is exactly one code block.
6
6
  * Note: If there are multiple or no code blocks the function throws an error
7
7
  *
8
+ * Note: There are 3 simmilar function:
9
+ * - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
10
+ * - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
11
+ * - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
12
+ *
8
13
  * @param markdown any valid markdown
9
14
  * @returns code block with language and content
10
15
  */
11
- export declare function extractOneBlockFromMarkdown(markdown: string_markdown): {
12
- language: string | null;
13
- content: string;
14
- };
16
+ export declare function extractOneBlockFromMarkdown(markdown: string_markdown): CodeBlock;
15
17
  /***
16
18
  * TODO: [🌻] !!! Decide of this is internal util, external util OR validator/postprocessor
17
19
  */
@@ -0,0 +1,12 @@
1
+ import { string_markdown } from '../../types/typeAliases';
2
+ /**
3
+ * Extracts code block from markdown.
4
+ *
5
+ * Note: If there are multiple or no code blocks the function throws an error
6
+ *
7
+ * Note: There are 3 simmilar function:
8
+ * - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
9
+ * - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
10
+ * - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
11
+ */
12
+ export declare function extractBlock(markdown: string_markdown): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/openai",
3
- "version": "0.40.1-1",
3
+ "version": "0.41.0",
4
4
  "description": "Library to supercharge your use of large language models",
5
5
  "private": false,
6
6
  "sideEffects": false,
@@ -38,7 +38,7 @@
38
38
  "openai": "4.2.0"
39
39
  },
40
40
  "peerDependencies": {
41
- "@promptbook/core": "0.40.1-1"
41
+ "@promptbook/core": "0.41.0"
42
42
  },
43
43
  "main": "./umd/index.umd.js",
44
44
  "module": "./esm/index.es.js",
@@ -15,6 +15,7 @@ import { extractAllListItemsFromMarkdown } from '../utils/markdown/extractAllLis
15
15
  import { extractOneBlockFromMarkdown } from '../utils/markdown/extractOneBlockFromMarkdown';
16
16
  import { removeContentComments } from '../utils/markdown/removeContentComments';
17
17
  import { removeMarkdownFormatting } from '../utils/markdown/removeMarkdownFormatting';
18
+ import { extractBlock } from '../utils/postprocessing/extractBlock';
18
19
  import { removeEmojis } from '../utils/removeEmojis';
19
20
  import { removeQuotes } from '../utils/removeQuotes';
20
21
  import { trimCodeBlock } from '../utils/trimCodeBlock';
@@ -23,7 +24,7 @@ import { unwrapResult } from '../utils/unwrapResult';
23
24
  export { CountUtils, ExecutionReportStringOptions, ExecutionReportStringOptionsDefaults, assertsExecutionSuccessful, countCharacters, countLines, countPages, countParagraphs, countSentences, countWords, executionReportJsonToString, extractAllBlocksFromMarkdown, // <- [🌻]
24
25
  extractAllListItemsFromMarkdown, // <- [🌻]
25
26
  extractOneBlockFromMarkdown, // <- [🌻]
26
- isValidJsonString, parseNumber, removeContentComments, removeEmojis, removeMarkdownFormatting, removeQuotes, trimCodeBlock, trimEndOfCodeBlock, unwrapResult, };
27
+ extractBlock, isValidJsonString, parseNumber, removeContentComments, removeEmojis, removeMarkdownFormatting, removeQuotes, trimCodeBlock, trimEndOfCodeBlock, unwrapResult, };
27
28
  /**
28
29
  * TODO: [🧠] Maybe create some indipendent package like `markdown-tools` from both here exported and @private utilities
29
30
  */
@@ -2,7 +2,7 @@ import { string_markdown } from '../../types/typeAliases';
2
2
  /**
3
3
  * Single code block inside markdown.
4
4
  */
5
- type CodeBlock = {
5
+ export type CodeBlock = {
6
6
  /**
7
7
  * Language of the code block OR null if the language is not specified in opening ```
8
8
  */
@@ -15,8 +15,13 @@ type CodeBlock = {
15
15
  /**
16
16
  * Extracts all code blocks from markdown.
17
17
  *
18
+ * Note: There are 3 simmilar function:
19
+ * - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
20
+ * - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
21
+ * - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
22
+ *
18
23
  * @param markdown any valid markdown
19
24
  * @returns code blocks with language and content
25
+ *
20
26
  */
21
27
  export declare function extractAllBlocksFromMarkdown(markdown: string_markdown): Array<CodeBlock>;
22
- export {};
@@ -1,17 +1,19 @@
1
1
  import { string_markdown } from '../.././types/typeAliases';
2
+ import { CodeBlock } from './extractAllBlocksFromMarkdown';
2
3
  /**
3
4
  * Extracts exactly ONE code block from markdown.
4
5
  *
5
- * Note: This function is similar to extractAllBlocksFromMarkdown but it validates that there is exactly one code block.
6
6
  * Note: If there are multiple or no code blocks the function throws an error
7
7
  *
8
+ * Note: There are 3 simmilar function:
9
+ * - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
10
+ * - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
11
+ * - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
12
+ *
8
13
  * @param markdown any valid markdown
9
14
  * @returns code block with language and content
10
15
  */
11
- export declare function extractOneBlockFromMarkdown(markdown: string_markdown): {
12
- language: string | null;
13
- content: string;
14
- };
16
+ export declare function extractOneBlockFromMarkdown(markdown: string_markdown): CodeBlock;
15
17
  /***
16
18
  * TODO: [🌻] !!! Decide of this is internal util, external util OR validator/postprocessor
17
19
  */
@@ -0,0 +1,12 @@
1
+ import { string_markdown } from '../../types/typeAliases';
2
+ /**
3
+ * Extracts code block from markdown.
4
+ *
5
+ * Note: If there are multiple or no code blocks the function throws an error
6
+ *
7
+ * Note: There are 3 simmilar function:
8
+ * - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
9
+ * - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
10
+ * - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
11
+ */
12
+ export declare function extractBlock(markdown: string_markdown): string;