@promptbook/cli 0.71.0-0 โ†’ 0.72.0-1

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.
Files changed (31) hide show
  1. package/esm/index.es.js +403 -129
  2. package/esm/index.es.js.map +1 -1
  3. package/esm/typings/src/_packages/cli.index.d.ts +4 -0
  4. package/esm/typings/src/_packages/core.index.d.ts +6 -2
  5. package/esm/typings/src/_packages/openai.index.d.ts +8 -0
  6. package/esm/typings/src/_packages/types.index.d.ts +2 -0
  7. package/esm/typings/src/execution/createPipelineExecutor/10-executePipeline.d.ts +1 -1
  8. package/esm/typings/src/execution/translation/automatic-translate/automatic-translators/LindatAutomaticTranslator.d.ts +1 -1
  9. package/esm/typings/src/execution/utils/addUsage.d.ts +0 -56
  10. package/esm/typings/src/execution/utils/usage-constants.d.ts +127 -0
  11. package/esm/typings/src/knowledge/dialogs/callback/CallbackInterfaceTools.d.ts +1 -1
  12. package/esm/typings/src/knowledge/dialogs/simple-prompt/SimplePromptInterfaceTools.d.ts +1 -1
  13. package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +3 -2
  14. package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.d.ts +3 -2
  15. package/esm/typings/src/llm-providers/mocked/MockedEchoLlmExecutionTools.d.ts +1 -1
  16. package/esm/typings/src/llm-providers/mocked/MockedFackedLlmExecutionTools.d.ts +1 -1
  17. package/esm/typings/src/llm-providers/openai/OpenAiAssistantExecutionTools.d.ts +37 -0
  18. package/esm/typings/src/llm-providers/openai/OpenAiAssistantExecutionToolsOptions.d.ts +14 -0
  19. package/esm/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +12 -2
  20. package/esm/typings/src/llm-providers/openai/createOpenAiAssistantExecutionTools.d.ts +15 -0
  21. package/esm/typings/src/llm-providers/openai/register-configuration.d.ts +9 -0
  22. package/esm/typings/src/llm-providers/openai/register-constructor.d.ts +9 -0
  23. package/esm/typings/src/llm-providers/remote/RemoteLlmExecutionTools.d.ts +1 -1
  24. package/esm/typings/src/scripting/javascript/JavascriptEvalExecutionTools.d.ts +1 -1
  25. package/esm/typings/src/scripting/python/PythonExecutionTools.d.ts +1 -1
  26. package/esm/typings/src/scripting/typescript/TypescriptExecutionTools.d.ts +1 -1
  27. package/esm/typings/src/storage/files-storage/FilesStorage.d.ts +1 -1
  28. package/esm/typings/src/types/PipelineJson/KnowledgeSourceJson.d.ts +2 -9
  29. package/package.json +1 -1
  30. package/umd/index.umd.js +404 -128
  31. package/umd/index.umd.js.map +1 -1
package/esm/index.es.js CHANGED
@@ -21,7 +21,7 @@ import OpenAI from 'openai';
21
21
  /**
22
22
  * The version of the Promptbook library
23
23
  */
24
- var PROMPTBOOK_VERSION = '0.70.0-1';
24
+ var PROMPTBOOK_VERSION = '0.72.0-0';
25
25
  // TODO:[main] !!!! List here all the versions and annotate + put into script
26
26
 
27
27
  /*! *****************************************************************************
@@ -866,127 +866,6 @@ function templateParameterJsonToString(templateParameterJson) {
866
866
  * TODO: [๐Ÿง ] Should be in generated .ptbk.md file GENERATOR_WARNING
867
867
  */
868
868
 
