@promptbook/core 0.66.0-0 → 0.66.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.
- package/esm/index.es.js +108 -56
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/anthropic-claude.index.d.ts +2 -0
- package/esm/typings/src/_packages/core.index.d.ts +6 -2
- package/esm/typings/src/config.d.ts +22 -0
- package/esm/typings/src/execution/LlmExecutionTools.d.ts +11 -5
- package/esm/typings/src/llm-providers/_common/config.d.ts +1 -6
- package/esm/typings/src/llm-providers/anthropic-claude/computeAnthropicClaudeUsage.d.ts +18 -0
- package/esm/typings/src/llm-providers/anthropic-claude/computeAnthropicClaudeUsage.test.d.ts +4 -0
- package/esm/typings/src/llm-providers/anthropic-claude/register1.d.ts +4 -0
- package/esm/typings/src/llm-providers/openai/computeOpenaiUsage.d.ts +5 -1
- package/esm/typings/src/llm-providers/openai/computeOpenaiUsage.test.d.ts +3 -0
- package/esm/typings/src/llm-providers/remote/interfaces/RemoteLlmExecutionToolsOptions.d.ts +4 -1
- package/esm/typings/src/utils/environment/getGlobalScope.d.ts +3 -0
- package/package.json +1 -1
- package/umd/index.umd.js +110 -56
- package/umd/index.umd.js.map +1 -1
|
@@ -5,6 +5,7 @@ import type { AnthropicClaudeExecutionToolsOptions } from '../llm-providers/anth
|
|
|
5
5
|
import type { AnthropicClaudeExecutionToolsDirectOptions } from '../llm-providers/anthropic-claude/AnthropicClaudeExecutionToolsOptions';
|
|
6
6
|
import type { AnthropicClaudeExecutionToolsProxiedOptions } from '../llm-providers/anthropic-claude/AnthropicClaudeExecutionToolsOptions';
|
|
7
7
|
import { createAnthropicClaudeExecutionTools } from '../llm-providers/anthropic-claude/createAnthropicClaudeExecutionTools';
|
|
8
|
+
import { _ } from '../llm-providers/anthropic-claude/register1';
|
|
8
9
|
export { PROMPTBOOK_VERSION };
|
|
9
10
|
export { ANTHROPIC_CLAUDE_MODELS };
|
|
10
11
|
export { AnthropicClaudeExecutionTools };
|
|
@@ -12,3 +13,4 @@ export type { AnthropicClaudeExecutionToolsOptions };
|
|
|
12
13
|
export type { AnthropicClaudeExecutionToolsDirectOptions };
|
|
13
14
|
export type { AnthropicClaudeExecutionToolsProxiedOptions };
|
|
14
15
|
export { createAnthropicClaudeExecutionTools };
|
|
16
|
+
export { _ };
|
|
@@ -15,6 +15,9 @@ import { MAX_KNOWLEDGE_SOURCES_SCRAPING_TOTAL } from '../config';
|
|
|
15
15
|
import { EXECUTIONS_CACHE_DIRNAME } from '../config';
|
|
16
16
|
import { PIPELINE_COLLECTION_BASE_FILENAME } from '../config';
|
|
17
17
|
import { RESERVED_PARAMETER_NAMES } from '../config';
|
|
18
|
+
import { DEFAULT_REMOTE_URL } from '../config';
|
|
19
|
+
import { DEFAULT_REMOTE_URL_PATH } from '../config';
|
|
20
|
+
import { BOILERPLATE_LLM_TOOLS_CONFIGURATION_ } from '../config';
|
|
18
21
|
import { pipelineJsonToString } from '../conversion/pipelineJsonToString';
|
|
19
22
|
import type { PipelineStringToJsonOptions } from '../conversion/pipelineStringToJson';
|
|
20
23
|
import { pipelineStringToJson } from '../conversion/pipelineStringToJson';
|
|
@@ -45,7 +48,6 @@ import { CallbackInterfaceTools } from '../knowledge/dialogs/callback/CallbackIn
|
|
|
45
48
|
import type { CallbackInterfaceToolsOptions } from '../knowledge/dialogs/callback/CallbackInterfaceToolsOptions';
|
|
46
49
|
import { prepareKnowledgePieces } from '../knowledge/prepare-knowledge/_common/prepareKnowledgePieces';
|
|
47
50
|
import { prepareKnowledgeFromMarkdown } from '../knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown';
|
|
48
|
-
import { LLM_CONFIGURATION_BOILERPLATES } from '../llm-providers/_common/config';
|
|
49
51
|
import { createLlmToolsFromConfiguration } from '../llm-providers/_common/createLlmToolsFromConfiguration';
|
|
50
52
|
import { cacheLlmTools } from '../llm-providers/_common/utils/cache/cacheLlmTools';
|
|
51
53
|
import { countTotalUsage } from '../llm-providers/_common/utils/count-total-usage/countTotalUsage';
|
|
@@ -80,6 +82,9 @@ export { MAX_KNOWLEDGE_SOURCES_SCRAPING_TOTAL };
|
|
|
80
82
|
export { EXECUTIONS_CACHE_DIRNAME };
|
|
81
83
|
export { PIPELINE_COLLECTION_BASE_FILENAME };
|
|
82
84
|
export { RESERVED_PARAMETER_NAMES };
|
|
85
|
+
export { DEFAULT_REMOTE_URL };
|
|
86
|
+
export { DEFAULT_REMOTE_URL_PATH };
|
|
87
|
+
export { BOILERPLATE_LLM_TOOLS_CONFIGURATION_ };
|
|
83
88
|
export { pipelineJsonToString };
|
|
84
89
|
export type { PipelineStringToJsonOptions };
|
|
85
90
|
export { pipelineStringToJson };
|
|
@@ -110,7 +115,6 @@ export { CallbackInterfaceTools };
|
|
|
110
115
|
export type { CallbackInterfaceToolsOptions };
|
|
111
116
|
export { prepareKnowledgePieces };
|
|
112
117
|
export { prepareKnowledgeFromMarkdown };
|
|
113
|
-
export { LLM_CONFIGURATION_BOILERPLATES };
|
|
114
118
|
export { createLlmToolsFromConfiguration };
|
|
115
119
|
export { cacheLlmTools };
|
|
116
120
|
export { countTotalUsage };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { LlmToolsConfiguration } from './llm-providers/_common/LlmToolsConfiguration';
|
|
1
2
|
/**
|
|
2
3
|
* Warning message for the generated sections and files files
|
|
3
4
|
*
|
|
@@ -107,9 +108,30 @@ export declare const RESERVED_PARAMETER_RESTRICTED: string;
|
|
|
107
108
|
export declare const MOMENT_ARG_THRESHOLDS: {
|
|
108
109
|
readonly ss: 3;
|
|
109
110
|
};
|
|
111
|
+
/**
|
|
112
|
+
* @@@
|
|
113
|
+
*
|
|
114
|
+
* @public exported from `@promptbook/core`
|
|
115
|
+
*/
|
|
116
|
+
export declare const DEFAULT_REMOTE_URL = "https://api.pavolhejny.com/";
|
|
117
|
+
/**
|
|
118
|
+
* @@@
|
|
119
|
+
*
|
|
120
|
+
* @public exported from `@promptbook/core`
|
|
121
|
+
*/
|
|
122
|
+
export declare const DEFAULT_REMOTE_URL_PATH = "/promptbook/socket.io";
|
|
123
|
+
/**
|
|
124
|
+
* @@@
|
|
125
|
+
*
|
|
126
|
+
* @public exported from `@promptbook/core`
|
|
127
|
+
*/
|
|
128
|
+
export declare const BOILERPLATE_LLM_TOOLS_CONFIGURATION_: LlmToolsConfiguration;
|
|
110
129
|
/**
|
|
111
130
|
* @@@
|
|
112
131
|
*
|
|
113
132
|
* @private within the repository
|
|
114
133
|
*/
|
|
115
134
|
export declare const DEBUG_ALLOW_PAYED_TESTING: boolean;
|
|
135
|
+
/**
|
|
136
|
+
* TODO: [🧠][🧜♂️] Maybe join remoteUrl and path into single value
|
|
137
|
+
*/
|
|
@@ -28,6 +28,16 @@ export type LlmExecutionTools = {
|
|
|
28
28
|
* @example "Use all models from OpenAI"
|
|
29
29
|
*/
|
|
30
30
|
readonly description: string_markdown;
|
|
31
|
+
/**
|
|
32
|
+
* Check comfiguration
|
|
33
|
+
*
|
|
34
|
+
* @returns nothing if configuration is correct
|
|
35
|
+
* @throws {Error} if configuration is incorrect
|
|
36
|
+
*/
|
|
37
|
+
/**
|
|
38
|
+
* List all available models that can be used
|
|
39
|
+
*/
|
|
40
|
+
listModels(): Promisable<Array<AvailableModel>>;
|
|
31
41
|
/**
|
|
32
42
|
* Calls a chat model
|
|
33
43
|
*/
|
|
@@ -40,10 +50,6 @@ export type LlmExecutionTools = {
|
|
|
40
50
|
* Calls an embedding model
|
|
41
51
|
*/
|
|
42
52
|
callEmbeddingModel?(prompt: Prompt): Promise<EmbeddingPromptResult>;
|
|
43
|
-
/**
|
|
44
|
-
* List all available models that can be used
|
|
45
|
-
*/
|
|
46
|
-
listModels(): Promisable<Array<AvailableModel>>;
|
|
47
53
|
};
|
|
48
54
|
/**
|
|
49
55
|
* Represents a model that can be used for prompt execution
|
|
@@ -63,8 +69,8 @@ export type AvailableModel = {
|
|
|
63
69
|
readonly modelVariant: ModelVariant;
|
|
64
70
|
};
|
|
65
71
|
/**
|
|
72
|
+
* TODO: Implement destroyable pattern to free resources
|
|
66
73
|
* TODO: [🏳] Add `callTranslationModel`
|
|
67
|
-
* TODO: Maybe reorder `listModels` and put it befor `callChatModel`, `callCompletionModel`, `callEmbeddingModel`
|
|
68
74
|
* TODO: [🧠] Emulation of one type of model with another one - emuate chat with completion; emulate translation with chat
|
|
69
75
|
* TODO: [🍓][♐] Some heuristic to pick the best model in listed models
|
|
70
76
|
* TODO: [🧠] Should or should not there be a word "GPT" in both callCompletionModel and callChatModel
|
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
import type { LlmExecutionTools } from '../../execution/LlmExecutionTools';
|
|
2
2
|
import type { TODO_any } from '../../utils/organization/TODO_any';
|
|
3
|
-
import type { LlmToolsConfiguration } from './LlmToolsConfiguration';
|
|
4
|
-
/**
|
|
5
|
-
* @public exported from `@promptbook/core`
|
|
6
|
-
*/
|
|
7
|
-
export declare const LLM_CONFIGURATION_BOILERPLATES: LlmToolsConfiguration;
|
|
8
3
|
/**
|
|
9
4
|
* @private internal type for `createLlmToolsFromConfiguration`
|
|
10
5
|
*/
|
|
11
6
|
export declare const EXECUTION_TOOLS_CLASSES: Record<`create${string}`, (options: TODO_any) => LlmExecutionTools>;
|
|
12
7
|
/**
|
|
13
|
-
* TODO:
|
|
8
|
+
* TODO: !!!!!!! Make global register for this
|
|
14
9
|
* TODO: [🧠][🎌] Adding this should be responsibility of each provider package NOT this one central place
|
|
15
10
|
*/
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type Anthropic from '@anthropic-ai/sdk';
|
|
2
|
+
import type { PartialDeep } from 'type-fest';
|
|
3
|
+
import type { PromptResultUsage } from '../../execution/PromptResultUsage';
|
|
4
|
+
import type { Prompt } from '../../types/Prompt';
|
|
5
|
+
/**
|
|
6
|
+
* Computes the usage of the Anthropic Claude API based on the response from Anthropic Claude
|
|
7
|
+
*
|
|
8
|
+
* @param promptContent The content of the prompt
|
|
9
|
+
* @param resultContent The content of the result (for embedding prompts or failed prompts pass empty string)
|
|
10
|
+
* @param rawResponse The raw response from Anthropic Claude API
|
|
11
|
+
* @throws {PipelineExecutionError} If the usage is not defined in the response from Anthropic Claude
|
|
12
|
+
* @private internal utility of `AnthropicClaudeExecutionTools`
|
|
13
|
+
*/
|
|
14
|
+
export declare function computeAnthropicClaudeUsage(promptContent: Prompt['content'], // <- Note: Intentionally using [] to access type properties to bring jsdoc from Prompt/PromptResult to consumer
|
|
15
|
+
resultContent: string, rawResponse: PartialDeep<Pick<Anthropic.Messages.Message, 'model' | 'usage'>>): PromptResultUsage;
|
|
16
|
+
/**
|
|
17
|
+
* TODO: [🤝] DRY Maybe some common abstraction between `computeOpenaiUsage` and `computeAnthropicClaudeUsage`
|
|
18
|
+
*/
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type OpenAI from 'openai';
|
|
2
|
+
import type { PartialDeep } from 'type-fest';
|
|
2
3
|
import type { PromptResultUsage } from '../../execution/PromptResultUsage';
|
|
3
4
|
import type { Prompt } from '../../types/Prompt';
|
|
4
5
|
/**
|
|
@@ -11,4 +12,7 @@ import type { Prompt } from '../../types/Prompt';
|
|
|
11
12
|
* @private internal utility of `OpenAiExecutionTools`
|
|
12
13
|
*/
|
|
13
14
|
export declare function computeOpenaiUsage(promptContent: Prompt['content'], // <- Note: Intentionally using [] to access type properties to bring jsdoc from Prompt/PromptResult to consumer
|
|
14
|
-
resultContent: string, rawResponse: Pick<OpenAI.Chat.Completions.ChatCompletion | OpenAI.Completions.Completion | OpenAI.Embeddings.CreateEmbeddingResponse, 'model' | 'usage'
|
|
15
|
+
resultContent: string, rawResponse: PartialDeep<Pick<OpenAI.Chat.Completions.ChatCompletion | OpenAI.Completions.Completion | OpenAI.Embeddings.CreateEmbeddingResponse, 'model' | 'usage'>>): PromptResultUsage;
|
|
16
|
+
/**
|
|
17
|
+
* TODO: [🤝] DRY Maybe some common abstraction between `computeOpenaiUsage` and `computeAnthropicClaudeUsage`
|
|
18
|
+
*/
|
|
@@ -25,7 +25,7 @@ export type RemoteLlmExecutionToolsOptions = CommonExecutionToolsOptions & {
|
|
|
25
25
|
/**
|
|
26
26
|
* If set, only these models will be listed as available
|
|
27
27
|
*
|
|
28
|
-
* TODO: [🧠]
|
|
28
|
+
* TODO: [🧠] !!!!!! Figure out better solution
|
|
29
29
|
*/
|
|
30
30
|
readonly models?: Array<AvailableModel>;
|
|
31
31
|
/**
|
|
@@ -51,3 +51,6 @@ export type RemoteLlmExecutionToolsOptions = CommonExecutionToolsOptions & {
|
|
|
51
51
|
*/
|
|
52
52
|
readonly clientId: client_id;
|
|
53
53
|
});
|
|
54
|
+
/**
|
|
55
|
+
* TODO: [🧠][🧜♂️] Maybe join remoteUrl and path into single value
|
|
56
|
+
*/
|
package/package.json
CHANGED
package/umd/index.umd.js
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
/**
|
|
20
20
|
* The version of the Promptbook library
|
|
21
21
|
*/
|
|
22
|
-
var PROMPTBOOK_VERSION = '0.
|
|
22
|
+
var PROMPTBOOK_VERSION = '0.66.0-0';
|
|
23
23
|
// TODO: !!!! List here all the versions and annotate + put into script
|
|
24
24
|
|
|
25
25
|
/*! *****************************************************************************
|
|
@@ -588,6 +588,59 @@
|
|
|
588
588
|
var MOMENT_ARG_THRESHOLDS = {
|
|
589
589
|
ss: 3, // <- least number of seconds to be counted in seconds, minus 1. Must be set after setting the `s` unit or without setting the `s` unit.
|
|
590
590
|
};
|
|
591
|
+
/**
|
|
592
|
+
* @@@
|
|
593
|
+
*
|
|
594
|
+
* @public exported from `@promptbook/core`
|
|
595
|
+
*/
|
|
596
|
+
var DEFAULT_REMOTE_URL = 'https://api.pavolhejny.com/';
|
|
597
|
+
/**
|
|
598
|
+
* @@@
|
|
599
|
+
*
|
|
600
|
+
* @public exported from `@promptbook/core`
|
|
601
|
+
*/
|
|
602
|
+
var DEFAULT_REMOTE_URL_PATH = '/promptbook/socket.io';
|
|
603
|
+
// <- TODO: [🧜♂️]
|
|
604
|
+
/**
|
|
605
|
+
* @@@
|
|
606
|
+
*
|
|
607
|
+
* @public exported from `@promptbook/core`
|
|
608
|
+
*/
|
|
609
|
+
var BOILERPLATE_LLM_TOOLS_CONFIGURATION_ = [
|
|
610
|
+
{
|
|
611
|
+
title: 'Open AI',
|
|
612
|
+
packageName: '@promptbook/openai',
|
|
613
|
+
className: 'OpenAiExecutionTools',
|
|
614
|
+
options: {
|
|
615
|
+
apiKey: 'sk-',
|
|
616
|
+
},
|
|
617
|
+
},
|
|
618
|
+
{
|
|
619
|
+
title: 'Anthropic Claude',
|
|
620
|
+
packageName: '@promptbook/anthropic-claude',
|
|
621
|
+
className: 'AnthropicClaudeExecutionTools',
|
|
622
|
+
options: {
|
|
623
|
+
apiKey: 'sk-ant-api03-',
|
|
624
|
+
isProxied: true,
|
|
625
|
+
remoteUrl: DEFAULT_REMOTE_URL,
|
|
626
|
+
path: DEFAULT_REMOTE_URL_PATH,
|
|
627
|
+
},
|
|
628
|
+
},
|
|
629
|
+
{
|
|
630
|
+
title: 'Azure Open AI',
|
|
631
|
+
packageName: '@promptbook/azure-openai',
|
|
632
|
+
className: 'AzureOpenAiExecutionTools',
|
|
633
|
+
options: {
|
|
634
|
+
// TODO: !!!> resourceName
|
|
635
|
+
// TODO: !!!> deploymentName
|
|
636
|
+
apiKey: 'sk-',
|
|
637
|
+
},
|
|
638
|
+
},
|
|
639
|
+
// <- Note: [🦑] Add here new LLM provider
|
|
640
|
+
];
|
|
641
|
+
/**
|
|
642
|
+
* TODO: [🧠][🧜♂️] Maybe join remoteUrl and path into single value
|
|
643
|
+
*/
|
|
591
644
|
|
|
592
645
|
/**
|
|
593
646
|
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
@@ -1635,7 +1688,7 @@
|
|
|
1635
1688
|
});
|
|
1636
1689
|
}
|
|
1637
1690
|
|
|
1638
|
-
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.
|
|
1691
|
+
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.66.0-0",parameters:[{name:"knowledgeContent",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",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> {knowledgeContent}",dependentParameterNames:["knowledgeContent"],resultingParameterName:"knowledgePieces"}],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",promptbookVersion:"0.66.0-0",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",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> {knowledgePieceContent}",dependentParameterNames:["knowledgePieceContent"],resultingParameterName:"keywords"}],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",promptbookVersion:"0.66.0-0",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},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}",expectations:{words:{min:1,max:8}},dependentParameterNames:["knowledgePieceContent"],resultingParameterName:"title"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-title.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.ptbk.md",promptbookVersion:"0.66.0-0",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}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"make-model-requirements",title:"Make modelRequirements",modelRequirements:{modelVariant:"CHAT",modelName:"gpt-4-turbo"},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### Option `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Option `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### Option `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}",expectFormat:"JSON",dependentParameterNames:["availableModelNames","personaDescription"],resultingParameterName:"modelRequirements"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-persona.ptbk.md"}];
|
|
1639
1692
|
|
|
1640
1693
|
var defaultDiacriticsRemovalMap = [
|
|
1641
1694
|
{
|
|
@@ -6723,6 +6776,15 @@
|
|
|
6723
6776
|
* TODO: [🎰] Some mechanism to auto-update available models
|
|
6724
6777
|
*/
|
|
6725
6778
|
|
|
6779
|
+
/**
|
|
6780
|
+
* Get current date in ISO 8601 format
|
|
6781
|
+
*
|
|
6782
|
+
* @private internal utility
|
|
6783
|
+
*/
|
|
6784
|
+
function getCurrentIsoDate() {
|
|
6785
|
+
return new Date().toISOString();
|
|
6786
|
+
}
|
|
6787
|
+
|
|
6726
6788
|
/**
|
|
6727
6789
|
* Helper of usage compute
|
|
6728
6790
|
*
|
|
@@ -6757,13 +6819,42 @@
|
|
|
6757
6819
|
}
|
|
6758
6820
|
|
|
6759
6821
|
/**
|
|
6760
|
-
*
|
|
6822
|
+
* Computes the usage of the Anthropic Claude API based on the response from Anthropic Claude
|
|
6761
6823
|
*
|
|
6762
|
-
* @
|
|
6824
|
+
* @param promptContent The content of the prompt
|
|
6825
|
+
* @param resultContent The content of the result (for embedding prompts or failed prompts pass empty string)
|
|
6826
|
+
* @param rawResponse The raw response from Anthropic Claude API
|
|
6827
|
+
* @throws {PipelineExecutionError} If the usage is not defined in the response from Anthropic Claude
|
|
6828
|
+
* @private internal utility of `AnthropicClaudeExecutionTools`
|
|
6763
6829
|
*/
|
|
6764
|
-
function
|
|
6765
|
-
|
|
6830
|
+
function computeAnthropicClaudeUsage(promptContent, // <- Note: Intentionally using [] to access type properties to bring jsdoc from Prompt/PromptResult to consumer
|
|
6831
|
+
resultContent, rawResponse) {
|
|
6832
|
+
var _a, _b;
|
|
6833
|
+
if (rawResponse.usage === undefined) {
|
|
6834
|
+
throw new PipelineExecutionError('The usage is not defined in the response from Anthropic Claude');
|
|
6835
|
+
}
|
|
6836
|
+
if (((_a = rawResponse.usage) === null || _a === void 0 ? void 0 : _a.input_tokens) === undefined) {
|
|
6837
|
+
throw new PipelineExecutionError('In Anthropic Claude response `usage.prompt_tokens` not defined');
|
|
6838
|
+
}
|
|
6839
|
+
var inputTokens = rawResponse.usage.input_tokens;
|
|
6840
|
+
var outputTokens = ((_b = rawResponse.usage) === null || _b === void 0 ? void 0 : _b.output_tokens) || 0;
|
|
6841
|
+
var modelInfo = ANTHROPIC_CLAUDE_MODELS.find(function (model) { return model.modelName === rawResponse.model; });
|
|
6842
|
+
var price;
|
|
6843
|
+
if (modelInfo === undefined || modelInfo.pricing === undefined) {
|
|
6844
|
+
price = uncertainNumber();
|
|
6845
|
+
}
|
|
6846
|
+
else {
|
|
6847
|
+
price = uncertainNumber(inputTokens * modelInfo.pricing.prompt + outputTokens * modelInfo.pricing.output);
|
|
6848
|
+
}
|
|
6849
|
+
return {
|
|
6850
|
+
price: price,
|
|
6851
|
+
input: __assign({ tokensCount: uncertainNumber(rawResponse.usage.input_tokens) }, computeUsageCounts(promptContent)),
|
|
6852
|
+
output: __assign({ tokensCount: uncertainNumber(outputTokens) }, computeUsageCounts(resultContent)),
|
|
6853
|
+
};
|
|
6766
6854
|
}
|
|
6855
|
+
/**
|
|
6856
|
+
* TODO: [🤝] DRY Maybe some common abstraction between `computeOpenaiUsage` and `computeAnthropicClaudeUsage`
|
|
6857
|
+
*/
|
|
6767
6858
|
|
|
6768
6859
|
/**
|
|
6769
6860
|
* Execution Tools for calling Anthropic Claude API.
|
|
@@ -6784,9 +6875,8 @@
|
|
|
6784
6875
|
var anthropicOptions = __assign({}, options);
|
|
6785
6876
|
delete anthropicOptions.isVerbose;
|
|
6786
6877
|
delete anthropicOptions.isProxied;
|
|
6787
|
-
this.client = new Anthropic__default["default"](
|
|
6788
|
-
//
|
|
6789
|
-
anthropicOptions);
|
|
6878
|
+
this.client = new Anthropic__default["default"](anthropicOptions);
|
|
6879
|
+
// <- TODO: !!!!!! Lazy-load client
|
|
6790
6880
|
}
|
|
6791
6881
|
Object.defineProperty(AnthropicClaudeExecutionTools.prototype, "title", {
|
|
6792
6882
|
get: function () {
|
|
@@ -6857,15 +6947,10 @@
|
|
|
6857
6947
|
if (contentBlock.type !== 'text') {
|
|
6858
6948
|
throw new PipelineExecutionError("Returned content is not \"text\" type but \"".concat(contentBlock.type, "\""));
|
|
6859
6949
|
}
|
|
6860
|
-
console.log('!!!!!! rawResponse.usage', rawResponse.usage);
|
|
6861
6950
|
resultContent = contentBlock.text;
|
|
6862
6951
|
// eslint-disable-next-line prefer-const
|
|
6863
6952
|
complete = getCurrentIsoDate();
|
|
6864
|
-
usage =
|
|
6865
|
-
price: { value: 0, isUncertain: true } /* <- TODO: [🐞] !!!!!! Compute usage */,
|
|
6866
|
-
input: __assign({ tokensCount: uncertainNumber(rawResponse.usage.input_tokens) }, computeUsageCounts(prompt.content)),
|
|
6867
|
-
output: __assign({ tokensCount: uncertainNumber(rawResponse.usage.output_tokens) }, computeUsageCounts(prompt.content)),
|
|
6868
|
-
};
|
|
6953
|
+
usage = computeAnthropicClaudeUsage(content, '', rawResponse);
|
|
6869
6954
|
return [2 /*return*/, {
|
|
6870
6955
|
content: resultContent,
|
|
6871
6956
|
modelName: rawResponse.model,
|
|
@@ -7390,9 +7475,8 @@
|
|
|
7390
7475
|
this.options = options;
|
|
7391
7476
|
this.client = new openai.OpenAIClient(
|
|
7392
7477
|
// <- TODO: [🧱] Implement in a functional (not new Class) way
|
|
7393
|
-
"https://".concat(options.resourceName, ".openai.azure.com/"), new openai.AzureKeyCredential(
|
|
7394
|
-
//
|
|
7395
|
-
options.apiKey));
|
|
7478
|
+
"https://".concat(options.resourceName, ".openai.azure.com/"), new openai.AzureKeyCredential(options.apiKey));
|
|
7479
|
+
// <- TODO: !!!!!! Lazy-load client
|
|
7396
7480
|
}
|
|
7397
7481
|
Object.defineProperty(AzureOpenAiExecutionTools.prototype, "title", {
|
|
7398
7482
|
get: function () {
|
|
@@ -7662,6 +7746,9 @@
|
|
|
7662
7746
|
output: __assign({ tokensCount: uncertainNumber(outputTokens) }, computeUsageCounts(resultContent)),
|
|
7663
7747
|
};
|
|
7664
7748
|
}
|
|
7749
|
+
/**
|
|
7750
|
+
* TODO: [🤝] DRY Maybe some common abstraction between `computeOpenaiUsage` and `computeAnthropicClaudeUsage`
|
|
7751
|
+
*/
|
|
7665
7752
|
|
|
7666
7753
|
/**
|
|
7667
7754
|
* Execution Tools for calling OpenAI API.
|
|
@@ -7682,6 +7769,7 @@
|
|
|
7682
7769
|
delete openAiOptions.isVerbose;
|
|
7683
7770
|
delete openAiOptions.user;
|
|
7684
7771
|
this.client = new OpenAI__default["default"](__assign({}, openAiOptions));
|
|
7772
|
+
// <- TODO: !!!!!! Lazy-load client
|
|
7685
7773
|
}
|
|
7686
7774
|
Object.defineProperty(OpenAiExecutionTools.prototype, "title", {
|
|
7687
7775
|
get: function () {
|
|
@@ -7967,42 +8055,6 @@
|
|
|
7967
8055
|
* TODO: [🧠][🌰] Allow to pass `title` for tracking purposes
|
|
7968
8056
|
*/
|
|
7969
8057
|
|
|
7970
|
-
/**
|
|
7971
|
-
* @public exported from `@promptbook/core`
|
|
7972
|
-
*/
|
|
7973
|
-
var LLM_CONFIGURATION_BOILERPLATES = [
|
|
7974
|
-
{
|
|
7975
|
-
title: 'Open AI',
|
|
7976
|
-
packageName: '@promptbook/openai',
|
|
7977
|
-
className: 'OpenAiExecutionTools',
|
|
7978
|
-
options: {
|
|
7979
|
-
apiKey: 'sk-',
|
|
7980
|
-
},
|
|
7981
|
-
},
|
|
7982
|
-
{
|
|
7983
|
-
title: 'Anthropic Claude',
|
|
7984
|
-
packageName: '@promptbook/anthropic-claude',
|
|
7985
|
-
className: 'AnthropicClaudeExecutionTools',
|
|
7986
|
-
options: {
|
|
7987
|
-
apiKey: 'sk-ant-api03-',
|
|
7988
|
-
isProxied: true,
|
|
7989
|
-
remoteUrl: "https://api.pavolhejny.com/",
|
|
7990
|
-
path: '/promptbook/socket.io', // <- TODO: !!!!!! To config DEFAULT_REMOTE_URL_PATH
|
|
7991
|
-
},
|
|
7992
|
-
},
|
|
7993
|
-
{
|
|
7994
|
-
title: 'Azure Open AI',
|
|
7995
|
-
packageName: '@promptbook/azure-openai',
|
|
7996
|
-
className: 'AzureOpenAiExecutionTools',
|
|
7997
|
-
options: {
|
|
7998
|
-
// TODO: !!!> resourceName
|
|
7999
|
-
// TODO: !!!> deploymentName
|
|
8000
|
-
apiKey: 'sk-',
|
|
8001
|
-
},
|
|
8002
|
-
},
|
|
8003
|
-
// <- TODO: !!!!!! To config
|
|
8004
|
-
// <- Note: [🦑] Add here new LLM provider
|
|
8005
|
-
];
|
|
8006
8058
|
/**
|
|
8007
8059
|
* @private internal type for `createLlmToolsFromConfiguration`
|
|
8008
8060
|
*/
|
|
@@ -8019,7 +8071,7 @@
|
|
|
8019
8071
|
// <- Note: [🦑] Add here new LLM provider
|
|
8020
8072
|
};
|
|
8021
8073
|
/**
|
|
8022
|
-
* TODO:
|
|
8074
|
+
* TODO: !!!!!!! Make global register for this
|
|
8023
8075
|
* TODO: [🧠][🎌] Adding this should be responsibility of each provider package NOT this one central place
|
|
8024
8076
|
*/
|
|
8025
8077
|
|
|
@@ -8627,15 +8679,17 @@
|
|
|
8627
8679
|
* TODO: [🧠] Should be in generated file GENERATOR_WARNING
|
|
8628
8680
|
*/
|
|
8629
8681
|
|
|
8682
|
+
exports.BOILERPLATE_LLM_TOOLS_CONFIGURATION_ = BOILERPLATE_LLM_TOOLS_CONFIGURATION_;
|
|
8630
8683
|
exports.BlockTypes = BlockTypes;
|
|
8631
8684
|
exports.CLAIM = CLAIM;
|
|
8632
8685
|
exports.CallbackInterfaceTools = CallbackInterfaceTools;
|
|
8633
8686
|
exports.CollectionError = CollectionError;
|
|
8687
|
+
exports.DEFAULT_REMOTE_URL = DEFAULT_REMOTE_URL;
|
|
8688
|
+
exports.DEFAULT_REMOTE_URL_PATH = DEFAULT_REMOTE_URL_PATH;
|
|
8634
8689
|
exports.EXECUTIONS_CACHE_DIRNAME = EXECUTIONS_CACHE_DIRNAME;
|
|
8635
8690
|
exports.EXPECTATION_UNITS = EXPECTATION_UNITS;
|
|
8636
8691
|
exports.EnvironmentMismatchError = EnvironmentMismatchError;
|
|
8637
8692
|
exports.ExecutionReportStringOptionsDefaults = ExecutionReportStringOptionsDefaults;
|
|
8638
|
-
exports.LLM_CONFIGURATION_BOILERPLATES = LLM_CONFIGURATION_BOILERPLATES;
|
|
8639
8693
|
exports.LimitReachedError = LimitReachedError;
|
|
8640
8694
|
exports.MAX_EXECUTION_ATTEMPTS = MAX_EXECUTION_ATTEMPTS;
|
|
8641
8695
|
exports.MAX_FILENAME_LENGTH = MAX_FILENAME_LENGTH;
|