@promptbook/cli 0.103.0-67 → 0.103.0-68
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/apps/agents-server/TODO.txt +1 -5
- package/apps/agents-server/package-lock.json +8 -2317
- package/apps/agents-server/package.json +0 -9
- package/apps/agents-server/src/app/agents/[agentName]/AgentOptionsMenu.tsx +34 -2
- package/apps/agents-server/src/app/agents/[agentName]/AgentProfileWrapper.tsx +4 -0
- package/apps/agents-server/src/app/humans.txt/route.ts +15 -0
- package/apps/agents-server/src/app/layout.tsx +31 -0
- package/apps/agents-server/src/app/robots.txt/route.ts +15 -0
- package/apps/agents-server/src/app/security.txt/route.ts +15 -0
- package/apps/agents-server/src/app/sitemap.xml/route.ts +37 -0
- package/apps/agents-server/src/components/DocumentationContent/DocumentationContent.tsx +19 -18
- package/apps/agents-server/src/components/Footer/Footer.tsx +13 -13
- package/apps/agents-server/src/components/Header/Header.tsx +95 -20
- package/apps/agents-server/src/components/LayoutWrapper/LayoutWrapper.tsx +3 -0
- package/apps/agents-server/src/components/_utils/generateMetaTxt.ts +28 -0
- package/apps/agents-server/src/components/_utils/headlessParam.tsx +36 -0
- package/apps/agents-server/src/middleware.ts +6 -2
- package/esm/index.es.js +191 -14
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/components.index.d.ts +2 -0
- package/esm/typings/src/_packages/types.index.d.ts +6 -0
- package/esm/typings/src/book-components/BookEditor/BookEditor.d.ts +10 -0
- package/esm/typings/src/book-components/BookEditor/BookEditorActionbar.d.ts +4 -0
- package/esm/typings/src/book-components/icons/CameraIcon.d.ts +11 -0
- package/esm/typings/src/execution/LlmExecutionTools.d.ts +5 -1
- package/esm/typings/src/execution/PromptResult.d.ts +7 -1
- package/esm/typings/src/llm-providers/ollama/OllamaExecutionTools.d.ts +4 -0
- package/esm/typings/src/llm-providers/openai/OpenAiCompatibleExecutionTools.d.ts +13 -1
- package/esm/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +4 -0
- package/esm/typings/src/llm-providers/openai/createOpenAiCompatibleExecutionTools.d.ts +6 -6
- package/esm/typings/src/types/ModelRequirements.d.ts +13 -1
- package/esm/typings/src/types/ModelVariant.d.ts +1 -1
- package/esm/typings/src/types/Prompt.d.ts +13 -1
- package/esm/typings/src/version.d.ts +1 -1
- package/package.json +1 -1
- package/umd/index.umd.js +191 -14
- package/umd/index.umd.js.map +1 -1
|
@@ -45,6 +45,7 @@ import type { MessageButton } from '../book-components/Chat/utils/parseMessageBu
|
|
|
45
45
|
import { parseMessageButtons } from '../book-components/Chat/utils/parseMessageButtons';
|
|
46
46
|
import { ArrowIcon } from '../book-components/icons/ArrowIcon';
|
|
47
47
|
import { AttachmentIcon } from '../book-components/icons/AttachmentIcon';
|
|
48
|
+
import { CameraIcon } from '../book-components/icons/CameraIcon';
|
|
48
49
|
import { MicIcon } from '../book-components/icons/MicIcon';
|
|
49
50
|
import { PauseIcon } from '../book-components/icons/PauseIcon';
|
|
50
51
|
import { PlayIcon } from '../book-components/icons/PlayIcon';
|
|
@@ -105,6 +106,7 @@ export type { MessageButton };
|
|
|
105
106
|
export { parseMessageButtons };
|
|
106
107
|
export { ArrowIcon };
|
|
107
108
|
export { AttachmentIcon };
|
|
109
|
+
export { CameraIcon };
|
|
108
110
|
export { MicIcon };
|
|
109
111
|
export { PauseIcon };
|
|
110
112
|
export { PlayIcon };
|
|
@@ -88,6 +88,7 @@ import type { PromptbookFetch } from '../execution/PromptbookFetch';
|
|
|
88
88
|
import type { PromptResult } from '../execution/PromptResult';
|
|
89
89
|
import type { CompletionPromptResult } from '../execution/PromptResult';
|
|
90
90
|
import type { ChatPromptResult } from '../execution/PromptResult';
|
|
91
|
+
import type { ImagePromptResult } from '../execution/PromptResult';
|
|
91
92
|
import type { EmbeddingPromptResult } from '../execution/PromptResult';
|
|
92
93
|
import type { ScriptExecutionTools } from '../execution/ScriptExecutionTools';
|
|
93
94
|
import type { ScriptExecutionToolsExecuteOptions } from '../execution/ScriptExecutionTools';
|
|
@@ -187,6 +188,7 @@ import type { LlmCall } from '../types/LlmCall';
|
|
|
187
188
|
import type { ModelRequirements } from '../types/ModelRequirements';
|
|
188
189
|
import type { CompletionModelRequirements } from '../types/ModelRequirements';
|
|
189
190
|
import type { ChatModelRequirements } from '../types/ModelRequirements';
|
|
191
|
+
import type { ImageGenerationModelRequirements } from '../types/ModelRequirements';
|
|
190
192
|
import type { EmbeddingModelRequirements } from '../types/ModelRequirements';
|
|
191
193
|
import type { ModelVariant } from '../types/ModelVariant';
|
|
192
194
|
import type { NonEmptyArray } from '../types/NonEmptyArray';
|
|
@@ -194,6 +196,7 @@ import type { NonEmptyReadonlyArray } from '../types/NonEmptyArray';
|
|
|
194
196
|
import type { Prompt } from '../types/Prompt';
|
|
195
197
|
import type { CompletionPrompt } from '../types/Prompt';
|
|
196
198
|
import type { ChatPrompt } from '../types/Prompt';
|
|
199
|
+
import type { ImagePrompt } from '../types/Prompt';
|
|
197
200
|
import type { EmbeddingPrompt } from '../types/Prompt';
|
|
198
201
|
import type { ScriptLanguage } from '../types/ScriptLanguage';
|
|
199
202
|
import type { SectionType } from '../types/SectionType';
|
|
@@ -449,6 +452,7 @@ export type { PromptbookFetch };
|
|
|
449
452
|
export type { PromptResult };
|
|
450
453
|
export type { CompletionPromptResult };
|
|
451
454
|
export type { ChatPromptResult };
|
|
455
|
+
export type { ImagePromptResult };
|
|
452
456
|
export type { EmbeddingPromptResult };
|
|
453
457
|
export type { ScriptExecutionTools };
|
|
454
458
|
export type { ScriptExecutionToolsExecuteOptions };
|
|
@@ -548,6 +552,7 @@ export type { LlmCall };
|
|
|
548
552
|
export type { ModelRequirements };
|
|
549
553
|
export type { CompletionModelRequirements };
|
|
550
554
|
export type { ChatModelRequirements };
|
|
555
|
+
export type { ImageGenerationModelRequirements };
|
|
551
556
|
export type { EmbeddingModelRequirements };
|
|
552
557
|
export type { ModelVariant };
|
|
553
558
|
export type { NonEmptyArray };
|
|
@@ -555,6 +560,7 @@ export type { NonEmptyReadonlyArray };
|
|
|
555
560
|
export type { Prompt };
|
|
556
561
|
export type { CompletionPrompt };
|
|
557
562
|
export type { ChatPrompt };
|
|
563
|
+
export type { ImagePrompt };
|
|
558
564
|
export type { EmbeddingPrompt };
|
|
559
565
|
export type { ScriptLanguage };
|
|
560
566
|
export type { SectionType };
|
|
@@ -81,6 +81,16 @@ export type BookEditorProps = {
|
|
|
81
81
|
*/
|
|
82
82
|
readonly readonlyMessage?: string;
|
|
83
83
|
};
|
|
84
|
+
/**
|
|
85
|
+
* If true, shows the upload button in the action bar.
|
|
86
|
+
* By default, the upload button is shown.
|
|
87
|
+
*/
|
|
88
|
+
readonly isUploadButtonShown?: boolean;
|
|
89
|
+
/**
|
|
90
|
+
* If true, shows the camera button in the action bar.
|
|
91
|
+
* By default, the camera button is shown on mobile devices.
|
|
92
|
+
*/
|
|
93
|
+
readonly isCameraButtonShown?: boolean;
|
|
84
94
|
/**
|
|
85
95
|
* If true, shows the download button in the action bar.
|
|
86
96
|
* By default, the download button is shown.
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
type BookEditorActionbarProps = {
|
|
2
2
|
value: string | undefined;
|
|
3
3
|
isDownloadButtonShown?: boolean;
|
|
4
|
+
isUploadButtonShown?: boolean;
|
|
5
|
+
isCameraButtonShown?: boolean;
|
|
4
6
|
isAboutButtonShown?: boolean;
|
|
5
7
|
isFullscreenButtonShown?: boolean;
|
|
6
8
|
onFullscreenClick?: () => void;
|
|
9
|
+
onUploadDocument?: () => void;
|
|
10
|
+
onTakePhoto?: () => void;
|
|
7
11
|
isFullscreen?: boolean;
|
|
8
12
|
};
|
|
9
13
|
/**
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
type CameraIconProps = {
|
|
2
|
+
size?: number;
|
|
3
|
+
color?: string;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* @@@
|
|
7
|
+
*
|
|
8
|
+
* @public exported from `@promptbook/components`
|
|
9
|
+
*/
|
|
10
|
+
export declare function CameraIcon({ size, color }: CameraIconProps): import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
export {};
|
|
@@ -3,7 +3,7 @@ import type { ChatParticipant } from '../book-components/Chat/types/ChatParticip
|
|
|
3
3
|
import type { Prompt } from '../types/Prompt';
|
|
4
4
|
import type { string_markdown, string_markdown_text, string_title } from '../types/typeAliases';
|
|
5
5
|
import type { AvailableModel } from './AvailableModel';
|
|
6
|
-
import type { ChatPromptResult, CompletionPromptResult, EmbeddingPromptResult } from './PromptResult';
|
|
6
|
+
import type { ChatPromptResult, CompletionPromptResult, EmbeddingPromptResult, ImagePromptResult } from './PromptResult';
|
|
7
7
|
/**
|
|
8
8
|
* Container for all the tools needed to execute prompts to large language models like GPT-4
|
|
9
9
|
* On its interface it exposes common methods for prompt execution.
|
|
@@ -70,6 +70,10 @@ export type LlmExecutionTools = {
|
|
|
70
70
|
* Calls a completion model
|
|
71
71
|
*/
|
|
72
72
|
callCompletionModel?(prompt: Prompt): Promise<CompletionPromptResult>;
|
|
73
|
+
/**
|
|
74
|
+
* Calls a image generation model
|
|
75
|
+
*/
|
|
76
|
+
callImageGenerationModel?(prompt: Prompt): Promise<ImagePromptResult>;
|
|
73
77
|
/**
|
|
74
78
|
* Calls an embedding model
|
|
75
79
|
*/
|
|
@@ -8,7 +8,7 @@ import type { Usage } from './Usage';
|
|
|
8
8
|
*
|
|
9
9
|
* @see https://github.com/webgptorg/promptbook#prompt-result
|
|
10
10
|
*/
|
|
11
|
-
export type PromptResult = CompletionPromptResult | ChatPromptResult | EmbeddingPromptResult;
|
|
11
|
+
export type PromptResult = CompletionPromptResult | ChatPromptResult | ImagePromptResult | EmbeddingPromptResult;
|
|
12
12
|
/**
|
|
13
13
|
* Completion prompt result
|
|
14
14
|
*
|
|
@@ -22,6 +22,12 @@ export type CompletionPromptResult = CommonPromptResult;
|
|
|
22
22
|
* Note: [🚉] This is fully serializable as JSON
|
|
23
23
|
*/
|
|
24
24
|
export type ChatPromptResult = CommonPromptResult & {};
|
|
25
|
+
/**
|
|
26
|
+
* Image prompt result
|
|
27
|
+
*
|
|
28
|
+
* Note: [🚉] This is fully serializable as JSON
|
|
29
|
+
*/
|
|
30
|
+
export type ImagePromptResult = CommonPromptResult;
|
|
25
31
|
/**
|
|
26
32
|
* Embedding prompt result
|
|
27
33
|
*
|
|
@@ -38,6 +38,10 @@ export declare class OllamaExecutionTools extends OpenAiCompatibleExecutionTools
|
|
|
38
38
|
* Default model for completion variant.
|
|
39
39
|
*/
|
|
40
40
|
protected getDefaultEmbeddingModel(): AvailableModel;
|
|
41
|
+
/**
|
|
42
|
+
* Default model for image generation variant.
|
|
43
|
+
*/
|
|
44
|
+
protected getDefaultImageGenerationModel(): AvailableModel;
|
|
41
45
|
}
|
|
42
46
|
/**
|
|
43
47
|
* TODO: [🛄] Some way how to re-wrap the errors from `OpenAiCompatibleExecutionTools`
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import OpenAI from 'openai';
|
|
2
2
|
import type { AvailableModel } from '../../execution/AvailableModel';
|
|
3
3
|
import type { LlmExecutionTools } from '../../execution/LlmExecutionTools';
|
|
4
|
-
import type { ChatPromptResult, CompletionPromptResult, EmbeddingPromptResult } from '../../execution/PromptResult';
|
|
4
|
+
import type { ChatPromptResult, CompletionPromptResult, EmbeddingPromptResult, ImagePromptResult } from '../../execution/PromptResult';
|
|
5
5
|
import type { Usage } from '../../execution/Usage';
|
|
6
6
|
import type { Prompt } from '../../types/Prompt';
|
|
7
7
|
import type { string_markdown, string_markdown_text, string_model_name, string_title } from '../../types/typeAliases';
|
|
@@ -63,6 +63,14 @@ export declare abstract class OpenAiCompatibleExecutionTools implements LlmExecu
|
|
|
63
63
|
* Internal method that handles parameter retry for embedding model calls
|
|
64
64
|
*/
|
|
65
65
|
private callEmbeddingModelWithRetry;
|
|
66
|
+
/**
|
|
67
|
+
* Calls OpenAI compatible API to use a image generation model
|
|
68
|
+
*/
|
|
69
|
+
callImageGenerationModel(prompt: Pick<Prompt, 'content' | 'parameters' | 'modelRequirements'>): Promise<ImagePromptResult>;
|
|
70
|
+
/**
|
|
71
|
+
* Internal method that handles parameter retry for image generation model calls
|
|
72
|
+
*/
|
|
73
|
+
private callImageGenerationModelWithRetry;
|
|
66
74
|
/**
|
|
67
75
|
* Get the model that should be used as default
|
|
68
76
|
*/
|
|
@@ -89,6 +97,10 @@ export declare abstract class OpenAiCompatibleExecutionTools implements LlmExecu
|
|
|
89
97
|
* Default model for completion variant.
|
|
90
98
|
*/
|
|
91
99
|
protected abstract getDefaultEmbeddingModel(): AvailableModel;
|
|
100
|
+
/**
|
|
101
|
+
* Default model for image generation variant.
|
|
102
|
+
*/
|
|
103
|
+
protected abstract getDefaultImageGenerationModel(): AvailableModel;
|
|
92
104
|
/**
|
|
93
105
|
* Makes a request with retry logic for network errors like ECONNRESET
|
|
94
106
|
*/
|
|
@@ -35,4 +35,8 @@ export declare class OpenAiExecutionTools extends OpenAiCompatibleExecutionTools
|
|
|
35
35
|
* Default model for completion variant.
|
|
36
36
|
*/
|
|
37
37
|
protected getDefaultEmbeddingModel(): AvailableModel;
|
|
38
|
+
/**
|
|
39
|
+
* Default model for image generation variant.
|
|
40
|
+
*/
|
|
41
|
+
protected getDefaultImageGenerationModel(): AvailableModel;
|
|
38
42
|
}
|
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
import type { AvailableModel } from '../../execution/AvailableModel';
|
|
2
2
|
import type { LlmExecutionTools } from '../../execution/LlmExecutionTools';
|
|
3
3
|
import type { Usage } from '../../execution/Usage';
|
|
4
|
-
import type { string_markdown } from '../../types/typeAliases';
|
|
5
|
-
import type { string_markdown_text } from '../../types/typeAliases';
|
|
6
|
-
import type { string_model_name } from '../../types/typeAliases';
|
|
7
|
-
import type { string_title } from '../../types/typeAliases';
|
|
4
|
+
import type { string_markdown, string_markdown_text, string_model_name, string_title } from '../../types/typeAliases';
|
|
8
5
|
import { RemoteLlmExecutionTools } from '../remote/RemoteLlmExecutionTools';
|
|
9
6
|
import { computeOpenAiUsage } from './computeOpenAiUsage';
|
|
10
7
|
import { OpenAiCompatibleExecutionTools } from './OpenAiCompatibleExecutionTools';
|
|
11
|
-
import type { OpenAiCompatibleExecutionToolsNonProxiedOptions } from './OpenAiCompatibleExecutionToolsOptions';
|
|
12
|
-
import type { OpenAiCompatibleExecutionToolsOptions } from './OpenAiCompatibleExecutionToolsOptions';
|
|
8
|
+
import type { OpenAiCompatibleExecutionToolsNonProxiedOptions, OpenAiCompatibleExecutionToolsOptions } from './OpenAiCompatibleExecutionToolsOptions';
|
|
13
9
|
/**
|
|
14
10
|
* Execution Tools for calling OpenAI compatible API
|
|
15
11
|
*
|
|
@@ -67,6 +63,10 @@ export declare class HardcodedOpenAiCompatibleExecutionTools extends OpenAiCompa
|
|
|
67
63
|
* Default model for completion variant.
|
|
68
64
|
*/
|
|
69
65
|
protected getDefaultEmbeddingModel(): AvailableModel;
|
|
66
|
+
/**
|
|
67
|
+
* Default model for image generation variant.
|
|
68
|
+
*/
|
|
69
|
+
protected getDefaultImageGenerationModel(): AvailableModel;
|
|
70
70
|
}
|
|
71
71
|
/**
|
|
72
72
|
* TODO: [🦺] Is there some way how to put `packageName` and `className` on top and function definition on bottom?
|
|
@@ -7,7 +7,7 @@ import type { number_model_temperature, number_seed, string_model_name, string_s
|
|
|
7
7
|
* Note: [🚉] This is fully serializable as JSON
|
|
8
8
|
* @see https://github.com/webgptorg/promptbook#model-requirements
|
|
9
9
|
*/
|
|
10
|
-
export type ModelRequirements = CompletionModelRequirements | ChatModelRequirements | EmbeddingModelRequirements;
|
|
10
|
+
export type ModelRequirements = CompletionModelRequirements | ChatModelRequirements | ImageGenerationModelRequirements | EmbeddingModelRequirements;
|
|
11
11
|
/**
|
|
12
12
|
* Model requirements for the completion variant
|
|
13
13
|
*
|
|
@@ -34,6 +34,17 @@ export type ChatModelRequirements = CommonModelRequirements & {
|
|
|
34
34
|
*/
|
|
35
35
|
readonly systemMessage?: string_system_message;
|
|
36
36
|
};
|
|
37
|
+
/**
|
|
38
|
+
* Model requirements for the image generation variant
|
|
39
|
+
*
|
|
40
|
+
* Note: [🚉] This is fully serializable as JSON
|
|
41
|
+
*/
|
|
42
|
+
export type ImageGenerationModelRequirements = CommonModelRequirements & {
|
|
43
|
+
/**
|
|
44
|
+
* Image generation model variant
|
|
45
|
+
*/
|
|
46
|
+
modelVariant: 'IMAGE_GENERATION';
|
|
47
|
+
};
|
|
37
48
|
/**
|
|
38
49
|
* Model requirements for the embedding variant
|
|
39
50
|
*
|
|
@@ -59,6 +70,7 @@ export type CommonModelRequirements = {
|
|
|
59
70
|
* There are 3 variants:
|
|
60
71
|
* - **COMPLETION** - model that takes prompt and writes the rest of the text
|
|
61
72
|
* - **CHAT** - model that takes prompt and previous messages and returns response
|
|
73
|
+
* - **IMAGE_GENERATION** - model that takes prompt and returns image
|
|
62
74
|
* - **EMBEDDING** - model that takes prompt and returns embedding
|
|
63
75
|
* <- [🤖]
|
|
64
76
|
*/
|
|
@@ -12,4 +12,4 @@ export type ModelVariant = TupleToUnion<typeof MODEL_VARIANTS>;
|
|
|
12
12
|
* @see {@link ModelVariant}
|
|
13
13
|
* @public exported from `@promptbook/core`
|
|
14
14
|
*/
|
|
15
|
-
export declare const MODEL_VARIANTS: readonly ["COMPLETION", "CHAT", "EMBEDDING"];
|
|
15
|
+
export declare const MODEL_VARIANTS: readonly ["COMPLETION", "CHAT", "IMAGE_GENERATION", "EMBEDDING"];
|
|
@@ -4,6 +4,7 @@ import type { Expectations } from '../pipeline/PipelineJson/Expectations';
|
|
|
4
4
|
import type { ChatModelRequirements } from './ModelRequirements';
|
|
5
5
|
import type { CompletionModelRequirements } from './ModelRequirements';
|
|
6
6
|
import type { EmbeddingModelRequirements } from './ModelRequirements';
|
|
7
|
+
import type { ImageGenerationModelRequirements } from './ModelRequirements';
|
|
7
8
|
import type { ModelRequirements } from './ModelRequirements';
|
|
8
9
|
import type { Parameters } from './typeAliases';
|
|
9
10
|
import type { string_pipeline_url_with_task_hash } from './typeAliases';
|
|
@@ -17,7 +18,7 @@ import type { string_title } from './typeAliases';
|
|
|
17
18
|
* Note: [🚉] This is fully serializable as JSON
|
|
18
19
|
* @see https://github.com/webgptorg/promptbook#prompt
|
|
19
20
|
*/
|
|
20
|
-
export type Prompt = CompletionPrompt | ChatPrompt | EmbeddingPrompt;
|
|
21
|
+
export type Prompt = CompletionPrompt | ChatPrompt | ImagePrompt | EmbeddingPrompt;
|
|
21
22
|
/**
|
|
22
23
|
* Completion prompt
|
|
23
24
|
*
|
|
@@ -44,6 +45,17 @@ export type ChatPrompt = CommonPrompt & {
|
|
|
44
45
|
*/
|
|
45
46
|
thread?: ChatMessage[];
|
|
46
47
|
};
|
|
48
|
+
/**
|
|
49
|
+
* Image prompt
|
|
50
|
+
*
|
|
51
|
+
* Note: [🚉] This is fully serializable as JSON
|
|
52
|
+
*/
|
|
53
|
+
export type ImagePrompt = CommonPrompt & {
|
|
54
|
+
/**
|
|
55
|
+
* Requirements for image generation model
|
|
56
|
+
*/
|
|
57
|
+
modelRequirements: ImageGenerationModelRequirements;
|
|
58
|
+
};
|
|
47
59
|
/**
|
|
48
60
|
* Embedding prompt
|
|
49
61
|
*
|
|
@@ -15,7 +15,7 @@ export declare const BOOK_LANGUAGE_VERSION: string_semantic_version;
|
|
|
15
15
|
export declare const PROMPTBOOK_ENGINE_VERSION: string_promptbook_version;
|
|
16
16
|
/**
|
|
17
17
|
* Represents the version string of the Promptbook engine.
|
|
18
|
-
* It follows semantic versioning (e.g., `0.103.0-
|
|
18
|
+
* It follows semantic versioning (e.g., `0.103.0-67`).
|
|
19
19
|
*
|
|
20
20
|
* @generated
|
|
21
21
|
*/
|
package/package.json
CHANGED
package/umd/index.umd.js
CHANGED
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
* @generated
|
|
57
57
|
* @see https://github.com/webgptorg/promptbook
|
|
58
58
|
*/
|
|
59
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.103.0-
|
|
59
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.103.0-68';
|
|
60
60
|
/**
|
|
61
61
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
62
62
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -10945,7 +10945,7 @@
|
|
|
10945
10945
|
* @see {@link ModelVariant}
|
|
10946
10946
|
* @public exported from `@promptbook/core`
|
|
10947
10947
|
*/
|
|
10948
|
-
const MODEL_VARIANTS = ['COMPLETION', 'CHAT', 'EMBEDDING' /* <- TODO [🏳] */ /* <- [🤖] */];
|
|
10948
|
+
const MODEL_VARIANTS = ['COMPLETION', 'CHAT', 'IMAGE_GENERATION', 'EMBEDDING' /* <- TODO [🏳] */ /* <- [🤖] */];
|
|
10949
10949
|
|
|
10950
10950
|
/**
|
|
10951
10951
|
* Parses the model command
|
|
@@ -17584,12 +17584,18 @@
|
|
|
17584
17584
|
},
|
|
17585
17585
|
},
|
|
17586
17586
|
/**/
|
|
17587
|
-
|
|
17588
|
-
|
|
17589
|
-
|
|
17590
|
-
|
|
17591
|
-
|
|
17592
|
-
|
|
17587
|
+
/**/
|
|
17588
|
+
{
|
|
17589
|
+
modelVariant: 'IMAGE_GENERATION',
|
|
17590
|
+
modelTitle: 'dall-e-3',
|
|
17591
|
+
modelName: 'dall-e-3',
|
|
17592
|
+
modelDescription: 'DALL·E 3 is the latest version of the DALL·E art generation model. It understands significantly more nuance and detail than our previous systems, allowing you to easily translate your ideas into exceptionally accurate images.',
|
|
17593
|
+
pricing: {
|
|
17594
|
+
prompt: 0,
|
|
17595
|
+
output: 0.04,
|
|
17596
|
+
},
|
|
17597
|
+
},
|
|
17598
|
+
/**/
|
|
17593
17599
|
/*/
|
|
17594
17600
|
{
|
|
17595
17601
|
modelTitle: 'whisper-1',
|
|
@@ -17608,12 +17614,18 @@
|
|
|
17608
17614
|
},
|
|
17609
17615
|
},
|
|
17610
17616
|
/**/
|
|
17611
|
-
|
|
17612
|
-
|
|
17613
|
-
|
|
17614
|
-
|
|
17615
|
-
|
|
17616
|
-
|
|
17617
|
+
/**/
|
|
17618
|
+
{
|
|
17619
|
+
modelVariant: 'IMAGE_GENERATION',
|
|
17620
|
+
modelTitle: 'dall-e-2',
|
|
17621
|
+
modelName: 'dall-e-2',
|
|
17622
|
+
modelDescription: 'DALL·E 2 is an AI system that can create realistic images and art from a description in natural language.',
|
|
17623
|
+
pricing: {
|
|
17624
|
+
prompt: 0,
|
|
17625
|
+
output: 0.02,
|
|
17626
|
+
},
|
|
17627
|
+
},
|
|
17628
|
+
/**/
|
|
17617
17629
|
/**/
|
|
17618
17630
|
{
|
|
17619
17631
|
modelVariant: 'CHAT',
|
|
@@ -19828,6 +19840,151 @@
|
|
|
19828
19840
|
return this.callEmbeddingModelWithRetry(prompt, modifiedModelRequirements, attemptStack, retriedUnsupportedParameters);
|
|
19829
19841
|
}
|
|
19830
19842
|
}
|
|
19843
|
+
/**
|
|
19844
|
+
* Calls OpenAI compatible API to use a image generation model
|
|
19845
|
+
*/
|
|
19846
|
+
async callImageGenerationModel(prompt) {
|
|
19847
|
+
// Deep clone prompt and modelRequirements to avoid mutation across calls
|
|
19848
|
+
const clonedPrompt = JSON.parse(JSON.stringify(prompt));
|
|
19849
|
+
const retriedUnsupportedParameters = new Set();
|
|
19850
|
+
return this.callImageGenerationModelWithRetry(clonedPrompt, clonedPrompt.modelRequirements, [], retriedUnsupportedParameters);
|
|
19851
|
+
}
|
|
19852
|
+
/**
|
|
19853
|
+
* Internal method that handles parameter retry for image generation model calls
|
|
19854
|
+
*/
|
|
19855
|
+
async callImageGenerationModelWithRetry(prompt, currentModelRequirements, attemptStack = [], retriedUnsupportedParameters = new Set()) {
|
|
19856
|
+
var _a, _b;
|
|
19857
|
+
if (this.options.isVerbose) {
|
|
19858
|
+
console.info(`🎨 ${this.title} callImageGenerationModel call`, { prompt, currentModelRequirements });
|
|
19859
|
+
}
|
|
19860
|
+
const { content, parameters } = prompt;
|
|
19861
|
+
const client = await this.getClient();
|
|
19862
|
+
// TODO: [☂] Use here more modelRequirements
|
|
19863
|
+
if (currentModelRequirements.modelVariant !== 'IMAGE_GENERATION') {
|
|
19864
|
+
throw new PipelineExecutionError('Use callImageGenerationModel only for IMAGE_GENERATION variant');
|
|
19865
|
+
}
|
|
19866
|
+
const modelName = currentModelRequirements.modelName || this.getDefaultImageGenerationModel().modelName;
|
|
19867
|
+
const modelSettings = {
|
|
19868
|
+
model: modelName,
|
|
19869
|
+
// size: currentModelRequirements.size,
|
|
19870
|
+
// quality: currentModelRequirements.quality,
|
|
19871
|
+
// style: currentModelRequirements.style,
|
|
19872
|
+
};
|
|
19873
|
+
const rawPromptContent = templateParameters(content, { ...parameters, modelName });
|
|
19874
|
+
const rawRequest = {
|
|
19875
|
+
...modelSettings,
|
|
19876
|
+
prompt: rawPromptContent,
|
|
19877
|
+
user: (_a = this.options.userId) === null || _a === void 0 ? void 0 : _a.toString(),
|
|
19878
|
+
response_format: 'url', // TODO: [🧠] Maybe allow b64_json
|
|
19879
|
+
};
|
|
19880
|
+
const start = $getCurrentDate();
|
|
19881
|
+
if (this.options.isVerbose) {
|
|
19882
|
+
console.info(colors__default["default"].bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
|
|
19883
|
+
}
|
|
19884
|
+
try {
|
|
19885
|
+
const rawResponse = await this.limiter
|
|
19886
|
+
.schedule(() => this.makeRequestWithNetworkRetry(() => client.images.generate(rawRequest)))
|
|
19887
|
+
.catch((error) => {
|
|
19888
|
+
assertsError(error);
|
|
19889
|
+
if (this.options.isVerbose) {
|
|
19890
|
+
console.info(colors__default["default"].bgRed('error'), error);
|
|
19891
|
+
}
|
|
19892
|
+
throw error;
|
|
19893
|
+
});
|
|
19894
|
+
if (this.options.isVerbose) {
|
|
19895
|
+
console.info(colors__default["default"].bgWhite('rawResponse'), JSON.stringify(rawResponse, null, 4));
|
|
19896
|
+
}
|
|
19897
|
+
const complete = $getCurrentDate();
|
|
19898
|
+
if (!rawResponse.data[0]) {
|
|
19899
|
+
throw new PipelineExecutionError(`No choises from ${this.title}`);
|
|
19900
|
+
}
|
|
19901
|
+
if (rawResponse.data.length > 1) {
|
|
19902
|
+
throw new PipelineExecutionError(`More than one choise from ${this.title}`);
|
|
19903
|
+
}
|
|
19904
|
+
const resultContent = rawResponse.data[0].url;
|
|
19905
|
+
const modelInfo = this.HARDCODED_MODELS.find((model) => model.modelName === modelName);
|
|
19906
|
+
const price = ((_b = modelInfo === null || modelInfo === void 0 ? void 0 : modelInfo.pricing) === null || _b === void 0 ? void 0 : _b.output) ? uncertainNumber(modelInfo.pricing.output) : uncertainNumber();
|
|
19907
|
+
return exportJson({
|
|
19908
|
+
name: 'promptResult',
|
|
19909
|
+
message: `Result of \`OpenAiCompatibleExecutionTools.callImageGenerationModel\``,
|
|
19910
|
+
order: [],
|
|
19911
|
+
value: {
|
|
19912
|
+
content: resultContent,
|
|
19913
|
+
modelName: modelName,
|
|
19914
|
+
timing: {
|
|
19915
|
+
start,
|
|
19916
|
+
complete,
|
|
19917
|
+
},
|
|
19918
|
+
usage: {
|
|
19919
|
+
price,
|
|
19920
|
+
input: {
|
|
19921
|
+
tokensCount: uncertainNumber(0),
|
|
19922
|
+
...computeUsageCounts(rawPromptContent),
|
|
19923
|
+
},
|
|
19924
|
+
output: {
|
|
19925
|
+
tokensCount: uncertainNumber(0),
|
|
19926
|
+
...computeUsageCounts(''),
|
|
19927
|
+
},
|
|
19928
|
+
},
|
|
19929
|
+
rawPromptContent,
|
|
19930
|
+
rawRequest,
|
|
19931
|
+
rawResponse,
|
|
19932
|
+
},
|
|
19933
|
+
});
|
|
19934
|
+
}
|
|
19935
|
+
catch (error) {
|
|
19936
|
+
assertsError(error);
|
|
19937
|
+
if (!isUnsupportedParameterError(error)) {
|
|
19938
|
+
if (attemptStack.length > 0) {
|
|
19939
|
+
throw new PipelineExecutionError(`All attempts failed. Attempt history:\n` +
|
|
19940
|
+
attemptStack
|
|
19941
|
+
.map((a, i) => ` ${i + 1}. Model: ${a.modelName}` +
|
|
19942
|
+
(a.unsupportedParameter ? `, Stripped: ${a.unsupportedParameter}` : '') +
|
|
19943
|
+
`, Error: ${a.errorMessage}` +
|
|
19944
|
+
(a.stripped ? ' (stripped and retried)' : ''))
|
|
19945
|
+
.join('\n') +
|
|
19946
|
+
`\nFinal error: ${error.message}`);
|
|
19947
|
+
}
|
|
19948
|
+
throw error;
|
|
19949
|
+
}
|
|
19950
|
+
const unsupportedParameter = parseUnsupportedParameterError(error.message);
|
|
19951
|
+
if (!unsupportedParameter) {
|
|
19952
|
+
if (this.options.isVerbose) {
|
|
19953
|
+
console.warn(colors__default["default"].bgYellow('Warning'), 'Could not parse unsupported parameter from error:', error.message);
|
|
19954
|
+
}
|
|
19955
|
+
throw error;
|
|
19956
|
+
}
|
|
19957
|
+
const retryKey = `${modelName}-${unsupportedParameter}`;
|
|
19958
|
+
if (retriedUnsupportedParameters.has(retryKey)) {
|
|
19959
|
+
attemptStack.push({
|
|
19960
|
+
modelName,
|
|
19961
|
+
unsupportedParameter,
|
|
19962
|
+
errorMessage: error.message,
|
|
19963
|
+
stripped: true,
|
|
19964
|
+
});
|
|
19965
|
+
throw new PipelineExecutionError(`All attempts failed. Attempt history:\n` +
|
|
19966
|
+
attemptStack
|
|
19967
|
+
.map((a, i) => ` ${i + 1}. Model: ${a.modelName}` +
|
|
19968
|
+
(a.unsupportedParameter ? `, Stripped: ${a.unsupportedParameter}` : '') +
|
|
19969
|
+
`, Error: ${a.errorMessage}` +
|
|
19970
|
+
(a.stripped ? ' (stripped and retried)' : ''))
|
|
19971
|
+
.join('\n') +
|
|
19972
|
+
`\nFinal error: ${error.message}`);
|
|
19973
|
+
}
|
|
19974
|
+
retriedUnsupportedParameters.add(retryKey);
|
|
19975
|
+
if (this.options.isVerbose) {
|
|
19976
|
+
console.warn(colors__default["default"].bgYellow('Warning'), `Removing unsupported parameter '${unsupportedParameter}' for model '${modelName}' and retrying request`);
|
|
19977
|
+
}
|
|
19978
|
+
attemptStack.push({
|
|
19979
|
+
modelName,
|
|
19980
|
+
unsupportedParameter,
|
|
19981
|
+
errorMessage: error.message,
|
|
19982
|
+
stripped: true,
|
|
19983
|
+
});
|
|
19984
|
+
const modifiedModelRequirements = removeUnsupportedModelRequirement(currentModelRequirements, unsupportedParameter);
|
|
19985
|
+
return this.callImageGenerationModelWithRetry(prompt, modifiedModelRequirements, attemptStack, retriedUnsupportedParameters);
|
|
19986
|
+
}
|
|
19987
|
+
}
|
|
19831
19988
|
// <- Note: [🤖] callXxxModel
|
|
19832
19989
|
/**
|
|
19833
19990
|
* Get the model that should be used as default
|
|
@@ -20251,6 +20408,13 @@
|
|
|
20251
20408
|
return this.getDefaultModel('text-embedding-3-large'); // <- TODO: [🧠] Pick the best default model
|
|
20252
20409
|
// <- TODO: [🛄]
|
|
20253
20410
|
}
|
|
20411
|
+
/**
|
|
20412
|
+
* Default model for image generation variant.
|
|
20413
|
+
*/
|
|
20414
|
+
getDefaultImageGenerationModel() {
|
|
20415
|
+
return this.getDefaultModel('!!!'); // <- TODO: [🧠] Pick the best default model
|
|
20416
|
+
// <- TODO: [🛄]
|
|
20417
|
+
}
|
|
20254
20418
|
}
|
|
20255
20419
|
/**
|
|
20256
20420
|
* TODO: [🛄] Some way how to re-wrap the errors from `OpenAiCompatibleExecutionTools`
|
|
@@ -20486,6 +20650,12 @@
|
|
|
20486
20650
|
getDefaultEmbeddingModel() {
|
|
20487
20651
|
return this.getDefaultModel('text-embedding-3-large');
|
|
20488
20652
|
}
|
|
20653
|
+
/**
|
|
20654
|
+
* Default model for image generation variant.
|
|
20655
|
+
*/
|
|
20656
|
+
getDefaultImageGenerationModel() {
|
|
20657
|
+
return this.getDefaultModel('dall-e-3');
|
|
20658
|
+
}
|
|
20489
20659
|
}
|
|
20490
20660
|
|
|
20491
20661
|
/**
|
|
@@ -21056,6 +21226,13 @@
|
|
|
21056
21226
|
getDefaultEmbeddingModel() {
|
|
21057
21227
|
throw new PipelineExecutionError(`${this.title} does not support EMBEDDING model variant`);
|
|
21058
21228
|
}
|
|
21229
|
+
/**
|
|
21230
|
+
* Default model for image generation variant.
|
|
21231
|
+
*/
|
|
21232
|
+
getDefaultImageGenerationModel() {
|
|
21233
|
+
return this.getDefaultModel('!!!'); // <- TODO: [🧠] Pick the best default model
|
|
21234
|
+
// <- TODO: [🛄]
|
|
21235
|
+
}
|
|
21059
21236
|
}
|
|
21060
21237
|
/**
|
|
21061
21238
|
* TODO: [🦺] Is there some way how to put `packageName` and `className` on top and function definition on bottom?
|