@promptbook/openai 0.92.0-8 → 0.92.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 +84 -46
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/browser.index.d.ts +2 -0
- package/esm/typings/src/_packages/core.index.d.ts +26 -14
- package/esm/typings/src/_packages/types.index.d.ts +6 -2
- package/esm/typings/src/collection/PipelineCollection.d.ts +0 -2
- package/esm/typings/src/collection/SimplePipelineCollection.d.ts +1 -1
- package/esm/typings/src/commands/FOREACH/ForeachJson.d.ts +6 -6
- package/esm/typings/src/commands/FOREACH/foreachCommandParser.d.ts +0 -2
- package/esm/typings/src/commands/FORMFACTOR/formfactorCommandParser.d.ts +1 -1
- package/esm/typings/src/commands/_BOILERPLATE/boilerplateCommandParser.d.ts +1 -1
- package/esm/typings/src/commands/_common/types/CommandParser.d.ts +36 -28
- package/esm/typings/src/config.d.ts +41 -11
- package/esm/typings/src/constants.d.ts +43 -2
- package/esm/typings/src/conversion/parsePipeline.d.ts +2 -2
- package/esm/typings/src/errors/0-BoilerplateError.d.ts +2 -2
- package/esm/typings/src/errors/CollectionError.d.ts +1 -1
- package/esm/typings/src/executables/$provideExecutablesForNode.d.ts +1 -1
- package/esm/typings/src/executables/apps/locateLibreoffice.d.ts +2 -1
- package/esm/typings/src/executables/apps/locatePandoc.d.ts +2 -1
- package/esm/typings/src/executables/locateApp.d.ts +2 -2
- package/esm/typings/src/executables/platforms/locateAppOnLinux.d.ts +2 -1
- package/esm/typings/src/executables/platforms/locateAppOnMacOs.d.ts +2 -1
- package/esm/typings/src/executables/platforms/locateAppOnWindows.d.ts +2 -1
- package/esm/typings/src/execution/AbstractTaskResult.d.ts +1 -1
- package/esm/typings/src/execution/CommonToolsOptions.d.ts +5 -1
- package/esm/typings/src/execution/ExecutionTask.d.ts +19 -1
- package/esm/typings/src/execution/LlmExecutionToolsConstructor.d.ts +2 -1
- package/esm/typings/src/execution/PipelineExecutorResult.d.ts +4 -2
- package/esm/typings/src/execution/PromptbookFetch.d.ts +1 -1
- package/esm/typings/src/execution/ScriptExecutionTools.d.ts +1 -1
- package/esm/typings/src/execution/createPipelineExecutor/$OngoingTaskResult.d.ts +12 -9
- package/esm/typings/src/execution/createPipelineExecutor/10-executePipeline.d.ts +13 -10
- package/esm/typings/src/execution/createPipelineExecutor/20-executeTask.d.ts +12 -9
- package/esm/typings/src/execution/createPipelineExecutor/30-executeFormatSubvalues.d.ts +15 -3
- package/esm/typings/src/execution/createPipelineExecutor/40-executeAttempts.d.ts +21 -15
- package/esm/typings/src/execution/createPipelineExecutor/computeCosineSimilarity.d.ts +13 -0
- package/esm/typings/src/execution/createPipelineExecutor/filterJustOutputParameters.d.ts +7 -6
- package/esm/typings/src/execution/createPipelineExecutor/getContextForTask.d.ts +5 -1
- package/esm/typings/src/execution/createPipelineExecutor/getExamplesForTask.d.ts +1 -1
- package/esm/typings/src/execution/createPipelineExecutor/getKnowledgeForTask.d.ts +12 -9
- package/esm/typings/src/execution/createPipelineExecutor/getReservedParametersForTask.d.ts +18 -5
- package/esm/typings/src/execution/createPipelineExecutor/knowledgePiecesToString.d.ts +9 -0
- package/esm/typings/src/execution/execution-report/ExecutionReportJson.d.ts +1 -1
- package/esm/typings/src/execution/execution-report/ExecutionReportString.d.ts +1 -1
- package/esm/typings/src/execution/translation/automatic-translate/automatic-translators/LindatAutomaticTranslator.d.ts +4 -4
- package/esm/typings/src/execution/utils/checkExpectations.d.ts +3 -3
- package/esm/typings/src/execution/utils/uncertainNumber.d.ts +3 -2
- package/esm/typings/src/execution/utils/usageToWorktime.d.ts +1 -1
- package/esm/typings/src/formats/_common/{FormatDefinition.d.ts → FormatParser.d.ts} +8 -6
- package/esm/typings/src/formats/_common/FormatSubvalueParser.d.ts +66 -0
- package/esm/typings/src/formats/csv/CsvFormatParser.d.ts +17 -0
- package/esm/typings/src/formats/csv/CsvSettings.d.ts +2 -2
- package/esm/typings/src/formats/csv/utils/csvParse.d.ts +12 -0
- package/esm/typings/src/formats/csv/utils/isValidCsvString.d.ts +1 -1
- package/esm/typings/src/formats/index.d.ts +2 -2
- package/esm/typings/src/formats/json/JsonFormatParser.d.ts +19 -0
- package/esm/typings/src/formats/json/utils/isValidJsonString.d.ts +1 -1
- package/esm/typings/src/formats/json/utils/jsonParse.d.ts +0 -3
- package/esm/typings/src/formats/text/{TextFormatDefinition.d.ts → TextFormatParser.d.ts} +7 -7
- package/esm/typings/src/formats/xml/XmlFormatParser.d.ts +19 -0
- package/esm/typings/src/formats/xml/utils/isValidXmlString.d.ts +1 -1
- package/esm/typings/src/formfactors/_boilerplate/BoilerplateFormfactorDefinition.d.ts +3 -2
- package/esm/typings/src/formfactors/_common/AbstractFormfactorDefinition.d.ts +16 -7
- package/esm/typings/src/formfactors/_common/FormfactorDefinition.d.ts +3 -1
- package/esm/typings/src/formfactors/_common/string_formfactor_name.d.ts +2 -1
- package/esm/typings/src/formfactors/chatbot/ChatbotFormfactorDefinition.d.ts +2 -2
- package/esm/typings/src/formfactors/completion/CompletionFormfactorDefinition.d.ts +29 -0
- package/esm/typings/src/formfactors/generator/GeneratorFormfactorDefinition.d.ts +2 -1
- package/esm/typings/src/formfactors/generic/GenericFormfactorDefinition.d.ts +2 -2
- package/esm/typings/src/formfactors/index.d.ts +33 -8
- package/esm/typings/src/formfactors/matcher/MatcherFormfactorDefinition.d.ts +4 -2
- package/esm/typings/src/formfactors/sheets/SheetsFormfactorDefinition.d.ts +3 -2
- package/esm/typings/src/formfactors/translator/TranslatorFormfactorDefinition.d.ts +3 -2
- package/esm/typings/src/high-level-abstractions/index.d.ts +2 -2
- package/esm/typings/src/llm-providers/_common/register/$llmToolsMetadataRegister.d.ts +3 -3
- package/esm/typings/src/llm-providers/_common/register/$llmToolsRegister.d.ts +3 -3
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsConfigurationFromEnv.d.ts +4 -4
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForTestingAndScriptsAndPlayground.d.ts +4 -3
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsFromEnv.d.ts +18 -5
- package/esm/typings/src/llm-providers/_common/register/LlmToolsConfiguration.d.ts +11 -4
- package/esm/typings/src/llm-providers/_common/register/LlmToolsMetadata.d.ts +21 -42
- package/esm/typings/src/llm-providers/_common/register/LlmToolsOptions.d.ts +9 -2
- package/esm/typings/src/llm-providers/_common/register/createLlmToolsFromConfiguration.d.ts +13 -4
- package/esm/typings/src/llm-providers/_common/utils/cache/CacheItem.d.ts +10 -5
- package/esm/typings/src/llm-providers/_common/utils/cache/CacheLlmToolsOptions.d.ts +11 -3
- package/esm/typings/src/llm-providers/_common/utils/cache/cacheLlmTools.d.ts +3 -3
- package/esm/typings/src/llm-providers/_common/utils/count-total-usage/limitTotalUsage.d.ts +5 -5
- package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +6 -0
- package/esm/typings/src/llm-providers/anthropic-claude/anthropic-claude-models.d.ts +1 -1
- package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.d.ts +5 -1
- package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionToolsOptions.d.ts +4 -4
- package/esm/typings/src/llm-providers/deepseek/deepseek-models.d.ts +1 -1
- package/esm/typings/src/llm-providers/google/google-models.d.ts +1 -1
- package/esm/typings/src/llm-providers/openai/OpenAiAssistantExecutionTools.d.ts +1 -1
- package/esm/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +4 -0
- package/esm/typings/src/llm-providers/openai/openai-models.d.ts +1 -1
- package/esm/typings/src/llm-providers/openai/register-configuration.d.ts +2 -2
- package/esm/typings/src/llm-providers/openai/register-constructor.d.ts +2 -2
- package/esm/typings/src/migrations/migratePipeline.d.ts +9 -0
- package/esm/typings/src/other/templates/getBookTemplates.d.ts +2 -2
- package/esm/typings/src/pipeline/PipelineInterface/PipelineInterface.d.ts +3 -3
- package/esm/typings/src/pipeline/PipelineInterface/constants.d.ts +1 -1
- package/esm/typings/src/pipeline/PipelineInterface/getPipelineInterface.d.ts +1 -1
- package/esm/typings/src/pipeline/PipelineInterface/isPipelineImplementingInterface.d.ts +5 -4
- package/esm/typings/src/pipeline/PipelineInterface/isPipelineInterfacesEqual.d.ts +1 -1
- package/esm/typings/src/pipeline/PipelineJson/CommonTaskJson.d.ts +10 -7
- package/esm/typings/src/pipeline/PipelineJson/ParameterJson.d.ts +1 -1
- package/esm/typings/src/pipeline/PipelineJson/PipelineJson.d.ts +3 -2
- package/esm/typings/src/pipeline/PipelineString.d.ts +3 -1
- package/esm/typings/src/pipeline/book-notation.d.ts +2 -2
- package/esm/typings/src/postprocessing/utils/extractBlock.d.ts +1 -1
- package/esm/typings/src/postprocessing/utils/extractJsonBlock.d.ts +2 -2
- package/esm/typings/src/prepare/prepareTasks.d.ts +8 -5
- package/esm/typings/src/remote-server/openapi.d.ts +1 -1
- package/esm/typings/src/remote-server/socket-types/listModels/PromptbookServer_ListModels_Response.d.ts +1 -1
- package/esm/typings/src/remote-server/startRemoteServer.d.ts +1 -1
- package/esm/typings/src/remote-server/types/RemoteServerOptions.d.ts +7 -6
- package/esm/typings/src/scrapers/_boilerplate/BoilerplateScraper.d.ts +3 -3
- package/esm/typings/src/scrapers/_boilerplate/createBoilerplateScraper.d.ts +1 -1
- package/esm/typings/src/scrapers/_boilerplate/register-metadata.d.ts +1 -1
- package/esm/typings/src/scrapers/_common/Converter.d.ts +3 -1
- package/esm/typings/src/scrapers/_common/Scraper.d.ts +4 -3
- package/esm/typings/src/scrapers/_common/ScraperIntermediateSource.d.ts +4 -2
- package/esm/typings/src/scrapers/_common/prepareKnowledgePieces.d.ts +2 -2
- package/esm/typings/src/scrapers/_common/register/$provideFilesystemForNode.d.ts +2 -1
- package/esm/typings/src/scrapers/_common/register/$provideScrapersForBrowser.d.ts +6 -3
- package/esm/typings/src/scrapers/_common/register/$provideScrapersForNode.d.ts +3 -5
- package/esm/typings/src/scrapers/_common/register/$scrapersMetadataRegister.d.ts +3 -3
- package/esm/typings/src/scrapers/_common/register/$scrapersRegister.d.ts +3 -2
- package/esm/typings/src/scrapers/_common/register/ScraperAndConverterMetadata.d.ts +8 -5
- package/esm/typings/src/scrapers/_common/register/ScraperConstructor.d.ts +2 -1
- package/esm/typings/src/scrapers/_common/utils/getScraperIntermediateSource.d.ts +6 -5
- package/esm/typings/src/scrapers/_common/utils/makeKnowledgeSourceHandler.d.ts +3 -1
- package/esm/typings/src/scrapers/document/createDocumentScraper.d.ts +1 -1
- package/esm/typings/src/scrapers/document-legacy/createLegacyDocumentScraper.d.ts +2 -1
- package/esm/typings/src/scrapers/markdown/createMarkdownScraper.d.ts +4 -1
- package/esm/typings/src/scrapers/markitdown/MarkitdownScraper.d.ts +1 -1
- package/esm/typings/src/scrapers/pdf/createPdfScraper.d.ts +2 -1
- package/esm/typings/src/scrapers/website/createWebsiteScraper.d.ts +3 -4
- package/esm/typings/src/scripting/javascript/JavascriptExecutionTools.d.ts +1 -1
- package/esm/typings/src/scripting/javascript/postprocessing-functions.d.ts +5 -1
- package/esm/typings/src/scripting/javascript/utils/preserve.d.ts +1 -1
- package/esm/typings/src/storage/_common/PromptbookStorage.d.ts +1 -1
- package/esm/typings/src/storage/file-cache-storage/FileCacheStorage.d.ts +12 -5
- package/esm/typings/src/storage/file-cache-storage/FileCacheStorageOptions.d.ts +4 -2
- package/esm/typings/src/storage/file-cache-storage/utils/nameToSubfolderPath.d.ts +2 -1
- package/esm/typings/src/storage/local-storage/getIndexedDbStorage.d.ts +11 -0
- package/esm/typings/src/storage/local-storage/utils/IndexedDbStorageOptions.d.ts +14 -0
- package/esm/typings/src/storage/local-storage/utils/makePromptbookStorageFromIndexedDb.d.ts +8 -0
- package/esm/typings/src/storage/local-storage/utils/makePromptbookStorageFromWebStorage.d.ts +2 -1
- package/esm/typings/src/types/IntermediateFilesStrategy.d.ts +2 -1
- package/esm/typings/src/types/ModelRequirements.d.ts +2 -2
- package/esm/typings/src/types/ModelVariant.d.ts +5 -5
- package/esm/typings/src/types/typeAliases.d.ts +22 -19
- package/esm/typings/src/utils/$Register.d.ts +8 -7
- package/esm/typings/src/utils/editable/edit-pipeline-string/addPipelineCommand.d.ts +2 -2
- package/esm/typings/src/utils/editable/edit-pipeline-string/deflatePipeline.d.ts +4 -1
- package/esm/typings/src/utils/editable/utils/isFlatPipeline.d.ts +2 -1
- package/esm/typings/src/utils/editable/utils/stringifyPipelineJson.d.ts +1 -1
- package/esm/typings/src/utils/environment/$getGlobalScope.d.ts +2 -1
- package/esm/typings/src/utils/expectation-counters/index.d.ts +1 -1
- package/esm/typings/src/utils/markdown/extractAllBlocksFromMarkdown.d.ts +2 -2
- package/esm/typings/src/utils/markdown/extractAllListItemsFromMarkdown.d.ts +1 -1
- package/esm/typings/src/utils/markdown/extractOneBlockFromMarkdown.d.ts +2 -2
- package/esm/typings/src/utils/normalization/nameToUriPart.d.ts +4 -4
- package/esm/typings/src/utils/normalization/nameToUriParts.d.ts +4 -4
- package/esm/typings/src/utils/normalization/normalize-to-kebab-case.d.ts +3 -3
- package/esm/typings/src/utils/normalization/normalizeTo_SCREAMING_CASE.d.ts +3 -3
- package/esm/typings/src/utils/normalization/normalizeTo_camelCase.d.ts +4 -4
- package/esm/typings/src/utils/normalization/normalizeTo_snake_case.d.ts +3 -3
- package/esm/typings/src/utils/normalization/removeDiacritics.d.ts +3 -3
- package/esm/typings/src/utils/normalization/searchKeywords.d.ts +4 -1
- package/esm/typings/src/utils/normalization/titleToName.d.ts +4 -4
- package/esm/typings/src/utils/organization/TODO_USE.d.ts +1 -1
- package/esm/typings/src/utils/organization/empty_object.d.ts +2 -2
- package/esm/typings/src/utils/organization/just.d.ts +1 -1
- package/esm/typings/src/utils/organization/just_empty_object.d.ts +4 -4
- package/esm/typings/src/utils/organization/keepUnused.d.ts +1 -1
- package/esm/typings/src/utils/parameters/mapAvailableToExpectedParameters.d.ts +7 -7
- package/esm/typings/src/utils/removeQuotes.d.ts +2 -2
- package/esm/typings/src/utils/serialization/clonePipeline.d.ts +4 -3
- package/esm/typings/src/utils/serialization/deepClone.d.ts +5 -1
- package/esm/typings/src/utils/trimCodeBlock.d.ts +1 -1
- package/esm/typings/src/utils/trimEndOfCodeBlock.d.ts +1 -1
- package/esm/typings/src/utils/unwrapResult.d.ts +2 -2
- package/esm/typings/src/utils/validators/javascriptName/isValidJavascriptName.d.ts +3 -3
- package/esm/typings/src/utils/validators/parameterName/validateParameterName.d.ts +5 -4
- package/esm/typings/src/utils/validators/semanticVersion/isValidPromptbookVersion.d.ts +1 -1
- package/esm/typings/src/utils/validators/semanticVersion/isValidSemanticVersion.d.ts +1 -1
- package/esm/typings/src/utils/validators/url/isHostnameOnPrivateNetwork.d.ts +1 -1
- package/esm/typings/src/utils/validators/url/isUrlOnPrivateNetwork.d.ts +1 -1
- package/esm/typings/src/utils/validators/url/isValidPipelineUrl.d.ts +1 -1
- package/esm/typings/src/utils/validators/url/isValidUrl.d.ts +1 -1
- package/esm/typings/src/version.d.ts +2 -1
- package/esm/typings/src/wizzard/wizzard.d.ts +1 -1
- package/package.json +15 -2
- package/umd/index.umd.js +88 -50
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/formats/_common/FormatSubvalueDefinition.d.ts +0 -31
- package/esm/typings/src/formats/csv/CsvFormatDefinition.d.ts +0 -17
- package/esm/typings/src/formats/json/JsonFormatDefinition.d.ts +0 -19
- package/esm/typings/src/formats/xml/XmlFormatDefinition.d.ts +0 -19
- /package/esm/typings/src/llm-providers/{multiple → _multiple}/MultipleLlmExecutionTools.d.ts +0 -0
- /package/esm/typings/src/llm-providers/{multiple → _multiple}/joinLlmExecutionTools.d.ts +0 -0
- /package/esm/typings/src/llm-providers/{multiple → _multiple}/playground/playground.d.ts +0 -0
package/umd/index.umd.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('colors'), require('spacetrim'), require('crypto'), require('openai')) :
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports', 'colors', 'spacetrim', 'crypto', 'openai'], factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-openai"] = {}, global.colors, global.spaceTrim, global.crypto, global.OpenAI));
|
|
5
|
-
})(this, (function (exports, colors, spaceTrim, crypto, OpenAI) { 'use strict';
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('colors'), require('spacetrim'), require('crypto'), require('bottleneck'), require('openai')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', 'colors', 'spacetrim', 'crypto', 'bottleneck', 'openai'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-openai"] = {}, global.colors, global.spaceTrim, global.crypto, global.Bottleneck, global.OpenAI));
|
|
5
|
+
})(this, (function (exports, colors, spaceTrim, crypto, Bottleneck, OpenAI) { 'use strict';
|
|
6
6
|
|
|
7
7
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
8
|
|
|
9
9
|
var colors__default = /*#__PURE__*/_interopDefaultLegacy(colors);
|
|
10
10
|
var spaceTrim__default = /*#__PURE__*/_interopDefaultLegacy(spaceTrim);
|
|
11
|
+
var Bottleneck__default = /*#__PURE__*/_interopDefaultLegacy(Bottleneck);
|
|
11
12
|
var OpenAI__default = /*#__PURE__*/_interopDefaultLegacy(OpenAI);
|
|
12
13
|
|
|
13
14
|
// ⚠️ WARNING: This code has been generated so that any manual changes will be overwritten
|
|
@@ -24,7 +25,7 @@
|
|
|
24
25
|
* @generated
|
|
25
26
|
* @see https://github.com/webgptorg/promptbook
|
|
26
27
|
*/
|
|
27
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.92.0
|
|
28
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.92.0';
|
|
28
29
|
/**
|
|
29
30
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
30
31
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -119,7 +120,7 @@
|
|
|
119
120
|
super(message);
|
|
120
121
|
this.name = 'PipelineExecutionError';
|
|
121
122
|
// TODO: [🐙] DRY - Maybe $randomId
|
|
122
|
-
this.id = `error-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid
|
|
123
|
+
this.id = `error-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid similar char conflicts */)}`;
|
|
123
124
|
Object.setPrototypeOf(this, PipelineExecutionError.prototype);
|
|
124
125
|
}
|
|
125
126
|
}
|
|
@@ -284,7 +285,7 @@
|
|
|
284
285
|
const SMALL_NUMBER = 0.001;
|
|
285
286
|
// <- TODO: [🧜♂️]
|
|
286
287
|
/**
|
|
287
|
-
*
|
|
288
|
+
* Default settings for parsing and generating CSV files in Promptbook.
|
|
288
289
|
*
|
|
289
290
|
* @public exported from `@promptbook/core`
|
|
290
291
|
*/
|
|
@@ -294,6 +295,14 @@
|
|
|
294
295
|
newline: '\n',
|
|
295
296
|
skipEmptyLines: true,
|
|
296
297
|
});
|
|
298
|
+
/**
|
|
299
|
+
* Default rate limits (requests per minute)
|
|
300
|
+
*
|
|
301
|
+
* Note: Adjust based on the provider tier you are have
|
|
302
|
+
*
|
|
303
|
+
* @public exported from `@promptbook/core`
|
|
304
|
+
*/
|
|
305
|
+
const DEFAULT_MAX_REQUESTS_PER_MINUTE = 60;
|
|
297
306
|
/**
|
|
298
307
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
299
308
|
* TODO: [🧠][🧜♂️] Maybe join remoteServerUrl and path into single value
|
|
@@ -369,7 +378,7 @@
|
|
|
369
378
|
${block(message)}
|
|
370
379
|
|
|
371
380
|
Note: This error should not happen.
|
|
372
|
-
It's
|
|
381
|
+
It's probably a bug in the pipeline collection
|
|
373
382
|
|
|
374
383
|
Please report issue:
|
|
375
384
|
${block(getErrorReportUrl(new Error(message)).href)}
|
|
@@ -569,8 +578,12 @@
|
|
|
569
578
|
*/
|
|
570
579
|
|
|
571
580
|
/**
|
|
572
|
-
*
|
|
581
|
+
* Creates a deep clone of the given object
|
|
582
|
+
*
|
|
583
|
+
* Note: This method only works for objects that are fully serializable to JSON and do not contain functions, Dates, or special types.
|
|
573
584
|
*
|
|
585
|
+
* @param objectValue The object to clone.
|
|
586
|
+
* @returns A deep, writable clone of the input object.
|
|
574
587
|
* @public exported from `@promptbook/utils`
|
|
575
588
|
*/
|
|
576
589
|
function deepClone(objectValue) {
|
|
@@ -632,13 +645,19 @@
|
|
|
632
645
|
*/
|
|
633
646
|
const REPLACING_NONCE = 'ptbkauk42kV2dzao34faw7FudQUHYPtW';
|
|
634
647
|
/**
|
|
635
|
-
*
|
|
648
|
+
* Nonce which is used as string which is not occurring in normal text
|
|
649
|
+
*
|
|
650
|
+
* @private within the repository
|
|
651
|
+
*/
|
|
652
|
+
const SALT_NONCE = 'ptbkghhewbvruets21t54et5';
|
|
653
|
+
/**
|
|
654
|
+
* Placeholder value indicating a parameter is missing its value.
|
|
636
655
|
*
|
|
637
656
|
* @private within the repository
|
|
638
657
|
*/
|
|
639
658
|
const RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE;
|
|
640
659
|
/**
|
|
641
|
-
*
|
|
660
|
+
* Placeholder value indicating a parameter is restricted and cannot be used directly.
|
|
642
661
|
*
|
|
643
662
|
* @private within the repository
|
|
644
663
|
*/
|
|
@@ -1175,10 +1194,10 @@
|
|
|
1175
1194
|
*/
|
|
1176
1195
|
|
|
1177
1196
|
/**
|
|
1178
|
-
*
|
|
1197
|
+
* Removes diacritic marks (accents) from characters in a string.
|
|
1179
1198
|
*
|
|
1180
|
-
* @param input
|
|
1181
|
-
* @returns
|
|
1199
|
+
* @param input The string containing diacritics to be normalized.
|
|
1200
|
+
* @returns The string with diacritics removed or normalized.
|
|
1182
1201
|
* @public exported from `@promptbook/utils`
|
|
1183
1202
|
*/
|
|
1184
1203
|
function removeDiacritics(input) {
|
|
@@ -1229,14 +1248,18 @@
|
|
|
1229
1248
|
/**
|
|
1230
1249
|
* Make UncertainNumber
|
|
1231
1250
|
*
|
|
1232
|
-
* @param value
|
|
1251
|
+
* @param value value of the uncertain number, if `NaN` or `undefined`, it will be set to 0 and `isUncertain=true`
|
|
1252
|
+
* @param isUncertain if `true`, the value is uncertain, otherwise depends on the value
|
|
1233
1253
|
*
|
|
1234
1254
|
* @private utility for initializating UncertainNumber
|
|
1235
1255
|
*/
|
|
1236
|
-
function uncertainNumber(value) {
|
|
1256
|
+
function uncertainNumber(value, isUncertain) {
|
|
1237
1257
|
if (value === null || value === undefined || Number.isNaN(value)) {
|
|
1238
1258
|
return UNCERTAIN_ZERO_VALUE;
|
|
1239
1259
|
}
|
|
1260
|
+
if (isUncertain === true) {
|
|
1261
|
+
return { value, isUncertain };
|
|
1262
|
+
}
|
|
1240
1263
|
return { value };
|
|
1241
1264
|
}
|
|
1242
1265
|
|
|
@@ -1253,7 +1276,7 @@
|
|
|
1253
1276
|
/**
|
|
1254
1277
|
* List of available OpenAI models with pricing
|
|
1255
1278
|
*
|
|
1256
|
-
* Note: Done at
|
|
1279
|
+
* Note: Done at 2025-05-06
|
|
1257
1280
|
*
|
|
1258
1281
|
* @see https://platform.openai.com/docs/models/
|
|
1259
1282
|
* @see https://openai.com/api/pricing/
|
|
@@ -1514,7 +1537,7 @@
|
|
|
1514
1537
|
modelName: 'text-embedding-3-large',
|
|
1515
1538
|
modelDescription: "OpenAI's most capable text embedding model designed for high-quality embeddings for complex similarity tasks and information retrieval.",
|
|
1516
1539
|
pricing: {
|
|
1517
|
-
prompt: computeUsage(`$0.13
|
|
1540
|
+
prompt: computeUsage(`$0.13 / 1M tokens`),
|
|
1518
1541
|
// TODO: [🏏] Leverage the batch API @see https://platform.openai.com/docs/guides/batch
|
|
1519
1542
|
output: 0, // <- Note: [🆖] In Embedding models you dont pay for output
|
|
1520
1543
|
},
|
|
@@ -1607,8 +1630,8 @@
|
|
|
1607
1630
|
modelName: 'gpt-4o-mini',
|
|
1608
1631
|
modelDescription: 'Smaller, more cost-effective version of GPT-4o with good performance across text, vision, and audio tasks at reduced complexity.',
|
|
1609
1632
|
pricing: {
|
|
1610
|
-
prompt: computeUsage(`$
|
|
1611
|
-
output: computeUsage(`$
|
|
1633
|
+
prompt: computeUsage(`$0.15 / 1M tokens`),
|
|
1634
|
+
output: computeUsage(`$0.60 / 1M tokens`),
|
|
1612
1635
|
},
|
|
1613
1636
|
},
|
|
1614
1637
|
/**/
|
|
@@ -1630,7 +1653,7 @@
|
|
|
1630
1653
|
modelTitle: 'o1-preview-2024-09-12',
|
|
1631
1654
|
modelName: 'o1-preview-2024-09-12',
|
|
1632
1655
|
modelDescription: 'September 2024 version of O1 preview with specialized reasoning capabilities for complex tasks requiring precise analytical thinking.',
|
|
1633
|
-
// <- TODO: [💩] Some better system to organize
|
|
1656
|
+
// <- TODO: [💩] Some better system to organize these date suffixes and versions
|
|
1634
1657
|
pricing: {
|
|
1635
1658
|
prompt: computeUsage(`$15.00 / 1M tokens`),
|
|
1636
1659
|
output: computeUsage(`$60.00 / 1M tokens`),
|
|
@@ -1736,13 +1759,21 @@
|
|
|
1736
1759
|
}
|
|
1737
1760
|
const inputTokens = rawResponse.usage.prompt_tokens;
|
|
1738
1761
|
const outputTokens = ((_b = rawResponse.usage) === null || _b === void 0 ? void 0 : _b.completion_tokens) || 0;
|
|
1739
|
-
|
|
1762
|
+
let isUncertain = false;
|
|
1763
|
+
let modelInfo = OPENAI_MODELS.find((model) => model.modelName === rawResponse.model);
|
|
1764
|
+
if (modelInfo === undefined) {
|
|
1765
|
+
// Note: Model is not in the list of known models, fallback to the family of the models and mark price as uncertain
|
|
1766
|
+
modelInfo = OPENAI_MODELS.find((model) => (rawResponse.model || SALT_NONCE).startsWith(model.modelName));
|
|
1767
|
+
if (modelInfo !== undefined) {
|
|
1768
|
+
isUncertain = true;
|
|
1769
|
+
}
|
|
1770
|
+
}
|
|
1740
1771
|
let price;
|
|
1741
1772
|
if (modelInfo === undefined || modelInfo.pricing === undefined) {
|
|
1742
1773
|
price = uncertainNumber();
|
|
1743
1774
|
}
|
|
1744
1775
|
else {
|
|
1745
|
-
price = uncertainNumber(inputTokens * modelInfo.pricing.prompt + outputTokens * modelInfo.pricing.output);
|
|
1776
|
+
price = uncertainNumber(inputTokens * modelInfo.pricing.prompt + outputTokens * modelInfo.pricing.output, isUncertain);
|
|
1746
1777
|
}
|
|
1747
1778
|
return {
|
|
1748
1779
|
price,
|
|
@@ -1777,6 +1808,10 @@
|
|
|
1777
1808
|
* OpenAI API client.
|
|
1778
1809
|
*/
|
|
1779
1810
|
this.client = null;
|
|
1811
|
+
// TODO: Allow configuring rate limits via options
|
|
1812
|
+
this.limiter = new Bottleneck__default["default"]({
|
|
1813
|
+
minTime: 60000 / (this.options.maxRequestsPerMinute || DEFAULT_MAX_REQUESTS_PER_MINUTE),
|
|
1814
|
+
});
|
|
1780
1815
|
}
|
|
1781
1816
|
get title() {
|
|
1782
1817
|
return 'OpenAI';
|
|
@@ -1876,11 +1911,12 @@
|
|
|
1876
1911
|
user: (_a = this.options.userId) === null || _a === void 0 ? void 0 : _a.toString(),
|
|
1877
1912
|
};
|
|
1878
1913
|
const start = $getCurrentDate();
|
|
1879
|
-
let complete;
|
|
1880
1914
|
if (this.options.isVerbose) {
|
|
1881
1915
|
console.info(colors__default["default"].bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
|
|
1882
1916
|
}
|
|
1883
|
-
const rawResponse = await
|
|
1917
|
+
const rawResponse = await this.limiter
|
|
1918
|
+
.schedule(() => client.chat.completions.create(rawRequest))
|
|
1919
|
+
.catch((error) => {
|
|
1884
1920
|
assertsError(error);
|
|
1885
1921
|
if (this.options.isVerbose) {
|
|
1886
1922
|
console.info(colors__default["default"].bgRed('error'), error);
|
|
@@ -1890,6 +1926,7 @@
|
|
|
1890
1926
|
if (this.options.isVerbose) {
|
|
1891
1927
|
console.info(colors__default["default"].bgWhite('rawResponse'), JSON.stringify(rawResponse, null, 4));
|
|
1892
1928
|
}
|
|
1929
|
+
const complete = $getCurrentDate();
|
|
1893
1930
|
if (!rawResponse.choices[0]) {
|
|
1894
1931
|
throw new PipelineExecutionError('No choises from OpenAI');
|
|
1895
1932
|
}
|
|
@@ -1898,8 +1935,6 @@
|
|
|
1898
1935
|
throw new PipelineExecutionError('More than one choise from OpenAI');
|
|
1899
1936
|
}
|
|
1900
1937
|
const resultContent = rawResponse.choices[0].message.content;
|
|
1901
|
-
// eslint-disable-next-line prefer-const
|
|
1902
|
-
complete = $getCurrentDate();
|
|
1903
1938
|
const usage = computeOpenAiUsage(content || '', resultContent || '', rawResponse);
|
|
1904
1939
|
if (resultContent === null) {
|
|
1905
1940
|
throw new PipelineExecutionError('No response message from OpenAI');
|
|
@@ -1953,11 +1988,12 @@
|
|
|
1953
1988
|
user: (_a = this.options.userId) === null || _a === void 0 ? void 0 : _a.toString(),
|
|
1954
1989
|
};
|
|
1955
1990
|
const start = $getCurrentDate();
|
|
1956
|
-
let complete;
|
|
1957
1991
|
if (this.options.isVerbose) {
|
|
1958
1992
|
console.info(colors__default["default"].bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
|
|
1959
1993
|
}
|
|
1960
|
-
const rawResponse = await
|
|
1994
|
+
const rawResponse = await this.limiter
|
|
1995
|
+
.schedule(() => client.completions.create(rawRequest))
|
|
1996
|
+
.catch((error) => {
|
|
1961
1997
|
assertsError(error);
|
|
1962
1998
|
if (this.options.isVerbose) {
|
|
1963
1999
|
console.info(colors__default["default"].bgRed('error'), error);
|
|
@@ -1967,6 +2003,7 @@
|
|
|
1967
2003
|
if (this.options.isVerbose) {
|
|
1968
2004
|
console.info(colors__default["default"].bgWhite('rawResponse'), JSON.stringify(rawResponse, null, 4));
|
|
1969
2005
|
}
|
|
2006
|
+
const complete = $getCurrentDate();
|
|
1970
2007
|
if (!rawResponse.choices[0]) {
|
|
1971
2008
|
throw new PipelineExecutionError('No choises from OpenAI');
|
|
1972
2009
|
}
|
|
@@ -1975,8 +2012,6 @@
|
|
|
1975
2012
|
throw new PipelineExecutionError('More than one choise from OpenAI');
|
|
1976
2013
|
}
|
|
1977
2014
|
const resultContent = rawResponse.choices[0].text;
|
|
1978
|
-
// eslint-disable-next-line prefer-const
|
|
1979
|
-
complete = $getCurrentDate();
|
|
1980
2015
|
const usage = computeOpenAiUsage(content || '', resultContent || '', rawResponse);
|
|
1981
2016
|
return exportJson({
|
|
1982
2017
|
name: 'promptResult',
|
|
@@ -2017,11 +2052,12 @@
|
|
|
2017
2052
|
model: modelName,
|
|
2018
2053
|
};
|
|
2019
2054
|
const start = $getCurrentDate();
|
|
2020
|
-
let complete;
|
|
2021
2055
|
if (this.options.isVerbose) {
|
|
2022
2056
|
console.info(colors__default["default"].bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
|
|
2023
2057
|
}
|
|
2024
|
-
const rawResponse = await
|
|
2058
|
+
const rawResponse = await this.limiter
|
|
2059
|
+
.schedule(() => client.embeddings.create(rawRequest))
|
|
2060
|
+
.catch((error) => {
|
|
2025
2061
|
assertsError(error);
|
|
2026
2062
|
if (this.options.isVerbose) {
|
|
2027
2063
|
console.info(colors__default["default"].bgRed('error'), error);
|
|
@@ -2031,12 +2067,11 @@
|
|
|
2031
2067
|
if (this.options.isVerbose) {
|
|
2032
2068
|
console.info(colors__default["default"].bgWhite('rawResponse'), JSON.stringify(rawResponse, null, 4));
|
|
2033
2069
|
}
|
|
2070
|
+
const complete = $getCurrentDate();
|
|
2034
2071
|
if (rawResponse.data.length !== 1) {
|
|
2035
2072
|
throw new PipelineExecutionError(`Expected exactly 1 data item in response, got ${rawResponse.data.length}`);
|
|
2036
2073
|
}
|
|
2037
2074
|
const resultContent = rawResponse.data[0].embedding;
|
|
2038
|
-
// eslint-disable-next-line prefer-const
|
|
2039
|
-
complete = $getCurrentDate();
|
|
2040
2075
|
const usage = computeOpenAiUsage(content || '', '',
|
|
2041
2076
|
// <- Note: Embedding does not have result content
|
|
2042
2077
|
rawResponse);
|
|
@@ -2064,7 +2099,8 @@
|
|
|
2064
2099
|
* Get the model that should be used as default
|
|
2065
2100
|
*/
|
|
2066
2101
|
getDefaultModel(defaultModelName) {
|
|
2067
|
-
|
|
2102
|
+
// Note: Match exact or prefix for model families
|
|
2103
|
+
const model = OPENAI_MODELS.find(({ modelName }) => modelName === defaultModelName || modelName.startsWith(defaultModelName));
|
|
2068
2104
|
if (model === undefined) {
|
|
2069
2105
|
throw new UnexpectedError(spaceTrim__default["default"]((block) => `
|
|
2070
2106
|
Cannot find model in OpenAI models with name "${defaultModelName}" which should be used as default.
|
|
@@ -2106,7 +2142,7 @@
|
|
|
2106
2142
|
/**
|
|
2107
2143
|
* Execution Tools for calling OpenAI API Assistants
|
|
2108
2144
|
*
|
|
2109
|
-
* This is
|
|
2145
|
+
* This is useful for calling OpenAI API with a single assistant, for more wide usage use `OpenAiExecutionTools`.
|
|
2110
2146
|
*
|
|
2111
2147
|
* @public exported from `@promptbook/openai`
|
|
2112
2148
|
*/
|
|
@@ -2119,6 +2155,7 @@
|
|
|
2119
2155
|
constructor(options) {
|
|
2120
2156
|
super(options);
|
|
2121
2157
|
this.assistantId = options.assistantId;
|
|
2158
|
+
// TODO: [👱] Make limiter same as in `OpenAiExecutionTools`
|
|
2122
2159
|
}
|
|
2123
2160
|
get title() {
|
|
2124
2161
|
return 'OpenAI Assistant';
|
|
@@ -2310,7 +2347,8 @@
|
|
|
2310
2347
|
*/
|
|
2311
2348
|
|
|
2312
2349
|
/**
|
|
2313
|
-
*
|
|
2350
|
+
* Safely retrieves the global scope object (window in browser, global in Node.js)
|
|
2351
|
+
* regardless of the JavaScript environment in which the code is running
|
|
2314
2352
|
*
|
|
2315
2353
|
* Note: `$` is used to indicate that this function is not a pure function - it access global scope
|
|
2316
2354
|
*
|
|
@@ -2321,10 +2359,10 @@
|
|
|
2321
2359
|
}
|
|
2322
2360
|
|
|
2323
2361
|
/**
|
|
2324
|
-
*
|
|
2362
|
+
* Normalizes a text string to SCREAMING_CASE (all uppercase with underscores).
|
|
2325
2363
|
*
|
|
2326
|
-
* @param text
|
|
2327
|
-
* @returns
|
|
2364
|
+
* @param text The text string to be converted to SCREAMING_CASE format.
|
|
2365
|
+
* @returns The normalized text in SCREAMING_CASE format.
|
|
2328
2366
|
* @example 'HELLO_WORLD'
|
|
2329
2367
|
* @example 'I_LOVE_PROMPTBOOK'
|
|
2330
2368
|
* @public exported from `@promptbook/utils`
|
|
@@ -2376,10 +2414,10 @@
|
|
|
2376
2414
|
*/
|
|
2377
2415
|
|
|
2378
2416
|
/**
|
|
2379
|
-
*
|
|
2417
|
+
* Normalizes a text string to snake_case format.
|
|
2380
2418
|
*
|
|
2381
|
-
* @param text
|
|
2382
|
-
* @returns
|
|
2419
|
+
* @param text The text string to be converted to snake_case format.
|
|
2420
|
+
* @returns The normalized text in snake_case format.
|
|
2383
2421
|
* @example 'hello_world'
|
|
2384
2422
|
* @example 'i_love_promptbook'
|
|
2385
2423
|
* @public exported from `@promptbook/utils`
|
|
@@ -2389,11 +2427,11 @@
|
|
|
2389
2427
|
}
|
|
2390
2428
|
|
|
2391
2429
|
/**
|
|
2392
|
-
*
|
|
2430
|
+
* Global registry for storing and managing registered entities of a given type.
|
|
2393
2431
|
*
|
|
2394
2432
|
* Note: `$` is used to indicate that this function is not a pure function - it accesses and adds variables in global scope.
|
|
2395
2433
|
*
|
|
2396
|
-
* @private internal utility, exported are only
|
|
2434
|
+
* @private internal utility, exported are only singleton instances of this class
|
|
2397
2435
|
*/
|
|
2398
2436
|
class $Register {
|
|
2399
2437
|
constructor(registerName) {
|
|
@@ -2437,10 +2475,10 @@
|
|
|
2437
2475
|
}
|
|
2438
2476
|
|
|
2439
2477
|
/**
|
|
2440
|
-
*
|
|
2478
|
+
* Register for LLM tools.
|
|
2441
2479
|
*
|
|
2442
2480
|
* Note: `$` is used to indicate that this interacts with the global scope
|
|
2443
|
-
* @singleton Only one instance of each register is created per build, but
|
|
2481
|
+
* @singleton Only one instance of each register is created per build, but there can be more instances across different builds or environments.
|
|
2444
2482
|
* @public exported from `@promptbook/core`
|
|
2445
2483
|
*/
|
|
2446
2484
|
const $llmToolsRegister = new $Register('llm_execution_tools_constructors');
|
|
@@ -2459,9 +2497,9 @@
|
|
|
2459
2497
|
*/
|
|
2460
2498
|
const _OpenAiRegistration = $llmToolsRegister.register(createOpenAiExecutionTools);
|
|
2461
2499
|
/**
|
|
2462
|
-
*
|
|
2500
|
+
* Registration of the OpenAI Assistant provider
|
|
2463
2501
|
*
|
|
2464
|
-
* Note: [🏐] Configurations registrations are done in
|
|
2502
|
+
* Note: [🏐] Configurations registrations are done in register-constructor.ts BUT constructor register-constructor.ts
|
|
2465
2503
|
*
|
|
2466
2504
|
* @public exported from `@promptbook/openai`
|
|
2467
2505
|
* @public exported from `@promptbook/wizzard`
|