@promptbook/cli 0.59.0-30 → 0.59.0-32

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 (27) hide show
  1. package/esm/index.es.js +6 -5
  2. package/esm/index.es.js.map +1 -1
  3. package/esm/typings/src/_packages/core.index.d.ts +2 -1
  4. package/esm/typings/src/_packages/types.index.d.ts +3 -2
  5. package/esm/typings/src/conversion/promptbookStringToJson.d.ts +1 -0
  6. package/esm/typings/src/execution/EmbeddingVector.d.ts +8 -0
  7. package/esm/typings/src/execution/PromptResult.d.ts +11 -0
  8. package/esm/typings/src/execution/embeddingVectorToString.d.ts +5 -0
  9. package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +4 -0
  10. package/esm/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +7 -2
  11. package/esm/typings/src/llm-providers/openai/computeOpenaiUsage.d.ts +4 -2
  12. package/esm/typings/src/types/PromptbookJson/MaterialKnowledgePieceJson.d.ts +2 -1
  13. package/package.json +2 -2
  14. package/umd/index.umd.js +6 -5
  15. package/umd/index.umd.js.map +1 -1
  16. package/umd/typings/src/_packages/core.index.d.ts +2 -1
  17. package/umd/typings/src/_packages/types.index.d.ts +3 -2
  18. package/umd/typings/src/conversion/promptbookStringToJson.d.ts +1 -0
  19. package/umd/typings/src/execution/EmbeddingVector.d.ts +8 -0
  20. package/umd/typings/src/execution/PromptResult.d.ts +11 -0
  21. package/umd/typings/src/execution/embeddingVectorToString.d.ts +5 -0
  22. package/umd/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +4 -0
  23. package/umd/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +7 -2
  24. package/umd/typings/src/llm-providers/openai/computeOpenaiUsage.d.ts +4 -2
  25. package/umd/typings/src/types/PromptbookJson/MaterialKnowledgePieceJson.d.ts +2 -1
  26. package/esm/typings/src/knowledge/prepare-knowledge/_common/IndexPreparer.d.ts +0 -4
  27. package/umd/typings/src/knowledge/prepare-knowledge/_common/IndexPreparer.d.ts +0 -4
@@ -27,4 +27,5 @@ export {};
27
27
  * TODO: Report here line/column of error
28
28
  * TODO: Use spaceTrim more effectively
29
29
  * TODO: [🧠] Parameter flags - isInput, isOutput, isInternal
30
+ * TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
30
31
  */
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Represents a vector in an latent space of the embedding model
3
+ */
4
+ export type EmbeddingVector = Array<number>;
5
+ /**
6
+ * TODO: Figure out how to use library xyzt
7
+ * Not using IVectorData due to HUGE dimensionality
8
+ */
@@ -4,6 +4,7 @@ import type { number_positive } from '../types/typeAliases';
4
4
  import type { number_usd } from '../types/typeAliases';
5
5
  import type { string_date_iso8601 } from '../types/typeAliases';
6
6
  import type { string_model_name } from '../types/typeAliases';
7
+ import type { EmbeddingVector } from './EmbeddingVector';
7
8
  /**
8
9
  * Prompt result is the simplest concept of execution.
9
10
  * It is the result of executing one prompt _(NOT a template)_.
@@ -20,6 +21,16 @@ export type PromptCompletionResult = PromptCommonResult;
20
21
  * Prompt chat result
21
22
  */
22
23
  export type PromptChatResult = PromptCommonResult & {};
