@promptbook/node 0.63.3 → 0.64.0-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 +462 -94
- package/esm/index.es.js.map +1 -1
- package/esm/typings/promptbook-collection/index.d.ts +9 -171
- package/esm/typings/src/_packages/node.index.d.ts +6 -0
- package/esm/typings/src/_packages/types.index.d.ts +5 -2
- package/esm/typings/src/commands/KNOWLEDGE/KnowledgeCommand.d.ts +2 -2
- package/esm/typings/src/llm-providers/_common/LlmConfiguration.d.ts +28 -0
- package/esm/typings/src/llm-providers/_common/LlmToolsConfiguration.d.ts +22 -0
- package/esm/typings/src/llm-providers/_common/config.d.ts +15 -0
- package/esm/typings/src/llm-providers/_common/createLlmToolsFromConfiguration.d.ts +32 -0
- package/esm/typings/src/llm-providers/_common/createLlmToolsFromConfigurationFromEnv.d.ts +23 -0
- package/esm/typings/src/llm-providers/_common/createLlmToolsFromEnv.d.ts +7 -22
- package/esm/typings/src/llm-providers/_common/getLlmToolsForCli.d.ts +1 -0
- package/esm/typings/src/llm-providers/_common/getLlmToolsForTestingAndScriptsAndPlayground.d.ts +3 -2
- package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +1 -0
- package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.d.ts +1 -0
- package/esm/typings/src/llm-providers/multiple/MultipleLlmExecutionTools.d.ts +3 -1
- package/esm/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +1 -0
- package/esm/typings/src/llm-providers/remote/RemoteLlmExecutionTools.d.ts +1 -0
- package/esm/typings/src/prepare/preparePipeline.d.ts +1 -0
- package/esm/typings/src/types/PipelineJson/KnowledgeSourceJson.d.ts +8 -2
- package/esm/typings/src/types/typeAliases.d.ts +2 -2
- package/esm/typings/src/utils/organization/TODO_string.d.ts +6 -0
- package/package.json +3 -2
- package/umd/index.umd.js +467 -97
- package/umd/index.umd.js.map +1 -1
package/umd/index.umd.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('colors'), require('fs/promises'), require('path'), require('spacetrim'), require('prettier'), require('prettier/parser-html'), require('
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports', 'colors', 'fs/promises', 'path', 'spacetrim', 'prettier', 'prettier/parser-html', '
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-node"] = {}, global.colors, global.promises, global.path, global.spaceTrim, global.prettier, global.parserHtml, global.
|
|
5
|
-
})(this, (function (exports, colors, promises, path, spaceTrim, prettier, parserHtml,
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('colors'), require('fs/promises'), require('path'), require('spacetrim'), require('prettier'), require('prettier/parser-html'), require('crypto-js/enc-hex'), require('crypto-js/sha256'), require('path/posix'), require('@anthropic-ai/sdk'), require('@azure/openai'), require('openai'), require('dotenv')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', 'colors', 'fs/promises', 'path', 'spacetrim', 'prettier', 'prettier/parser-html', 'crypto-js/enc-hex', 'crypto-js/sha256', 'path/posix', '@anthropic-ai/sdk', '@azure/openai', 'openai', 'dotenv'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-node"] = {}, global.colors, global.promises, global.path, global.spaceTrim, global.prettier, global.parserHtml, global.hexEncoder, global.sha256, global.posix, global.Anthropic, global.openai, global.OpenAI, global.dotenv));
|
|
5
|
+
})(this, (function (exports, colors, promises, path, spaceTrim, prettier, parserHtml, hexEncoder, sha256, posix, Anthropic, openai, OpenAI, dotenv) { 'use strict';
|
|
6
6
|
|
|
7
7
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
8
|
|
|
@@ -27,17 +27,17 @@
|
|
|
27
27
|
var colors__default = /*#__PURE__*/_interopDefaultLegacy(colors);
|
|
28
28
|
var spaceTrim__default = /*#__PURE__*/_interopDefaultLegacy(spaceTrim);
|
|
29
29
|
var parserHtml__default = /*#__PURE__*/_interopDefaultLegacy(parserHtml);
|
|
30
|
-
var dotenv__namespace = /*#__PURE__*/_interopNamespace(dotenv);
|
|
31
|
-
var Anthropic__default = /*#__PURE__*/_interopDefaultLegacy(Anthropic);
|
|
32
|
-
var OpenAI__default = /*#__PURE__*/_interopDefaultLegacy(OpenAI);
|
|
33
30
|
var hexEncoder__default = /*#__PURE__*/_interopDefaultLegacy(hexEncoder);
|
|
34
31
|
var sha256__default = /*#__PURE__*/_interopDefaultLegacy(sha256);
|
|
32
|
+
var Anthropic__default = /*#__PURE__*/_interopDefaultLegacy(Anthropic);
|
|
33
|
+
var OpenAI__default = /*#__PURE__*/_interopDefaultLegacy(OpenAI);
|
|
34
|
+
var dotenv__namespace = /*#__PURE__*/_interopNamespace(dotenv);
|
|
35
35
|
|
|
36
36
|
// ⚠️ WARNING: This code has been generated so that any manual changes will be overwritten
|
|
37
37
|
/**
|
|
38
38
|
* The version of the Promptbook library
|
|
39
39
|
*/
|
|
40
|
-
var PROMPTBOOK_VERSION = '0.63.
|
|
40
|
+
var PROMPTBOOK_VERSION = '0.63.4';
|
|
41
41
|
// TODO: !!!! List here all the versions and annotate + put into script
|
|
42
42
|
|
|
43
43
|
/*! *****************************************************************************
|
|
@@ -412,7 +412,7 @@
|
|
|
412
412
|
else if (blockType === 'PROMPT_DIALOG') {
|
|
413
413
|
commands_1.push("PROMPT DIALOG");
|
|
414
414
|
// Note: Nothing special here
|
|
415
|
-
} // <- }else if([
|
|
415
|
+
} // <- }else if([🅱]
|
|
416
416
|
if (jokers) {
|
|
417
417
|
try {
|
|
418
418
|
for (var jokers_1 = (e_4 = void 0, __values(jokers)), jokers_1_1 = jokers_1.next(); !jokers_1_1.done; jokers_1_1 = jokers_1.next()) {
|
|
@@ -712,7 +712,7 @@
|
|
|
712
712
|
});
|
|
713
713
|
}
|
|
714
714
|
|
|
715
|
-
var PipelineCollection = [{pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",
|
|
715
|
+
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.63.4",parameters:[{name:"knowledgeContent",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},content:"You are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {knowledgeContent}",dependentParameterNames:["knowledgeContent"],resultingParameterName:"knowledgePieces"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-from-markdown.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.ptbk.md",promptbookVersion:"0.63.4",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},content:"You are experienced data researcher, detect the important keywords in the document.\n\n# Rules\n\n- Write just keywords separated by comma\n\n# The document\n\nTake information from this document:\n\n> {knowledgePieceContent}",dependentParameterNames:["knowledgePieceContent"],resultingParameterName:"keywords"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-keywords.ptbk.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.ptbk.md",promptbookVersion:"0.63.4",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},content:"You are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Title should be concise and clear\n- Write maximum 5 words for the title\n\n# The document\n\n> {knowledgePieceContent}",expectations:{words:{min:1,max:8}},dependentParameterNames:["knowledgePieceContent"],resultingParameterName:"title"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-title.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.ptbk.md",promptbookVersion:"0.63.4",parameters:[{name:"availableModelNames",description:"List of available model names separated by comma (,)",isInput:true,isOutput:false},{name:"personaDescription",description:"Description of the persona",isInput:true,isOutput:false},{name:"modelRequirements",description:"Specific requirements for the model",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"make-model-requirements",title:"Make modelRequirements",modelRequirements:{modelVariant:"CHAT",modelName:"gpt-4-turbo"},content:"You are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Sample\n\n```json\n{\n\"modelName\": \"gpt-4o\",\n\"systemMessage\": \"You are experienced AI engineer and helpfull assistant.\",\n\"temperature\": 0.7\n}\n```\n\n## Instructions\n\n### Option `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Option `systemMessage`\n\nThe system message is used to communicate instructions or provide context to the model at the beginning of a conversation. It is displayed in a different format compared to user messages, helping the model understand its role in the conversation. The system message typically guides the model's behavior, sets the tone, or specifies desired output from the model. By utilizing the system message effectively, users can steer the model towards generating more accurate and relevant responses.\n\nFor example:\n\n> You are an experienced AI engineer and helpful assistant.\n\n> You are a friendly and knowledgeable chatbot.\n\n### Option `temperature`\n\nThe sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit.\n\nYou can pick a value between 0 and 2. For example:\n\n- `0.1`: Low temperature, extremely conservative and deterministic\n- `0.5`: Medium temperature, balanced between conservative and creative\n- `1.0`: High temperature, creative and bit random\n- `1.5`: Very high temperature, extremely creative and often chaotic and unpredictable\n- `2.0`: Maximum temperature, completely random and unpredictable, for some extreme creative use cases\n\n# The assistant\n\nTake this description of the persona:\n\n> {personaDescription}",expectFormat:"JSON",dependentParameterNames:["availableModelNames","personaDescription"],resultingParameterName:"modelRequirements"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-persona.ptbk.md"}];
|
|
716
716
|
|
|
717
717
|
/**
|
|
718
718
|
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
@@ -1279,7 +1279,7 @@
|
|
|
1279
1279
|
pipelineJsonToString(unpreparePipeline(pipeline)) !==
|
|
1280
1280
|
pipelineJsonToString(unpreparePipeline(this.collection.get(pipeline.pipelineUrl)))) {
|
|
1281
1281
|
var existing = this.collection.get(pipeline.pipelineUrl);
|
|
1282
|
-
throw new ReferenceError$1(spaceTrim.spaceTrim("\n Pipeline with URL \"".concat(pipeline.pipelineUrl, "\" is already in the collection\n\n Conflicting files:\n ").concat(existing.sourceFile || 'Unknown', "\n ").concat(pipeline.sourceFile || 'Unknown', "\n\n Note: Pipelines with the same URL are not allowed\n Only exepction is when the pipelines are identical\n\n ")));
|
|
1282
|
+
throw new ReferenceError$1(spaceTrim.spaceTrim("\n Pipeline with URL \"".concat(pipeline.pipelineUrl, "\" is already in the collection \uD83C\uDF4E\n\n Conflicting files:\n ").concat(existing.sourceFile || 'Unknown', "\n ").concat(pipeline.sourceFile || 'Unknown', "\n\n Note: You have probably forgotten to run \"ptbk make\" to update the collection\n Note: Pipelines with the same URL are not allowed\n Only exepction is when the pipelines are identical\n\n ")));
|
|
1283
1283
|
}
|
|
1284
1284
|
// Note: [🧠] Overwrite existing pipeline with the same URL
|
|
1285
1285
|
this.collection.set(pipeline.pipelineUrl, pipeline);
|
|
@@ -1956,6 +1956,8 @@
|
|
|
1956
1956
|
// <- Note: [🤖]
|
|
1957
1957
|
/**
|
|
1958
1958
|
* Calls the best available model
|
|
1959
|
+
*
|
|
1960
|
+
* Note: This should be private or protected but is public to be usable with duck typing
|
|
1959
1961
|
*/
|
|
1960
1962
|
MultipleLlmExecutionTools.prototype.callCommonModel = function (prompt) {
|
|
1961
1963
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -3464,7 +3466,7 @@
|
|
|
3464
3466
|
var partialPieces, pieces;
|
|
3465
3467
|
return __generator(this, function (_a) {
|
|
3466
3468
|
switch (_a.label) {
|
|
3467
|
-
case 0: return [4 /*yield*/, prepareKnowledgeFromMarkdown(knowledgeSource.
|
|
3469
|
+
case 0: return [4 /*yield*/, prepareKnowledgeFromMarkdown(knowledgeSource.sourceContent, // <- TODO: [🐝] !!! Unhardcode markdown, detect which type it is - BE AWARE of big package size
|
|
3468
3470
|
options)];
|
|
3469
3471
|
case 1:
|
|
3470
3472
|
partialPieces = _a.sent();
|
|
@@ -3654,6 +3656,35 @@
|
|
|
3654
3656
|
* TODO: [🏢] !! Check validity of `temperature` in pipeline
|
|
3655
3657
|
*/
|
|
3656
3658
|
|
|
3659
|
+
/**
|
|
3660
|
+
* @@@
|
|
3661
|
+
*
|
|
3662
|
+
* Note: It is usefull @@@
|
|
3663
|
+
*
|
|
3664
|
+
* @param pipeline
|
|
3665
|
+
* @public exported from `@promptbook/utils`
|
|
3666
|
+
*/
|
|
3667
|
+
function clonePipeline(pipeline) {
|
|
3668
|
+
// Note: Not using spread operator (...) because @@@
|
|
3669
|
+
var pipelineUrl = pipeline.pipelineUrl, sourceFile = pipeline.sourceFile, title = pipeline.title, promptbookVersion = pipeline.promptbookVersion, description = pipeline.description, parameters = pipeline.parameters, promptTemplates = pipeline.promptTemplates, knowledgeSources = pipeline.knowledgeSources, knowledgePieces = pipeline.knowledgePieces, personas = pipeline.personas, preparations = pipeline.preparations;
|
|
3670
|
+
return {
|
|
3671
|
+
pipelineUrl: pipelineUrl,
|
|
3672
|
+
sourceFile: sourceFile,
|
|
3673
|
+
title: title,
|
|
3674
|
+
promptbookVersion: promptbookVersion,
|
|
3675
|
+
description: description,
|
|
3676
|
+
parameters: parameters,
|
|
3677
|
+
promptTemplates: promptTemplates,
|
|
3678
|
+
knowledgeSources: knowledgeSources,
|
|
3679
|
+
knowledgePieces: knowledgePieces,
|
|
3680
|
+
personas: personas,
|
|
3681
|
+
preparations: preparations,
|
|
3682
|
+
};
|
|
3683
|
+
}
|
|
3684
|
+
/**
|
|
3685
|
+
* TODO: [🍙] Make some standart order of json properties
|
|
3686
|
+
*/
|
|
3687
|
+
|
|
3657
3688
|
/**
|
|
3658
3689
|
* @@@
|
|
3659
3690
|
*
|
|
@@ -3706,40 +3737,12 @@
|
|
|
3706
3737
|
* TODO: [🧠][🥜]
|
|
3707
3738
|
*/
|
|
3708
3739
|
|
|
3709
|
-
/**
|
|
3710
|
-
* @@@
|
|
3711
|
-
*
|
|
3712
|
-
* Note: It is usefull @@@
|
|
3713
|
-
*
|
|
3714
|
-
* @param pipeline
|
|
3715
|
-
* @public exported from `@promptbook/utils`
|
|
3716
|
-
*/
|
|
3717
|
-
function clonePipeline(pipeline) {
|
|
3718
|
-
// Note: Not using spread operator (...) because @@@
|
|
3719
|
-
var pipelineUrl = pipeline.pipelineUrl, sourceFile = pipeline.sourceFile, title = pipeline.title, promptbookVersion = pipeline.promptbookVersion, description = pipeline.description, parameters = pipeline.parameters, promptTemplates = pipeline.promptTemplates, knowledgeSources = pipeline.knowledgeSources, knowledgePieces = pipeline.knowledgePieces, personas = pipeline.personas, preparations = pipeline.preparations;
|
|
3720
|
-
return {
|
|
3721
|
-
pipelineUrl: pipelineUrl,
|
|
3722
|
-
sourceFile: sourceFile,
|
|
3723
|
-
title: title,
|
|
3724
|
-
promptbookVersion: promptbookVersion,
|
|
3725
|
-
description: description,
|
|
3726
|
-
parameters: parameters,
|
|
3727
|
-
promptTemplates: promptTemplates,
|
|
3728
|
-
knowledgeSources: knowledgeSources,
|
|
3729
|
-
knowledgePieces: knowledgePieces,
|
|
3730
|
-
personas: personas,
|
|
3731
|
-
preparations: preparations,
|
|
3732
|
-
};
|
|
3733
|
-
}
|
|
3734
|
-
/**
|
|
3735
|
-
* TODO: [🍙] Make some standart order of json properties
|
|
3736
|
-
*/
|
|
3737
|
-
|
|
3738
3740
|
/**
|
|
3739
3741
|
* Prepare pipeline from string (markdown) format to JSON format
|
|
3740
3742
|
*
|
|
3741
3743
|
* Note: This function does not validate logic of the pipeline
|
|
3742
3744
|
* Note: This function acts as part of compilation process
|
|
3745
|
+
* Note: When the pipeline is already prepared, it returns the same pipeline
|
|
3743
3746
|
* @public exported from `@promptbook/core`
|
|
3744
3747
|
*/
|
|
3745
3748
|
function preparePipeline(pipeline, options) {
|
|
@@ -3754,6 +3757,9 @@
|
|
|
3754
3757
|
return __generator(this, function (_c) {
|
|
3755
3758
|
switch (_c.label) {
|
|
3756
3759
|
case 0:
|
|
3760
|
+
if (isPipelinePrepared(pipeline)) {
|
|
3761
|
+
return [2 /*return*/, pipeline];
|
|
3762
|
+
}
|
|
3757
3763
|
llmTools = options.llmTools, _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a, _b = options.isVerbose, isVerbose = _b === void 0 ? false : _b;
|
|
3758
3764
|
parameters = pipeline.parameters, promptTemplates = pipeline.promptTemplates, knowledgeSources = pipeline.knowledgeSources, personas = pipeline.personas;
|
|
3759
3765
|
llmToolsWithUsage = countTotalUsage(llmTools);
|
|
@@ -3887,34 +3893,37 @@
|
|
|
3887
3893
|
*/
|
|
3888
3894
|
parse: function (input) {
|
|
3889
3895
|
var args = input.args;
|
|
3890
|
-
var
|
|
3891
|
-
if (
|
|
3896
|
+
var sourceContent = spaceTrim__default["default"](args[0] || '');
|
|
3897
|
+
if (sourceContent === '') {
|
|
3892
3898
|
throw new ParsingError("Source is not defined");
|
|
3893
3899
|
}
|
|
3894
|
-
|
|
3900
|
+
// TODO: !!!! Following checks should be applied every link in the `sourceContent`
|
|
3901
|
+
if (sourceContent.startsWith('http://')) {
|
|
3895
3902
|
throw new ParsingError("Source is not secure");
|
|
3896
3903
|
}
|
|
3897
|
-
if (!(isValidFilePath(
|
|
3904
|
+
if (!(isValidFilePath(sourceContent) || isValidUrl(sourceContent))) {
|
|
3898
3905
|
throw new ParsingError("Source not valid");
|
|
3899
3906
|
}
|
|
3900
|
-
if (
|
|
3907
|
+
if (sourceContent.startsWith('../') || sourceContent.startsWith('/') || /^[A-Z]:[\\/]+/i.test(sourceContent)) {
|
|
3901
3908
|
throw new ParsingError("Source cannot be outside of the .ptbk.md folder");
|
|
3902
3909
|
}
|
|
3903
3910
|
return {
|
|
3904
3911
|
type: 'KNOWLEDGE',
|
|
3905
|
-
|
|
3912
|
+
sourceContent: sourceContent,
|
|
3906
3913
|
};
|
|
3907
3914
|
},
|
|
3908
3915
|
/**
|
|
3909
3916
|
* Note: Prototype of [🍧] (remove this comment after full implementation)
|
|
3910
3917
|
*/
|
|
3911
3918
|
applyToPipelineJson: function (personaCommand, subjects) {
|
|
3912
|
-
var
|
|
3919
|
+
var sourceContent = personaCommand.sourceContent;
|
|
3913
3920
|
var pipelineJson = subjects.pipelineJson;
|
|
3914
|
-
var name =
|
|
3921
|
+
var name = 'source-' + sha256__default["default"](hexEncoder__default["default"].parse(JSON.stringify(sourceContent))).toString( /* hex */);
|
|
3922
|
+
// <- TODO: [🥬] Encapsulate sha256 to some private utility function
|
|
3923
|
+
// <- TODO: This should be replaced with a better name later in preparation (done with some propper LLM summarization)
|
|
3915
3924
|
pipelineJson.knowledgeSources.push({
|
|
3916
3925
|
name: name,
|
|
3917
|
-
|
|
3926
|
+
sourceContent: sourceContent,
|
|
3918
3927
|
});
|
|
3919
3928
|
},
|
|
3920
3929
|
};
|
|
@@ -4107,7 +4116,7 @@
|
|
|
4107
4116
|
'KNOWLEDGE',
|
|
4108
4117
|
'INSTRUMENT',
|
|
4109
4118
|
'ACTION',
|
|
4110
|
-
// <- [
|
|
4119
|
+
// <- [🅱]
|
|
4111
4120
|
];
|
|
4112
4121
|
|
|
4113
4122
|
/**
|
|
@@ -4134,7 +4143,7 @@
|
|
|
4134
4143
|
'KNOWLEDGE',
|
|
4135
4144
|
'INSTRUMENT',
|
|
4136
4145
|
'ACTION',
|
|
4137
|
-
// <- [
|
|
4146
|
+
// <- [🅱]
|
|
4138
4147
|
],
|
|
4139
4148
|
/**
|
|
4140
4149
|
* Aliases for the BLOCK command
|
|
@@ -5600,7 +5609,7 @@
|
|
|
5600
5609
|
if (command.blockType === 'KNOWLEDGE') {
|
|
5601
5610
|
knowledgeCommandParser.applyToPipelineJson({
|
|
5602
5611
|
type: 'KNOWLEDGE',
|
|
5603
|
-
|
|
5612
|
+
sourceContent: content, // <- TODO: [🐝] !!! Work with KNOWLEDGE which not referring to the source file or website, but its content itself
|
|
5604
5613
|
}, {
|
|
5605
5614
|
pipelineJson: pipelineJson,
|
|
5606
5615
|
templateJson: templateJson,
|
|
@@ -6211,7 +6220,7 @@
|
|
|
6211
6220
|
}
|
|
6212
6221
|
else {
|
|
6213
6222
|
existing = collection.get(pipeline.pipelineUrl);
|
|
6214
|
-
throw new ReferenceError(spaceTrim__default["default"]("\n Pipeline with URL \"".concat(pipeline.pipelineUrl, "\" is already in the collection\n\n Conflicting files:\n ").concat(existing.sourceFile || 'Unknown', "\n ").concat(pipeline.sourceFile || 'Unknown', "\n\n Note: Pipelines with the same URL are not allowed\n Only exepction is when the pipelines are identical\n\n ")));
|
|
6223
|
+
throw new ReferenceError(spaceTrim__default["default"]("\n Pipeline with URL \"".concat(pipeline.pipelineUrl, "\" is already in the collection \uD83C\uDF4F\n\n Conflicting files:\n ").concat(existing.sourceFile || 'Unknown', "\n ").concat(pipeline.sourceFile || 'Unknown', "\n\n Note: You have probably forgotten to run \"ptbk make\" to update the collection\n Note: Pipelines with the same URL are not allowed\n Only exepction is when the pipelines are identical\n\n ")));
|
|
6215
6224
|
}
|
|
6216
6225
|
}
|
|
6217
6226
|
}
|
|
@@ -6277,22 +6286,6 @@
|
|
|
6277
6286
|
* TODO: [🖇] What about symlinks? Maybe option isSymlinksFollowed
|
|
6278
6287
|
*/
|
|
6279
6288
|
|
|
6280
|
-
/**
|
|
6281
|
-
* This error type indicates that you try to use a feature that is not available in the current environment
|
|
6282
|
-
*
|
|
6283
|
-
* @public exported from `@promptbook/core`
|
|
6284
|
-
*/
|
|
6285
|
-
var EnvironmentMismatchError = /** @class */ (function (_super) {
|
|
6286
|
-
__extends(EnvironmentMismatchError, _super);
|
|
6287
|
-
function EnvironmentMismatchError(message) {
|
|
6288
|
-
var _this = _super.call(this, message) || this;
|
|
6289
|
-
_this.name = 'EnvironmentMismatchError';
|
|
6290
|
-
Object.setPrototypeOf(_this, EnvironmentMismatchError.prototype);
|
|
6291
|
-
return _this;
|
|
6292
|
-
}
|
|
6293
|
-
return EnvironmentMismatchError;
|
|
6294
|
-
}(Error));
|
|
6295
|
-
|
|
6296
6289
|
/**
|
|
6297
6290
|
* Helper of usage compute
|
|
6298
6291
|
*
|
|
@@ -6638,6 +6631,7 @@
|
|
|
6638
6631
|
* TODO: Maybe make custom OpenaiError
|
|
6639
6632
|
* TODO: [🧠][🈁] Maybe use `isDeterministic` from options
|
|
6640
6633
|
* TODO: [🍜] Auto use anonymous server in browser
|
|
6634
|
+
* TODO: [🧠][🌰] Allow to pass `title` for tracking purposes
|
|
6641
6635
|
*/
|
|
6642
6636
|
|
|
6643
6637
|
/**
|
|
@@ -6991,6 +6985,255 @@
|
|
|
6991
6985
|
* TODO: [🚸] Not all models are compatible with JSON mode, add this information here and use it
|
|
6992
6986
|
*/
|
|
6993
6987
|
|
|
6988
|
+
/**
|
|
6989
|
+
* Execution Tools for calling Azure OpenAI API.
|
|
6990
|
+
*
|
|
6991
|
+
* @public exported from `@promptbook/azure-openai`
|
|
6992
|
+
*/
|
|
6993
|
+
var AzureOpenAiExecutionTools = /** @class */ (function () {
|
|
6994
|
+
/**
|
|
6995
|
+
* Creates OpenAI Execution Tools.
|
|
6996
|
+
*
|
|
6997
|
+
* @param options which are relevant are directly passed to the OpenAI client
|
|
6998
|
+
*/
|
|
6999
|
+
function AzureOpenAiExecutionTools(options) {
|
|
7000
|
+
this.options = options;
|
|
7001
|
+
this.client = new openai.OpenAIClient("https://".concat(options.resourceName, ".openai.azure.com/"), new openai.AzureKeyCredential(options.apiKey));
|
|
7002
|
+
}
|
|
7003
|
+
Object.defineProperty(AzureOpenAiExecutionTools.prototype, "title", {
|
|
7004
|
+
get: function () {
|
|
7005
|
+
return 'Azure OpenAI';
|
|
7006
|
+
},
|
|
7007
|
+
enumerable: false,
|
|
7008
|
+
configurable: true
|
|
7009
|
+
});
|
|
7010
|
+
Object.defineProperty(AzureOpenAiExecutionTools.prototype, "description", {
|
|
7011
|
+
get: function () {
|
|
7012
|
+
return 'Use all models trained by OpenAI provided by Azure';
|
|
7013
|
+
},
|
|
7014
|
+
enumerable: false,
|
|
7015
|
+
configurable: true
|
|
7016
|
+
});
|
|
7017
|
+
/**
|
|
7018
|
+
* Calls OpenAI API to use a chat model.
|
|
7019
|
+
*/
|
|
7020
|
+
AzureOpenAiExecutionTools.prototype.callChatModel = function (prompt) {
|
|
7021
|
+
var _a, _b;
|
|
7022
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
7023
|
+
var content, parameters, modelRequirements, modelName, modelSettings, rawPromptContent, messages, start, complete, rawRequest, rawResponse, resultContent, usage, error_1;
|
|
7024
|
+
var _c;
|
|
7025
|
+
return __generator(this, function (_d) {
|
|
7026
|
+
switch (_d.label) {
|
|
7027
|
+
case 0:
|
|
7028
|
+
if (this.options.isVerbose) {
|
|
7029
|
+
console.info('💬 OpenAI callChatModel call');
|
|
7030
|
+
}
|
|
7031
|
+
content = prompt.content, parameters = prompt.parameters, modelRequirements = prompt.modelRequirements;
|
|
7032
|
+
// TODO: [☂] Use here more modelRequirements
|
|
7033
|
+
if (modelRequirements.modelVariant !== 'CHAT') {
|
|
7034
|
+
throw new PipelineExecutionError('Use callChatModel only for CHAT variant');
|
|
7035
|
+
}
|
|
7036
|
+
_d.label = 1;
|
|
7037
|
+
case 1:
|
|
7038
|
+
_d.trys.push([1, 3, , 4]);
|
|
7039
|
+
modelName = prompt.modelRequirements.modelName || this.options.deploymentName;
|
|
7040
|
+
modelSettings = {
|
|
7041
|
+
maxTokens: modelRequirements.maxTokens,
|
|
7042
|
+
// <- TODO: [🌾] Make some global max cap for maxTokens
|
|
7043
|
+
temperature: modelRequirements.temperature,
|
|
7044
|
+
user: this.options.user,
|
|
7045
|
+
// <- TODO: [🈁] Use `seed` here AND/OR use is `isDeterministic` for entire execution tools
|
|
7046
|
+
// <- Note: [🧆]
|
|
7047
|
+
};
|
|
7048
|
+
rawPromptContent = replaceParameters(content, __assign(__assign({}, parameters), { modelName: modelName }));
|
|
7049
|
+
messages = __spreadArray(__spreadArray([], __read((modelRequirements.systemMessage === undefined
|
|
7050
|
+
? []
|
|
7051
|
+
: [
|
|
7052
|
+
{
|
|
7053
|
+
role: 'system',
|
|
7054
|
+
content: modelRequirements.systemMessage,
|
|
7055
|
+
},
|
|
7056
|
+
])), false), [
|
|
7057
|
+
{
|
|
7058
|
+
role: 'user',
|
|
7059
|
+
content: rawPromptContent,
|
|
7060
|
+
},
|
|
7061
|
+
], false);
|
|
7062
|
+
start = getCurrentIsoDate();
|
|
7063
|
+
complete = void 0;
|
|
7064
|
+
if (this.options.isVerbose) {
|
|
7065
|
+
console.info(colors__default["default"].bgWhite('messages'), JSON.stringify(messages, null, 4));
|
|
7066
|
+
}
|
|
7067
|
+
rawRequest = [modelName, messages, modelSettings];
|
|
7068
|
+
return [4 /*yield*/, (_c = this.client).getChatCompletions.apply(_c, __spreadArray([], __read(rawRequest), false))];
|
|
7069
|
+
case 2:
|
|
7070
|
+
rawResponse = _d.sent();
|
|
7071
|
+
if (this.options.isVerbose) {
|
|
7072
|
+
console.info(colors__default["default"].bgWhite('rawResponse'), JSON.stringify(rawResponse, null, 4));
|
|
7073
|
+
}
|
|
7074
|
+
if (!rawResponse.choices[0]) {
|
|
7075
|
+
throw new PipelineExecutionError('No choises from Azure OpenAI');
|
|
7076
|
+
}
|
|
7077
|
+
if (rawResponse.choices.length > 1) {
|
|
7078
|
+
// TODO: This should be maybe only warning
|
|
7079
|
+
throw new PipelineExecutionError('More than one choise from Azure OpenAI');
|
|
7080
|
+
}
|
|
7081
|
+
if (!rawResponse.choices[0].message || !rawResponse.choices[0].message.content) {
|
|
7082
|
+
throw new PipelineExecutionError('Empty response from Azure OpenAI');
|
|
7083
|
+
}
|
|
7084
|
+
resultContent = rawResponse.choices[0].message.content;
|
|
7085
|
+
// eslint-disable-next-line prefer-const
|
|
7086
|
+
complete = getCurrentIsoDate();
|
|
7087
|
+
usage = {
|
|
7088
|
+
price: uncertainNumber() /* <- TODO: [🐞] Compute usage */,
|
|
7089
|
+
input: __assign({ tokensCount: uncertainNumber((_a = rawResponse.usage) === null || _a === void 0 ? void 0 : _a.promptTokens) }, computeUsageCounts(prompt.content)),
|
|
7090
|
+
output: __assign({ tokensCount: uncertainNumber((_b = rawResponse.usage) === null || _b === void 0 ? void 0 : _b.completionTokens) }, computeUsageCounts(prompt.content)),
|
|
7091
|
+
};
|
|
7092
|
+
return [2 /*return*/, {
|
|
7093
|
+
content: resultContent,
|
|
7094
|
+
modelName: modelName,
|
|
7095
|
+
timing: {
|
|
7096
|
+
start: start,
|
|
7097
|
+
complete: complete,
|
|
7098
|
+
},
|
|
7099
|
+
usage: usage,
|
|
7100
|
+
rawPromptContent: rawPromptContent,
|
|
7101
|
+
rawRequest: rawRequest,
|
|
7102
|
+
rawResponse: rawResponse,
|
|
7103
|
+
// <- [🗯]
|
|
7104
|
+
}];
|
|
7105
|
+
case 3:
|
|
7106
|
+
error_1 = _d.sent();
|
|
7107
|
+
throw this.transformAzureError(error_1);
|
|
7108
|
+
case 4: return [2 /*return*/];
|
|
7109
|
+
}
|
|
7110
|
+
});
|
|
7111
|
+
});
|
|
7112
|
+
};
|
|
7113
|
+
/**
|
|
7114
|
+
* Calls Azure OpenAI API to use a complete model.
|
|
7115
|
+
*/
|
|
7116
|
+
AzureOpenAiExecutionTools.prototype.callCompletionModel = function (prompt) {
|
|
7117
|
+
var _a, _b;
|
|
7118
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
7119
|
+
var content, parameters, modelRequirements, modelName, modelSettings, start, complete, rawPromptContent, rawRequest, rawResponse, resultContent, usage, error_2;
|
|
7120
|
+
var _c;
|
|
7121
|
+
return __generator(this, function (_d) {
|
|
7122
|
+
switch (_d.label) {
|
|
7123
|
+
case 0:
|
|
7124
|
+
if (this.options.isVerbose) {
|
|
7125
|
+
console.info('🖋 OpenAI callCompletionModel call');
|
|
7126
|
+
}
|
|
7127
|
+
content = prompt.content, parameters = prompt.parameters, modelRequirements = prompt.modelRequirements;
|
|
7128
|
+
// TODO: [☂] Use here more modelRequirements
|
|
7129
|
+
if (modelRequirements.modelVariant !== 'COMPLETION') {
|
|
7130
|
+
throw new PipelineExecutionError('Use callCompletionModel only for COMPLETION variant');
|
|
7131
|
+
}
|
|
7132
|
+
_d.label = 1;
|
|
7133
|
+
case 1:
|
|
7134
|
+
_d.trys.push([1, 3, , 4]);
|
|
7135
|
+
modelName = prompt.modelRequirements.modelName || this.options.deploymentName;
|
|
7136
|
+
modelSettings = {
|
|
7137
|
+
maxTokens: modelRequirements.maxTokens || 2000,
|
|
7138
|
+
// <- TODO: [🌾] Make some global max cap for maxTokens
|
|
7139
|
+
temperature: modelRequirements.temperature,
|
|
7140
|
+
user: this.options.user,
|
|
7141
|
+
// <- TODO: [🈁] Use `seed` here AND/OR use is `isDeterministic` for entire execution tools
|
|
7142
|
+
// <- Note: [🧆]
|
|
7143
|
+
};
|
|
7144
|
+
start = getCurrentIsoDate();
|
|
7145
|
+
complete = void 0;
|
|
7146
|
+
if (this.options.isVerbose) {
|
|
7147
|
+
console.info(colors__default["default"].bgWhite('content'), JSON.stringify(content, null, 4));
|
|
7148
|
+
console.info(colors__default["default"].bgWhite('parameters'), JSON.stringify(parameters, null, 4));
|
|
7149
|
+
}
|
|
7150
|
+
rawPromptContent = replaceParameters(content, __assign(__assign({}, parameters), { modelName: modelName }));
|
|
7151
|
+
rawRequest = [
|
|
7152
|
+
modelName,
|
|
7153
|
+
[rawPromptContent],
|
|
7154
|
+
modelSettings,
|
|
7155
|
+
];
|
|
7156
|
+
return [4 /*yield*/, (_c = this.client).getCompletions.apply(_c, __spreadArray([], __read(rawRequest), false))];
|
|
7157
|
+
case 2:
|
|
7158
|
+
rawResponse = _d.sent();
|
|
7159
|
+
if (this.options.isVerbose) {
|
|
7160
|
+
console.info(colors__default["default"].bgWhite('rawResponse'), JSON.stringify(rawResponse, null, 4));
|
|
7161
|
+
}
|
|
7162
|
+
if (!rawResponse.choices[0]) {
|
|
7163
|
+
throw new PipelineExecutionError('No choises from OpenAI');
|
|
7164
|
+
}
|
|
7165
|
+
if (rawResponse.choices.length > 1) {
|
|
7166
|
+
// TODO: This should be maybe only warning
|
|
7167
|
+
throw new PipelineExecutionError('More than one choise from OpenAI');
|
|
7168
|
+
}
|
|
7169
|
+
resultContent = rawResponse.choices[0].text;
|
|
7170
|
+
// eslint-disable-next-line prefer-const
|
|
7171
|
+
complete = getCurrentIsoDate();
|
|
7172
|
+
usage = {
|
|
7173
|
+
price: uncertainNumber() /* <- TODO: [🐞] Compute usage */,
|
|
7174
|
+
input: __assign({ tokensCount: uncertainNumber((_a = rawResponse.usage) === null || _a === void 0 ? void 0 : _a.promptTokens) }, computeUsageCounts(prompt.content)),
|
|
7175
|
+
output: __assign({ tokensCount: uncertainNumber((_b = rawResponse.usage) === null || _b === void 0 ? void 0 : _b.completionTokens) }, computeUsageCounts(prompt.content)),
|
|
7176
|
+
};
|
|
7177
|
+
return [2 /*return*/, {
|
|
7178
|
+
content: resultContent,
|
|
7179
|
+
modelName: modelName,
|
|
7180
|
+
timing: {
|
|
7181
|
+
start: start,
|
|
7182
|
+
complete: complete,
|
|
7183
|
+
},
|
|
7184
|
+
usage: usage,
|
|
7185
|
+
rawPromptContent: rawPromptContent,
|
|
7186
|
+
rawRequest: rawRequest,
|
|
7187
|
+
rawResponse: rawResponse,
|
|
7188
|
+
// <- [🗯]
|
|
7189
|
+
}];
|
|
7190
|
+
case 3:
|
|
7191
|
+
error_2 = _d.sent();
|
|
7192
|
+
throw this.transformAzureError(error_2);
|
|
7193
|
+
case 4: return [2 /*return*/];
|
|
7194
|
+
}
|
|
7195
|
+
});
|
|
7196
|
+
});
|
|
7197
|
+
};
|
|
7198
|
+
// <- Note: [🤖] callXxxModel
|
|
7199
|
+
/**
|
|
7200
|
+
* Changes Azure error (which is not propper Error but object) to propper Error
|
|
7201
|
+
*/
|
|
7202
|
+
AzureOpenAiExecutionTools.prototype.transformAzureError = function (azureError) {
|
|
7203
|
+
if (typeof azureError !== 'object' || azureError === null) {
|
|
7204
|
+
return new PipelineExecutionError("Unknown Azure OpenAI error");
|
|
7205
|
+
}
|
|
7206
|
+
var code = azureError.code, message = azureError.message;
|
|
7207
|
+
return new PipelineExecutionError("".concat(code, ": ").concat(message));
|
|
7208
|
+
};
|
|
7209
|
+
/**
|
|
7210
|
+
* List all available Azure OpenAI models that can be used
|
|
7211
|
+
*/
|
|
7212
|
+
AzureOpenAiExecutionTools.prototype.listModels = function () {
|
|
7213
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
7214
|
+
return __generator(this, function (_a) {
|
|
7215
|
+
// TODO: !!! Do here some filtering which models are really available as deployment
|
|
7216
|
+
// @see https://management.azure.com/subscriptions/subscriptionId/resourceGroups/resourceGroupName/providers/Microsoft.CognitiveServices/accounts/accountName/deployments?api-version=2023-05-01
|
|
7217
|
+
return [2 /*return*/, OPENAI_MODELS.map(function (_a) {
|
|
7218
|
+
var modelTitle = _a.modelTitle, modelName = _a.modelName, modelVariant = _a.modelVariant;
|
|
7219
|
+
return ({
|
|
7220
|
+
modelTitle: "Azure ".concat(modelTitle),
|
|
7221
|
+
modelName: modelName,
|
|
7222
|
+
modelVariant: modelVariant,
|
|
7223
|
+
});
|
|
7224
|
+
})];
|
|
7225
|
+
});
|
|
7226
|
+
});
|
|
7227
|
+
};
|
|
7228
|
+
return AzureOpenAiExecutionTools;
|
|
7229
|
+
}());
|
|
7230
|
+
/**
|
|
7231
|
+
* TODO: Maybe Create some common util for callChatModel and callCompletionModel
|
|
7232
|
+
* TODO: Maybe make custom AzureOpenaiError
|
|
7233
|
+
* TODO: [🧠][🈁] Maybe use `isDeterministic` from options
|
|
7234
|
+
* TODO: [🧠][🌰] Allow to pass `title` for tracking purposes
|
|
7235
|
+
*/
|
|
7236
|
+
|
|
6994
7237
|
/**
|
|
6995
7238
|
* Computes the usage of the OpenAI API based on the response from OpenAI
|
|
6996
7239
|
*
|
|
@@ -7327,12 +7570,104 @@
|
|
|
7327
7570
|
* TODO: Maybe Create some common util for callChatModel and callCompletionModel
|
|
7328
7571
|
* TODO: Maybe make custom OpenaiError
|
|
7329
7572
|
* TODO: [🧠][🈁] Maybe use `isDeterministic` from options
|
|
7573
|
+
* TODO: [🧠][🌰] Allow to pass `title` for tracking purposes
|
|
7330
7574
|
*/
|
|
7331
7575
|
|
|
7576
|
+
/**
|
|
7577
|
+
* @public exported from `@promptbook/node`
|
|
7578
|
+
*/
|
|
7579
|
+
var LLM_CONFIGURATION_BOILERPLATES = [
|
|
7580
|
+
{
|
|
7581
|
+
title: 'Open AI',
|
|
7582
|
+
packageName: '@promptbook/openai',
|
|
7583
|
+
className: 'OpenAiExecutionTools',
|
|
7584
|
+
options: {
|
|
7585
|
+
apiKey: 'sk-',
|
|
7586
|
+
},
|
|
7587
|
+
},
|
|
7588
|
+
{
|
|
7589
|
+
title: 'Anthropic Claude',
|
|
7590
|
+
packageName: '@promptbook/anthropic-claude',
|
|
7591
|
+
className: 'AnthropicClaudeExecutionTools',
|
|
7592
|
+
options: {
|
|
7593
|
+
apiKey: 'sk-ant-api03-',
|
|
7594
|
+
},
|
|
7595
|
+
},
|
|
7596
|
+
{
|
|
7597
|
+
title: 'Azure Open AI',
|
|
7598
|
+
packageName: '@promptbook/azure-openai',
|
|
7599
|
+
className: 'AzureOpenAiExecutionTools',
|
|
7600
|
+
options: {
|
|
7601
|
+
// TODO: !!!> resourceName
|
|
7602
|
+
// TODO: !!!> deploymentName
|
|
7603
|
+
apiKey: 'sk-',
|
|
7604
|
+
},
|
|
7605
|
+
},
|
|
7606
|
+
// <- Note: [🦑] Add here new LLM provider
|
|
7607
|
+
];
|
|
7608
|
+
/**
|
|
7609
|
+
* @private internal type for `createLlmToolsFromConfiguration`
|
|
7610
|
+
*/
|
|
7611
|
+
var EXECUTION_TOOLS_CLASSES = {
|
|
7612
|
+
getOpenAiExecutionTools: function (options) {
|
|
7613
|
+
return new OpenAiExecutionTools(__assign(__assign({}, options), { dangerouslyAllowBrowser: true /* <- TODO: [🧠] !!! Some mechanism for auto-detection of browser, maybe hide in `OpenAiExecutionTools` */ }));
|
|
7614
|
+
},
|
|
7615
|
+
getAnthropicClaudeExecutionTools: function (options) { return new AnthropicClaudeExecutionTools(options); },
|
|
7616
|
+
getAzureOpenAiExecutionTools: function (options) { return new AzureOpenAiExecutionTools(options); },
|
|
7617
|
+
// <- Note: [🦑] Add here new LLM provider
|
|
7618
|
+
};
|
|
7619
|
+
/**
|
|
7620
|
+
* TODO: [🧠] Better file name than `config.ts` + maybe move to two separate files
|
|
7621
|
+
* TODO: [🧠][🎌] Adding this should be responsibility of each provider package NOT this one central place
|
|
7622
|
+
*/
|
|
7623
|
+
|
|
7624
|
+
/**
|
|
7625
|
+
* This error type indicates that you try to use a feature that is not available in the current environment
|
|
7626
|
+
*
|
|
7627
|
+
* @public exported from `@promptbook/core`
|
|
7628
|
+
*/
|
|
7629
|
+
var EnvironmentMismatchError = /** @class */ (function (_super) {
|
|
7630
|
+
__extends(EnvironmentMismatchError, _super);
|
|
7631
|
+
function EnvironmentMismatchError(message) {
|
|
7632
|
+
var _this = _super.call(this, message) || this;
|
|
7633
|
+
_this.name = 'EnvironmentMismatchError';
|
|
7634
|
+
Object.setPrototypeOf(_this, EnvironmentMismatchError.prototype);
|
|
7635
|
+
return _this;
|
|
7636
|
+
}
|
|
7637
|
+
return EnvironmentMismatchError;
|
|
7638
|
+
}(Error));
|
|
7639
|
+
|
|
7332
7640
|
/**
|
|
7333
7641
|
* @@@
|
|
7334
7642
|
*
|
|
7335
|
-
* Note: This function is not cached, every call creates new instance of `
|
|
7643
|
+
* Note: This function is not cached, every call creates new instance of `MultipleLlmExecutionTools`
|
|
7644
|
+
*
|
|
7645
|
+
* @returns @@@
|
|
7646
|
+
* @public exported from `@promptbook/node`
|
|
7647
|
+
*/
|
|
7648
|
+
function createLlmToolsFromConfiguration(configuration, options) {
|
|
7649
|
+
if (options === void 0) { options = {}; }
|
|
7650
|
+
if (!isRunningInNode()) {
|
|
7651
|
+
throw new EnvironmentMismatchError('Function `createLlmToolsFromEnv` works only in Node.js environment');
|
|
7652
|
+
}
|
|
7653
|
+
var _a = options.isVerbose, isVerbose = _a === void 0 ? false : _a;
|
|
7654
|
+
dotenv__namespace.config();
|
|
7655
|
+
var llmTools = configuration.map(function (llmConfiguration) {
|
|
7656
|
+
return EXECUTION_TOOLS_CLASSES["get".concat(llmConfiguration.className)](__assign({ isVerbose: isVerbose }, llmConfiguration.options));
|
|
7657
|
+
});
|
|
7658
|
+
return joinLlmExecutionTools.apply(void 0, __spreadArray([], __read(llmTools), false));
|
|
7659
|
+
}
|
|
7660
|
+
/**
|
|
7661
|
+
* TODO: [🧠][🎌] Dynamically install required providers
|
|
7662
|
+
* TODO: @@@ write discussion about this - wizzard
|
|
7663
|
+
* TODO: [🧠][🍛] Which name is better `createLlmToolsFromConfig` or `createLlmToolsFromConfiguration`?
|
|
7664
|
+
* TODO: [🧠] Is there some meaningfull way how to test this util
|
|
7665
|
+
* Note: [🟢] This code should never be published outside of `@promptbook/node` and `@promptbook/cli` and `@promptbook/cli`
|
|
7666
|
+
* TODO: This should be maybe not under `_common` but under `utils`
|
|
7667
|
+
*/
|
|
7668
|
+
|
|
7669
|
+
/**
|
|
7670
|
+
* @@@
|
|
7336
7671
|
*
|
|
7337
7672
|
* @@@ .env
|
|
7338
7673
|
*
|
|
@@ -7343,46 +7678,77 @@
|
|
|
7343
7678
|
* @returns @@@
|
|
7344
7679
|
* @public exported from `@promptbook/node`
|
|
7345
7680
|
*/
|
|
7346
|
-
function
|
|
7347
|
-
if (options === void 0) { options = {}; }
|
|
7681
|
+
function createLlmToolsFromConfigurationFromEnv() {
|
|
7348
7682
|
if (!isRunningInNode()) {
|
|
7349
7683
|
throw new EnvironmentMismatchError('Function `createLlmToolsFromEnv` works only in Node.js environment');
|
|
7350
7684
|
}
|
|
7351
|
-
var
|
|
7352
|
-
dotenv__namespace.config();
|
|
7353
|
-
var llmTools = [];
|
|
7685
|
+
var llmToolsConfiguration = [];
|
|
7354
7686
|
if (typeof process.env.OPENAI_API_KEY === 'string') {
|
|
7355
|
-
|
|
7356
|
-
|
|
7357
|
-
|
|
7358
|
-
|
|
7687
|
+
llmToolsConfiguration.push({
|
|
7688
|
+
title: 'OpenAI (from env)',
|
|
7689
|
+
packageName: '@promptbook/openai',
|
|
7690
|
+
className: 'OpenAiExecutionTools',
|
|
7691
|
+
options: {
|
|
7692
|
+
apiKey: process.env.OPENAI_API_KEY,
|
|
7693
|
+
},
|
|
7694
|
+
});
|
|
7359
7695
|
}
|
|
7360
7696
|
if (typeof process.env.ANTHROPIC_CLAUDE_API_KEY === 'string') {
|
|
7361
|
-
|
|
7362
|
-
|
|
7363
|
-
|
|
7364
|
-
|
|
7365
|
-
|
|
7366
|
-
|
|
7367
|
-
|
|
7697
|
+
llmToolsConfiguration.push({
|
|
7698
|
+
title: 'Claude (from env)',
|
|
7699
|
+
packageName: '@promptbook/antrhopic-claude',
|
|
7700
|
+
className: 'AnthropicClaudeExecutionTools',
|
|
7701
|
+
options: {
|
|
7702
|
+
apiKey: process.env.ANTHROPIC_CLAUDE_API_KEY,
|
|
7703
|
+
},
|
|
7704
|
+
});
|
|
7368
7705
|
}
|
|
7369
|
-
|
|
7370
|
-
|
|
7706
|
+
// <- Note: [🦑] Add here new LLM provider
|
|
7707
|
+
return llmToolsConfiguration;
|
|
7708
|
+
}
|
|
7709
|
+
/**
|
|
7710
|
+
* TODO: Add Azure OpenAI
|
|
7711
|
+
* TODO: [🧠][🍛]
|
|
7712
|
+
* TODO: [🧠] Is there some meaningfull way how to test this util
|
|
7713
|
+
* Note: [🟢] This code should never be published outside of `@promptbook/node` and `@promptbook/cli` and `@promptbook/cli`
|
|
7714
|
+
* TODO: [👷♂️] @@@ Manual about construction of llmTools
|
|
7715
|
+
* TODO: This should be maybe not under `_common` but under `utils`
|
|
7716
|
+
* TODO: [🧠] Maybe pass env as argument
|
|
7717
|
+
*/
|
|
7718
|
+
|
|
7719
|
+
/**
|
|
7720
|
+
* @@@
|
|
7721
|
+
*
|
|
7722
|
+
* Note: This function is not cached, every call creates new instance of `MultipleLlmExecutionTools`
|
|
7723
|
+
*
|
|
7724
|
+
* @@@ .env
|
|
7725
|
+
*
|
|
7726
|
+
* It looks for environment variables:
|
|
7727
|
+
* - `process.env.OPENAI_API_KEY`
|
|
7728
|
+
* - `process.env.ANTHROPIC_CLAUDE_API_KEY`
|
|
7729
|
+
*
|
|
7730
|
+
* @returns @@@
|
|
7731
|
+
* @public exported from `@promptbook/node`
|
|
7732
|
+
*/
|
|
7733
|
+
function createLlmToolsFromEnv(options) {
|
|
7734
|
+
if (options === void 0) { options = {}; }
|
|
7735
|
+
if (!isRunningInNode()) {
|
|
7736
|
+
throw new EnvironmentMismatchError('Function `createLlmToolsFromEnv` works only in Node.js environment');
|
|
7371
7737
|
}
|
|
7372
|
-
|
|
7373
|
-
|
|
7738
|
+
var configuration = createLlmToolsFromConfigurationFromEnv();
|
|
7739
|
+
if (configuration.length === 0) {
|
|
7740
|
+
// TODO: [🥃]
|
|
7741
|
+
throw new Error(spaceTrim__default["default"]("\n No LLM tools found in the environment\n\n Please set one of environment variables:\n - OPENAI_API_KEY\n - ANTHROPIC_CLAUDE_API_KEY\n "));
|
|
7374
7742
|
}
|
|
7743
|
+
return createLlmToolsFromConfiguration(configuration, options);
|
|
7375
7744
|
}
|
|
7376
7745
|
/**
|
|
7377
|
-
* TODO:
|
|
7378
|
-
* TODO:
|
|
7379
|
-
* TODO: Add Azure
|
|
7380
|
-
* TODO: [🧠] Which name is better `createLlmToolsFromEnv` or `createLlmToolsFromEnvironment`?
|
|
7746
|
+
* TODO: @@@ write `createLlmToolsFromEnv` vs `createLlmToolsFromConfigurationFromEnv` vs `createLlmToolsFromConfiguration`
|
|
7747
|
+
* TODO: [🧠][🍛] Which name is better `createLlmToolsFromEnv` or `createLlmToolsFromEnvironment`?
|
|
7381
7748
|
* TODO: [🧠] Is there some meaningfull way how to test this util
|
|
7382
|
-
* TODO: [🧠] Maybe pass env as argument
|
|
7383
7749
|
* Note: [🟢] This code should never be published outside of `@promptbook/node` and `@promptbook/cli` and `@promptbook/cli`
|
|
7384
|
-
* TODO: [👷♂️] @@@ Manual about construction of llmTools
|
|
7385
7750
|
* TODO: [🥃] Allow `ptbk make` without llm tools
|
|
7751
|
+
* TODO: This should be maybe not under `_common` but under `utils`
|
|
7386
7752
|
*/
|
|
7387
7753
|
|
|
7388
7754
|
/**
|
|
@@ -7436,6 +7802,7 @@
|
|
|
7436
7802
|
FilesStorage.prototype.getFilenameForKey = function (key) {
|
|
7437
7803
|
var name = titleToName(key);
|
|
7438
7804
|
var hash = sha256__default["default"](hexEncoder__default["default"].parse(name)).toString( /* hex */);
|
|
7805
|
+
// <- TODO: [🥬] Encapsulate sha256 to some private utility function
|
|
7439
7806
|
return path.join.apply(void 0, __spreadArray(__spreadArray([this.options.cacheFolderPath], __read(nameToSubfolderPath(hash /* <- TODO: [🎎] Maybe add some SHA256 prefix */)), false), ["".concat(name.substring(0, MAX_FILENAME_LENGTH), ".json")], false));
|
|
7440
7807
|
};
|
|
7441
7808
|
/**
|
|
@@ -7513,8 +7880,11 @@
|
|
|
7513
7880
|
*/
|
|
7514
7881
|
|
|
7515
7882
|
exports.FilesStorage = FilesStorage;
|
|
7883
|
+
exports.LLM_CONFIGURATION_BOILERPLATES = LLM_CONFIGURATION_BOILERPLATES;
|
|
7516
7884
|
exports.PROMPTBOOK_VERSION = PROMPTBOOK_VERSION;
|
|
7517
7885
|
exports.createCollectionFromDirectory = createCollectionFromDirectory;
|
|
7886
|
+
exports.createLlmToolsFromConfiguration = createLlmToolsFromConfiguration;
|
|
7887
|
+
exports.createLlmToolsFromConfigurationFromEnv = createLlmToolsFromConfigurationFromEnv;
|
|
7518
7888
|
exports.createLlmToolsFromEnv = createLlmToolsFromEnv;
|
|
7519
7889
|
|
|
7520
7890
|
Object.defineProperty(exports, '__esModule', { value: true });
|