@promptbook/utils 0.46.0 → 0.47.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 +18 -8
- package/esm/index.es.js +53 -39
- package/esm/index.es.js.map +1 -1
- package/esm/typings/_packages/langtail.index.d.ts +2 -2
- package/esm/typings/_packages/mock.index.d.ts +3 -3
- package/esm/typings/_packages/openai.index.d.ts +2 -2
- package/esm/typings/_packages/remote-client.index.d.ts +4 -4
- package/esm/typings/_packages/remote-server.index.d.ts +2 -2
- package/esm/typings/_packages/types.index.d.ts +2 -2
- package/esm/typings/_packages/utils.index.d.ts +2 -0
- package/esm/typings/conversion/prettify/PrettifyOptions.d.ts +9 -3
- package/esm/typings/conversion/prettify/prettifyPromptbookString.d.ts +1 -1
- package/esm/typings/conversion/prettify/renderPromptbookMermaid.d.ts +11 -0
- package/esm/typings/execution/ExecutionTools.d.ts +5 -2
- package/esm/typings/execution/{NaturalExecutionTools.d.ts → LlmExecutionTools.d.ts} +2 -2
- package/{umd/typings/execution/plugins/natural-execution-tools → esm/typings/execution/plugins/llm-execution-tools}/langtail/LangtailExecutionTools.d.ts +2 -2
- package/{umd/typings/execution/plugins/natural-execution-tools/mocked/MockedEchoNaturalExecutionTools.d.ts → esm/typings/execution/plugins/llm-execution-tools/mocked/MockedEchoLlmExecutionTools.d.ts} +2 -2
- package/{umd/typings/execution/plugins/natural-execution-tools/mocked/MockedFackedNaturalExecutionTools.d.ts → esm/typings/execution/plugins/llm-execution-tools/mocked/MockedFackedLlmExecutionTools.d.ts} +2 -2
- package/{umd/typings/execution/plugins/natural-execution-tools → esm/typings/execution/plugins/llm-execution-tools}/mocked/fakeTextToExpectations.d.ts +1 -1
- package/esm/typings/execution/plugins/{natural-execution-tools → llm-execution-tools}/openai/OpenAiExecutionTools.d.ts +2 -2
- package/esm/typings/execution/plugins/{natural-execution-tools/remote/RemoteNaturalExecutionTools.d.ts → llm-execution-tools/remote/RemoteLlmExecutionTools.d.ts} +5 -5
- package/esm/typings/execution/plugins/{natural-execution-tools/remote/RemoteNaturalExecutionToolsOptions.d.ts → llm-execution-tools/remote/RemoteLlmExecutionToolsOptions.d.ts} +3 -3
- package/{umd/typings/execution/plugins/natural-execution-tools → esm/typings/execution/plugins/llm-execution-tools}/remote/interfaces/RemoteServerOptions.d.ts +3 -3
- package/esm/typings/types/PromptbookJson/PromptTemplateJson.d.ts +2 -2
- package/package.json +13 -3
- package/umd/index.umd.js +53 -38
- package/umd/index.umd.js.map +1 -1
- package/umd/typings/_packages/langtail.index.d.ts +2 -2
- package/umd/typings/_packages/mock.index.d.ts +3 -3
- package/umd/typings/_packages/openai.index.d.ts +2 -2
- package/umd/typings/_packages/remote-client.index.d.ts +4 -4
- package/umd/typings/_packages/remote-server.index.d.ts +2 -2
- package/umd/typings/_packages/types.index.d.ts +2 -2
- package/umd/typings/_packages/utils.index.d.ts +2 -0
- package/umd/typings/conversion/prettify/PrettifyOptions.d.ts +9 -3
- package/umd/typings/conversion/prettify/prettifyPromptbookString.d.ts +1 -1
- package/umd/typings/conversion/prettify/renderPromptbookMermaid.d.ts +11 -0
- package/umd/typings/execution/ExecutionTools.d.ts +5 -2
- package/umd/typings/execution/{NaturalExecutionTools.d.ts → LlmExecutionTools.d.ts} +2 -2
- package/{esm/typings/execution/plugins/natural-execution-tools → umd/typings/execution/plugins/llm-execution-tools}/langtail/LangtailExecutionTools.d.ts +2 -2
- package/{esm/typings/execution/plugins/natural-execution-tools/mocked/MockedEchoNaturalExecutionTools.d.ts → umd/typings/execution/plugins/llm-execution-tools/mocked/MockedEchoLlmExecutionTools.d.ts} +2 -2
- package/{esm/typings/execution/plugins/natural-execution-tools/mocked/MockedFackedNaturalExecutionTools.d.ts → umd/typings/execution/plugins/llm-execution-tools/mocked/MockedFackedLlmExecutionTools.d.ts} +2 -2
- package/{esm/typings/execution/plugins/natural-execution-tools → umd/typings/execution/plugins/llm-execution-tools}/mocked/fakeTextToExpectations.d.ts +1 -1
- package/umd/typings/execution/plugins/{natural-execution-tools → llm-execution-tools}/openai/OpenAiExecutionTools.d.ts +2 -2
- package/umd/typings/execution/plugins/{natural-execution-tools/remote/RemoteNaturalExecutionTools.d.ts → llm-execution-tools/remote/RemoteLlmExecutionTools.d.ts} +5 -5
- package/umd/typings/execution/plugins/{natural-execution-tools/remote/RemoteNaturalExecutionToolsOptions.d.ts → llm-execution-tools/remote/RemoteLlmExecutionToolsOptions.d.ts} +3 -3
- package/{esm/typings/execution/plugins/natural-execution-tools → umd/typings/execution/plugins/llm-execution-tools}/remote/interfaces/RemoteServerOptions.d.ts +3 -3
- package/umd/typings/types/PromptbookJson/PromptTemplateJson.d.ts +2 -2
- /package/esm/typings/execution/plugins/{natural-execution-tools → llm-execution-tools}/langtail/LangtailExecutionToolsOptions.d.ts +0 -0
- /package/esm/typings/execution/plugins/{natural-execution-tools → llm-execution-tools}/mocked/fakeTextToExpectations.test.d.ts +0 -0
- /package/esm/typings/execution/plugins/{natural-execution-tools → llm-execution-tools}/mocked/faked-completion.test.d.ts +0 -0
- /package/esm/typings/execution/plugins/{natural-execution-tools → llm-execution-tools}/mocked/joker.test.d.ts +0 -0
- /package/esm/typings/execution/plugins/{natural-execution-tools → llm-execution-tools}/mocked/mocked-chat.test.d.ts +0 -0
- /package/esm/typings/execution/plugins/{natural-execution-tools → llm-execution-tools}/mocked/mocked-completion.test.d.ts +0 -0
- /package/esm/typings/execution/plugins/{natural-execution-tools → llm-execution-tools}/openai/OpenAiExecutionToolsOptions.d.ts +0 -0
- /package/esm/typings/execution/plugins/{natural-execution-tools → llm-execution-tools}/openai/computeOpenaiUsage.d.ts +0 -0
- /package/esm/typings/execution/plugins/{natural-execution-tools → llm-execution-tools}/remote/interfaces/Promptbook_Server_Error.d.ts +0 -0
- /package/esm/typings/execution/plugins/{natural-execution-tools → llm-execution-tools}/remote/interfaces/Promptbook_Server_Progress.d.ts +0 -0
- /package/esm/typings/execution/plugins/{natural-execution-tools → llm-execution-tools}/remote/interfaces/Promptbook_Server_Request.d.ts +0 -0
- /package/esm/typings/execution/plugins/{natural-execution-tools → llm-execution-tools}/remote/interfaces/Promptbook_Server_Response.d.ts +0 -0
- /package/esm/typings/execution/plugins/{natural-execution-tools → llm-execution-tools}/remote/startRemoteServer.d.ts +0 -0
- /package/umd/typings/execution/plugins/{natural-execution-tools → llm-execution-tools}/langtail/LangtailExecutionToolsOptions.d.ts +0 -0
- /package/umd/typings/execution/plugins/{natural-execution-tools → llm-execution-tools}/mocked/fakeTextToExpectations.test.d.ts +0 -0
- /package/umd/typings/execution/plugins/{natural-execution-tools → llm-execution-tools}/mocked/faked-completion.test.d.ts +0 -0
- /package/umd/typings/execution/plugins/{natural-execution-tools → llm-execution-tools}/mocked/joker.test.d.ts +0 -0
- /package/umd/typings/execution/plugins/{natural-execution-tools → llm-execution-tools}/mocked/mocked-chat.test.d.ts +0 -0
- /package/umd/typings/execution/plugins/{natural-execution-tools → llm-execution-tools}/mocked/mocked-completion.test.d.ts +0 -0
- /package/umd/typings/execution/plugins/{natural-execution-tools → llm-execution-tools}/openai/OpenAiExecutionToolsOptions.d.ts +0 -0
- /package/umd/typings/execution/plugins/{natural-execution-tools → llm-execution-tools}/openai/computeOpenaiUsage.d.ts +0 -0
- /package/umd/typings/execution/plugins/{natural-execution-tools → llm-execution-tools}/remote/interfaces/Promptbook_Server_Error.d.ts +0 -0
- /package/umd/typings/execution/plugins/{natural-execution-tools → llm-execution-tools}/remote/interfaces/Promptbook_Server_Progress.d.ts +0 -0
- /package/umd/typings/execution/plugins/{natural-execution-tools → llm-execution-tools}/remote/interfaces/Promptbook_Server_Request.d.ts +0 -0
- /package/umd/typings/execution/plugins/{natural-execution-tools → llm-execution-tools}/remote/interfaces/Promptbook_Server_Response.d.ts +0 -0
- /package/umd/typings/execution/plugins/{natural-execution-tools → llm-execution-tools}/remote/startRemoteServer.d.ts +0 -0
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { RemoteServerOptions } from '../execution/plugins/
|
|
2
|
-
import { startRemoteServer } from '../execution/plugins/
|
|
1
|
+
import { RemoteServerOptions } from '../execution/plugins/llm-execution-tools/remote/interfaces/RemoteServerOptions';
|
|
2
|
+
import { startRemoteServer } from '../execution/plugins/llm-execution-tools/remote/startRemoteServer';
|
|
3
3
|
export { RemoteServerOptions, startRemoteServer };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { CommonExecutionToolsOptions } from '../execution/CommonExecutionToolsOptions';
|
|
2
2
|
import type { ExecutionTools } from '../execution/ExecutionTools';
|
|
3
|
-
import type {
|
|
3
|
+
import type { LlmExecutionTools } from '../execution/LlmExecutionTools';
|
|
4
4
|
import type { PromptChatResult, PromptCommonResult, PromptCompletionResult, PromptResult } from '../execution/PromptResult';
|
|
5
5
|
import type { PromptbookExecutor } from '../execution/PromptbookExecutor';
|
|
6
6
|
import type { ScriptExecutionTools, ScriptExecutionToolsExecuteOptions } from '../execution/ScriptExecutionTools';
|
|
@@ -20,7 +20,7 @@ import type { ExecutionReportJson } from '../types/execution-report/ExecutionRep
|
|
|
20
20
|
import type { string_char_emoji } from '../types/typeAliasEmoji';
|
|
21
21
|
import type { client_id, string_char, string_chat_prompt, string_completion_prompt, string_data_url, string_domain, string_email, string_file_absolute_path, string_file_extension, string_file_path, string_file_relative_path, string_filename, string_folder_absolute_path, string_folder_path, string_folder_relative_path, string_host, string_hostname, string_href, string_html, string_javascript, string_javascript_name, string_license, string_markdown, string_markdown_text, string_mime_type, string_mime_type_with_wildcard, string_model_name, string_name, string_person_fullname, string_prompt, string_promptbook_url, string_promptbook_url_with_hashtemplate, string_script, string_sha256, string_tdl, string_template, string_text_prompt, string_title, string_token, string_translate_language, string_uri, string_uri_part, string_url, string_url_image, string_version } from '../types/typeAliases';
|
|
22
22
|
import { FromtoItems } from '../utils/FromtoItems';
|
|
23
|
-
export {
|
|
23
|
+
export { client_id, CommonExecutionToolsOptions, ExecutionReportJson, ExecutionTools, ExecutionType, EXPECTATION_UNITS, ExpectationAmount, ExpectationUnit, FromtoItems, LlmExecutionTools as LlmExecutionTools, ModelRequirements, ModelVariant, Parameters, Prompt, PromptbookExecutor, PromptbookJson, PromptbookLibrary, PromptbookString, PromptChatResult, PromptCommonResult, PromptCompletionResult, PromptResult, PromptTemplateJson, PromptTemplateParameterJson, ScriptExecutionTools, ScriptExecutionToolsExecuteOptions, ScriptLanguage, string_char, string_char_emoji, string_chat_prompt, string_completion_prompt, string_data_url, string_domain, string_email, string_file_absolute_path, string_file_extension, string_file_path, string_file_relative_path, string_filename, string_folder_absolute_path, string_folder_path, string_folder_relative_path, string_host, string_hostname, string_href, string_html, string_javascript, string_javascript_name, string_license, string_markdown, string_markdown_text, string_mime_type, string_mime_type_with_wildcard, string_model_name, string_name, string_person_fullname, string_prompt, string_promptbook_url, string_promptbook_url_with_hashtemplate, string_script, string_sha256, string_tdl, string_template, string_text_prompt, string_title, string_token, string_translate_language, string_uri, string_uri_part, string_url, string_url_image, string_version, TaskProgress, UserInterfaceTools, UserInterfaceToolsPromptDialogOptions, };
|
|
24
24
|
/**
|
|
25
25
|
* TODO: [🧠][🆔] Is this the best package to export custom errors from?
|
|
26
26
|
* TODO: Delete type aliases (from ../types/typeAliases) that are not exported here
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { spaceTrim } from 'spacetrim';
|
|
2
2
|
import { prettifyPromptbookString } from '../conversion/prettify/prettifyPromptbookString';
|
|
3
|
+
import { renderPromptbookMermaid } from '../conversion/prettify/renderPromptbookMermaid';
|
|
3
4
|
import { parseNumber } from '../conversion/utils/parseNumber';
|
|
4
5
|
import { assertsExecutionSuccessful } from '../execution/assertsExecutionSuccessful';
|
|
5
6
|
import { checkExpectations, isPassingExpectations } from '../execution/utils/checkExpectations';
|
|
@@ -56,6 +57,7 @@ export declare const normalizeTo: {
|
|
|
56
57
|
'kebab-case': typeof normalizeToKebabCase;
|
|
57
58
|
};
|
|
58
59
|
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, };
|
|
60
|
+
export { renderPromptbookMermaid };
|
|
59
61
|
/**
|
|
60
62
|
* TODO: [🧠] Maybe create some indipendent package like `markdown-tools` from both here exported and @private utilities
|
|
61
63
|
* Note: [🕙] It does not make sence to have simple lower / UPPER case normalization
|
|
@@ -1,7 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for `prettifyPromptbookString` function
|
|
3
|
+
*/
|
|
1
4
|
export type PrettifyOptions = {
|
|
5
|
+
/***
|
|
6
|
+
* If true, adds Mermaid graph to the Promptbook string
|
|
7
|
+
*/
|
|
2
8
|
isGraphAdded?: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* If true, the string is prettifyed as markdown
|
|
11
|
+
*/
|
|
3
12
|
isPrettifyed?: boolean;
|
|
4
13
|
};
|
|
5
|
-
/**
|
|
6
|
-
* TODO: !!! Annotate all
|
|
7
|
-
*/
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PromptbookString } from '../../types/PromptbookString';
|
|
2
2
|
import type { PrettifyOptions } from './PrettifyOptions';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Prettyfies Promptbook string and adds Mermaid graph
|
|
5
5
|
*/
|
|
6
6
|
export declare function prettifyPromptbookString(promptbookString: PromptbookString, options: PrettifyOptions): PromptbookString;
|
|
7
7
|
/**
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { PromptbookJson } from '../../_packages/types.index';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a Mermaid graph based on the promptbook
|
|
4
|
+
*
|
|
5
|
+
* Note: The result is not wrapped in a Markdown code block
|
|
6
|
+
*/
|
|
7
|
+
export declare function renderPromptbookMermaid(promptbookJson: PromptbookJson): string;
|
|
8
|
+
/**
|
|
9
|
+
* TODO: Maybe use some Mermaid library instead of string templating
|
|
10
|
+
* TODO: [🕌] When more than 2 functionalities, split into separate functions
|
|
11
|
+
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { LlmExecutionTools } from './LlmExecutionTools';
|
|
2
2
|
import type { ScriptExecutionTools } from './ScriptExecutionTools';
|
|
3
3
|
import type { UserInterfaceTools } from './UserInterfaceTools';
|
|
4
4
|
/**
|
|
@@ -10,7 +10,7 @@ export type ExecutionTools = {
|
|
|
10
10
|
/**
|
|
11
11
|
* Tools for executing prompts to large language models like GPT-4
|
|
12
12
|
*/
|
|
13
|
-
|
|
13
|
+
llm: LlmExecutionTools;
|
|
14
14
|
/**
|
|
15
15
|
* Tools for executing scripts
|
|
16
16
|
*
|
|
@@ -23,3 +23,6 @@ export type ExecutionTools = {
|
|
|
23
23
|
*/
|
|
24
24
|
userInterface: UserInterfaceTools;
|
|
25
25
|
};
|
|
26
|
+
/**
|
|
27
|
+
* TODO: !!!! Allow more
|
|
28
|
+
*/
|
|
@@ -5,9 +5,9 @@ import type { PromptChatResult, PromptCompletionResult } from './PromptResult';
|
|
|
5
5
|
* On its interface it exposes common methods for prompt execution.
|
|
6
6
|
* Inside (in constructor) it calls OpenAI, Azure, GPU, proxy, cache, logging,...
|
|
7
7
|
*
|
|
8
|
-
* @see https://github.com/webgptorg/promptbook#
|
|
8
|
+
* @see https://github.com/webgptorg/promptbook#llm-execution-tools
|
|
9
9
|
*/
|
|
10
|
-
export type
|
|
10
|
+
export type LlmExecutionTools = {
|
|
11
11
|
/**
|
|
12
12
|
* Use a chat model
|
|
13
13
|
*/
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { LlmExecutionTools } from '../../../LlmExecutionTools';
|
|
2
2
|
import { OpenAiExecutionTools } from '../openai/OpenAiExecutionTools';
|
|
3
3
|
/**
|
|
4
4
|
* Execution Tools for calling OpenAI API.
|
|
5
5
|
*/
|
|
6
|
-
export declare class LangtailExecutionTools extends OpenAiExecutionTools implements
|
|
6
|
+
export declare class LangtailExecutionTools extends OpenAiExecutionTools implements LlmExecutionTools {
|
|
7
7
|
}
|
|
8
8
|
/**
|
|
9
9
|
* TODO: !!! Make lib which exports this
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Prompt } from '../../../../types/Prompt';
|
|
2
2
|
import { CommonExecutionToolsOptions } from '../../../CommonExecutionToolsOptions';
|
|
3
|
-
import {
|
|
3
|
+
import { LlmExecutionTools } from '../../../LlmExecutionTools';
|
|
4
4
|
import { PromptChatResult, PromptCompletionResult } from '../../../PromptResult';
|
|
5
5
|
/**
|
|
6
6
|
* Mocked execution Tools for just echoing the requests for testing purposes.
|
|
7
7
|
*/
|
|
8
|
-
export declare class
|
|
8
|
+
export declare class MockedEchoLlmExecutionTools implements LlmExecutionTools {
|
|
9
9
|
private readonly options;
|
|
10
10
|
constructor(options: CommonExecutionToolsOptions);
|
|
11
11
|
/**
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Prompt } from '../../../../types/Prompt';
|
|
2
2
|
import { CommonExecutionToolsOptions } from '../../../CommonExecutionToolsOptions';
|
|
3
|
-
import {
|
|
3
|
+
import { LlmExecutionTools } from '../../../LlmExecutionTools';
|
|
4
4
|
import { PromptChatResult, PromptCompletionResult } from '../../../PromptResult';
|
|
5
5
|
/**
|
|
6
6
|
* Mocked execution Tools for just faking expected responses for testing purposes
|
|
7
7
|
*/
|
|
8
|
-
export declare class
|
|
8
|
+
export declare class MockedFackedLlmExecutionTools implements LlmExecutionTools {
|
|
9
9
|
private readonly options;
|
|
10
10
|
constructor(options: CommonExecutionToolsOptions);
|
|
11
11
|
/**
|
|
@@ -6,7 +6,7 @@ import { PostprocessingFunction } from '../../script-execution-tools/javascript/
|
|
|
6
6
|
* Note: You can provide postprocessing functions to modify the text before checking the expectations
|
|
7
7
|
* The result will be the text BEFORE the postprocessing
|
|
8
8
|
*
|
|
9
|
-
* @private internal util for
|
|
9
|
+
* @private internal util for MockedFackedLlmExecutionTools
|
|
10
10
|
*/
|
|
11
11
|
export declare function $fakeTextToExpectations(expectations: Expectations, postprocessing?: Array<PostprocessingFunction>): Promise<string>;
|
|
12
12
|
/**
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { Prompt } from '../../../../types/Prompt';
|
|
2
|
-
import type {
|
|
2
|
+
import type { LlmExecutionTools } from '../../../LlmExecutionTools';
|
|
3
3
|
import type { PromptChatResult, PromptCompletionResult } from '../../../PromptResult';
|
|
4
4
|
import type { OpenAiExecutionToolsOptions } from './OpenAiExecutionToolsOptions';
|
|
5
5
|
/**
|
|
6
6
|
* Execution Tools for calling OpenAI API.
|
|
7
7
|
*/
|
|
8
|
-
export declare class OpenAiExecutionTools implements
|
|
8
|
+
export declare class OpenAiExecutionTools implements LlmExecutionTools {
|
|
9
9
|
private readonly options;
|
|
10
10
|
/**
|
|
11
11
|
* OpenAI API client.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Prompt } from '../../../../types/Prompt';
|
|
2
|
-
import {
|
|
2
|
+
import { LlmExecutionTools } from '../../../LlmExecutionTools';
|
|
3
3
|
import { PromptChatResult, PromptCompletionResult } from '../../../PromptResult';
|
|
4
|
-
import {
|
|
4
|
+
import { RemoteLlmExecutionToolsOptions } from './RemoteLlmExecutionToolsOptions';
|
|
5
5
|
/**
|
|
6
6
|
* Remote server is a proxy server that uses its execution tools internally and exposes the executor interface externally.
|
|
7
7
|
*
|
|
@@ -10,9 +10,9 @@ import { RemoteNaturalExecutionToolsOptions } from './RemoteNaturalExecutionTool
|
|
|
10
10
|
*
|
|
11
11
|
* @see https://github.com/webgptorg/promptbook#remote-server
|
|
12
12
|
*/
|
|
13
|
-
export declare class
|
|
13
|
+
export declare class RemoteLlmExecutionTools implements LlmExecutionTools {
|
|
14
14
|
private readonly options;
|
|
15
|
-
constructor(options:
|
|
15
|
+
constructor(options: RemoteLlmExecutionToolsOptions);
|
|
16
16
|
/**
|
|
17
17
|
* Creates a connection to the remote proxy server.
|
|
18
18
|
*/
|
|
@@ -31,5 +31,5 @@ export declare class RemoteNaturalExecutionTools implements NaturalExecutionTool
|
|
|
31
31
|
private gptCommon;
|
|
32
32
|
}
|
|
33
33
|
/**
|
|
34
|
-
* TODO: [🤹♂️]
|
|
34
|
+
* TODO: [🤹♂️] RemoteLlmExecutionTools should extend Destroyable and implement IDestroyable
|
|
35
35
|
*/
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { client_id, string_uri } from '
|
|
1
|
+
import type { client_id, string_uri } from '../../../../types/typeAliases';
|
|
2
2
|
import type { CommonExecutionToolsOptions } from '../../../CommonExecutionToolsOptions';
|
|
3
3
|
/**
|
|
4
|
-
* Options for
|
|
4
|
+
* Options for RemoteLlmExecutionTools
|
|
5
5
|
*/
|
|
6
|
-
export type
|
|
6
|
+
export type RemoteLlmExecutionToolsOptions = CommonExecutionToolsOptions & {
|
|
7
7
|
/**
|
|
8
8
|
* URL of the remote PROMPTBOOK server
|
|
9
9
|
* On this server will be connected to the socket.io server
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { PromptbookLibrary } from '../../../../../library/PromptbookLibrary';
|
|
2
2
|
import type { client_id, string_uri } from '../../../../../types/typeAliases';
|
|
3
3
|
import type { CommonExecutionToolsOptions } from '../../../../CommonExecutionToolsOptions';
|
|
4
|
-
import type {
|
|
4
|
+
import type { LlmExecutionTools } from '../../../../LlmExecutionTools';
|
|
5
5
|
export type RemoteServerOptions = CommonExecutionToolsOptions & {
|
|
6
6
|
/**
|
|
7
7
|
* Port on which the server will listen
|
|
@@ -21,7 +21,7 @@ export type RemoteServerOptions = CommonExecutionToolsOptions & {
|
|
|
21
21
|
*/
|
|
22
22
|
readonly library: PromptbookLibrary;
|
|
23
23
|
/**
|
|
24
|
-
* Creates
|
|
24
|
+
* Creates llm execution tools for each client
|
|
25
25
|
*/
|
|
26
|
-
|
|
26
|
+
createLlmExecutionTools(clientId: client_id): LlmExecutionTools;
|
|
27
27
|
};
|
|
@@ -6,11 +6,11 @@ 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 =
|
|
9
|
+
export type PromptTemplateJson = LlmTemplateJson | SimpleTemplateJson | ScriptTemplateJson | PromptDialogJson;
|
|
10
10
|
/**
|
|
11
11
|
* Template for prompt to LLM
|
|
12
12
|
*/
|
|
13
|
-
export type
|
|
13
|
+
export type LlmTemplateJson = PromptTemplateJsonCommon & {
|
|
14
14
|
readonly executionType: 'PROMPT_TEMPLATE';
|
|
15
15
|
/**
|
|
16
16
|
* Requirements for the model
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@promptbook/utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.47.0",
|
|
4
4
|
"description": "Library to supercharge your use of large language models",
|
|
5
5
|
"private": false,
|
|
6
6
|
"sideEffects": false,
|
|
@@ -34,10 +34,20 @@
|
|
|
34
34
|
},
|
|
35
35
|
"homepage": "https://www.npmjs.com/package/@promptbook/core",
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"moment": "
|
|
37
|
+
"moment": "2.30.1",
|
|
38
38
|
"prettier": "2.8.1",
|
|
39
|
-
"spacetrim": "0.11.
|
|
39
|
+
"spacetrim": "0.11.23"
|
|
40
40
|
},
|
|
41
|
+
"funding": [
|
|
42
|
+
{
|
|
43
|
+
"type": "individual",
|
|
44
|
+
"url": "https://buymeacoffee.com/hejny"
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"type": "github",
|
|
48
|
+
"url": "https://github.com/webgptorg/promptbook/blob/main/README.md#%EF%B8%8F-contributing"
|
|
49
|
+
}
|
|
50
|
+
],
|
|
41
51
|
"main": "./umd/index.umd.js",
|
|
42
52
|
"module": "./esm/index.es.js",
|
|
43
53
|
"typings": "./esm/typings/_packages/utils.index.d.ts"
|
package/umd/index.umd.js
CHANGED
|
@@ -408,7 +408,7 @@
|
|
|
408
408
|
/**
|
|
409
409
|
* The version of the Promptbook library
|
|
410
410
|
*/
|
|
411
|
-
var PROMPTBOOK_VERSION = '0.
|
|
411
|
+
var PROMPTBOOK_VERSION = '0.47.0-0';
|
|
412
412
|
|
|
413
413
|
/**
|
|
414
414
|
* Parses the given script and returns the list of all used variables that are not defined in the script
|
|
@@ -1140,45 +1140,59 @@
|
|
|
1140
1140
|
}
|
|
1141
1141
|
|
|
1142
1142
|
/**
|
|
1143
|
-
*
|
|
1143
|
+
* Creates a Mermaid graph based on the promptbook
|
|
1144
|
+
*
|
|
1145
|
+
* Note: The result is not wrapped in a Markdown code block
|
|
1146
|
+
*/
|
|
1147
|
+
function renderPromptbookMermaid(promptbookJson) {
|
|
1148
|
+
var parameterNameToTemplateName = function (parameterName) {
|
|
1149
|
+
var parameter = promptbookJson.parameters.find(function (parameter) { return parameter.name === parameterName; });
|
|
1150
|
+
if (!parameter) {
|
|
1151
|
+
throw new UnexpectedError("Could not find {".concat(parameterName, "}"));
|
|
1152
|
+
}
|
|
1153
|
+
if (parameter.isInput) {
|
|
1154
|
+
return 'input';
|
|
1155
|
+
}
|
|
1156
|
+
var template = promptbookJson.promptTemplates.find(function (template) { return template.resultingParameterName === parameterName; });
|
|
1157
|
+
if (!template) {
|
|
1158
|
+
throw new Error("Could not find template for {".concat(parameterName, "}"));
|
|
1159
|
+
}
|
|
1160
|
+
return 'template' + normalizeTo_PascalCase(template.title);
|
|
1161
|
+
};
|
|
1162
|
+
var promptbookMermaid = spacetrim.spaceTrim(function (block) { return "\n\n %% \uD83D\uDD2E Tip: Open this on GitHub or in the VSCode website to see the Mermaid graph visually\n\n flowchart LR\n subgraph \"".concat(promptbookJson.title, "\"\n\n direction TB\n\n input((Input)):::input\n ").concat(block(promptbookJson.promptTemplates
|
|
1163
|
+
.flatMap(function (_a) {
|
|
1164
|
+
var title = _a.title, dependentParameterNames = _a.dependentParameterNames, resultingParameterName = _a.resultingParameterName;
|
|
1165
|
+
return __spreadArray([
|
|
1166
|
+
"".concat(parameterNameToTemplateName(resultingParameterName), "(\"").concat(title, "\")")
|
|
1167
|
+
], __read(dependentParameterNames.map(function (dependentParameterName) {
|
|
1168
|
+
return "".concat(parameterNameToTemplateName(dependentParameterName), "--\"{").concat(dependentParameterName, "}\"-->").concat(parameterNameToTemplateName(resultingParameterName));
|
|
1169
|
+
})), false);
|
|
1170
|
+
})
|
|
1171
|
+
.join('\n')), "\n\n ").concat(block(promptbookJson.parameters
|
|
1172
|
+
.filter(function (_a) {
|
|
1173
|
+
var isOutput = _a.isOutput;
|
|
1174
|
+
return isOutput;
|
|
1175
|
+
})
|
|
1176
|
+
.map(function (_a) {
|
|
1177
|
+
var name = _a.name;
|
|
1178
|
+
return "".concat(parameterNameToTemplateName(name), "--\"{").concat(name, "}\"-->output");
|
|
1179
|
+
})
|
|
1180
|
+
.join('\n')), "\n output((Output)):::output\n\n classDef input color: grey;\n classDef output color: grey;\n\n end;\n\n "); });
|
|
1181
|
+
return promptbookMermaid;
|
|
1182
|
+
}
|
|
1183
|
+
/**
|
|
1184
|
+
* TODO: Maybe use some Mermaid library instead of string templating
|
|
1185
|
+
* TODO: [🕌] When more than 2 functionalities, split into separate functions
|
|
1186
|
+
*/
|
|
1187
|
+
|
|
1188
|
+
/**
|
|
1189
|
+
* Prettyfies Promptbook string and adds Mermaid graph
|
|
1144
1190
|
*/
|
|
1145
1191
|
function prettifyPromptbookString(promptbookString, options) {
|
|
1146
1192
|
var isGraphAdded = options.isGraphAdded, isPrettifyed = options.isPrettifyed;
|
|
1147
1193
|
if (isGraphAdded) {
|
|
1148
|
-
var
|
|
1149
|
-
var
|
|
1150
|
-
var parameter = promptbookJson_1.parameters.find(function (parameter) { return parameter.name === parameterName; });
|
|
1151
|
-
if (!parameter) {
|
|
1152
|
-
throw new UnexpectedError("Could not find {".concat(parameterName, "}"));
|
|
1153
|
-
}
|
|
1154
|
-
if (parameter.isInput) {
|
|
1155
|
-
return 'input';
|
|
1156
|
-
}
|
|
1157
|
-
var template = promptbookJson_1.promptTemplates.find(function (template) { return template.resultingParameterName === parameterName; });
|
|
1158
|
-
if (!template) {
|
|
1159
|
-
throw new Error("Could not find template for {".concat(parameterName, "}"));
|
|
1160
|
-
}
|
|
1161
|
-
return 'template' + normalizeTo_PascalCase(template.title);
|
|
1162
|
-
};
|
|
1163
|
-
var promptbookMermaid_1 = spacetrim.spaceTrim(function (block) { return "\n\n %% \uD83D\uDD2E Tip: Open this on GitHub or in the VSCode website to see the Mermaid graph visually\n\n flowchart LR\n subgraph \"".concat(promptbookJson_1.title, "\"\n\n direction TB\n\n input((Input)):::input\n ").concat(block(promptbookJson_1.promptTemplates
|
|
1164
|
-
.flatMap(function (_a) {
|
|
1165
|
-
var title = _a.title, dependentParameterNames = _a.dependentParameterNames, resultingParameterName = _a.resultingParameterName;
|
|
1166
|
-
return __spreadArray([
|
|
1167
|
-
"".concat(parameterNameToTemplateName_1(resultingParameterName), "(\"").concat(title, "\")")
|
|
1168
|
-
], __read(dependentParameterNames.map(function (dependentParameterName) {
|
|
1169
|
-
return "".concat(parameterNameToTemplateName_1(dependentParameterName), "--\"{").concat(dependentParameterName, "}\"-->").concat(parameterNameToTemplateName_1(resultingParameterName));
|
|
1170
|
-
})), false);
|
|
1171
|
-
})
|
|
1172
|
-
.join('\n')), "\n\n ").concat(block(promptbookJson_1.parameters
|
|
1173
|
-
.filter(function (_a) {
|
|
1174
|
-
var isOutput = _a.isOutput;
|
|
1175
|
-
return isOutput;
|
|
1176
|
-
})
|
|
1177
|
-
.map(function (_a) {
|
|
1178
|
-
var name = _a.name;
|
|
1179
|
-
return "".concat(parameterNameToTemplateName_1(name), "--\"{").concat(name, "}\"-->output");
|
|
1180
|
-
})
|
|
1181
|
-
.join('\n')), "\n output((Output)):::output\n\n classDef input color: grey;\n classDef output color: grey;\n\n end;\n\n\n\n "); });
|
|
1194
|
+
var promptbookJson = promptbookStringToJson(promptbookString);
|
|
1195
|
+
var promptbookMermaid_1 = renderPromptbookMermaid(promptbookJson);
|
|
1182
1196
|
var promptbookMermaidBlock = spacetrim.spaceTrim(function (block) { return "\n ```mermaid\n ".concat(block(promptbookMermaid_1), "\n ```\n "); });
|
|
1183
1197
|
promptbookString = addAutoGeneratedSection(promptbookString, {
|
|
1184
1198
|
sectionName: 'Graph',
|
|
@@ -1928,13 +1942,13 @@
|
|
|
1928
1942
|
});
|
|
1929
1943
|
});
|
|
1930
1944
|
var duration = moment__default["default"].duration(completedAt.diff(startedAt));
|
|
1931
|
-
var
|
|
1945
|
+
var llmDuration = moment__default["default"].duration(countWorkingDuration(timingItems) * 1000);
|
|
1932
1946
|
var executionsWithKnownCost = executionReportJson.promptExecutions.filter(function (promptExecution) { var _a, _b; return (((_b = (_a = promptExecution.result) === null || _a === void 0 ? void 0 : _a.usage) === null || _b === void 0 ? void 0 : _b.price) || 'UNKNOWN') !== 'UNKNOWN'; });
|
|
1933
1947
|
var cost = executionsWithKnownCost.reduce(function (cost, promptExecution) { return cost + (promptExecution.result.usage.price || 0); }, 0);
|
|
1934
1948
|
headerList.push("STARTED AT ".concat(moment__default["default"](startedAt).format("YYYY-MM-DD HH:mm:ss")));
|
|
1935
1949
|
headerList.push("COMPLETED AT ".concat(moment__default["default"](completedAt).format("YYYY-MM-DD HH:mm:ss")));
|
|
1936
1950
|
headerList.push("TOTAL DURATION ".concat(duration.humanize(MOMENT_ARG_THRESHOLDS)));
|
|
1937
|
-
headerList.push("TOTAL
|
|
1951
|
+
headerList.push("TOTAL LLM DURATION ".concat(llmDuration.humanize(MOMENT_ARG_THRESHOLDS)));
|
|
1938
1952
|
headerList.push("TOTAL COST $".concat(formatNumber(cost * (1 + taxRate))) +
|
|
1939
1953
|
(executionsWithKnownCost.length === executionReportJson.promptExecutions.length
|
|
1940
1954
|
? ''
|
|
@@ -2566,6 +2580,7 @@
|
|
|
2566
2580
|
exports.removeEmojis = removeEmojis;
|
|
2567
2581
|
exports.removeMarkdownFormatting = removeMarkdownFormatting;
|
|
2568
2582
|
exports.removeQuotes = removeQuotes;
|
|
2583
|
+
exports.renderPromptbookMermaid = renderPromptbookMermaid;
|
|
2569
2584
|
exports.replaceParameters = replaceParameters;
|
|
2570
2585
|
exports.searchKeywords = searchKeywords;
|
|
2571
2586
|
exports.splitIntoSentences = splitIntoSentences;
|