869
- /**
870
- * @@@
871
- *
872
- * @public exported from `@promptbook/utils`
873
- */
874
- function deepClone(objectValue) {
875
- return JSON.parse(JSON.stringify(objectValue));
876
- /*
877
- TODO: [๐Ÿง ] Is there a better implementation?
878
- > const propertyNames = Object.getOwnPropertyNames(objectValue);
879
- > for (const propertyName of propertyNames) {
880
- > const value = (objectValue as really_any)[propertyName];
881
- > if (value && typeof value === 'object') {
882
- > deepClone(value);
883
- > }
884
- > }
885
- > return Object.assign({}, objectValue);
886
- */
887
- }
888
- /**
889
- * TODO: [๐Ÿง ] Is there a way how to meaningfully test this utility
890
- */
891
-
892
- /**
893
- * @@@
894
- *
895
- * @public exported from `@promptbook/core`
896
- */
897
- var ZERO_USAGE = $deepFreeze({
898
- price: { value: 0 },
899
- input: {
900
- tokensCount: { value: 0 },
901
- charactersCount: { value: 0 },
902
- wordsCount: { value: 0 },
903
- sentencesCount: { value: 0 },
904
- linesCount: { value: 0 },
905
- paragraphsCount: { value: 0 },
906
- pagesCount: { value: 0 },
907
- },
908
- output: {
909
- tokensCount: { value: 0 },
910
- charactersCount: { value: 0 },
911
- wordsCount: { value: 0 },
912
- sentencesCount: { value: 0 },
913
- linesCount: { value: 0 },
914
- paragraphsCount: { value: 0 },
915
- pagesCount: { value: 0 },
916
- },
917
- });
918
- /**
919
- * Function `addUsage` will add multiple usages into one
920
- *
921
- * Note: If you provide 0 values, it returns ZERO_USAGE
922
- *
923
- * @public exported from `@promptbook/core`
924
- */
925
- function addUsage() {
926
- var usageItems = [];
927
- for (var _i = 0; _i < arguments.length; _i++) {
928
- usageItems[_i] = arguments[_i];
929
- }
930
- return usageItems.reduce(function (acc, item) {
931
- var e_1, _a, e_2, _b;
932
- var _c;
933
- acc.price.value += ((_c = item.price) === null || _c === void 0 ? void 0 : _c.value) || 0;
934
- try {
935
- for (var _d = __values(Object.keys(acc.input)), _e = _d.next(); !_e.done; _e = _d.next()) {
936
- var key = _e.value;
937
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
938
- //@ts-ignore
939
- if (item.input[key]) {
940
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
941
- //@ts-ignore
942
- acc.input[key].value += item.input[key].value || 0;
943
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
944
- //@ts-ignore
945
- if (item.input[key].isUncertain) {
946
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
947
- //@ts-ignore
948
- acc.input[key].isUncertain = true;
949
- }
950
- }
951
- }
952
- }
953
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
954
- finally {
955
- try {
956
- if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
957
- }
958
- finally { if (e_1) throw e_1.error; }
959
- }
960
- try {
961
- for (var _f = __values(Object.keys(acc.output)), _g = _f.next(); !_g.done; _g = _f.next()) {
962
- var key = _g.value;
963
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
964
- //@ts-ignore
965
- if (item.output[key]) {
966
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
967
- //@ts-ignore
968
- acc.output[key].value += item.output[key].value || 0;
969
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
970
- //@ts-ignore
971
- if (item.output[key].isUncertain) {
972
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
973
- //@ts-ignore
974
- acc.output[key].isUncertain = true;
975
- }
976
- }
977
- }
978
- }
979
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
980
- finally {
981
- try {
982
- if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
983
- }
984
- finally { if (e_2) throw e_2.error; }
985
- }
986
- return acc;
987
- }, deepClone(ZERO_USAGE));
988
- }
989
-
990
869
  /**
991
870
  * Async version of Array.forEach
992
871
  *
@@ -1062,6 +941,59 @@ function forEachAsync(array, options, callbackfunction) {
1062
941
  });
1063
942
  }
1064
943
 
944
+ /**
945
+ * Represents the usage with no resources consumed
946
+ *
947
+ * @public exported from `@promptbook/core`
948
+ */
949
+ var ZERO_USAGE = $deepFreeze({
950
+ price: { value: 0 },
951
+ input: {
952
+ tokensCount: { value: 0 },
953
+ charactersCount: { value: 0 },
954
+ wordsCount: { value: 0 },
955
+ sentencesCount: { value: 0 },
956
+ linesCount: { value: 0 },
957
+ paragraphsCount: { value: 0 },
958
+ pagesCount: { value: 0 },
959
+ },
960
+ output: {
961
+ tokensCount: { value: 0 },
962
+ charactersCount: { value: 0 },
963
+ wordsCount: { value: 0 },
964
+ sentencesCount: { value: 0 },
965
+ linesCount: { value: 0 },
966
+ paragraphsCount: { value: 0 },
967
+ pagesCount: { value: 0 },
968
+ },
969
+ });
970
+ /**
971
+ * Represents the usage with unknown resources consumed
972
+ *
973
+ * @public exported from `@promptbook/core`
974
+ */
975
+ var UNCERTAIN_USAGE = $deepFreeze({
976
+ price: { value: 0, isUncertain: true },
977
+ input: {
978
+ tokensCount: { value: 0, isUncertain: true },
979
+ charactersCount: { value: 0, isUncertain: true },
980
+ wordsCount: { value: 0, isUncertain: true },
981
+ sentencesCount: { value: 0, isUncertain: true },
982
+ linesCount: { value: 0, isUncertain: true },
983
+ paragraphsCount: { value: 0, isUncertain: true },
984
+ pagesCount: { value: 0, isUncertain: true },
985
+ },
986
+ output: {
987
+ tokensCount: { value: 0, isUncertain: true },
988
+ charactersCount: { value: 0, isUncertain: true },
989
+ wordsCount: { value: 0, isUncertain: true },
990
+ sentencesCount: { value: 0, isUncertain: true },
991
+ linesCount: { value: 0, isUncertain: true },
992
+ paragraphsCount: { value: 0, isUncertain: true },
993
+ pagesCount: { value: 0, isUncertain: true },
994
+ },
995
+ });
996
+
1065
997
  var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",parameters:[{name:"knowledgeContent",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],templates:[{templateType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",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}",resultingParameterName:"knowledgePieces",dependentParameterNames:["knowledgeContent"]}],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",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],templates:[{templateType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",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}",resultingParameterName:"keywords",dependentParameterNames:["knowledgePieceContent"]}],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",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],templates:[{templateType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",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}",resultingParameterName:"title",expectations:{words:{min:1,max:8}},dependentParameterNames:["knowledgePieceContent"]}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-title.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.ptbk.md",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}],templates:[{templateType:"PROMPT_TEMPLATE",name:"make-model-requirements",title:"Make modelRequirements",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- Your output format is JSON object\n- Write just the JSON object, no other text should be present\n- It contains the following keys:\n - `modelName`: The name of the model to use\n - `systemMessage`: The system message to provide context to the model\n - `temperature`: The sampling temperature to use\n\n### Key `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Key `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### Key `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}",resultingParameterName:"modelRequirements",format:"JSON",dependentParameterNames:["availableModelNames","personaDescription"]}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-persona.ptbk.md"}];
1066
998
 
1067
999
  /**
@@ -2570,6 +2502,101 @@ function arrayableToArray(input) {
2570
2502
  return [input];
2571
2503
  }
2572
2504
 
2505
+ /**
2506
+ * @@@
2507
+ *
2508
+ * @public exported from `@promptbook/utils`
2509
+ */
2510
+ function deepClone(objectValue) {
2511
+ return JSON.parse(JSON.stringify(objectValue));
2512
+ /*
2513
+ TODO: [๐Ÿง ] Is there a better implementation?
2514
+ > const propertyNames = Object.getOwnPropertyNames(objectValue);
2515
+ > for (const propertyName of propertyNames) {
2516
+ > const value = (objectValue as really_any)[propertyName];
2517
+ > if (value && typeof value === 'object') {
2518
+ > deepClone(value);
2519
+ > }
2520
+ > }
2521
+ > return Object.assign({}, objectValue);
2522
+ */
2523
+ }
2524
+ /**
2525
+ * TODO: [๐Ÿง ] Is there a way how to meaningfully test this utility
2526
+ */
2527
+
2528
+ /**
2529
+ * Function `addUsage` will add multiple usages into one
2530
+ *
2531
+ * Note: If you provide 0 values, it returns ZERO_USAGE
2532
+ *
2533
+ * @public exported from `@promptbook/core`
2534
+ */
2535
+ function addUsage() {
2536
+ var usageItems = [];
2537
+ for (var _i = 0; _i < arguments.length; _i++) {
2538
+ usageItems[_i] = arguments[_i];
2539
+ }
2540
+ return usageItems.reduce(function (acc, item) {
2541
+ var e_1, _a, e_2, _b;
2542
+ var _c;
2543
+ acc.price.value += ((_c = item.price) === null || _c === void 0 ? void 0 : _c.value) || 0;
2544
+ try {
2545
+ for (var _d = __values(Object.keys(acc.input)), _e = _d.next(); !_e.done; _e = _d.next()) {
2546
+ var key = _e.value;
2547
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2548
+ //@ts-ignore
2549
+ if (item.input[key]) {
2550
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2551
+ //@ts-ignore
2552
+ acc.input[key].value += item.input[key].value || 0;
2553
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2554
+ //@ts-ignore
2555
+ if (item.input[key].isUncertain) {
2556
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2557
+ //@ts-ignore
2558
+ acc.input[key].isUncertain = true;
2559
+ }
2560
+ }
2561
+ }
2562
+ }
2563
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
2564
+ finally {
2565
+ try {
2566
+ if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
2567
+ }
2568
+ finally { if (e_1) throw e_1.error; }
2569
+ }
2570
+ try {
2571
+ for (var _f = __values(Object.keys(acc.output)), _g = _f.next(); !_g.done; _g = _f.next()) {
2572
+ var key = _g.value;
2573
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2574
+ //@ts-ignore
2575
+ if (item.output[key]) {
2576
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2577
+ //@ts-ignore
2578
+ acc.output[key].value += item.output[key].value || 0;
2579
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2580
+ //@ts-ignore
2581
+ if (item.output[key].isUncertain) {
2582
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2583
+ //@ts-ignore
2584
+ acc.output[key].isUncertain = true;
2585
+ }
2586
+ }
2587
+ }
2588
+ }
2589
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
2590
+ finally {
2591
+ try {
2592
+ if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
2593
+ }
2594
+ finally { if (e_2) throw e_2.error; }
2595
+ }
2596
+ return acc;
2597
+ }, deepClone(ZERO_USAGE));
2598
+ }
2599
+
2573
2600
  /**
2574
2601
  * Parses the given script and returns the list of all used variables that are not defined in the script
2575
2602
  *
@@ -3929,12 +3956,12 @@ function executeFormatCells(options) {
3929
3956
  if (!(error instanceof PipelineExecutionError)) {
3930
3957
  throw error;
3931
3958
  }
3932
- throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n ".concat(error.message, "\n\n This is error in FOREACH command\n You have probbably passed wrong data to pipeline or wrong data was generated which are processed by FOREACH command\n\n ").concat(block(pipelineIdentification), "\n "); }));
3959
+ throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n ".concat(error.message, "\n\n This is error in FOREACH command\n You have probbably passed wrong data to pipeline or wrong data was generated which are processed by FOREACH command\n\n ").concat(block(pipelineIdentification), "\n Subparameter index: ").concat(index, "\n "); }));
3933
3960
  }
3934
3961
  allSubparameters = __assign(__assign({}, parameters), mappedParameters);
3935
3962
  // Note: [๐Ÿ‘จโ€๐Ÿ‘จโ€๐Ÿ‘ง] Now we can freeze `subparameters` because we are sure that all and only used parameters are defined and are not going to be changed
3936
3963
  Object.freeze(allSubparameters);
3937
- return [4 /*yield*/, executeAttempts(__assign(__assign({}, options), { priority: priority + index, parameters: allSubparameters, pipelineIdentification: pipelineIdentification }))];
3964
+ return [4 /*yield*/, executeAttempts(__assign(__assign({}, options), { priority: priority + index, parameters: allSubparameters, pipelineIdentification: spaceTrim$1(function (block) { return "\n ".concat(block(pipelineIdentification), "\n Subparameter index: ").concat(index, "\n "); }) }))];
3938
3965
  case 1:
3939
3966
  subresultString = _a.sent();
3940
3967
  return [2 /*return*/, subresultString];
@@ -4444,7 +4471,7 @@ function executePipeline(options) {
4444
4471
  },
4445
4472
  settings: settings,
4446
4473
  $executionReport: executionReport,
4447
- pipelineIdentification: pipelineIdentification,
4474
+ pipelineIdentification: spaceTrim(function (block) { return "\n ".concat(block(pipelineIdentification), "\n Template name: ").concat(currentTemplate.name, "\n Template title: ").concat(currentTemplate.title, "\n "); }),
4448
4475
  })
