@promptbook/node 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.
- package/esm/index.es.js +2 -2
- package/esm/typings/src/_packages/core.index.d.ts +2 -1
- package/esm/typings/src/_packages/types.index.d.ts +3 -2
- package/esm/typings/src/execution/EmbeddingVector.d.ts +8 -0
- package/esm/typings/src/execution/PromptResult.d.ts +11 -0
- package/esm/typings/src/execution/embeddingVectorToString.d.ts +5 -0
- package/esm/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +3 -2
- package/esm/typings/src/llm-providers/openai/computeOpenaiUsage.d.ts +4 -2
- package/esm/typings/src/types/PromptbookJson/MaterialKnowledgePieceJson.d.ts +2 -1
- package/package.json +2 -2
- package/umd/index.umd.js +2 -2
- package/umd/typings/src/_packages/core.index.d.ts +2 -1
- package/umd/typings/src/_packages/types.index.d.ts +3 -2
- package/umd/typings/src/execution/EmbeddingVector.d.ts +8 -0
- package/umd/typings/src/execution/PromptResult.d.ts +11 -0
- package/umd/typings/src/execution/embeddingVectorToString.d.ts +5 -0
- package/umd/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +3 -2
- package/umd/typings/src/llm-providers/openai/computeOpenaiUsage.d.ts +4 -2
- package/umd/typings/src/types/PromptbookJson/MaterialKnowledgePieceJson.d.ts +2 -1
package/esm/index.es.js
CHANGED
|
@@ -147,7 +147,7 @@ var PromptbookSyntaxError = /** @class */ (function (_super) {
|
|
|
147
147
|
return PromptbookSyntaxError;
|
|
148
148
|
}(Error));
|
|
149
149
|
|
|
150
|
-
var promptbookLibrary = [{title:"Prepare Keywords",promptbookUrl:"https://promptbook.studio/promptbook/prepare-keywords.ptbk.md",promptbookVersion:"0.59.0-
|
|
150
|
+
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:[]}];
|
|
151
151
|
|
|
152
152
|
/**
|
|
153
153
|
* This error indicates errors during the execution of the promptbook
|
|
@@ -466,7 +466,7 @@ function isValidJsonString(value /* <-[👨⚖️] */) {
|
|
|
466
466
|
/**
|
|
467
467
|
* The version of the Promptbook library
|
|
468
468
|
*/
|
|
469
|
-
var PROMPTBOOK_VERSION = '0.59.0-
|
|
469
|
+
var PROMPTBOOK_VERSION = '0.59.0-30';
|
|
470
470
|
|
|
471
471
|
/**
|
|
472
472
|
* Function `addUsage` will add multiple usages into one
|
|
@@ -13,6 +13,7 @@ import { TemplateError } from '../errors/TemplateError';
|
|
|
13
13
|
import { UnexpectedError } from '../errors/UnexpectedError';
|
|
14
14
|
import { assertsExecutionSuccessful } from '../execution/assertsExecutionSuccessful';
|
|
15
15
|
import { createPromptbookExecutor } from '../execution/createPromptbookExecutor';
|
|
16
|
+
import { embeddingVectorToString } from '../execution/embeddingVectorToString';
|
|
16
17
|
import { addUsage } from '../execution/utils/addUsage';
|
|
17
18
|
import { checkExpectations, isPassingExpectations } from '../execution/utils/checkExpectations';
|
|
18
19
|
import { usageToWorktime } from '../execution/utils/usageToWorktime';
|
|
@@ -33,7 +34,7 @@ import { ExecutionTypes } from '../types/ExecutionTypes';
|
|
|
33
34
|
import { PROMPTBOOK_VERSION } from '../version';
|
|
34
35
|
export { PROMPTBOOK_VERSION };
|
|
35
36
|
export { ExecutionTypes };
|
|
36
|
-
export { addUsage, assertsExecutionSuccessful, checkExpectations, executionReportJsonToString, ExecutionReportStringOptions, ExecutionReportStringOptionsDefaults, isPassingExpectations, prepareKnowledgeFromMarkdown, prettifyPromptbookString, usageToWorktime, };
|
|
37
|
+
export { addUsage, assertsExecutionSuccessful, checkExpectations, embeddingVectorToString, executionReportJsonToString, ExecutionReportStringOptions, ExecutionReportStringOptionsDefaults, isPassingExpectations, prepareKnowledgeFromMarkdown, prettifyPromptbookString, usageToWorktime, };
|
|
37
38
|
export { createLibraryFromJson, createLibraryFromPromise, createLibraryFromUrl, createSublibrary, libraryToJson };
|
|
38
39
|
export { SimplePromptInterfaceTools };
|
|
39
40
|
export { promptbookJsonToString, promptbookStringToJson, validatePromptbook };
|
|
@@ -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
|
*/
|
|
@@ -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
|
|
@@ -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<
|
|
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:
|
|
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:
|
|
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/node",
|
|
3
|
-
"version": "0.59.0-
|
|
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,
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
}
|
|
50
50
|
],
|
|
51
51
|
"peerDependencies": {
|
|
52
|
-
"@promptbook/core": "0.59.0-
|
|
52
|
+
"@promptbook/core": "0.59.0-31"
|
|
53
53
|
},
|
|
54
54
|
"main": "./umd/index.umd.js",
|
|
55
55
|
"module": "./esm/index.es.js",
|
package/umd/index.umd.js
CHANGED
|
@@ -152,7 +152,7 @@
|
|
|
152
152
|
return PromptbookSyntaxError;
|
|
153
153
|
}(Error));
|
|
154
154
|
|
|
155
|
-
var promptbookLibrary = [{title:"Prepare Keywords",promptbookUrl:"https://promptbook.studio/promptbook/prepare-keywords.ptbk.md",promptbookVersion:"0.59.0-
|
|
155
|
+
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:[]}];
|
|
156
156
|
|
|
157
157
|
/**
|
|
158
158
|
* This error indicates errors during the execution of the promptbook
|
|
@@ -471,7 +471,7 @@
|
|
|
471
471
|
/**
|
|
472
472
|
* The version of the Promptbook library
|
|
473
473
|
*/
|
|
474
|
-
var PROMPTBOOK_VERSION = '0.59.0-
|
|
474
|
+
var PROMPTBOOK_VERSION = '0.59.0-30';
|
|
475
475
|
|
|
476
476
|
/**
|
|
477
477
|
* Function `addUsage` will add multiple usages into one
|
|
@@ -13,6 +13,7 @@ import { TemplateError } from '../errors/TemplateError';
|
|
|
13
13
|
import { UnexpectedError } from '../errors/UnexpectedError';
|
|
14
14
|
import { assertsExecutionSuccessful } from '../execution/assertsExecutionSuccessful';
|
|
15
15
|
import { createPromptbookExecutor } from '../execution/createPromptbookExecutor';
|
|
16
|
+
import { embeddingVectorToString } from '../execution/embeddingVectorToString';
|
|
16
17
|
import { addUsage } from '../execution/utils/addUsage';
|
|
17
18
|
import { checkExpectations, isPassingExpectations } from '../execution/utils/checkExpectations';
|
|
18
19
|
import { usageToWorktime } from '../execution/utils/usageToWorktime';
|
|
@@ -33,7 +34,7 @@ import { ExecutionTypes } from '../types/ExecutionTypes';
|
|
|
33
34
|
import { PROMPTBOOK_VERSION } from '../version';
|
|
34
35
|
export { PROMPTBOOK_VERSION };
|
|
35
36
|
export { ExecutionTypes };
|
|
36
|
-
export { addUsage, assertsExecutionSuccessful, checkExpectations, executionReportJsonToString, ExecutionReportStringOptions, ExecutionReportStringOptionsDefaults, isPassingExpectations, prepareKnowledgeFromMarkdown, prettifyPromptbookString, usageToWorktime, };
|
|
37
|
+
export { addUsage, assertsExecutionSuccessful, checkExpectations, embeddingVectorToString, executionReportJsonToString, ExecutionReportStringOptions, ExecutionReportStringOptionsDefaults, isPassingExpectations, prepareKnowledgeFromMarkdown, prettifyPromptbookString, usageToWorktime, };
|
|
37
38
|
export { createLibraryFromJson, createLibraryFromPromise, createLibraryFromUrl, createSublibrary, libraryToJson };
|
|
38
39
|
export { SimplePromptInterfaceTools };
|
|
39
40
|
export { promptbookJsonToString, promptbookStringToJson, validatePromptbook };
|
|
@@ -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
|
*/
|
|
@@ -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
|
|
@@ -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<
|
|
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:
|
|
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:
|
|
15
|
+
position: EmbeddingVector;
|
|
15
16
|
}>;
|
|
16
17
|
readonly sources: Array<{
|
|
17
18
|
title: string_markdown_text;
|