@promptbook/cli 0.89.0-1 → 0.89.0-2
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 +195 -97
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/core.index.d.ts +4 -0
- package/esm/typings/src/_packages/types.index.d.ts +6 -4
- package/esm/typings/src/cli/cli-commands/login.d.ts +15 -0
- package/esm/typings/src/execution/PipelineExecutorResult.d.ts +2 -2
- package/esm/typings/src/execution/PromptResult.d.ts +2 -2
- package/esm/typings/src/execution/{PromptResultUsage.d.ts → Usage.d.ts} +5 -5
- package/esm/typings/src/execution/utils/addUsage.d.ts +2 -2
- package/esm/typings/src/execution/utils/computeUsageCounts.d.ts +3 -3
- package/esm/typings/src/execution/utils/usage-constants.d.ts +77 -60
- package/esm/typings/src/execution/utils/usageToHuman.d.ts +5 -5
- package/esm/typings/src/execution/utils/usageToWorktime.d.ts +5 -5
- package/esm/typings/src/llm-providers/_common/utils/count-total-usage/LlmExecutionToolsWithTotalUsage.d.ts +3 -3
- package/esm/typings/src/llm-providers/_common/utils/count-total-usage/limitTotalUsage.d.ts +2 -2
- package/esm/typings/src/llm-providers/anthropic-claude/computeAnthropicClaudeUsage.d.ts +2 -2
- package/esm/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +0 -9
- package/esm/typings/src/llm-providers/openai/computeOpenAiUsage.d.ts +2 -2
- package/esm/typings/src/pipeline/PipelineJson/PreparationJson.d.ts +2 -2
- package/esm/typings/src/playground/BrjappConnector.d.ts +3 -0
- package/esm/typings/src/types/typeAliases.d.ts +6 -0
- package/package.json +1 -1
- package/umd/index.umd.js +195 -97
- package/umd/index.umd.js.map +1 -1
package/esm/index.es.js
CHANGED
|
@@ -44,7 +44,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
44
44
|
* @generated
|
|
45
45
|
* @see https://github.com/webgptorg/promptbook
|
|
46
46
|
*/
|
|
47
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.89.0-
|
|
47
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.89.0-2';
|
|
48
48
|
/**
|
|
49
49
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
50
50
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -1679,30 +1679,42 @@ function cacheLlmTools(llmTools, options = {}) {
|
|
|
1679
1679
|
* @@@ write how to combine multiple interceptors
|
|
1680
1680
|
*/
|
|
1681
1681
|
|
|
1682
|
+
/**
|
|
1683
|
+
* Represents the uncertain value
|
|
1684
|
+
*
|
|
1685
|
+
* @public exported from `@promptbook/core`
|
|
1686
|
+
*/
|
|
1687
|
+
const ZERO_VALUE = $deepFreeze({ value: 0 });
|
|
1688
|
+
/**
|
|
1689
|
+
* Represents the uncertain value
|
|
1690
|
+
*
|
|
1691
|
+
* @public exported from `@promptbook/core`
|
|
1692
|
+
*/
|
|
1693
|
+
const UNCERTAIN_ZERO_VALUE = $deepFreeze({ value: 0, isUncertain: true });
|
|
1682
1694
|
/**
|
|
1683
1695
|
* Represents the usage with no resources consumed
|
|
1684
1696
|
*
|
|
1685
1697
|
* @public exported from `@promptbook/core`
|
|
1686
1698
|
*/
|
|
1687
1699
|
const ZERO_USAGE = $deepFreeze({
|
|
1688
|
-
price:
|
|
1700
|
+
price: ZERO_VALUE,
|
|
1689
1701
|
input: {
|
|
1690
|
-
tokensCount:
|
|
1691
|
-
charactersCount:
|
|
1692
|
-
wordsCount:
|
|
1693
|
-
sentencesCount:
|
|
1694
|
-
linesCount:
|
|
1695
|
-
paragraphsCount:
|
|
1696
|
-
pagesCount:
|
|
1702
|
+
tokensCount: ZERO_VALUE,
|
|
1703
|
+
charactersCount: ZERO_VALUE,
|
|
1704
|
+
wordsCount: ZERO_VALUE,
|
|
1705
|
+
sentencesCount: ZERO_VALUE,
|
|
1706
|
+
linesCount: ZERO_VALUE,
|
|
1707
|
+
paragraphsCount: ZERO_VALUE,
|
|
1708
|
+
pagesCount: ZERO_VALUE,
|
|
1697
1709
|
},
|
|
1698
1710
|
output: {
|
|
1699
|
-
tokensCount:
|
|
1700
|
-
charactersCount:
|
|
1701
|
-
wordsCount:
|
|
1702
|
-
sentencesCount:
|
|
1703
|
-
linesCount:
|
|
1704
|
-
paragraphsCount:
|
|
1705
|
-
pagesCount:
|
|
1711
|
+
tokensCount: ZERO_VALUE,
|
|
1712
|
+
charactersCount: ZERO_VALUE,
|
|
1713
|
+
wordsCount: ZERO_VALUE,
|
|
1714
|
+
sentencesCount: ZERO_VALUE,
|
|
1715
|
+
linesCount: ZERO_VALUE,
|
|
1716
|
+
paragraphsCount: ZERO_VALUE,
|
|
1717
|
+
pagesCount: ZERO_VALUE,
|
|
1706
1718
|
},
|
|
1707
1719
|
});
|
|
1708
1720
|
/**
|
|
@@ -1711,24 +1723,24 @@ const ZERO_USAGE = $deepFreeze({
|
|
|
1711
1723
|
* @public exported from `@promptbook/core`
|
|
1712
1724
|
*/
|
|
1713
1725
|
const UNCERTAIN_USAGE = $deepFreeze({
|
|
1714
|
-
price:
|
|
1726
|
+
price: UNCERTAIN_ZERO_VALUE,
|
|
1715
1727
|
input: {
|
|
1716
|
-
tokensCount:
|
|
1717
|
-
charactersCount:
|
|
1718
|
-
wordsCount:
|
|
1719
|
-
sentencesCount:
|
|
1720
|
-
linesCount:
|
|
1721
|
-
paragraphsCount:
|
|
1722
|
-
pagesCount:
|
|
1728
|
+
tokensCount: UNCERTAIN_ZERO_VALUE,
|
|
1729
|
+
charactersCount: UNCERTAIN_ZERO_VALUE,
|
|
1730
|
+
wordsCount: UNCERTAIN_ZERO_VALUE,
|
|
1731
|
+
sentencesCount: UNCERTAIN_ZERO_VALUE,
|
|
1732
|
+
linesCount: UNCERTAIN_ZERO_VALUE,
|
|
1733
|
+
paragraphsCount: UNCERTAIN_ZERO_VALUE,
|
|
1734
|
+
pagesCount: UNCERTAIN_ZERO_VALUE,
|
|
1723
1735
|
},
|
|
1724
1736
|
output: {
|
|
1725
|
-
tokensCount:
|
|
1726
|
-
charactersCount:
|
|
1727
|
-
wordsCount:
|
|
1728
|
-
sentencesCount:
|
|
1729
|
-
linesCount:
|
|
1730
|
-
paragraphsCount:
|
|
1731
|
-
pagesCount:
|
|
1737
|
+
tokensCount: UNCERTAIN_ZERO_VALUE,
|
|
1738
|
+
charactersCount: UNCERTAIN_ZERO_VALUE,
|
|
1739
|
+
wordsCount: UNCERTAIN_ZERO_VALUE,
|
|
1740
|
+
sentencesCount: UNCERTAIN_ZERO_VALUE,
|
|
1741
|
+
linesCount: UNCERTAIN_ZERO_VALUE,
|
|
1742
|
+
paragraphsCount: UNCERTAIN_ZERO_VALUE,
|
|
1743
|
+
pagesCount: UNCERTAIN_ZERO_VALUE,
|
|
1732
1744
|
},
|
|
1733
1745
|
});
|
|
1734
1746
|
/**
|
|
@@ -2411,6 +2423,7 @@ function joinLlmExecutionTools(...llmExecutionTools) {
|
|
|
2411
2423
|
`);
|
|
2412
2424
|
// TODO: [🟥] Detect browser / node and make it colorfull
|
|
2413
2425
|
console.warn(warningMessage);
|
|
2426
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
2414
2427
|
/*
|
|
2415
2428
|
return {
|
|
2416
2429
|
async listModels() {
|
|
@@ -2704,6 +2717,7 @@ function $execCommand(options) {
|
|
|
2704
2717
|
}
|
|
2705
2718
|
else {
|
|
2706
2719
|
console.warn(`Command "${humanReadableCommand}" exceeded time limit of ${timeout}ms but continues running`);
|
|
2720
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
2707
2721
|
resolve('Command exceeded time limit');
|
|
2708
2722
|
}
|
|
2709
2723
|
});
|
|
@@ -2729,6 +2743,7 @@ function $execCommand(options) {
|
|
|
2729
2743
|
output.push(stderr.toString());
|
|
2730
2744
|
if (isVerbose && stderr.toString().trim()) {
|
|
2731
2745
|
console.warn(stderr.toString());
|
|
2746
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
2732
2747
|
}
|
|
2733
2748
|
});
|
|
2734
2749
|
const finishWithCode = (code) => {
|
|
@@ -2740,6 +2755,7 @@ function $execCommand(options) {
|
|
|
2740
2755
|
else {
|
|
2741
2756
|
if (isVerbose) {
|
|
2742
2757
|
console.warn(`Command "${humanReadableCommand}" exited with code ${code}`);
|
|
2758
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
2743
2759
|
}
|
|
2744
2760
|
resolve(spaceTrim$1(output.join('\n')));
|
|
2745
2761
|
}
|
|
@@ -2761,6 +2777,7 @@ function $execCommand(options) {
|
|
|
2761
2777
|
else {
|
|
2762
2778
|
if (isVerbose) {
|
|
2763
2779
|
console.warn(error);
|
|
2780
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
2764
2781
|
}
|
|
2765
2782
|
resolve(spaceTrim$1(output.join('\n')));
|
|
2766
2783
|
}
|
|
@@ -4314,6 +4331,7 @@ function assertsTaskSuccessful(executionResult) {
|
|
|
4314
4331
|
const { isSuccessful, errors, warnings } = executionResult;
|
|
4315
4332
|
for (const warning of warnings) {
|
|
4316
4333
|
console.warn(warning.message);
|
|
4334
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
4317
4335
|
}
|
|
4318
4336
|
if (isSuccessful === true) {
|
|
4319
4337
|
return;
|
|
@@ -4655,7 +4673,7 @@ function extractParameterNamesFromTask(task) {
|
|
|
4655
4673
|
if (parameterNames.has(subparameterName)) {
|
|
4656
4674
|
parameterNames.delete(subparameterName);
|
|
4657
4675
|
parameterNames.add(foreach.parameterName);
|
|
4658
|
-
// <- TODO: [
|
|
4676
|
+
// <- TODO: [🏮] Warn/logic error when `subparameterName` not used
|
|
4659
4677
|
}
|
|
4660
4678
|
}
|
|
4661
4679
|
}
|
|
@@ -6270,6 +6288,7 @@ function createPipelineExecutor(options) {
|
|
|
6270
6288
|
|
|
6271
6289
|
@see more at https://ptbk.io/prepare-pipeline
|
|
6272
6290
|
`));
|
|
6291
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
6273
6292
|
}
|
|
6274
6293
|
let runCount = 0;
|
|
6275
6294
|
const pipelineExecutorWithCallback = async (inputParameters, onProgress) => {
|
|
@@ -6612,63 +6631,73 @@ async function prepareKnowledgePieces(knowledgeSources, tools, options) {
|
|
|
6612
6631
|
const { maxParallelCount = DEFAULT_MAX_PARALLEL_COUNT, rootDirname, isVerbose = DEFAULT_IS_VERBOSE } = options;
|
|
6613
6632
|
const knowledgePreparedUnflatten = new Array(knowledgeSources.length);
|
|
6614
6633
|
await forEachAsync(knowledgeSources, { maxParallelCount }, async (knowledgeSource, index) => {
|
|
6615
|
-
|
|
6616
|
-
|
|
6617
|
-
|
|
6618
|
-
|
|
6619
|
-
|
|
6620
|
-
|
|
6621
|
-
|
|
6622
|
-
|
|
6623
|
-
|
|
6624
|
-
|
|
6625
|
-
|
|
6626
|
-
|
|
6627
|
-
|
|
6628
|
-
|
|
6629
|
-
|
|
6630
|
-
|
|
6631
|
-
|
|
6634
|
+
try {
|
|
6635
|
+
let partialPieces = null;
|
|
6636
|
+
const sourceHandler = await makeKnowledgeSourceHandler(knowledgeSource, tools, { rootDirname, isVerbose });
|
|
6637
|
+
const scrapers = arrayableToArray(tools.scrapers);
|
|
6638
|
+
for (const scraper of scrapers) {
|
|
6639
|
+
if (!scraper.metadata.mimeTypes.includes(sourceHandler.mimeType)
|
|
6640
|
+
// <- TODO: [🦔] Implement mime-type wildcards
|
|
6641
|
+
) {
|
|
6642
|
+
continue;
|
|
6643
|
+
}
|
|
6644
|
+
const partialPiecesUnchecked = await scraper.scrape(sourceHandler);
|
|
6645
|
+
if (partialPiecesUnchecked !== null) {
|
|
6646
|
+
partialPieces = [...partialPiecesUnchecked];
|
|
6647
|
+
// <- TODO: [🪓] Here should be no need for spreading new array, just `partialPieces = partialPiecesUnchecked`
|
|
6648
|
+
break;
|
|
6649
|
+
}
|
|
6650
|
+
console.warn(spaceTrim((block) => `
|
|
6651
|
+
Cannot scrape knowledge from source despite the scraper \`${scraper.metadata.className}\` supports the mime type "${sourceHandler.mimeType}".
|
|
6632
6652
|
|
|
6633
|
-
|
|
6634
|
-
|
|
6635
|
-
|
|
6636
|
-
|
|
6637
|
-
|
|
6653
|
+
The source:
|
|
6654
|
+
${block(knowledgeSource.knowledgeSourceContent
|
|
6655
|
+
.split('\n')
|
|
6656
|
+
.map((line) => `> ${line}`)
|
|
6657
|
+
.join('\n'))}
|
|
6638
6658
|
|
|
6639
|
-
|
|
6659
|
+
${block($registeredScrapersMessage(scrapers))}
|
|
6640
6660
|
|
|
6641
6661
|
|
|
6642
|
-
|
|
6643
|
-
|
|
6644
|
-
|
|
6645
|
-
|
|
6646
|
-
|
|
6662
|
+
`));
|
|
6663
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
6664
|
+
}
|
|
6665
|
+
if (partialPieces === null) {
|
|
6666
|
+
throw new KnowledgeScrapeError(spaceTrim((block) => `
|
|
6667
|
+
Cannot scrape knowledge
|
|
6647
6668
|
|
|
6648
|
-
|
|
6649
|
-
|
|
6650
|
-
|
|
6651
|
-
|
|
6652
|
-
|
|
6669
|
+
The source:
|
|
6670
|
+
> ${block(knowledgeSource.knowledgeSourceContent
|
|
6671
|
+
.split('\n')
|
|
6672
|
+
.map((line) => `> ${line}`)
|
|
6673
|
+
.join('\n'))}
|
|
6653
6674
|
|
|
6654
|
-
|
|
6675
|
+
No scraper found for the mime type "${sourceHandler.mimeType}"
|
|
6655
6676
|
|
|
6656
|
-
|
|
6677
|
+
${block($registeredScrapersMessage(scrapers))}
|
|
6657
6678
|
|
|
6658
6679
|
|
|
6659
|
-
|
|
6680
|
+
`));
|
|
6681
|
+
}
|
|
6682
|
+
const pieces = partialPieces.map((partialPiece) => ({
|
|
6683
|
+
...partialPiece,
|
|
6684
|
+
sources: [
|
|
6685
|
+
{
|
|
6686
|
+
name: knowledgeSource.name,
|
|
6687
|
+
// line, column <- TODO: [☀]
|
|
6688
|
+
// <- TODO: [❎]
|
|
6689
|
+
},
|
|
6690
|
+
],
|
|
6691
|
+
}));
|
|
6692
|
+
knowledgePreparedUnflatten[index] = pieces;
|
|
6693
|
+
}
|
|
6694
|
+
catch (error) {
|
|
6695
|
+
if (!(error instanceof Error)) {
|
|
6696
|
+
throw error;
|
|
6697
|
+
}
|
|
6698
|
+
console.warn(error);
|
|
6699
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
6660
6700
|
}
|
|
6661
|
-
const pieces = partialPieces.map((partialPiece) => ({
|
|
6662
|
-
...partialPiece,
|
|
6663
|
-
sources: [
|
|
6664
|
-
{
|
|
6665
|
-
name: knowledgeSource.name,
|
|
6666
|
-
// line, column <- TODO: [☀]
|
|
6667
|
-
// <- TODO: [❎]
|
|
6668
|
-
},
|
|
6669
|
-
],
|
|
6670
|
-
}));
|
|
6671
|
-
knowledgePreparedUnflatten[index] = pieces;
|
|
6672
6701
|
});
|
|
6673
6702
|
const knowledgePrepared = knowledgePreparedUnflatten.flat();
|
|
6674
6703
|
return knowledgePrepared;
|
|
@@ -8493,7 +8522,8 @@ const modelCommandParser = {
|
|
|
8493
8522
|
if ($pipelineJson.defaultModelRequirements[command.key] !== undefined) {
|
|
8494
8523
|
if ($pipelineJson.defaultModelRequirements[command.key] === command.value) {
|
|
8495
8524
|
console.warn(`Multiple commands \`MODEL ${command.key} ${command.value}\` in the pipeline head`);
|
|
8496
|
-
// <- TODO: [
|
|
8525
|
+
// <- TODO: [🏮] Some better way how to get warnings from pipeline parsing / logic
|
|
8526
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
8497
8527
|
}
|
|
8498
8528
|
else {
|
|
8499
8529
|
throw new ParseError(spaceTrim(`
|
|
@@ -8525,6 +8555,7 @@ const modelCommandParser = {
|
|
|
8525
8555
|
modelVariant: 'VARIANT',
|
|
8526
8556
|
maxTokens: '???',
|
|
8527
8557
|
}[command.key]} ${command.value}\` in the task "${$taskJson.title || $taskJson.name}"`);
|
|
8558
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
8528
8559
|
}
|
|
8529
8560
|
else {
|
|
8530
8561
|
throw new ParseError(spaceTrim(`
|
|
@@ -8804,15 +8835,15 @@ function $applyToTaskJson(command, $taskJson, $pipelineJson) {
|
|
|
8804
8835
|
}
|
|
8805
8836
|
console.warn(spaceTrim(`
|
|
8806
8837
|
|
|
8807
|
-
|
|
8838
|
+
Persona "${personaName}" is defined multiple times with different description:
|
|
8808
8839
|
|
|
8809
|
-
|
|
8810
|
-
|
|
8840
|
+
First definition:
|
|
8841
|
+
${persona.description}
|
|
8811
8842
|
|
|
8812
|
-
|
|
8813
|
-
|
|
8843
|
+
Second definition:
|
|
8844
|
+
${personaDescription}
|
|
8814
8845
|
|
|
8815
|
-
|
|
8846
|
+
`));
|
|
8816
8847
|
persona.description += spaceTrim('\n\n' + personaDescription);
|
|
8817
8848
|
}
|
|
8818
8849
|
|
|
@@ -11443,6 +11474,7 @@ function $initializeMakeCommand(program) {
|
|
|
11443
11474
|
: join(path, `${DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME}.${extension}`);
|
|
11444
11475
|
if (!output.endsWith(`.${extension}`)) {
|
|
11445
11476
|
console.warn(colors.yellow(`Warning: Extension of output file should be "${extension}"`));
|
|
11477
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
11446
11478
|
}
|
|
11447
11479
|
await mkdir(dirname(filename), { recursive: true });
|
|
11448
11480
|
if (typeof content === 'string') {
|
|
@@ -11543,6 +11575,7 @@ function $initializeMakeCommand(program) {
|
|
|
11543
11575
|
}
|
|
11544
11576
|
if (formats.length > 0) {
|
|
11545
11577
|
console.warn(colors.yellow(`Format ${formats.join(' and ')} is not supported`));
|
|
11578
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
11546
11579
|
}
|
|
11547
11580
|
console.info(colors.green(`Collection builded successfully`));
|
|
11548
11581
|
if (isVerbose) {
|
|
@@ -11589,7 +11622,8 @@ function addAutoGeneratedSection(content, options) {
|
|
|
11589
11622
|
`));
|
|
11590
11623
|
}
|
|
11591
11624
|
console.warn(`No place where to put the section <!--${sectionName}-->, using the end of the file`);
|
|
11592
|
-
// <- TODO: [
|
|
11625
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
11626
|
+
// <- TODO: [🏮] Some better way how to get warnings from pipeline parsing / logic
|
|
11593
11627
|
return spaceTrim$1((block) => `
|
|
11594
11628
|
${block(content)}
|
|
11595
11629
|
|
|
@@ -12639,6 +12673,7 @@ function startRemoteServer(options) {
|
|
|
12639
12673
|
https://github.com/webgptorg/promptbook
|
|
12640
12674
|
`));
|
|
12641
12675
|
});
|
|
12676
|
+
// TODO: !!!!!! Add login route
|
|
12642
12677
|
app.get(`${rootPath}/books`, async (request, response) => {
|
|
12643
12678
|
if (collection === null) {
|
|
12644
12679
|
response.status(500).send('No collection available');
|
|
@@ -12972,6 +13007,7 @@ function $initializeStartServerCommand(program) {
|
|
|
12972
13007
|
const url = !rawUrl ? null : new URL(rawUrl);
|
|
12973
13008
|
if (url !== null && url.port !== port.toString()) {
|
|
12974
13009
|
console.warn(colors.yellow(`Port in --url is different from --port which the server will listen on, this is ok only if you proxy from one port to another, for exaple via nginx or docker`));
|
|
13010
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
12975
13011
|
}
|
|
12976
13012
|
let rootUrl = undefined;
|
|
12977
13013
|
if (url !== null) {
|
|
@@ -13117,6 +13153,58 @@ function $initializeTestCommand(program) {
|
|
|
13117
13153
|
* Note: This is named "test-command.ts" to avoid name collision with jest unit test files
|
|
13118
13154
|
*/
|
|
13119
13155
|
|
|
13156
|
+
/**
|
|
13157
|
+
* Initializes `login` command for Promptbook CLI utilities
|
|
13158
|
+
*
|
|
13159
|
+
* Note: `$` is used to indicate that this function is not a pure function - it registers a command in the CLI
|
|
13160
|
+
*
|
|
13161
|
+
* @private internal function of `promptbookCli`
|
|
13162
|
+
*/
|
|
13163
|
+
function $initializeLoginCommand(program) {
|
|
13164
|
+
const loginCommand = program.command('login');
|
|
13165
|
+
loginCommand.description(spaceTrim(`
|
|
13166
|
+
Login to the remote Promptbook server
|
|
13167
|
+
`));
|
|
13168
|
+
loginCommand.action(handleActionErrors(async () => {
|
|
13169
|
+
// @@@
|
|
13170
|
+
console.error(colors.green(spaceTrim(`
|
|
13171
|
+
You will be logged in to https://promptbook.studio server.
|
|
13172
|
+
If you don't have an account, it will be created automatically.
|
|
13173
|
+
`)));
|
|
13174
|
+
const { email, password } = await prompts([
|
|
13175
|
+
{
|
|
13176
|
+
type: 'text',
|
|
13177
|
+
name: 'email',
|
|
13178
|
+
message: 'Enter your email:',
|
|
13179
|
+
validate: (value) => (isValidEmail(value) ? true : 'Valid email is required'),
|
|
13180
|
+
},
|
|
13181
|
+
{
|
|
13182
|
+
type: 'password',
|
|
13183
|
+
name: 'password',
|
|
13184
|
+
message: 'Enter your password:',
|
|
13185
|
+
validate: (value) => value.length /* <- TODO: [🧠] Better password validation */ > 0 ? true : 'Password is required',
|
|
13186
|
+
},
|
|
13187
|
+
]);
|
|
13188
|
+
TODO_USE(email, password);
|
|
13189
|
+
await forTime(1000);
|
|
13190
|
+
console.error(colors.green(spaceTrim(`
|
|
13191
|
+
Your account ${email} was successfully created.
|
|
13192
|
+
|
|
13193
|
+
Please verify your email:
|
|
13194
|
+
https://brj.app/api/v1/customer/register-account?apiKey=PRODdh003eNKaec7PoO1AzU244tsL4WO
|
|
13195
|
+
|
|
13196
|
+
After verification, you will receive 500 000 credits for free 🎉
|
|
13197
|
+
`)));
|
|
13198
|
+
return process.exit(0);
|
|
13199
|
+
}));
|
|
13200
|
+
}
|
|
13201
|
+
/**
|
|
13202
|
+
* TODO: Pass remote server URL (and path)
|
|
13203
|
+
* TODO: Implement non-interactive login
|
|
13204
|
+
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
13205
|
+
* Note: [🟡] Code in this file should never be published outside of `@promptbook/cli`
|
|
13206
|
+
*/
|
|
13207
|
+
|
|
13120
13208
|
/**
|
|
13121
13209
|
* Runs CLI utilities of Promptbook package
|
|
13122
13210
|
*
|
|
@@ -13143,6 +13231,7 @@ async function promptbookCli() {
|
|
|
13143
13231
|
program.description(CLAIM);
|
|
13144
13232
|
$initializeAboutCommand(program);
|
|
13145
13233
|
$initializeRunCommand(program);
|
|
13234
|
+
$initializeLoginCommand(program);
|
|
13146
13235
|
$initializeHelloCommand(program);
|
|
13147
13236
|
$initializeMakeCommand(program);
|
|
13148
13237
|
$initializePrettifyCommand(program);
|
|
@@ -13463,7 +13552,7 @@ const ANTHROPIC_CLAUDE_MODELS = exportJson({
|
|
|
13463
13552
|
* Helper of usage compute
|
|
13464
13553
|
*
|
|
13465
13554
|
* @param content the content of prompt or response
|
|
13466
|
-
* @returns part of
|
|
13555
|
+
* @returns part of UsageCounts
|
|
13467
13556
|
*
|
|
13468
13557
|
* @private internal utility of LlmExecutionTools
|
|
13469
13558
|
*/
|
|
@@ -13487,7 +13576,7 @@ function computeUsageCounts(content) {
|
|
|
13487
13576
|
*/
|
|
13488
13577
|
function uncertainNumber(value) {
|
|
13489
13578
|
if (value === null || value === undefined || Number.isNaN(value)) {
|
|
13490
|
-
return
|
|
13579
|
+
return UNCERTAIN_ZERO_VALUE;
|
|
13491
13580
|
}
|
|
13492
13581
|
return { value };
|
|
13493
13582
|
}
|
|
@@ -13724,7 +13813,7 @@ class AnthropicClaudeExecutionTools {
|
|
|
13724
13813
|
const resultContent = rawResponse.choices[0].text;
|
|
13725
13814
|
// eslint-disable-next-line prefer-const
|
|
13726
13815
|
complete = $getCurrentDate();
|
|
13727
|
-
const usage = { price: 'UNKNOWN', inputTokens: 0, outputTokens: 0 /* <- TODO: [🐞] Compute usage * / } satisfies
|
|
13816
|
+
const usage = { price: 'UNKNOWN', inputTokens: 0, outputTokens: 0 /* <- TODO: [🐞] Compute usage * / } satisfies Usage;
|
|
13728
13817
|
|
|
13729
13818
|
|
|
13730
13819
|
|
|
@@ -14820,11 +14909,17 @@ function createExecutionToolsFromVercelProvider(options) {
|
|
|
14820
14909
|
throw new PipelineExecutionError('No response message');
|
|
14821
14910
|
}
|
|
14822
14911
|
const complete = $getCurrentDate();
|
|
14823
|
-
|
|
14824
|
-
|
|
14825
|
-
|
|
14826
|
-
|
|
14827
|
-
|
|
14912
|
+
const usage = {
|
|
14913
|
+
price: UNCERTAIN_ZERO_VALUE,
|
|
14914
|
+
input: {
|
|
14915
|
+
tokensCount: uncertainNumber(rawResponse.usage.promptTokens),
|
|
14916
|
+
...computeUsageCounts(rawPromptContent),
|
|
14917
|
+
},
|
|
14918
|
+
output: {
|
|
14919
|
+
tokensCount: uncertainNumber(rawResponse.usage.completionTokens),
|
|
14920
|
+
...computeUsageCounts(rawResponse.text),
|
|
14921
|
+
},
|
|
14922
|
+
};
|
|
14828
14923
|
return exportJson({
|
|
14829
14924
|
name: 'promptResult',
|
|
14830
14925
|
message: `Result of \`createExecutionToolsFromVercelProvider.callChatModel\``,
|
|
@@ -15177,15 +15272,18 @@ class OpenAiExecutionTools {
|
|
|
15177
15272
|
}
|
|
15178
15273
|
return this.client;
|
|
15179
15274
|
}
|
|
15275
|
+
/*
|
|
15276
|
+
Note: Commenting this out to avoid circular dependency
|
|
15180
15277
|
/**
|
|
15181
15278
|
* Create (sub)tools for calling OpenAI API Assistants
|
|
15182
15279
|
*
|
|
15183
15280
|
* @param assistantId Which assistant to use
|
|
15184
15281
|
* @returns Tools for calling OpenAI API Assistants with same token
|
|
15185
|
-
|
|
15186
|
-
createAssistantSubtools(assistantId) {
|
|
15282
|
+
* /
|
|
15283
|
+
public createAssistantSubtools(assistantId: string_token): OpenAiAssistantExecutionTools {
|
|
15187
15284
|
return new OpenAiAssistantExecutionTools({ ...this.options, assistantId });
|
|
15188
15285
|
}
|
|
15286
|
+
*/
|
|
15189
15287
|
/**
|
|
15190
15288
|
* Check the `options` passed to `constructor`
|
|
15191
15289
|
*/
|