@promptbook/core 0.59.0-30 → 0.59.0-31

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.
@@ -1,7 +1,8 @@
1
1
  import type { CommonExecutionToolsOptions } from '../execution/CommonExecutionToolsOptions';
2
+ import { EmbeddingVector } from '../execution/EmbeddingVector';
2
3
  import type { ExecutionTools } from '../execution/ExecutionTools';
3
4
  import type { AvailableModel, LlmExecutionTools } from '../execution/LlmExecutionTools';
4
- import type { PromptChatResult, PromptCommonResult, PromptCompletionResult, PromptResult, PromptResultUsage, PromptResultUsageCounts, UncertainNumber } from '../execution/PromptResult';
5
+ import type { PromptEmbeddingResult, PromptChatResult, PromptCommonResult, PromptCompletionResult, PromptResult, PromptResultUsage, PromptResultUsageCounts, UncertainNumber } from '../execution/PromptResult';
5
6
  import type { PromptbookExecutor } from '../execution/PromptbookExecutor';
6
7
  import type { ScriptExecutionTools, ScriptExecutionToolsExecuteOptions } from '../execution/ScriptExecutionTools';
7
8
  import type { UserInterfaceTools, UserInterfaceToolsPromptDialogOptions } from '../execution/UserInterfaceTools';
@@ -26,7 +27,7 @@ import type { FromtoItems } from '../utils/FromtoItems';
26
27
  import { PROMPTBOOK_VERSION } from '../version';
27
28
  export { PROMPTBOOK_VERSION };
28
29
  export { EXPECTATION_UNITS };
29
- export type { AvailableModel, client_id, CommonExecutionToolsOptions, ExecutionReportJson, ExecutionTools, ExecutionType, ExpectationAmount, Expectations, ExpectationUnit, FromtoItems, KnowledgeJson, LlmExecutionTools, LlmTemplateJson, MaterialKnowledgePieceJson, ModelRequirements, ModelVariant, Parameters, Prompt, PromptbookExecutor, PromptbookJson, PromptbookLibrary, PromptbookString, PromptChatResult, PromptCommonResult, PromptCompletionResult, PromptDialogJson, PromptResult, PromptResultUsage, PromptResultUsageCounts, PromptTemplateJson, PromptTemplateParameterJson, ScriptExecutionTools, ScriptExecutionToolsExecuteOptions, ScriptJson, ScriptLanguage, SimpleTemplateJson, string_char, string_char_emoji, string_chat_prompt, string_completion_prompt, string_data_url, string_domain, string_email, string_file_absolute_path, string_file_extension, string_file_path, string_file_relative_path, string_filename, string_folder_absolute_path, string_folder_path, string_folder_relative_path, string_host, string_hostname, string_href, string_html, string_javascript, string_javascript_name, string_license, string_markdown, string_markdown_text, string_mime_type, string_mime_type_with_wildcard, string_model_name, string_name, string_person_fullname, string_prompt, string_promptbook_url, string_promptbook_url_with_hashtemplate, string_script, string_sha256, string_tdl, string_template, string_text_prompt, string_title, string_token, string_translate_language, string_uri, string_uri_part, string_url, string_url_image, string_version, TaskProgress, UncertainNumber, UserInterfaceTools, UserInterfaceToolsPromptDialogOptions, };
30
+ export type { AvailableModel, client_id, CommonExecutionToolsOptions, ExecutionReportJson, ExecutionTools, ExecutionType, ExpectationAmount, Expectations, ExpectationUnit, FromtoItems, KnowledgeJson, LlmExecutionTools, LlmTemplateJson, MaterialKnowledgePieceJson, ModelRequirements, ModelVariant, Parameters, Prompt, PromptbookExecutor, PromptbookJson, PromptbookLibrary, PromptbookString, PromptChatResult, PromptEmbeddingResult, EmbeddingVector, PromptCommonResult, PromptCompletionResult, PromptDialogJson, PromptResult, PromptResultUsage, PromptResultUsageCounts, PromptTemplateJson, PromptTemplateParameterJson, ScriptExecutionTools, ScriptExecutionToolsExecuteOptions, ScriptJson, ScriptLanguage, SimpleTemplateJson, string_char, string_char_emoji, string_chat_prompt, string_completion_prompt, string_data_url, string_domain, string_email, string_file_absolute_path, string_file_extension, string_file_path, string_file_relative_path, string_filename, string_folder_absolute_path, string_folder_path, string_folder_relative_path, string_host, string_hostname, string_href, string_html, string_javascript, string_javascript_name, string_license, string_markdown, string_markdown_text, string_mime_type, string_mime_type_with_wildcard, string_model_name, string_name, string_person_fullname, string_prompt, string_promptbook_url, string_promptbook_url_with_hashtemplate, string_script, string_sha256, string_tdl, string_template, string_text_prompt, string_title, string_token, string_translate_language, string_uri, string_uri_part, string_url, string_url_image, string_version, TaskProgress, UncertainNumber, UserInterfaceTools, UserInterfaceToolsPromptDialogOptions, };
30
31
  /**
31
32
  * TODO: Delete type aliases (from ../types/typeAliases) that are not exported here
32
33
  */
