@promptbook/core 0.103.0-66 → 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 +177 -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 +177 -14
- package/umd/index.umd.js.map +1 -1
package/esm/index.es.js
CHANGED
|
@@ -27,7 +27,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
|
|
|
27
27
|
* @generated
|
|
28
28
|
* @see https://github.com/webgptorg/promptbook
|
|
29
29
|
*/
|
|
30
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.103.0-
|
|
30
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.103.0-68';
|
|
31
31
|
/**
|
|
32
32
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
33
33
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -13808,7 +13808,7 @@ const jokerCommandParser = {
|
|
|
13808
13808
|
* @see {@link ModelVariant}
|
|
13809
13809
|
* @public exported from `@promptbook/core`
|
|
13810
13810
|
*/
|
|
13811
|
-
const MODEL_VARIANTS = ['COMPLETION', 'CHAT', 'EMBEDDING' /* <- TODO [🏳] */ /* <- [🤖] */];
|
|
13811
|
+
const MODEL_VARIANTS = ['COMPLETION', 'CHAT', 'IMAGE_GENERATION', 'EMBEDDING' /* <- TODO [🏳] */ /* <- [🤖] */];
|
|
13812
13812
|
|
|
13813
13813
|
/**
|
|
13814
13814
|
* Parses the model command
|
|
@@ -17180,12 +17180,18 @@ const OPENAI_MODELS = exportJson({
|
|
|
17180
17180
|
},
|
|
17181
17181
|
},
|
|
17182
17182
|
/**/
|
|
17183
|
-
|
|
17184
|
-
|
|
17185
|
-
|
|
17186
|
-
|
|
17187
|
-
|
|
17188
|
-
|
|
17183
|
+
/**/
|
|
17184
|
+
{
|
|
17185
|
+
modelVariant: 'IMAGE_GENERATION',
|
|
17186
|
+
modelTitle: 'dall-e-3',
|
|
17187
|
+
modelName: 'dall-e-3',
|
|
17188
|
+
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.',
|
|
17189
|
+
pricing: {
|
|
17190
|
+
prompt: 0,
|
|
17191
|
+
output: 0.04,
|
|
17192
|
+
},
|
|
17193
|
+
},
|
|
17194
|
+
/**/
|
|
17189
17195
|
/*/
|
|
17190
17196
|
{
|
|
17191
17197
|
modelTitle: 'whisper-1',
|
|
@@ -17204,12 +17210,18 @@ const OPENAI_MODELS = exportJson({
|
|
|
17204
17210
|
},
|
|
17205
17211
|
},
|
|
17206
17212
|
/**/
|
|
17207
|
-
|
|
17208
|
-
|
|
17209
|
-
|
|
17210
|
-
|
|
17211
|
-
|
|
17212
|
-
|
|
17213
|
+
/**/
|
|
17214
|
+
{
|
|
17215
|
+
modelVariant: 'IMAGE_GENERATION',
|
|
17216
|
+
modelTitle: 'dall-e-2',
|
|
17217
|
+
modelName: 'dall-e-2',
|
|
17218
|
+
modelDescription: 'DALL·E 2 is an AI system that can create realistic images and art from a description in natural language.',
|
|
17219
|
+
pricing: {
|
|
17220
|
+
prompt: 0,
|
|
17221
|
+
output: 0.02,
|
|
17222
|
+
},
|
|
17223
|
+
},
|
|
17224
|
+
/**/
|
|
17213
17225
|
/**/
|
|
17214
17226
|
{
|
|
17215
17227
|
modelVariant: 'CHAT',
|
|
@@ -18243,6 +18255,151 @@ class OpenAiCompatibleExecutionTools {
|
|
|
18243
18255
|
return this.callEmbeddingModelWithRetry(prompt, modifiedModelRequirements, attemptStack, retriedUnsupportedParameters);
|
|
18244
18256
|
}
|
|
18245
18257
|
}
|
|
18258
|
+
/**
|
|
18259
|
+
* Calls OpenAI compatible API to use a image generation model
|
|
18260
|
+
*/
|
|
18261
|
+
async callImageGenerationModel(prompt) {
|
|
18262
|
+
// Deep clone prompt and modelRequirements to avoid mutation across calls
|
|
18263
|
+
const clonedPrompt = JSON.parse(JSON.stringify(prompt));
|
|
18264
|
+
const retriedUnsupportedParameters = new Set();
|
|
18265
|
+
return this.callImageGenerationModelWithRetry(clonedPrompt, clonedPrompt.modelRequirements, [], retriedUnsupportedParameters);
|
|
18266
|
+
}
|
|
18267
|
+
/**
|
|
18268
|
+
* Internal method that handles parameter retry for image generation model calls
|
|
18269
|
+
*/
|
|
18270
|
+
async callImageGenerationModelWithRetry(prompt, currentModelRequirements, attemptStack = [], retriedUnsupportedParameters = new Set()) {
|
|
18271
|
+
var _a, _b;
|
|
18272
|
+
if (this.options.isVerbose) {
|
|
18273
|
+
console.info(`🎨 ${this.title} callImageGenerationModel call`, { prompt, currentModelRequirements });
|
|
18274
|
+
}
|
|
18275
|
+
const { content, parameters } = prompt;
|
|
18276
|
+
const client = await this.getClient();
|
|
18277
|
+
// TODO: [☂] Use here more modelRequirements
|
|
18278
|
+
if (currentModelRequirements.modelVariant !== 'IMAGE_GENERATION') {
|
|
18279
|
+
throw new PipelineExecutionError('Use callImageGenerationModel only for IMAGE_GENERATION variant');
|
|
18280
|
+
}
|
|
18281
|
+
const modelName = currentModelRequirements.modelName || this.getDefaultImageGenerationModel().modelName;
|
|
18282
|
+
const modelSettings = {
|
|
18283
|
+
model: modelName,
|
|
18284
|
+
// size: currentModelRequirements.size,
|
|
18285
|
+
// quality: currentModelRequirements.quality,
|
|
18286
|
+
// style: currentModelRequirements.style,
|
|
18287
|
+
};
|
|
18288
|
+
const rawPromptContent = templateParameters(content, { ...parameters, modelName });
|
|
18289
|
+
const rawRequest = {
|
|
18290
|
+
...modelSettings,
|
|
18291
|
+
prompt: rawPromptContent,
|
|
18292
|
+
user: (_a = this.options.userId) === null || _a === void 0 ? void 0 : _a.toString(),
|
|
18293
|
+
response_format: 'url', // TODO: [🧠] Maybe allow b64_json
|
|
18294
|
+
};
|
|
18295
|
+
const start = $getCurrentDate();
|
|
18296
|
+
if (this.options.isVerbose) {
|
|
18297
|
+
console.info(colors.bgWhite('rawRequest'), JSON.stringify(rawRequest, null, 4));
|
|
18298
|
+
}
|
|
18299
|
+
try {
|
|
18300
|
+
const rawResponse = await this.limiter
|
|
18301
|
+
.schedule(() => this.makeRequestWithNetworkRetry(() => client.images.generate(rawRequest)))
|
|
18302
|
+
.catch((error) => {
|
|
18303
|
+
assertsError(error);
|
|
18304
|
+
if (this.options.isVerbose) {
|
|
18305
|
+
console.info(colors.bgRed('error'), error);
|
|
18306
|
+
}
|
|
18307
|
+
throw error;
|
|
18308
|
+
});
|
|
18309
|
+
if (this.options.isVerbose) {
|
|
18310
|
+
console.info(colors.bgWhite('rawResponse'), JSON.stringify(rawResponse, null, 4));
|
|
18311
|
+
}
|
|
18312
|
+
const complete = $getCurrentDate();
|
|
18313
|
+
if (!rawResponse.data[0]) {
|
|
18314
|
+
throw new PipelineExecutionError(`No choises from ${this.title}`);
|
|
18315
|
+
}
|
|
18316
|
+
if (rawResponse.data.length > 1) {
|
|
18317
|
+
throw new PipelineExecutionError(`More than one choise from ${this.title}`);
|
|
18318
|
+
}
|
|
18319
|
+
const resultContent = rawResponse.data[0].url;
|
|
18320
|
+
const modelInfo = this.HARDCODED_MODELS.find((model) => model.modelName === modelName);
|
|
18321
|
+
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();
|
|
18322
|
+
return exportJson({
|
|
18323
|
+
name: 'promptResult',
|
|
18324
|
+
message: `Result of \`OpenAiCompatibleExecutionTools.callImageGenerationModel\``,
|
|
18325
|
+
order: [],
|
|
18326
|
+
value: {
|
|
18327
|
+
content: resultContent,
|
|
18328
|
+
modelName: modelName,
|
|
18329
|
+
timing: {
|
|
18330
|
+
start,
|
|
18331
|
+
complete,
|
|
18332
|
+
},
|
|
18333
|
+
usage: {
|
|
18334
|
+
price,
|
|
18335
|
+
input: {
|
|
18336
|
+
tokensCount: uncertainNumber(0),
|
|
18337
|
+
...computeUsageCounts(rawPromptContent),
|
|
18338
|
+
},
|
|
18339
|
+
output: {
|
|
18340
|
+
tokensCount: uncertainNumber(0),
|
|
18341
|
+
...computeUsageCounts(''),
|
|
18342
|
+
},
|
|
18343
|
+
},
|
|
18344
|
+
rawPromptContent,
|
|
18345
|
+
rawRequest,
|
|
18346
|
+
rawResponse,
|
|
18347
|
+
},
|
|
18348
|
+
});
|
|
18349
|
+
}
|
|
18350
|
+
catch (error) {
|
|
18351
|
+
assertsError(error);
|
|
18352
|
+
if (!isUnsupportedParameterError(error)) {
|
|
18353
|
+
if (attemptStack.length > 0) {
|
|
18354
|
+
throw new PipelineExecutionError(`All attempts failed. Attempt history:\n` +
|
|
18355
|
+
attemptStack
|
|
18356
|
+
.map((a, i) => ` ${i + 1}. Model: ${a.modelName}` +
|
|
18357
|
+
(a.unsupportedParameter ? `, Stripped: ${a.unsupportedParameter}` : '') +
|
|
18358
|
+
`, Error: ${a.errorMessage}` +
|
|
18359
|
+
(a.stripped ? ' (stripped and retried)' : ''))
|
|
18360
|
+
.join('\n') +
|
|
18361
|
+
`\nFinal error: ${error.message}`);
|
|
18362
|
+
}
|
|
18363
|
+
throw error;
|
|
18364
|
+
}
|
|
18365
|
+
const unsupportedParameter = parseUnsupportedParameterError(error.message);
|
|
18366
|
+
if (!unsupportedParameter) {
|
|
18367
|
+
if (this.options.isVerbose) {
|
|
18368
|
+
console.warn(colors.bgYellow('Warning'), 'Could not parse unsupported parameter from error:', error.message);
|
|
18369
|
+
}
|
|
18370
|
+
throw error;
|
|
18371
|
+
}
|
|
18372
|
+
const retryKey = `${modelName}-${unsupportedParameter}`;
|
|
18373
|
+
if (retriedUnsupportedParameters.has(retryKey)) {
|
|
18374
|
+
attemptStack.push({
|
|
18375
|
+
modelName,
|
|
18376
|
+
unsupportedParameter,
|
|
18377
|
+
errorMessage: error.message,
|
|
18378
|
+
stripped: true,
|
|
18379
|
+
});
|
|
18380
|
+
throw new PipelineExecutionError(`All attempts failed. Attempt history:\n` +
|
|
18381
|
+
attemptStack
|
|
18382
|
+
.map((a, i) => ` ${i + 1}. Model: ${a.modelName}` +
|
|
18383
|
+
(a.unsupportedParameter ? `, Stripped: ${a.unsupportedParameter}` : '') +
|
|
18384
|
+
`, Error: ${a.errorMessage}` +
|
|
18385
|
+
(a.stripped ? ' (stripped and retried)' : ''))
|
|
18386
|
+
.join('\n') +
|
|
18387
|
+
`\nFinal error: ${error.message}`);
|
|
18388
|
+
}
|
|
18389
|
+
retriedUnsupportedParameters.add(retryKey);
|
|
18390
|
+
if (this.options.isVerbose) {
|
|
18391
|
+
console.warn(colors.bgYellow('Warning'), `Removing unsupported parameter '${unsupportedParameter}' for model '${modelName}' and retrying request`);
|
|
18392
|
+
}
|
|
18393
|
+
attemptStack.push({
|
|
18394
|
+
modelName,
|
|
18395
|
+
unsupportedParameter,
|
|
18396
|
+
errorMessage: error.message,
|
|
18397
|
+
stripped: true,
|
|
18398
|
+
});
|
|
18399
|
+
const modifiedModelRequirements = removeUnsupportedModelRequirement(currentModelRequirements, unsupportedParameter);
|
|
18400
|
+
return this.callImageGenerationModelWithRetry(prompt, modifiedModelRequirements, attemptStack, retriedUnsupportedParameters);
|
|
18401
|
+
}
|
|
18402
|
+
}
|
|
18246
18403
|
// <- Note: [🤖] callXxxModel
|
|
18247
18404
|
/**
|
|
18248
18405
|
* Get the model that should be used as default
|
|
@@ -18412,6 +18569,12 @@ class OpenAiExecutionTools extends OpenAiCompatibleExecutionTools {
|
|
|
18412
18569
|
getDefaultEmbeddingModel() {
|
|
18413
18570
|
return this.getDefaultModel('text-embedding-3-large');
|
|
18414
18571
|
}
|
|
18572
|
+
/**
|
|
18573
|
+
* Default model for image generation variant.
|
|
18574
|
+
*/
|
|
18575
|
+
getDefaultImageGenerationModel() {
|
|
18576
|
+
return this.getDefaultModel('dall-e-3');
|
|
18577
|
+
}
|
|
18415
18578
|
}
|
|
18416
18579
|
|
|
18417
18580
|
/**
|