4449
4476
  .then(function (newParametersToPass) {
4450
4477
  parametersToPass = __assign(__assign({}, newParametersToPass), parametersToPass);
@@ -4567,9 +4594,11 @@ function createPipelineExecutor(options) {
4567
4594
  else if (isNotPreparedWarningSupressed !== true) {
4568
4595
  console.warn(spaceTrim(function (block) { return "\n Pipeline is not prepared\n\n ".concat(block(pipelineIdentification), "\n\n It will be prepared ad-hoc before the first execution and **returned as `preparedPipeline` in `PipelineExecutorResult`**\n But it is recommended to prepare the pipeline during collection preparation\n\n @see more at https://ptbk.io/prepare-pipeline\n "); }));
4569
4596
  }
4597
+ var runCount = 0;
4570
4598
  var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
4571
4599
  return __generator(this, function (_a) {
4572
- return [2 /*return*/, executePipeline({
4600
+ runCount++;
4601
+ return [2 /*return*/, /* not await */ executePipeline({
4573
4602
  pipeline: pipeline,
4574
4603
  preparedPipeline: preparedPipeline,
4575
4604
  setPreparedPipeline: function (newPreparedPipeline) {
@@ -4578,7 +4607,7 @@ function createPipelineExecutor(options) {
4578
4607
  inputParameters: inputParameters,
4579
4608
  tools: tools,
4580
4609
  onProgress: onProgress,
4581
- pipelineIdentification: pipelineIdentification,
4610
+ pipelineIdentification: spaceTrim(function (block) { return "\n ".concat(block(pipelineIdentification), "\n ").concat(runCount === 1 ? '' : "Run #".concat(runCount), "\n "); }),
4582
4611
  settings: {
4583
4612
  maxExecutionAttempts: maxExecutionAttempts,
4584
4613
  maxParallelCount: maxParallelCount,
@@ -4751,7 +4780,7 @@ function prepareKnowledgePieces(knowledgeSources, options) {
4751
4780
  var partialPieces, pieces;
4752
4781
  return __generator(this, function (_a) {
4753
4782
  switch (_a.label) {
4754
- case 0: return [4 /*yield*/, prepareKnowledgeFromMarkdown(knowledgeSource.sourceContent, // <- TODO: [๐Ÿ] !!!!!! Unhardcode markdown, detect which type it is - BE AWARE of big package size
4783
+ case 0: return [4 /*yield*/, prepareKnowledgeFromMarkdown(knowledgeSource.sourceContent, // <- TODO: [๐Ÿ][main] !!! Unhardcode markdown, detect which type it is - BE AWARE of big package size
4755
4784
  options)];
4756
4785
  case 1:
4757
4786
  partialPieces = _a.sent();
@@ -10968,6 +10997,42 @@ var _OpenAiMetadataRegistration = $llmToolsMetadataRegister.register({
10968
10997
  return null;
10969
10998
  },
10970
10999
  });
11000
+ /**
11001
+ * @@@ registration1 of default configuration for Open AI
11002
+ *
11003
+ * Note: [๐Ÿ] Configurations registrations are done in @@@ BUT constructor @@@
11004
+ *
11005
+ * @public exported from `@promptbook/core`
11006
+ * @public exported from `@promptbook/cli`
11007
+ */
11008
+ var _OpenAiAssistantMetadataRegistration = $llmToolsMetadataRegister.register({
11009
+ title: 'Open AI Assistant',
11010
+ packageName: '@promptbook/openai',
11011
+ className: 'OpenAiAssistantExecutionTools',
11012
+ getBoilerplateConfiguration: function () {
11013
+ return {
11014
+ title: 'Open AI Assistant (boilerplate)',
11015
+ packageName: '@promptbook/openai',
11016
+ className: 'OpenAiAssistantExecutionTools',
11017
+ options: {
11018
+ apiKey: 'sk-',
11019
+ },
11020
+ };
11021
+ },
11022
+ createConfigurationFromEnv: function (env) {
11023
+ if (typeof env.OPENAI_API_KEY === 'string') {
11024
+ return {
11025
+ title: 'Open AI Assistant (from env)',
11026
+ packageName: '@promptbook/openai',
11027
+ className: 'OpenAiAssistantExecutionTools',
11028
+ options: {
11029
+ apiKey: process.env.OPENAI_API_KEY,
11030
+ },
11031
+ };
11032
+ }
11033
+ return null;
11034
+ },
11035
+ });
10971
11036
 
10972
11037
  /**
10973
11038
  * Detects if the code is running in a browser environment in main thread (Not in a web worker)
@@ -11072,6 +11137,15 @@ var OpenAiExecutionTools = /** @class */ (function () {
11072
11137
  });
11073
11138
  });
11074
11139
  };
11140
+ /**
11141
+ * Create (sub)tools for calling OpenAI API Assistants
11142
+ *
11143
+ * @param assistantId Which assistant to use
11144
+ * @returns Tools for calling OpenAI API Assistants with same token
11145
+ */
11146
+ OpenAiExecutionTools.prototype.createAssistantSubtools = function (assistantId) {
11147
+ return new OpenAiAssistantExecutionTools(__assign(__assign({}, this.options), { assistantId: assistantId }));
11148
+ };
11075
11149
  /**
11076
11150
  * Check the `options` passed to `constructor`
11077
11151
  */
@@ -11367,6 +11441,197 @@ var OpenAiExecutionTools = /** @class */ (function () {
11367
11441
  * TODO: [๐Ÿง ][๐ŸŒฐ] Allow to pass `title` for tracking purposes
11368
11442
  */
11369
11443
 
11444
+ /**
11445
+ * Execution Tools for calling OpenAI API Assistants
11446
+ *
11447
+ * This is usefull for calling OpenAI API with a single assistant, for more wide usage use `OpenAiExecutionTools`.
11448
+ *
11449
+ * @public exported from `@promptbook/openai`
11450
+ */
11451
+ var OpenAiAssistantExecutionTools = /** @class */ (function (_super) {
11452
+ __extends(OpenAiAssistantExecutionTools, _super);
11453
+ /**
11454
+ * Creates OpenAI Execution Tools.
11455
+ *
11456
+ * @param options which are relevant are directly passed to the OpenAI client
11457
+ */
11458
+ function OpenAiAssistantExecutionTools(options) {
11459
+ var _this = _super.call(this, options) || this;
11460
+ _this.assistantId = options.assistantId;
11461
+ return _this;
11462
+ }
11463
+ Object.defineProperty(OpenAiAssistantExecutionTools.prototype, "title", {
11464
+ get: function () {
11465
+ return 'OpenAI Assistant';
11466
+ },
11467
+ enumerable: false,
11468
+ configurable: true
11469
+ });
11470
+ Object.defineProperty(OpenAiAssistantExecutionTools.prototype, "description", {
11471
+ get: function () {
11472
+ return 'Use single assistant provided by OpenAI';
11473
+ },
11474
+ enumerable: false,
11475
+ configurable: true
11476
+ });
11477
+ /**
11478
+ * Calls OpenAI API to use a chat model.
11479
+ */
11480
+ OpenAiAssistantExecutionTools.prototype.callChatModel = function (prompt) {
11481
+ var _a, _b, _c;
11482
+ return __awaiter(this, void 0, void 0, function () {
11483
+ var content, parameters, modelRequirements /*, format*/, client, _d, _e, key, rawPromptContent, rawRequest, start, complete, stream, rawResponse, resultContent, usage;
11484
+ var e_1, _f;
11485
+ var _this = this;
11486
+ return __generator(this, function (_g) {
11487
+ switch (_g.label) {
11488
+ case 0:
11489
+ if (this.options.isVerbose) {
11490
+ console.info('๐Ÿ’ฌ OpenAI callChatModel call', { prompt: prompt });
11491
+ }
11492
+ content = prompt.content, parameters = prompt.parameters, modelRequirements = prompt.modelRequirements;
11493
+ return [4 /*yield*/, this.getClient()];
11494
+ case 1:
11495
+ client = _g.sent();
11496
+ // TODO: [โ˜‚] Use here more modelRequirements
11497
+ if (modelRequirements.modelVariant !== 'CHAT') {
11498
+ throw new PipelineExecutionError('Use callChatModel only for CHAT variant');
11499
+ }
11500
+ try {
11501
+ // TODO: [๐Ÿ‘จโ€๐Ÿ‘จโ€๐Ÿ‘งโ€๐Ÿ‘ง] Remove:
11502
+ for (_d = __values(['maxTokens', 'modelName', 'seed', 'temperature']), _e = _d.next(); !_e.done; _e = _d.next()) {
11503
+ key = _e.value;
11504
+ if (modelRequirements[key] !== undefined) {
11505
+ throw new NotYetImplementedError("In `OpenAiAssistantExecutionTools` you cannot specify `".concat(key, "`"));
11506
+ }
11507
+ }
11508
+ }
11509
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
11510
+ finally {
11511
+ try {
11512
+ if (_e && !_e.done && (_f = _d.return)) _f.call(_d);
11513
+ }
11514
+ finally { if (e_1) throw e_1.error; }
11515
+ }
11516
+ rawPromptContent = replaceParameters(content, __assign(__assign({}, parameters), { modelName: 'assistant' }));
11517
+ rawRequest = {
11518
+ // [๐Ÿ‘จโ€๐Ÿ‘จโ€๐Ÿ‘งโ€๐Ÿ‘ง] ...modelSettings,
11519
+ assistant_id: 'asst_CJCZzFCbBL0f2D4OWMXVTdBB',
11520
+ // <- Note: This is not a private information, just ID of the assistant which is accessible only with correct API key
11521
+ thread: {
11522
+ messages: [
11523
+ // TODO: !!!!!! Unhardcode
11524
+ // TODO: !!!!!! Allow threads to be passed
11525
+ { role: 'user', content: 'What is the meaning of life? I want breathtaking speech.' },
11526
+ ],
11527
+ },
11528
+ // !!!!!! user: this.options.user,
11529
+ };
11530
+ start = getCurrentIsoDate();
11531
+ if (this.options.isVerbose) {
11532
+ console.info(colors.bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
11533
+ }
11534
+ return [4 /*yield*/, client.beta.threads.createAndRunStream(rawRequest)];
11535
+ case 2:
11536
+ stream = _g.sent();
11537
+ stream.on('connect', function () {
11538
+ if (_this.options.isVerbose) {
11539
+ console.info('connect', stream.currentEvent);
11540
+ }
11541
+ });
11542
+ stream.on('messageDelta', function (messageDelta) {
11543
+ var _a;
11544
+ if (_this.options.isVerbose &&
11545
+ messageDelta &&
11546
+ messageDelta.content &&
11547
+ messageDelta.content[0] &&
11548
+ messageDelta.content[0].type === 'text') {
11549
+ console.info('messageDelta', (_a = messageDelta.content[0].text) === null || _a === void 0 ? void 0 : _a.value);
11550
+ }
11551
+ // TODO: !!!!!! report progress
11552
+ });
11553
+ stream.on('messageCreated', function (message) {
11554
+ if (_this.options.isVerbose) {
11555
+ console.info('messageCreated', message);
11556
+ }
11557
+ });
11558
+ stream.on('messageDone', function (message) {
11559
+ if (_this.options.isVerbose) {
11560
+ console.info('messageDone', message);
11561
+ }
11562
+ });
11563
+ return [4 /*yield*/, stream.finalMessages()];
11564
+ case 3:
11565
+ rawResponse = _g.sent();
11566
+ if (this.options.isVerbose) {
11567
+ console.info(colors.bgWhite('rawResponse'), JSON.stringify(rawResponse, null, 4));
11568
+ }
11569
+ if (rawResponse.length !== 1) {
11570
+ throw new PipelineExecutionError("There is NOT 1 BUT ".concat(rawResponse.length, " finalMessages from OpenAI"));
11571
+ }
11572
+ if (rawResponse[0].content.length !== 1) {
11573
+ throw new PipelineExecutionError("There is NOT 1 BUT ".concat(rawResponse[0].content.length, " finalMessages content from OpenAI"));
11574
+ }
11575
+ if (((_a = rawResponse[0].content[0]) === null || _a === void 0 ? void 0 : _a.type) !== 'text') {
11576
+ throw new PipelineExecutionError("There is NOT 'text' BUT ".concat((_b = rawResponse[0].content[0]) === null || _b === void 0 ? void 0 : _b.type, " finalMessages content type from OpenAI"));
11577
+ }
11578
+ resultContent = (_c = rawResponse[0].content[0]) === null || _c === void 0 ? void 0 : _c.text.value;
11579
+ // <- TODO: !!!!!! There are also annotations, maybe use them
11580
+ // eslint-disable-next-line prefer-const
11581
+ complete = getCurrentIsoDate();
11582
+ usage = UNCERTAIN_USAGE;
11583
+ // TODO: !!!!!!> = computeOpenAiUsage(content, resultContent || '', rawResponse);
11584
+ if (resultContent === null) {
11585
+ throw new PipelineExecutionError('No response message from OpenAI');
11586
+ }
11587
+ return [2 /*return*/, $asDeeplyFrozenSerializableJson('OpenAiAssistantExecutionTools ChatPromptResult', {
11588
+ content: resultContent,
11589
+ modelName: 'assistant',
11590
+ // <- TODO: !!!!!! Can we detect really used model: rawResponse.model || modelName,
11591
+ timing: {
11592
+ start: start,
11593
+ complete: complete,
11594
+ },
11595
+ usage: usage,
11596
+ rawPromptContent: rawPromptContent,
11597
+ rawRequest: rawRequest,
11598
+ rawResponse: rawResponse,
11599
+ // <- [๐Ÿ—ฏ]
11600
+ })];
11601
+ }
11602
+ });
11603
+ });
11604
+ };
11605
+ return OpenAiAssistantExecutionTools;
11606
+ }(OpenAiExecutionTools));
11607
+ /**
11608
+ * TODO: !!!!!! DO not use colors - can be used in browser
11609
+ * TODO: [๐Ÿง ][๐Ÿง™โ€โ™‚๏ธ] Maybe there can be some wizzard for thoose who want to use just OpenAI
11610
+ * TODO: Maybe make custom OpenAiError
11611
+ * TODO: [๐Ÿง ][๐Ÿˆ] Maybe use `isDeterministic` from options
11612
+ * TODO: [๐Ÿง ][๐ŸŒฐ] Allow to pass `title` for tracking purposes
11613
+ */
11614
+
11615
+ /**
11616
+ * Execution Tools for calling OpenAI API
11617
+ *
11618
+ * @public exported from `@promptbook/openai`
11619
+ */
11620
+ var createOpenAiAssistantExecutionTools = Object.assign(function (options) {
11621
+ // TODO: [๐Ÿง ][main] !!!! If browser, auto add `dangerouslyAllowBrowser`
11622
+ if (($isRunningInBrowser() || $isRunningInWebWorker()) && !options.dangerouslyAllowBrowser) {
11623
+ options = __assign(__assign({}, options), { dangerouslyAllowBrowser: true });
11624
+ }
11625
+ return new OpenAiAssistantExecutionTools(options);
11626
+ }, {
11627
+ packageName: '@promptbook/openai',
11628
+ className: 'OpenAiAssistantExecutionTools',
11629
+ });
11630
+ /**
11631
+ * TODO: [๐Ÿฆบ] Is there some way how to put `packageName` and `className` on top and function definition on bottom?
11632
+ * TODO: [๐ŸŽถ] Naming "constructor" vs "creator" vs "factory"
11633
+ */
11634
+
11370
11635
  /**
11371
11636
  * Execution Tools for calling OpenAI API
11372
11637
  *
@@ -11396,9 +11661,18 @@ var createOpenAiExecutionTools = Object.assign(function (options) {
11396
11661
  * @public exported from `@promptbook/cli`
11397
11662
  */
11398
11663
  var _OpenAiRegistration = $llmToolsRegister.register(createOpenAiExecutionTools);
11664
+ /**
11665
+ * @@@ registration2
11666
+ *
11667
+ * Note: [๐Ÿ] Configurations registrations are done in @@@ BUT constructor @@@
11668
+ *
11669
+ * @public exported from `@promptbook/openai`
11670
+ * @public exported from `@promptbook/cli`
11671
+ */
11672
+ var _OpenAiAssistantRegistration = $llmToolsRegister.register(createOpenAiAssistantExecutionTools);
11399
11673
  /**
11400
11674
  * TODO: [๐ŸŽถ] Naming "constructor" vs "creator" vs "factory"
11401
11675
  */
11402
11676
 
11403
- export { PROMPTBOOK_VERSION, _AnthropicClaudeMetadataRegistration, _AnthropicClaudeRegistration, _AzureOpenAiMetadataRegistration, _AzureOpenAiRegistration, _CLI, _OpenAiMetadataRegistration, _OpenAiRegistration };
11677
+ export { PROMPTBOOK_VERSION, _AnthropicClaudeMetadataRegistration, _AnthropicClaudeRegistration, _AzureOpenAiMetadataRegistration, _AzureOpenAiRegistration, _CLI, _OpenAiAssistantMetadataRegistration, _OpenAiAssistantRegistration, _OpenAiMetadataRegistration, _OpenAiRegistration };
11404
11678
  //# sourceMappingURL=index.es.js.map