24
+ /**
25
+ * Prompt embedding result
26
+ * It contains only the following text NOT the whole completion
27
+ */
28
+ export type PromptEmbeddingResult = Omit<PromptCommonResult, 'content'> & {
29
+ /**
30
+ * The response from the model
31
+ */
32
+ content: EmbeddingVector;
33
+ };
23
34
  export type PromptCommonResult = {
24
35
  /**
25
36
  * Exact text response from the model
@@ -0,0 +1,5 @@
1
+ import type { EmbeddingVector } from './EmbeddingVector';
2
+ /**
3
+ * Pretty print an embedding vector for logging
4
+ */
5
+ export declare function embeddingVectorToString(embeddingVector: EmbeddingVector): string;
@@ -27,6 +27,10 @@ export declare class AnthropicClaudeExecutionTools implements LlmExecutionTools
27
27
  * Calls Anthropic Claude API to use a complete model.
28
28
  */
29
29
  gptComplete(prompt: Pick<Prompt, 'content' | 'modelRequirements'>): Promise<PromptCompletionResult>;
30
+ /**
31
+ * Get the model that should be used as default
32
+ */
33
+ private getDefaultModel;
30
34
  /**
31
35
  * Default model for chat variant.
32
36
  */
@@ -2,6 +2,7 @@ import type { AvailableModel } from '../../execution/LlmExecutionTools';
2
2
  import type { LlmExecutionTools } from '../../execution/LlmExecutionTools';
3
3
  import type { PromptChatResult } from '../../execution/PromptResult';
4
4
  import type { PromptCompletionResult } from '../../execution/PromptResult';
5
+ import type { PromptEmbeddingResult } from '../../execution/PromptResult';
5
6
  import type { Prompt } from '../../types/Prompt';
6
7
  import type { OpenAiExecutionToolsOptions } from './OpenAiExecutionToolsOptions';
7
8
  /**
@@ -28,9 +29,13 @@ export declare class OpenAiExecutionTools implements LlmExecutionTools {
28
29
  */
29
30
  gptComplete(prompt: Pick<Prompt, 'content' | 'modelRequirements'>): Promise<PromptCompletionResult>;
30
31
  /**
31
- * !!!!
32
+ * Calls OpenAI API to use a embedding model
32
33
  */
33
- embed(prompt: Pick<Prompt, 'content' | 'modelRequirements'>): Promise<PromptCompletionResult>;
34
+ embed(prompt: Pick<Prompt, 'content' | 'modelRequirements'>): Promise<PromptEmbeddingResult>;
35
+ /**
36
+ * Get the model that should be used as default
37
+ */
38
+ private getDefaultModel;
34
39
  /**
35
40
  * Default model for chat variant.
36
41
  */
@@ -1,12 +1,14 @@
1
1
  import type OpenAI from 'openai';
2
- import type { PromptResult } from '../../execution/PromptResult';
3
2
  import type { PromptResultUsage } from '../../execution/PromptResult';
4
3
  import type { Prompt } from '../../types/Prompt';
5
4
  /**
6
5
  * Computes the usage of the OpenAI API based on the response from OpenAI
7
6
  *
7
+ * @param promptContent The content of the prompt
8
+ * @param resultContent The content of the result (for embedding prompts or failed prompts pass empty string)
9
+ * @param rawResponse The raw response from OpenAI API
8
10
  * @throws {PromptbookExecutionError} If the usage is not defined in the response from OpenAI
9
11
  * @private internal util of `OpenAiExecutionTools`
10
12
  */
11
13
  export declare function computeOpenaiUsage(promptContent: Prompt['content'], // <- Note: Intentionally using [] to access type properties to bring jsdoc from Prompt/PromptResult to consumer
12
- resultContent: PromptResult['content'], rawResponse: Pick<OpenAI.Chat.Completions.ChatCompletion | OpenAI.Completions.Completion, 'model' | 'usage'>): PromptResultUsage;
14
+ resultContent: string, rawResponse: Pick<OpenAI.Chat.Completions.ChatCompletion | OpenAI.Completions.Completion | OpenAI.Embeddings.CreateEmbeddingResponse, 'model' | 'usage'>): PromptResultUsage;
@@ -1,3 +1,4 @@
1
+ import type { EmbeddingVector } from '../../execution/EmbeddingVector';
1
2
  import type { string_keyword } from '../../utils/normalization/IKeywords';
2
3
  import type { string_href } from '../typeAliases';
3
4
  import type { string_markdown } from '../typeAliases';
