@promptbook/components 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/esm/index.es.js +248 -33
- 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 +248 -32
- package/umd/index.umd.js.map +1 -1
package/umd/index.umd.js
CHANGED
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
* @generated
|
|
32
32
|
* @see https://github.com/webgptorg/promptbook
|
|
33
33
|
*/
|
|
34
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.103.0-
|
|
34
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.103.0-68';
|
|
35
35
|
/**
|
|
36
36
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
37
37
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -7780,6 +7780,24 @@
|
|
|
7780
7780
|
return (jsxRuntime.jsx("svg", { xmlns: "http://www.w3.org/2000/svg", width: size || 24, height: size || 24, viewBox: "0 0 24 24", fill: "currentColor", ...rest, children: jsxRuntime.jsx("path", { d: "M11 7h2v2h-2zm0 4h2v6h-2zm1-9C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8z" }) }));
|
|
7781
7781
|
}
|
|
7782
7782
|
|
|
7783
|
+
/**
|
|
7784
|
+
* @@@
|
|
7785
|
+
*
|
|
7786
|
+
* @public exported from `@promptbook/components`
|
|
7787
|
+
*/
|
|
7788
|
+
function AttachmentIcon({ size = 24, color = 'currentColor' }) {
|
|
7789
|
+
return (jsxRuntime.jsx("svg", { width: size, height: size, viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: jsxRuntime.jsx("path", { d: "M21.44 11.05l-9.19 9.19a6 6 0 01-8.49-8.49l9.19-9.19a4 4 0 015.66 5.66L9.64 16.2a2 2 0 01-2.83-2.83l8.49-8.49", stroke: color, strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }) }));
|
|
7790
|
+
}
|
|
7791
|
+
|
|
7792
|
+
/**
|
|
7793
|
+
* @@@
|
|
7794
|
+
*
|
|
7795
|
+
* @public exported from `@promptbook/components`
|
|
7796
|
+
*/
|
|
7797
|
+
function CameraIcon({ size = 24, color = 'currentColor' }) {
|
|
7798
|
+
return (jsxRuntime.jsxs("svg", { width: size, height: size, viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [jsxRuntime.jsx("path", { d: "M23 19C23 19.5304 22.7893 20.0391 22.4142 20.4142C22.0391 20.7893 21.5304 21 21 21H3C2.46957 21 1.96086 20.7893 1.58579 20.4142C1.21071 20.0391 1 19.5304 1 19V8C1 7.46957 1.21071 6.96086 1.58579 6.58579C1.96086 6.21071 2.46957 6 3 6H7L9 3H15L17 6H21C21.5304 6 22.0391 6.21071 22.4142 6.58579C22.7893 6.96086 23 7.46957 23 8V19Z", stroke: color, strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }), jsxRuntime.jsx("path", { d: "M12 17C14.2091 17 16 15.2091 16 13C16 10.7909 14.2091 9 12 9C9.79086 9 8 10.7909 8 13C8 15.2091 9.79086 17 12 17Z", stroke: color, strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" })] }));
|
|
7799
|
+
}
|
|
7800
|
+
|
|
7783
7801
|
/**
|
|
7784
7802
|
* @@@
|
|
7785
7803
|
*
|
|
@@ -7905,13 +7923,27 @@
|
|
|
7905
7923
|
* @private Internal component used by `BookEditor`
|
|
7906
7924
|
*/
|
|
7907
7925
|
function BookEditorActionbar(props) {
|
|
7908
|
-
const { value, isDownloadButtonShown, isAboutButtonShown, isFullscreenButtonShown, onFullscreenClick, isFullscreen, } = props;
|
|
7926
|
+
const { value, isDownloadButtonShown, isUploadButtonShown, isCameraButtonShown, isAboutButtonShown, isFullscreenButtonShown, onFullscreenClick, onUploadDocument, onTakePhoto, isFullscreen, } = props;
|
|
7909
7927
|
const [isAboutModalOpen, setIsAboutModalOpen] = react.useState(false);
|
|
7910
7928
|
const handleDownload = () => {
|
|
7911
7929
|
const book = validateBook(value || DEFAULT_BOOK);
|
|
7912
7930
|
/* not await */ $induceBookDownload(book);
|
|
7913
7931
|
};
|
|
7914
7932
|
const actions = [];
|
|
7933
|
+
if (isUploadButtonShown && onUploadDocument) {
|
|
7934
|
+
actions.push({
|
|
7935
|
+
icon: jsxRuntime.jsx(AttachmentIcon, {}),
|
|
7936
|
+
name: 'Upload document',
|
|
7937
|
+
onClick: onUploadDocument,
|
|
7938
|
+
});
|
|
7939
|
+
}
|
|
7940
|
+
if (isCameraButtonShown && onTakePhoto) {
|
|
7941
|
+
actions.push({
|
|
7942
|
+
icon: jsxRuntime.jsx(CameraIcon, {}),
|
|
7943
|
+
name: 'Take photo',
|
|
7944
|
+
onClick: onTakePhoto,
|
|
7945
|
+
});
|
|
7946
|
+
}
|
|
7915
7947
|
if (isDownloadButtonShown) {
|
|
7916
7948
|
actions.push({
|
|
7917
7949
|
icon: jsxRuntime.jsx(DownloadIcon, {}),
|
|
@@ -7953,7 +7985,7 @@
|
|
|
7953
7985
|
* @private Internal component used by `BookEditor`
|
|
7954
7986
|
*/
|
|
7955
7987
|
function BookEditorMonaco(props) {
|
|
7956
|
-
const { value, onChange, isReadonly, translations, onFileUpload, isDownloadButtonShown, isAboutButtonShown = true, isFullscreenButtonShown = true, onFullscreenClick, isFullscreen, zoom = 1,
|
|
7988
|
+
const { value, onChange, isReadonly, translations, onFileUpload, isUploadButtonShown, isCameraButtonShown, isDownloadButtonShown, isAboutButtonShown = true, isFullscreenButtonShown = true, onFullscreenClick, isFullscreen, zoom = 1,
|
|
7957
7989
|
// [🚱]> sync,
|
|
7958
7990
|
} = props;
|
|
7959
7991
|
const zoomLevel = zoom;
|
|
@@ -7973,6 +8005,8 @@
|
|
|
7973
8005
|
const instanceClass = `book-editor-instance-${instanceIdRef.current}`;
|
|
7974
8006
|
// [1] Track touch start position to differentiate tap from drag
|
|
7975
8007
|
const touchStartRef = react.useRef(null);
|
|
8008
|
+
const fileUploadInputRef = react.useRef(null);
|
|
8009
|
+
const cameraInputRef = react.useRef(null);
|
|
7976
8010
|
/*
|
|
7977
8011
|
Note+TODO: [🚱] Yjs logic is commented out because it causes errors in the build of Next.js projects:
|
|
7978
8012
|
> ▲ Next.js 15.4.5
|
|
@@ -8196,12 +8230,9 @@
|
|
|
8196
8230
|
changeListener.dispose();
|
|
8197
8231
|
};
|
|
8198
8232
|
}, [editor, monaco]);
|
|
8199
|
-
const
|
|
8200
|
-
event.preventDefault();
|
|
8201
|
-
setIsDragOver(false);
|
|
8233
|
+
const handleFiles = react.useCallback(async (files) => {
|
|
8202
8234
|
if (!onFileUpload)
|
|
8203
8235
|
return;
|
|
8204
|
-
const files = Array.from(event.dataTransfer.files);
|
|
8205
8236
|
if (files.length === 0)
|
|
8206
8237
|
return;
|
|
8207
8238
|
// [1] Inject placeholders
|
|
@@ -8241,6 +8272,28 @@
|
|
|
8241
8272
|
console.error('File upload failed:', error);
|
|
8242
8273
|
}
|
|
8243
8274
|
}, [onFileUpload, value, onChange, editor]);
|
|
8275
|
+
const handleDrop = react.useCallback(async (event) => {
|
|
8276
|
+
event.preventDefault();
|
|
8277
|
+
setIsDragOver(false);
|
|
8278
|
+
const files = Array.from(event.dataTransfer.files);
|
|
8279
|
+
await handleFiles(files);
|
|
8280
|
+
}, [handleFiles]);
|
|
8281
|
+
const handleUploadDocument = react.useCallback(() => {
|
|
8282
|
+
if (fileUploadInputRef.current) {
|
|
8283
|
+
fileUploadInputRef.current.click();
|
|
8284
|
+
}
|
|
8285
|
+
}, []);
|
|
8286
|
+
const handleTakePhoto = react.useCallback(() => {
|
|
8287
|
+
if (cameraInputRef.current) {
|
|
8288
|
+
cameraInputRef.current.click();
|
|
8289
|
+
}
|
|
8290
|
+
}, []);
|
|
8291
|
+
const handleFileInputChange = react.useCallback((event) => {
|
|
8292
|
+
const files = Array.from(event.target.files || []);
|
|
8293
|
+
handleFiles(files);
|
|
8294
|
+
// Reset the input value so the same file can be selected again
|
|
8295
|
+
event.target.value = '';
|
|
8296
|
+
}, [handleFiles]);
|
|
8244
8297
|
const handleDragOver = react.useCallback((event) => {
|
|
8245
8298
|
event.preventDefault();
|
|
8246
8299
|
setIsDragOver(true);
|
|
@@ -8253,12 +8306,20 @@
|
|
|
8253
8306
|
event.preventDefault();
|
|
8254
8307
|
setIsDragOver(false);
|
|
8255
8308
|
}, []);
|
|
8256
|
-
return (jsxRuntime.jsxs("div", { className: classNames(styles$6.bookEditorContainer, instanceClass), onDrop: handleDrop, onDragOver: handleDragOver, onDragEnter: handleDragEnter, onDragLeave: handleDragLeave, children: [(
|
|
8309
|
+
return (jsxRuntime.jsxs("div", { className: classNames(styles$6.bookEditorContainer, instanceClass), onDrop: handleDrop, onDragOver: handleDragOver, onDragEnter: handleDragEnter, onDragLeave: handleDragLeave, children: [(isUploadButtonShown ||
|
|
8310
|
+
isCameraButtonShown ||
|
|
8311
|
+
isDownloadButtonShown ||
|
|
8312
|
+
isAboutButtonShown ||
|
|
8313
|
+
isFullscreenButtonShown) && (jsxRuntime.jsx(BookEditorActionbar, { value,
|
|
8314
|
+
isUploadButtonShown,
|
|
8315
|
+
isCameraButtonShown: isCameraButtonShown !== null && isCameraButtonShown !== void 0 ? isCameraButtonShown : isTouchDevice,
|
|
8257
8316
|
isDownloadButtonShown,
|
|
8258
8317
|
isAboutButtonShown,
|
|
8259
8318
|
isFullscreenButtonShown,
|
|
8260
8319
|
onFullscreenClick,
|
|
8261
|
-
|
|
8320
|
+
onUploadDocument: handleUploadDocument,
|
|
8321
|
+
onTakePhoto: handleTakePhoto,
|
|
8322
|
+
isFullscreen })), jsxRuntime.jsx("input", { type: "file", ref: fileUploadInputRef, style: { display: 'none' }, onChange: handleFileInputChange, multiple: true }), jsxRuntime.jsx("input", { type: "file", ref: cameraInputRef, style: { display: 'none' }, accept: "image/*", capture: "environment", onChange: handleFileInputChange }), isDragOver && jsxRuntime.jsx("div", { className: styles$6.dropOverlay, children: "Drop files to upload" }), jsxRuntime.jsxs("div", { style: {
|
|
8262
8323
|
position: 'relative',
|
|
8263
8324
|
flex: 1,
|
|
8264
8325
|
height: '100%',
|
|
@@ -8340,7 +8401,7 @@
|
|
|
8340
8401
|
* @public exported from `@promptbook/components`
|
|
8341
8402
|
*/
|
|
8342
8403
|
function BookEditor(props) {
|
|
8343
|
-
const { agentSource, className, style, zoom = 1, value, onChange, onFileUpload, isVerbose = DEFAULT_IS_VERBOSE, isBorderRadiusDisabled = false, isReadonly = false, translations, isDownloadButtonShown = true, isAboutButtonShown = true, isFullscreenButtonShown = true, sync, } = props;
|
|
8404
|
+
const { agentSource, className, style, zoom = 1, value, onChange, onFileUpload, isVerbose = DEFAULT_IS_VERBOSE, isBorderRadiusDisabled = false, isReadonly = false, translations, isUploadButtonShown = true, isCameraButtonShown, isDownloadButtonShown = true, isAboutButtonShown = true, isFullscreenButtonShown = true, sync, } = props;
|
|
8344
8405
|
const [isFullscreen, setIsFullscreen] = react.useState(false);
|
|
8345
8406
|
const handleFullscreenToggle = () => {
|
|
8346
8407
|
setIsFullscreen(!isFullscreen);
|
|
@@ -8356,7 +8417,7 @@
|
|
|
8356
8417
|
? `${props.height}px`
|
|
8357
8418
|
: props.height || `${DEFAULT_BOOK_EDITOR_HEIGHT}px`,
|
|
8358
8419
|
}),
|
|
8359
|
-
}, children: jsxRuntime.jsx(BookEditorMonaco, { value: agentSource || value, onChange: onChange, onFileUpload: onFileUpload, isVerbose: isVerbose, isBorderRadiusDisabled: isBorderRadiusDisabled, isReadonly: isReadonly, translations: translations, isDownloadButtonShown: isDownloadButtonShown, isAboutButtonShown: isAboutButtonShown, isFullscreenButtonShown: isFullscreenButtonShown, onFullscreenClick: handleFullscreenToggle, isFullscreen: isFullscreen, sync: sync, zoom: zoom }) }));
|
|
8420
|
+
}, children: jsxRuntime.jsx(BookEditorMonaco, { value: agentSource || value, onChange: onChange, onFileUpload: onFileUpload, isVerbose: isVerbose, isBorderRadiusDisabled: isBorderRadiusDisabled, isReadonly: isReadonly, translations: translations, isUploadButtonShown: isUploadButtonShown, isCameraButtonShown: isCameraButtonShown, isDownloadButtonShown: isDownloadButtonShown, isAboutButtonShown: isAboutButtonShown, isFullscreenButtonShown: isFullscreenButtonShown, onFullscreenClick: handleFullscreenToggle, isFullscreen: isFullscreen, sync: sync, zoom: zoom }) }));
|
|
8360
8421
|
return isFullscreen && typeof document !== 'undefined' ? reactDom.createPortal(editorContent, document.body) : editorContent;
|
|
8361
8422
|
}
|
|
8362
8423
|
|
|
@@ -8649,15 +8710,6 @@
|
|
|
8649
8710
|
*/
|
|
8650
8711
|
const ArrowIcon = ({ direction, size }) => (jsxRuntime.jsx("svg", { width: size, height: size, viewBox: "0 0 24 24", fill: "currentColor", children: jsxRuntime.jsx("path", { d: direction === 'DOWN' ? 'M7 10l5 5 5-5z' : 'M7 14l5-5 5 5z' }) }));
|
|
8651
8712
|
|
|
8652
|
-
/**
|
|
8653
|
-
* @@@
|
|
8654
|
-
*
|
|
8655
|
-
* @public exported from `@promptbook/components`
|
|
8656
|
-
*/
|
|
8657
|
-
function AttachmentIcon({ size = 24, color = 'currentColor' }) {
|
|
8658
|
-
return (jsxRuntime.jsx("svg", { width: size, height: size, viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: jsxRuntime.jsx("path", { d: "M21.44 11.05l-9.19 9.19a6 6 0 01-8.49-8.49l9.19-9.19a4 4 0 015.66 5.66L9.64 16.2a2 2 0 01-2.83-2.83l8.49-8.49", stroke: color, strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }) }));
|
|
8659
|
-
}
|
|
8660
|
-
|
|
8661
8713
|
/**
|
|
8662
8714
|
* Renders an icon that represents the close action
|
|
8663
8715
|
*
|
|
@@ -15265,12 +15317,18 @@
|
|
|
15265
15317
|
},
|
|
15266
15318
|
},
|
|
15267
15319
|
/**/
|
|
15268
|
-
|
|
15269
|
-
|
|
15270
|
-
|
|
15271
|
-
|
|
15272
|
-
|
|
15273
|
-
|
|
15320
|
+
/**/
|
|
15321
|
+
{
|
|
15322
|
+
modelVariant: 'IMAGE_GENERATION',
|
|
15323
|
+
modelTitle: 'dall-e-3',
|
|
15324
|
+
modelName: 'dall-e-3',
|
|
15325
|
+
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.',
|
|
15326
|
+
pricing: {
|
|
15327
|
+
prompt: 0,
|
|
15328
|
+
output: 0.04,
|
|
15329
|
+
},
|
|
15330
|
+
},
|
|
15331
|
+
/**/
|
|
15274
15332
|
/*/
|
|
15275
15333
|
{
|
|
15276
15334
|
modelTitle: 'whisper-1',
|
|
@@ -15289,12 +15347,18 @@
|
|
|
15289
15347
|
},
|
|
15290
15348
|
},
|
|
15291
15349
|
/**/
|
|
15292
|
-
|
|
15293
|
-
|
|
15294
|
-
|
|
15295
|
-
|
|
15296
|
-
|
|
15297
|
-
|
|
15350
|
+
/**/
|
|
15351
|
+
{
|
|
15352
|
+
modelVariant: 'IMAGE_GENERATION',
|
|
15353
|
+
modelTitle: 'dall-e-2',
|
|
15354
|
+
modelName: 'dall-e-2',
|
|
15355
|
+
modelDescription: 'DALL·E 2 is an AI system that can create realistic images and art from a description in natural language.',
|
|
15356
|
+
pricing: {
|
|
15357
|
+
prompt: 0,
|
|
15358
|
+
output: 0.02,
|
|
15359
|
+
},
|
|
15360
|
+
},
|
|
15361
|
+
/**/
|
|
15298
15362
|
/**/
|
|
15299
15363
|
{
|
|
15300
15364
|
modelVariant: 'CHAT',
|
|
@@ -16328,6 +16392,151 @@
|
|
|
16328
16392
|
return this.callEmbeddingModelWithRetry(prompt, modifiedModelRequirements, attemptStack, retriedUnsupportedParameters);
|
|
16329
16393
|
}
|
|
16330
16394
|
}
|
|
16395
|
+
/**
|
|
16396
|
+
* Calls OpenAI compatible API to use a image generation model
|
|
16397
|
+
*/
|
|
16398
|
+
async callImageGenerationModel(prompt) {
|
|
16399
|
+
// Deep clone prompt and modelRequirements to avoid mutation across calls
|
|
16400
|
+
const clonedPrompt = JSON.parse(JSON.stringify(prompt));
|
|
16401
|
+
const retriedUnsupportedParameters = new Set();
|
|
16402
|
+
return this.callImageGenerationModelWithRetry(clonedPrompt, clonedPrompt.modelRequirements, [], retriedUnsupportedParameters);
|
|
16403
|
+
}
|
|
16404
|
+
/**
|
|
16405
|
+
* Internal method that handles parameter retry for image generation model calls
|
|
16406
|
+
*/
|
|
16407
|
+
async callImageGenerationModelWithRetry(prompt, currentModelRequirements, attemptStack = [], retriedUnsupportedParameters = new Set()) {
|
|
16408
|
+
var _a, _b;
|
|
16409
|
+
if (this.options.isVerbose) {
|
|
16410
|
+
console.info(`🎨 ${this.title} callImageGenerationModel call`, { prompt, currentModelRequirements });
|
|
16411
|
+
}
|
|
16412
|
+
const { content, parameters } = prompt;
|
|
16413
|
+
const client = await this.getClient();
|
|
16414
|
+
// TODO: [☂] Use here more modelRequirements
|
|
16415
|
+
if (currentModelRequirements.modelVariant !== 'IMAGE_GENERATION') {
|
|
16416
|
+
throw new PipelineExecutionError('Use callImageGenerationModel only for IMAGE_GENERATION variant');
|
|
16417
|
+
}
|
|
16418
|
+
const modelName = currentModelRequirements.modelName || this.getDefaultImageGenerationModel().modelName;
|
|
16419
|
+
const modelSettings = {
|
|
16420
|
+
model: modelName,
|
|
16421
|
+
// size: currentModelRequirements.size,
|
|
16422
|
+
// quality: currentModelRequirements.quality,
|
|
16423
|
+
// style: currentModelRequirements.style,
|
|
16424
|
+
};
|
|
16425
|
+
const rawPromptContent = templateParameters(content, { ...parameters, modelName });
|
|
16426
|
+
const rawRequest = {
|
|
16427
|
+
...modelSettings,
|
|
16428
|
+
prompt: rawPromptContent,
|
|
16429
|
+
user: (_a = this.options.userId) === null || _a === void 0 ? void 0 : _a.toString(),
|
|
16430
|
+
response_format: 'url', // TODO: [🧠] Maybe allow b64_json
|
|
16431
|
+
};
|
|
16432
|
+
const start = $getCurrentDate();
|
|
16433
|
+
if (this.options.isVerbose) {
|
|
16434
|
+
console.info(colors__default["default"].bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
|
|
16435
|
+
}
|
|
16436
|
+
try {
|
|
16437
|
+
const rawResponse = await this.limiter
|
|
16438
|
+
.schedule(() => this.makeRequestWithNetworkRetry(() => client.images.generate(rawRequest)))
|
|
16439
|
+
.catch((error) => {
|
|
16440
|
+
assertsError(error);
|
|
16441
|
+
if (this.options.isVerbose) {
|
|
16442
|
+
console.info(colors__default["default"].bgRed('error'), error);
|
|
16443
|
+
}
|
|
16444
|
+
throw error;
|
|
16445
|
+
});
|
|
16446
|
+
if (this.options.isVerbose) {
|
|
16447
|
+
console.info(colors__default["default"].bgWhite('rawResponse'), JSON.stringify(rawResponse, null, 4));
|
|
16448
|
+
}
|
|
16449
|
+
const complete = $getCurrentDate();
|
|
16450
|
+
if (!rawResponse.data[0]) {
|
|
16451
|
+
throw new PipelineExecutionError(`No choises from ${this.title}`);
|
|
16452
|
+
}
|
|
16453
|
+
if (rawResponse.data.length > 1) {
|
|
16454
|
+
throw new PipelineExecutionError(`More than one choise from ${this.title}`);
|
|
16455
|
+
}
|
|
16456
|
+
const resultContent = rawResponse.data[0].url;
|
|
16457
|
+
const modelInfo = this.HARDCODED_MODELS.find((model) => model.modelName === modelName);
|
|
16458
|
+
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();
|
|
16459
|
+
return exportJson({
|
|
16460
|
+
name: 'promptResult',
|
|
16461
|
+
message: `Result of \`OpenAiCompatibleExecutionTools.callImageGenerationModel\``,
|
|
16462
|
+
order: [],
|
|
16463
|
+
value: {
|
|
16464
|
+
content: resultContent,
|
|
16465
|
+
modelName: modelName,
|
|
16466
|
+
timing: {
|
|
16467
|
+
start,
|
|
16468
|
+
complete,
|
|
16469
|
+
},
|
|
16470
|
+
usage: {
|
|
16471
|
+
price,
|
|
16472
|
+
input: {
|
|
16473
|
+
tokensCount: uncertainNumber(0),
|
|
16474
|
+
...computeUsageCounts(rawPromptContent),
|
|
16475
|
+
},
|
|
16476
|
+
output: {
|
|
16477
|
+
tokensCount: uncertainNumber(0),
|
|
16478
|
+
...computeUsageCounts(''),
|
|
16479
|
+
},
|
|
16480
|
+
},
|
|
16481
|
+
rawPromptContent,
|
|
16482
|
+
rawRequest,
|
|
16483
|
+
rawResponse,
|
|
16484
|
+
},
|
|
16485
|
+
});
|
|
16486
|
+
}
|
|
16487
|
+
catch (error) {
|
|
16488
|
+
assertsError(error);
|
|
16489
|
+
if (!isUnsupportedParameterError(error)) {
|
|
16490
|
+
if (attemptStack.length > 0) {
|
|
16491
|
+
throw new PipelineExecutionError(`All attempts failed. Attempt history:\n` +
|
|
16492
|
+
attemptStack
|
|
16493
|
+
.map((a, i) => ` ${i + 1}. Model: ${a.modelName}` +
|
|
16494
|
+
(a.unsupportedParameter ? `, Stripped: ${a.unsupportedParameter}` : '') +
|
|
16495
|
+
`, Error: ${a.errorMessage}` +
|
|
16496
|
+
(a.stripped ? ' (stripped and retried)' : ''))
|
|
16497
|
+
.join('\n') +
|
|
16498
|
+
`\nFinal error: ${error.message}`);
|
|
16499
|
+
}
|
|
16500
|
+
throw error;
|
|
16501
|
+
}
|
|
16502
|
+
const unsupportedParameter = parseUnsupportedParameterError(error.message);
|
|
16503
|
+
if (!unsupportedParameter) {
|
|
16504
|
+
if (this.options.isVerbose) {
|
|
16505
|
+
console.warn(colors__default["default"].bgYellow('Warning'), 'Could not parse unsupported parameter from error:', error.message);
|
|
16506
|
+
}
|
|
16507
|
+
throw error;
|
|
16508
|
+
}
|
|
16509
|
+
const retryKey = `${modelName}-${unsupportedParameter}`;
|
|
16510
|
+
if (retriedUnsupportedParameters.has(retryKey)) {
|
|
16511
|
+
attemptStack.push({
|
|
16512
|
+
modelName,
|
|
16513
|
+
unsupportedParameter,
|
|
16514
|
+
errorMessage: error.message,
|
|
16515
|
+
stripped: true,
|
|
16516
|
+
});
|
|
16517
|
+
throw new PipelineExecutionError(`All attempts failed. Attempt history:\n` +
|
|
16518
|
+
attemptStack
|
|
16519
|
+
.map((a, i) => ` ${i + 1}. Model: ${a.modelName}` +
|
|
16520
|
+
(a.unsupportedParameter ? `, Stripped: ${a.unsupportedParameter}` : '') +
|
|
16521
|
+
`, Error: ${a.errorMessage}` +
|
|
16522
|
+
(a.stripped ? ' (stripped and retried)' : ''))
|
|
16523
|
+
.join('\n') +
|
|
16524
|
+
`\nFinal error: ${error.message}`);
|
|
16525
|
+
}
|
|
16526
|
+
retriedUnsupportedParameters.add(retryKey);
|
|
16527
|
+
if (this.options.isVerbose) {
|
|
16528
|
+
console.warn(colors__default["default"].bgYellow('Warning'), `Removing unsupported parameter '${unsupportedParameter}' for model '${modelName}' and retrying request`);
|
|
16529
|
+
}
|
|
16530
|
+
attemptStack.push({
|
|
16531
|
+
modelName,
|
|
16532
|
+
unsupportedParameter,
|
|
16533
|
+
errorMessage: error.message,
|
|
16534
|
+
stripped: true,
|
|
16535
|
+
});
|
|
16536
|
+
const modifiedModelRequirements = removeUnsupportedModelRequirement(currentModelRequirements, unsupportedParameter);
|
|
16537
|
+
return this.callImageGenerationModelWithRetry(prompt, modifiedModelRequirements, attemptStack, retriedUnsupportedParameters);
|
|
16538
|
+
}
|
|
16539
|
+
}
|
|
16331
16540
|
// <- Note: [🤖] callXxxModel
|
|
16332
16541
|
/**
|
|
16333
16542
|
* Get the model that should be used as default
|
|
@@ -16497,6 +16706,12 @@
|
|
|
16497
16706
|
getDefaultEmbeddingModel() {
|
|
16498
16707
|
return this.getDefaultModel('text-embedding-3-large');
|
|
16499
16708
|
}
|
|
16709
|
+
/**
|
|
16710
|
+
* Default model for image generation variant.
|
|
16711
|
+
*/
|
|
16712
|
+
getDefaultImageGenerationModel() {
|
|
16713
|
+
return this.getDefaultModel('dall-e-3');
|
|
16714
|
+
}
|
|
16500
16715
|
}
|
|
16501
16716
|
|
|
16502
16717
|
/**
|
|
@@ -17915,6 +18130,7 @@
|
|
|
17915
18130
|
exports.BookEditor = BookEditor;
|
|
17916
18131
|
exports.BrandedQrCode = BrandedQrCode;
|
|
17917
18132
|
exports.CHAT_SAVE_FORMATS = CHAT_SAVE_FORMATS;
|
|
18133
|
+
exports.CameraIcon = CameraIcon;
|
|
17918
18134
|
exports.Chat = Chat;
|
|
17919
18135
|
exports.DEFAULT_BOOK_EDITOR_HEIGHT = DEFAULT_BOOK_EDITOR_HEIGHT;
|
|
17920
18136
|
exports.FAST_FLOW = FAST_FLOW;
|