@promptbook/cli 0.59.0-29 → 0.59.0-30
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 +55 -0
- package/esm/index.es.js +68 -35
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/config.d.ts +1 -1
- package/esm/typings/src/llm-providers/anthropic-claude/anthropic-claude-models.d.ts +1 -0
- package/esm/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +8 -0
- package/esm/typings/src/llm-providers/openai/openai-models.d.ts +1 -0
- package/esm/typings/src/types/ModelRequirements.d.ts +1 -1
- package/esm/typings/src/types/PromptbookJson/MaterialKnowledgePieceJson.d.ts +2 -2
- package/package.json +2 -2
- package/umd/index.umd.js +68 -35
- package/umd/index.umd.js.map +1 -1
- package/umd/typings/src/config.d.ts +1 -1
- package/umd/typings/src/llm-providers/anthropic-claude/anthropic-claude-models.d.ts +1 -0
- package/umd/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +8 -0
- package/umd/typings/src/llm-providers/openai/openai-models.d.ts +1 -0
- package/umd/typings/src/types/ModelRequirements.d.ts +1 -1
- package/umd/typings/src/types/PromptbookJson/MaterialKnowledgePieceJson.d.ts +2 -2
- /package/esm/typings/promptbook-library/{promptbook-library.d.ts → index.d.ts} +0 -0
- /package/umd/typings/promptbook-library/{promptbook-library.d.ts → index.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -34,6 +34,61 @@ npm i -g @promptbook/cli
|
|
|
34
34
|
|
|
35
35
|
CLI utils for Promptbook. After install you can use `promptbook` command in terminal:
|
|
36
36
|
|
|
37
|
+
## Make your Promptbook Library
|
|
38
|
+
|
|
39
|
+
You can prebuild your own Promptbook library with `promptbook make` command:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
npx promptbook make ./promptbook-library --format typescript --verbose
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
This will emit `index.ts` with `getPromptbookLibrary` function file in `promptbook-library` directory.
|
|
46
|
+
|
|
47
|
+
Then just use it:
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
import { createPromptbookExecutor, assertsExecutionSuccessful } from '@promptbook/core';
|
|
51
|
+
import { getPromptbookLibrary } from './promptbook-library'; // <- Importing from pre-built library
|
|
52
|
+
import { JavascriptExecutionTools } from '@promptbook/execute-javascript';
|
|
53
|
+
import { OpenAiExecutionTools } from '@promptbook/openai';
|
|
54
|
+
|
|
55
|
+
// ▶ Get one Promptbook
|
|
56
|
+
const promptbook = await getPromptbookLibrary().getPromptbookByUrl(
|
|
57
|
+
`https://promptbook.studio/my-library/write-article.ptbk.md`,
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
// ▶ Prepare tools
|
|
61
|
+
const tools = {
|
|
62
|
+
llm: new OpenAiExecutionTools({
|
|
63
|
+
isVerbose: true,
|
|
64
|
+
apiKey: process.env.OPENAI_API_KEY,
|
|
65
|
+
}),
|
|
66
|
+
script: [new JavascriptExecutionTools()],
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
// ▶ Create executor - the function that will execute the Promptbook
|
|
70
|
+
const promptbookExecutor = createPromptbookExecutor({ promptbook, tools });
|
|
71
|
+
|
|
72
|
+
// ▶ Prepare input parameters
|
|
73
|
+
const inputParameters = { word: 'cat' };
|
|
74
|
+
|
|
75
|
+
// 🚀▶ Execute the Promptbook
|
|
76
|
+
const result = await promptbookExecutor(inputParameters);
|
|
77
|
+
|
|
78
|
+
// ▶ Fail if the execution was not successful
|
|
79
|
+
assertsExecutionSuccessful(result);
|
|
80
|
+
|
|
81
|
+
// ▶ Handle the result
|
|
82
|
+
const { isSuccessful, errors, outputParameters, executionReport } = result;
|
|
83
|
+
console.info(outputParameters);
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
This is simmilar to compilation process, during the build time the `promptbook make` command will check promptbooks for errors, convert them to the more optimized format and build knowledge base (RAG) for the library.
|
|
87
|
+
|
|
88
|
+
There is also a javascript and json format available.
|
|
89
|
+
|
|
90
|
+
## Prettify
|
|
91
|
+
|
|
37
92
|
```bash
|
|
38
93
|
npx promptbook prettify promptbook/**/*.ptbk.md
|
|
39
94
|
```
|
package/esm/index.es.js
CHANGED
|
@@ -143,7 +143,7 @@ new Function("\n try {\n if (typeof WorkerGlobalScope !== 'undefined'
|
|
|
143
143
|
/**
|
|
144
144
|
* The version of the Promptbook library
|
|
145
145
|
*/
|
|
146
|
-
var PROMPTBOOK_VERSION = '0.59.0-
|
|
146
|
+
var PROMPTBOOK_VERSION = '0.59.0-29';
|
|
147
147
|
|
|
148
148
|
/**
|
|
149
149
|
* Initializes testing `hello` command for Promptbook CLI utilities
|
|
@@ -182,7 +182,7 @@ var LOOP_LIMIT = 1000;
|
|
|
182
182
|
/**
|
|
183
183
|
* The name of the builded promptbook library made by CLI `promptbook make` and for lookup in `createLibraryFromDirectory`
|
|
184
184
|
*/
|
|
185
|
-
var PROMPTBOOK_MAKED_BASE_FILENAME = "
|
|
185
|
+
var PROMPTBOOK_MAKED_BASE_FILENAME = "index";
|
|
186
186
|
|
|
187
187
|
/**
|
|
188
188
|
* This error indicates that the promptbook object has valid syntax but contains logical errors (like circular dependencies)
|
|
@@ -437,7 +437,7 @@ function validatePromptbook(promptbook) {
|
|
|
437
437
|
* > ex port function validatePromptbook(promptbook: unknown): asserts promptbook is PromptbookJson {
|
|
438
438
|
*/
|
|
439
439
|
|
|
440
|
-
var promptbookLibrary = [{title:"Prepare Knowledge from Markdown",promptbookUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.59.0-
|
|
440
|
+
var promptbookLibrary = [{title:"Prepare Keywords",promptbookUrl:"https://promptbook.studio/promptbook/prepare-keywords.ptbk.md",promptbookVersion:"0.59.0-29",parameters:[{name:"content",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],promptTemplates:[{name:"knowledge",title:"Knowledge",dependentParameterNames:["content"],executionType:"PROMPT_TEMPLATE",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> {content}",resultingParameterName:"keywords"}],knowledge:[]},{title:"Prepare Knowledge from Markdown",promptbookUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.59.0-29",parameters:[{name:"content",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledge",description:"The knowledge JSON object",isInput:false,isOutput:true}],promptTemplates:[{name:"knowledge",title:"Knowledge",dependentParameterNames:["content"],executionType:"PROMPT_TEMPLATE",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> {content}",resultingParameterName:"knowledge"}],knowledge:[]}];
|
|
441
441
|
|
|
442
442
|
/**
|
|
443
443
|
* This error indicates errors during the execution of the promptbook
|
|
@@ -1996,7 +1996,7 @@ function normalizeToKebabCase(sentence) {
|
|
|
1996
1996
|
|
|
1997
1997
|
function prepareKnowledgeFromMarkdown(options) {
|
|
1998
1998
|
return __awaiter(this, void 0, void 0, function () {
|
|
1999
|
-
var content, llmTools, _a, isVerbose, library,
|
|
1999
|
+
var content, llmTools, _a, isVerbose, library, prepareKnowledgeFromMarkdownPromptbook, prepareKnowledgeFromMarkdownExecutor, prepareKeywordsPromptbook, prepareKeywordsExecutor, result, outputParameters, knowledgeRaw, knowledgeTextPieces, knowledge;
|
|
2000
2000
|
var _this = this;
|
|
2001
2001
|
return __generator(this, function (_b) {
|
|
2002
2002
|
switch (_b.label) {
|
|
@@ -2005,9 +2005,9 @@ function prepareKnowledgeFromMarkdown(options) {
|
|
|
2005
2005
|
library = createLibraryFromJson.apply(void 0, __spreadArray([], __read(promptbookLibrary), false));
|
|
2006
2006
|
return [4 /*yield*/, library.getPromptbookByUrl('https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md')];
|
|
2007
2007
|
case 1:
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
promptbook:
|
|
2008
|
+
prepareKnowledgeFromMarkdownPromptbook = _b.sent();
|
|
2009
|
+
prepareKnowledgeFromMarkdownExecutor = createPromptbookExecutor({
|
|
2010
|
+
promptbook: prepareKnowledgeFromMarkdownPromptbook,
|
|
2011
2011
|
tools: {
|
|
2012
2012
|
llm: llmTools,
|
|
2013
2013
|
script: [
|
|
@@ -2015,8 +2015,20 @@ function prepareKnowledgeFromMarkdown(options) {
|
|
|
2015
2015
|
],
|
|
2016
2016
|
},
|
|
2017
2017
|
});
|
|
2018
|
-
return [4 /*yield*/,
|
|
2018
|
+
return [4 /*yield*/, library.getPromptbookByUrl('https://promptbook.studio/promptbook/prepare-keywords.ptbk.md')];
|
|
2019
2019
|
case 2:
|
|
2020
|
+
prepareKeywordsPromptbook = _b.sent();
|
|
2021
|
+
prepareKeywordsExecutor = createPromptbookExecutor({
|
|
2022
|
+
promptbook: prepareKeywordsPromptbook,
|
|
2023
|
+
tools: {
|
|
2024
|
+
llm: llmTools,
|
|
2025
|
+
script: [
|
|
2026
|
+
/* <- TODO: Allow to just keep script undefined */
|
|
2027
|
+
],
|
|
2028
|
+
},
|
|
2029
|
+
});
|
|
2030
|
+
return [4 /*yield*/, prepareKnowledgeFromMarkdownExecutor({ content: content })];
|
|
2031
|
+
case 3:
|
|
2020
2032
|
result = _b.sent();
|
|
2021
2033
|
assertsExecutionSuccessful(result);
|
|
2022
2034
|
outputParameters = result.outputParameters;
|
|
@@ -2026,36 +2038,57 @@ function prepareKnowledgeFromMarkdown(options) {
|
|
|
2026
2038
|
console.info('knowledgeTextPieces:', knowledgeTextPieces);
|
|
2027
2039
|
}
|
|
2028
2040
|
return [4 /*yield*/, Promise.all(knowledgeTextPieces.map(function (knowledgeTextPiece, i) { return __awaiter(_this, void 0, void 0, function () {
|
|
2029
|
-
var name, title, content, keywords, index, sources;
|
|
2030
|
-
return __generator(this, function (
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2041
|
+
var name, title, content, keywords, index, sources, result_1, _a, outputParameters_1, keywordsRaw, error_1;
|
|
2042
|
+
return __generator(this, function (_b) {
|
|
2043
|
+
switch (_b.label) {
|
|
2044
|
+
case 0:
|
|
2045
|
+
name = "piece-".concat(i);
|
|
2046
|
+
title = spaceTrim(knowledgeTextPiece.substring(0, 100));
|
|
2047
|
+
content = spaceTrim(knowledgeTextPiece);
|
|
2048
|
+
keywords = [];
|
|
2049
|
+
index = [];
|
|
2050
|
+
sources = [];
|
|
2051
|
+
_b.label = 1;
|
|
2052
|
+
case 1:
|
|
2053
|
+
_b.trys.push([1, 3, , 4]);
|
|
2054
|
+
// TODO: !!!! Summarize name and title from the content
|
|
2055
|
+
title = spaceTrim(knowledgeTextPiece.substring(0, 30));
|
|
2056
|
+
name = normalizeToKebabCase(title);
|
|
2057
|
+
return [4 /*yield*/, prepareKeywordsExecutor({ content: content })];
|
|
2058
|
+
case 2:
|
|
2059
|
+
result_1 = _b.sent();
|
|
2060
|
+
_a = result_1.outputParameters, outputParameters_1 = _a === void 0 ? {} : _a;
|
|
2061
|
+
keywordsRaw = outputParameters_1.keywords;
|
|
2062
|
+
keywords = (keywordsRaw || '')
|
|
2063
|
+
.split(',')
|
|
2064
|
+
.map(function (keyword) { return keyword.trim(); })
|
|
2065
|
+
.filter(function (keyword) { return keyword !== ''; });
|
|
2066
|
+
if (isVerbose) {
|
|
2067
|
+
console.info("Keywords for \"".concat(title, "\":"), keywords);
|
|
2068
|
+
}
|
|
2069
|
+
// ---
|
|
2070
|
+
// TODO: !!!! Index through LLM model
|
|
2071
|
+
index.push({
|
|
2072
|
+
modelName: 'fake-model',
|
|
2073
|
+
position: new Array(25).fill(0).map(function () { return Math.random() * 2 - 1; }),
|
|
2074
|
+
});
|
|
2075
|
+
return [3 /*break*/, 4];
|
|
2076
|
+
case 3:
|
|
2077
|
+
error_1 = _b.sent();
|
|
2078
|
+
console.error(error_1);
|
|
2079
|
+
return [3 /*break*/, 4];
|
|
2080
|
+
case 4: return [2 /*return*/, {
|
|
2081
|
+
name: name,
|
|
2082
|
+
title: title,
|
|
2083
|
+
content: content,
|
|
2084
|
+
keywords: keywords,
|
|
2085
|
+
index: index,
|
|
2086
|
+
sources: sources,
|
|
2087
|
+
}];
|
|
2047
2088
|
}
|
|
2048
|
-
return [2 /*return*/, {
|
|
2049
|
-
name: name,
|
|
2050
|
-
title: title,
|
|
2051
|
-
content: content,
|
|
2052
|
-
keywords: keywords,
|
|
2053
|
-
index: index,
|
|
2054
|
-
sources: sources,
|
|
2055
|
-
}];
|
|
2056
2089
|
});
|
|
2057
2090
|
}); }))];
|
|
2058
|
-
case
|
|
2091
|
+
case 4:
|
|
2059
2092
|
knowledge = _b.sent();
|
|
2060
2093
|
return [2 /*return*/, knowledge];
|
|
2061
2094
|
}
|