@promptbook/core 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 +55 -46
- 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 +1 -1
- package/umd/index.umd.js +55 -46
- package/umd/index.umd.js.map +1 -1
package/esm/index.es.js
CHANGED
|
@@ -9,7 +9,7 @@ import moment from 'moment';
|
|
|
9
9
|
/**
|
|
10
10
|
* The version of the Promptbook library
|
|
11
11
|
*/
|
|
12
|
-
var PROMPTBOOK_VERSION = '0.63.
|
|
12
|
+
var PROMPTBOOK_VERSION = '0.63.4';
|
|
13
13
|
// TODO: !!!! List here all the versions and annotate + put into script
|
|
14
14
|
|
|
15
15
|
/*! *****************************************************************************
|
|
@@ -301,7 +301,7 @@ function pipelineJsonToString(pipelineJson) {
|
|
|
301
301
|
else if (blockType === 'PROMPT_DIALOG') {
|
|
302
302
|
commands_1.push("PROMPT DIALOG");
|
|
303
303
|
// Note: Nothing special here
|
|
304
|
-
} // <- }else if([
|
|
304
|
+
} // <- }else if([🅱]
|
|
305
305
|
if (jokers) {
|
|
306
306
|
try {
|
|
307
307
|
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()) {
|
|
@@ -1143,7 +1143,7 @@ var SimplePipelineCollection = /** @class */ (function () {
|
|
|
1143
1143
|
pipelineJsonToString(unpreparePipeline(pipeline)) !==
|
|
1144
1144
|
pipelineJsonToString(unpreparePipeline(this.collection.get(pipeline.pipelineUrl)))) {
|
|
1145
1145
|
var existing = this.collection.get(pipeline.pipelineUrl);
|
|
1146
|
-
throw new ReferenceError$1(spaceTrim$1("\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 ")));
|
|
1146
|
+
throw new ReferenceError$1(spaceTrim$1("\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 ")));
|
|
1147
1147
|
}
|
|
1148
1148
|
// Note: [🧠] Overwrite existing pipeline with the same URL
|
|
1149
1149
|
this.collection.set(pipeline.pipelineUrl, pipeline);
|
|
@@ -1425,7 +1425,7 @@ var BlockTypes = [
|
|
|
1425
1425
|
'KNOWLEDGE',
|
|
1426
1426
|
'INSTRUMENT',
|
|
1427
1427
|
'ACTION',
|
|
1428
|
-
// <- [
|
|
1428
|
+
// <- [🅱]
|
|
1429
1429
|
];
|
|
1430
1430
|
|
|
1431
1431
|
/**
|
|
@@ -1624,7 +1624,7 @@ function forEachAsync(array, options, callbackfunction) {
|
|
|
1624
1624
|
});
|
|
1625
1625
|
}
|
|
1626
1626
|
|
|
1627
|
-
var PipelineCollection = [{pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",
|
|
1627
|
+
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"}];
|
|
1628
1628
|
|
|
1629
1629
|
var defaultDiacriticsRemovalMap = [
|
|
1630
1630
|
{
|
|
@@ -2238,6 +2238,8 @@ var MultipleLlmExecutionTools = /** @class */ (function () {
|
|
|
2238
2238
|
// <- Note: [🤖]
|
|
2239
2239
|
/**
|
|
2240
2240
|
* Calls the best available model
|
|
2241
|
+
*
|
|
2242
|
+
* Note: This should be private or protected but is public to be usable with duck typing
|
|
2241
2243
|
*/
|
|
2242
2244
|
MultipleLlmExecutionTools.prototype.callCommonModel = function (prompt) {
|
|
2243
2245
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -3768,7 +3770,7 @@ function prepareKnowledgePieces(knowledgeSources, options) {
|
|
|
3768
3770
|
var partialPieces, pieces;
|
|
3769
3771
|
return __generator(this, function (_a) {
|
|
3770
3772
|
switch (_a.label) {
|
|
3771
|
-
case 0: return [4 /*yield*/, prepareKnowledgeFromMarkdown(knowledgeSource.
|
|
3773
|
+
case 0: return [4 /*yield*/, prepareKnowledgeFromMarkdown(knowledgeSource.sourceContent, // <- TODO: [🐝] !!! Unhardcode markdown, detect which type it is - BE AWARE of big package size
|
|
3772
3774
|
options)];
|
|
3773
3775
|
case 1:
|
|
3774
3776
|
partialPieces = _a.sent();
|
|
@@ -3958,6 +3960,35 @@ function preparePersona(personaDescription, options) {
|
|
|
3958
3960
|
* TODO: [🏢] !! Check validity of `temperature` in pipeline
|
|
3959
3961
|
*/
|
|
3960
3962
|
|
|
3963
|
+
/**
|
|
3964
|
+
* @@@
|
|
3965
|
+
*
|
|
3966
|
+
* Note: It is usefull @@@
|
|
3967
|
+
*
|
|
3968
|
+
* @param pipeline
|
|
3969
|
+
* @public exported from `@promptbook/utils`
|
|
3970
|
+
*/
|
|
3971
|
+
function clonePipeline(pipeline) {
|
|
3972
|
+
// Note: Not using spread operator (...) because @@@
|
|
3973
|
+
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;
|
|
3974
|
+
return {
|
|
3975
|
+
pipelineUrl: pipelineUrl,
|
|
3976
|
+
sourceFile: sourceFile,
|
|
3977
|
+
title: title,
|
|
3978
|
+
promptbookVersion: promptbookVersion,
|
|
3979
|
+
description: description,
|
|
3980
|
+
parameters: parameters,
|
|
3981
|
+
promptTemplates: promptTemplates,
|
|
3982
|
+
knowledgeSources: knowledgeSources,
|
|
3983
|
+
knowledgePieces: knowledgePieces,
|
|
3984
|
+
personas: personas,
|
|
3985
|
+
preparations: preparations,
|
|
3986
|
+
};
|
|
3987
|
+
}
|
|
3988
|
+
/**
|
|
3989
|
+
* TODO: [🍙] Make some standart order of json properties
|
|
3990
|
+
*/
|
|
3991
|
+
|
|
3961
3992
|
/**
|
|
3962
3993
|
* @@@
|
|
3963
3994
|
*
|
|
@@ -4010,40 +4041,12 @@ function prepareTemplates(pipeline, options) {
|
|
|
4010
4041
|
* TODO: [🧠][🥜]
|
|
4011
4042
|
*/
|
|
4012
4043
|
|
|
4013
|
-
/**
|
|
4014
|
-
* @@@
|
|
4015
|
-
*
|
|
4016
|
-
* Note: It is usefull @@@
|
|
4017
|
-
*
|
|
4018
|
-
* @param pipeline
|
|
4019
|
-
* @public exported from `@promptbook/utils`
|
|
4020
|
-
*/
|
|
4021
|
-
function clonePipeline(pipeline) {
|
|
4022
|
-
// Note: Not using spread operator (...) because @@@
|
|
4023
|
-
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;
|
|
4024
|
-
return {
|
|
4025
|
-
pipelineUrl: pipelineUrl,
|
|
4026
|
-
sourceFile: sourceFile,
|
|
4027
|
-
title: title,
|
|
4028
|
-
promptbookVersion: promptbookVersion,
|
|
4029
|
-
description: description,
|
|
4030
|
-
parameters: parameters,
|
|
4031
|
-
promptTemplates: promptTemplates,
|
|
4032
|
-
knowledgeSources: knowledgeSources,
|
|
4033
|
-
knowledgePieces: knowledgePieces,
|
|
4034
|
-
personas: personas,
|
|
4035
|
-
preparations: preparations,
|
|
4036
|
-
};
|
|
4037
|
-
}
|
|
4038
|
-
/**
|
|
4039
|
-
* TODO: [🍙] Make some standart order of json properties
|
|
4040
|
-
*/
|
|
4041
|
-
|
|
4042
4044
|
/**
|
|
4043
4045
|
* Prepare pipeline from string (markdown) format to JSON format
|
|
4044
4046
|
*
|
|
4045
4047
|
* Note: This function does not validate logic of the pipeline
|
|
4046
4048
|
* Note: This function acts as part of compilation process
|
|
4049
|
+
* Note: When the pipeline is already prepared, it returns the same pipeline
|
|
4047
4050
|
* @public exported from `@promptbook/core`
|
|
4048
4051
|
*/
|
|
4049
4052
|
function preparePipeline(pipeline, options) {
|
|
@@ -4058,6 +4061,9 @@ function preparePipeline(pipeline, options) {
|
|
|
4058
4061
|
return __generator(this, function (_c) {
|
|
4059
4062
|
switch (_c.label) {
|
|
4060
4063
|
case 0:
|
|
4064
|
+
if (isPipelinePrepared(pipeline)) {
|
|
4065
|
+
return [2 /*return*/, pipeline];
|
|
4066
|
+
}
|
|
4061
4067
|
llmTools = options.llmTools, _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? MAX_PARALLEL_COUNT : _a, _b = options.isVerbose, isVerbose = _b === void 0 ? false : _b;
|
|
4062
4068
|
parameters = pipeline.parameters, promptTemplates = pipeline.promptTemplates, knowledgeSources = pipeline.knowledgeSources, personas = pipeline.personas;
|
|
4063
4069
|
llmToolsWithUsage = countTotalUsage(llmTools);
|
|
@@ -4191,34 +4197,37 @@ var knowledgeCommandParser = {
|
|
|
4191
4197
|
*/
|
|
4192
4198
|
parse: function (input) {
|
|
4193
4199
|
var args = input.args;
|
|
4194
|
-
var
|
|
4195
|
-
if (
|
|
4200
|
+
var sourceContent = spaceTrim(args[0] || '');
|
|
4201
|
+
if (sourceContent === '') {
|
|
4196
4202
|
throw new ParsingError("Source is not defined");
|
|
4197
4203
|
}
|
|
4198
|
-
|
|
4204
|
+
// TODO: !!!! Following checks should be applied every link in the `sourceContent`
|
|
4205
|
+
if (sourceContent.startsWith('http://')) {
|
|
4199
4206
|
throw new ParsingError("Source is not secure");
|
|
4200
4207
|
}
|
|
4201
|
-
if (!(isValidFilePath(
|
|
4208
|
+
if (!(isValidFilePath(sourceContent) || isValidUrl(sourceContent))) {
|
|
4202
4209
|
throw new ParsingError("Source not valid");
|
|
4203
4210
|
}
|
|
4204
|
-
if (
|
|
4211
|
+
if (sourceContent.startsWith('../') || sourceContent.startsWith('/') || /^[A-Z]:[\\/]+/i.test(sourceContent)) {
|
|
4205
4212
|
throw new ParsingError("Source cannot be outside of the .ptbk.md folder");
|
|
4206
4213
|
}
|
|
4207
4214
|
return {
|
|
4208
4215
|
type: 'KNOWLEDGE',
|
|
4209
|
-
|
|
4216
|
+
sourceContent: sourceContent,
|
|
4210
4217
|
};
|
|
4211
4218
|
},
|
|
4212
4219
|
/**
|
|
4213
4220
|
* Note: Prototype of [🍧] (remove this comment after full implementation)
|
|
4214
4221
|
*/
|
|
4215
4222
|
applyToPipelineJson: function (personaCommand, subjects) {
|
|
4216
|
-
var
|
|
4223
|
+
var sourceContent = personaCommand.sourceContent;
|
|
4217
4224
|
var pipelineJson = subjects.pipelineJson;
|
|
4218
|
-
var name =
|
|
4225
|
+
var name = 'source-' + sha256(hexEncoder.parse(JSON.stringify(sourceContent))).toString( /* hex */);
|
|
4226
|
+
// <- TODO: [🥬] Encapsulate sha256 to some private utility function
|
|
4227
|
+
// <- TODO: This should be replaced with a better name later in preparation (done with some propper LLM summarization)
|
|
4219
4228
|
pipelineJson.knowledgeSources.push({
|
|
4220
4229
|
name: name,
|
|
4221
|
-
|
|
4230
|
+
sourceContent: sourceContent,
|
|
4222
4231
|
});
|
|
4223
4232
|
},
|
|
4224
4233
|
};
|
|
@@ -4420,7 +4429,7 @@ var blockCommandParser = {
|
|
|
4420
4429
|
'KNOWLEDGE',
|
|
4421
4430
|
'INSTRUMENT',
|
|
4422
4431
|
'ACTION',
|
|
4423
|
-
// <- [
|
|
4432
|
+
// <- [🅱]
|
|
4424
4433
|
],
|
|
4425
4434
|
/**
|
|
4426
4435
|
* Aliases for the BLOCK command
|
|
@@ -5886,7 +5895,7 @@ function pipelineStringToJsonSync(pipelineString) {
|
|
|
5886
5895
|
if (command.blockType === 'KNOWLEDGE') {
|
|
5887
5896
|
knowledgeCommandParser.applyToPipelineJson({
|
|
5888
5897
|
type: 'KNOWLEDGE',
|
|
5889
|
-
|
|
5898
|
+
sourceContent: content, // <- TODO: [🐝] !!! Work with KNOWLEDGE which not referring to the source file or website, but its content itself
|
|
5890
5899
|
}, {
|
|
5891
5900
|
pipelineJson: pipelineJson,
|
|
5892
5901
|
templateJson: templateJson,
|