@@ -11,7 +12,7 @@ export type MaterialKnowledgePieceJson = {
11
12
  readonly keywords: Array<string_keyword>;
12
13
  readonly index: Array<{
13
14
  modelName: string_model_name;
14
- position: Array<number>;
15
+ position: EmbeddingVector;
15
16
  }>;
16
17
  readonly sources: Array<{
17
18
  title: string_markdown_text;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/cli",
3
- "version": "0.59.0-30",
3
+ "version": "0.59.0-32",
4
4
  "description": "Library to supercharge your use of large language models",
5
5
  "private": false,
6
6
  "sideEffects": false,
@@ -52,7 +52,7 @@
52
52
  }
53
53
  ],
54
54
  "peerDependencies": {
55
- "@promptbook/core": "0.59.0-30"
55
+ "@promptbook/core": "0.59.0-32"
56
56
  },
57
57
  "main": "./umd/index.umd.js",
58
58
  "module": "./esm/index.es.js",
package/umd/index.umd.js CHANGED
@@ -147,7 +147,7 @@
147
147
  /**
148
148
  * The version of the Promptbook library
149
149
  */
150
- var PROMPTBOOK_VERSION = '0.59.0-29';
150
+ var PROMPTBOOK_VERSION = '0.59.0-31';
151
151
 
152
152
  /**
153
153
  * Initializes testing `hello` command for Promptbook CLI utilities
@@ -441,7 +441,7 @@
441
441
  * > ex port function validatePromptbook(promptbook: unknown): asserts promptbook is PromptbookJson {
442
442
  */
443
443
 
444
- 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:[]}];
444
+ var promptbookLibrary = [{title:"Prepare Keywords",promptbookUrl:"https://promptbook.studio/promptbook/prepare-keywords.ptbk.md",promptbookVersion:"0.59.0-31",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-31",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:[]}];
445
445
 
446
446
  /**
447
447
  * This error indicates errors during the execution of the promptbook
@@ -3217,6 +3217,7 @@
3217
3217
  * TODO: Report here line/column of error
3218
3218
  * TODO: Use spaceTrim more effectively
3219
3219
  * TODO: [🧠] Parameter flags - isInput, isOutput, isInternal
3220
+ * TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
3220
3221
  */
3221
3222
 
3222
3223
  /**
@@ -3345,8 +3346,8 @@
3345
3346
  console.info(colors__default["default"].yellow("Tip: Prebuild your promptbook library (file with supposed prebuild ".concat(makedLibraryFilePath, " not found) with CLI util \"promptbook make\" to speed up the library creation.")));
3346
3347
  }
3347
3348
  else {
3348
- colors__default["default"].green("Using your prebuild promptbook library ".concat(makedLibraryFilePath));
3349
- // TODO: !!!!! Implement;
3349
+ colors__default["default"].green("(In future, not implemented yet) Using your prebuild promptbook library ".concat(makedLibraryFilePath));
3350
+ // TODO: !! Implement;
3350
3351
  }
3351
3352
  _a = options || {}, _b = _a.isRecursive, isRecursive = _b === void 0 ? true : _b, _c = _a.isVerbose, isVerbose = _c === void 0 ? false : _c, _d = _a.isLazyLoaded, isLazyLoaded = _d === void 0 ? false : _d, _e = _a.isCrashOnError, isCrashOnError = _e === void 0 ? true : _e;
3352
3353
  library = createLibraryFromPromise(function () { return __awaiter(_this, void 0, void 0, function () {
@@ -3661,7 +3662,7 @@
3661
3662
  return __generator(this, function (_a) {
3662
3663
  switch (_a.label) {
3663
3664
  case 0:
3664
- filePath = path.join(path$1, "promptbook-library.".concat(extension));
3665
+ filePath = path.join(path$1, "".concat(PROMPTBOOK_MAKED_BASE_FILENAME, ".").concat(extension));
3665
3666
  return [4 /*yield*/, promises.writeFile(filePath, content, 'utf-8')];
3666
3667
  case 1:
3667
3668
  _a.sent();