@@ -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;
@@ -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,9 @@ 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>;
34
35
  /**
35
36
  * Default model for chat variant.
36
37
  */
@@ -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/core",
3
- "version": "0.59.0-30",
3
+ "version": "0.59.0-31",
4
4
  "description": "Library to supercharge your use of large language models",
5
5
  "private": false,
6
6
  "sideEffects": false,
package/umd/index.umd.js CHANGED
@@ -206,7 +206,7 @@
206
206
  return PromptbookSyntaxError;
207
207
  }(Error));
208
208
 
209
- 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:[]}];
209
+ var promptbookLibrary = [{title:"Prepare Keywords",promptbookUrl:"https://promptbook.studio/promptbook/prepare-keywords.ptbk.md",promptbookVersion:"0.59.0-30",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-30",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:[]}];
210
210
 
211
211
  /**
212
212
  * This error indicates errors during the execution of the promptbook
@@ -530,7 +530,7 @@
530
530
  /**
531
531
  * The version of the Promptbook library
532
532
  */
533
- var PROMPTBOOK_VERSION = '0.59.0-29';
533
+ var PROMPTBOOK_VERSION = '0.59.0-30';
534
534
 
535
535
  /**
536
536
  * Function `addUsage` will add multiple usages into one
@@ -3395,6 +3395,14 @@
3395
3395
  return PromptbookLibraryError;
3396
3396
  }(Error));
3397
3397
 
3398
+ /**
3399
+ * Pretty print an embedding vector for logging
3400
+ */
3401
+ function embeddingVectorToString(embeddingVector) {
3402
+ var vectorLength = Math.pow(embeddingVector.reduce(function (acc, val) { return acc + Math.pow(val, 2); }, 0), 0.5);
3403
+ return "[EmbeddingVector; ".concat(embeddingVector.length, " dimensions; length: ").concat(vectorLength.toFixed(2), "; ").concat(embeddingVector.slice(0, 3).join(', '), "...]");
3404
+ }
3405
+
3398
3406
  /**
3399
3407
  * Function usageToWorktime will take usage and estimate saved worktime in hours of reading / writing
3400
3408
  *
@@ -4151,6 +4159,7 @@
4151
4159
  exports.createLibraryFromUrl = createLibraryFromUrl;
4152
4160
  exports.createPromptbookExecutor = createPromptbookExecutor;
4153
4161
  exports.createSublibrary = createSublibrary;
4162
+ exports.embeddingVectorToString = embeddingVectorToString;
4154
4163
  exports.executionReportJsonToString = executionReportJsonToString;
4155
4164
  exports.isPassingExpectations = isPassingExpectations;
4156
4165
  exports.libraryToJson = libraryToJson;