@picsart/ai-sdk 7.34.0 → 7.35.0
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/README.md +25 -0
- package/index.d.ts +40 -1
- package/index.js +22 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -205,6 +205,31 @@ uploads remain ordinary uploads: without generation context the SDK cannot infer
|
|
|
205
205
|
model, prompt or settings. Existing Drive files are not backfilled. The backend preserves SDK-supplied metadata; it cannot reconstruct SDK input
|
|
206
206
|
names or catalog model IDs from an arbitrary vendor request.
|
|
207
207
|
|
|
208
|
+
## Input Normalization
|
|
209
|
+
|
|
210
|
+
Some vendors reject an input that is out of their limits — an image too small,
|
|
211
|
+
a reference video too large or above 60 fps, audio that is not MP3 / WAV.
|
|
212
|
+
`inputsNormalization` asks the platform to bring such an input within the
|
|
213
|
+
limits and retry, instead of failing. It is set per generation, on
|
|
214
|
+
`generate()` and `submit()`; every fix is off unless you turn it on, and only
|
|
215
|
+
the fields you set are sent. The Seedance models serve it.
|
|
216
|
+
|
|
217
|
+
| Field | Fix |
|
|
218
|
+
|-------|-----|
|
|
219
|
+
| `upscaleUndersizedImages` | Scale up an image under 300 px per side or 90,000 pixels |
|
|
220
|
+
| `resizeOutOfRangeVideos` | Scale a reference video into 407,696..8,295,044 pixels / 300..6000 px per side |
|
|
221
|
+
| `reduceVideoFrameRate` | Re-encode a reference video above 60 fps at 60 fps |
|
|
222
|
+
| `transcodeUnsupportedAudio` | Transcode reference audio that is not MP3 / WAV to MP3 |
|
|
223
|
+
| `all` | Every fix above, plus `inputsTransformation.downscaleOversizedImages` unless that is set |
|
|
224
|
+
|
|
225
|
+
```typescript
|
|
226
|
+
await ai.generate(modelId, { prompt, videoUrls }, {
|
|
227
|
+
inputsNormalization: { resizeOutOfRangeVideos: true, reduceVideoFrameRate: true },
|
|
228
|
+
});
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
A fix set to `false` stays off even with `all: true`.
|
|
232
|
+
|
|
208
233
|
## Service Tier
|
|
209
234
|
|
|
210
235
|
`serviceTier` chooses how a generation is served. It is sent to the platform as
|
package/index.d.ts
CHANGED
|
@@ -1354,6 +1354,30 @@ interface PayloadInputsTransformationOptions {
|
|
|
1354
1354
|
*/
|
|
1355
1355
|
downscaleOversizedImages?: boolean;
|
|
1356
1356
|
}
|
|
1357
|
+
/**
|
|
1358
|
+
* Opt-in fixes for inputs a vendor rejects as out of its limits, sent as the
|
|
1359
|
+
* command's `inputs_normalization`: the model workflow brings the rejected
|
|
1360
|
+
* input within the limits and retries. Every fix is off unless set here, and
|
|
1361
|
+
* only the fields you set are sent. Served by the Seedance models; a model
|
|
1362
|
+
* whose workflow has no such fixes answers per its own validation.
|
|
1363
|
+
*/
|
|
1364
|
+
interface PayloadInputsNormalizationOptions {
|
|
1365
|
+
/**
|
|
1366
|
+
* Turn every fix on — `inputsTransformation.downscaleOversizedImages`
|
|
1367
|
+
* included, unless that is set explicitly. A fix set to `false` here stays off.
|
|
1368
|
+
*/
|
|
1369
|
+
all?: boolean;
|
|
1370
|
+
/** Scale up an input image under 300 px per side or 90,000 pixels (reference
|
|
1371
|
+
* images and first / last frames) to the minimum, and retry. */
|
|
1372
|
+
upscaleUndersizedImages?: boolean;
|
|
1373
|
+
/** Scale a reference video outside 407,696..8,295,044 pixels or 300..6000 px
|
|
1374
|
+
* per side into the range, keeping its aspect ratio, and retry. */
|
|
1375
|
+
resizeOutOfRangeVideos?: boolean;
|
|
1376
|
+
/** Re-encode a reference video above 60 fps at 60 fps, and retry. */
|
|
1377
|
+
reduceVideoFrameRate?: boolean;
|
|
1378
|
+
/** Transcode reference audio that is not MP3 / WAV to MP3, and retry. */
|
|
1379
|
+
transcodeUnsupportedAudio?: boolean;
|
|
1380
|
+
}
|
|
1357
1381
|
/** Polling controls for result()/subscribe() on an already-submitted job. */
|
|
1358
1382
|
interface GenerationOptions {
|
|
1359
1383
|
/** Poll interval in ms. Overrides the model's `pollOptions` and the mode default. */
|
|
@@ -1384,6 +1408,12 @@ interface GenerateOptions {
|
|
|
1384
1408
|
* `inputsTransformation`. When neither is set, oversized-image downscaling
|
|
1385
1409
|
* stays off (opt-in). */
|
|
1386
1410
|
inputsTransformation?: PayloadInputsTransformationOptions;
|
|
1411
|
+
/**
|
|
1412
|
+
* Fixes for inputs the vendor rejects as out of its limits, for this
|
|
1413
|
+
* generation only — see {@link PayloadInputsNormalizationOptions}. Applies
|
|
1414
|
+
* to `generate()` and `submit()`; unset, nothing is sent and every fix stays off.
|
|
1415
|
+
*/
|
|
1416
|
+
inputsNormalization?: PayloadInputsNormalizationOptions;
|
|
1387
1417
|
/**
|
|
1388
1418
|
* Service tier for this call — overrides the client-level `serviceTier`.
|
|
1389
1419
|
* `priority` pays the regular price to skip the limits of the user's
|
|
@@ -1502,11 +1532,20 @@ interface ModelsGenAIOptions {
|
|
|
1502
1532
|
};
|
|
1503
1533
|
service_tier?: ServiceTier;
|
|
1504
1534
|
}
|
|
1535
|
+
/** `inputs_normalization` on a {@link ModelsCommand} — the opt-in input fixes, snake_cased. */
|
|
1536
|
+
interface ModelsInputsNormalization {
|
|
1537
|
+
all?: boolean;
|
|
1538
|
+
upscale_undersized_images?: boolean;
|
|
1539
|
+
resize_out_of_range_videos?: boolean;
|
|
1540
|
+
reduce_video_frame_rate?: boolean;
|
|
1541
|
+
transcode_unsupported_audio?: boolean;
|
|
1542
|
+
}
|
|
1505
1543
|
/** The `v1/models` request body: which model, the SDK-shaped params, platform options. */
|
|
1506
1544
|
interface ModelsCommand {
|
|
1507
1545
|
model: string;
|
|
1508
1546
|
params: Record<string, unknown>;
|
|
1509
1547
|
options?: ModelsGenAIOptions;
|
|
1548
|
+
inputs_normalization?: ModelsInputsNormalization;
|
|
1510
1549
|
}
|
|
1511
1550
|
|
|
1512
1551
|
/**
|
|
@@ -1705,4 +1744,4 @@ declare const getModel: (id: string) => ModelDefinition | undefined;
|
|
|
1705
1744
|
*/
|
|
1706
1745
|
declare const findModel: (ref: string) => ModelDefinition | undefined;
|
|
1707
1746
|
|
|
1708
|
-
export { type AiClient, ApiError, type ApiErrorCode, type ApiErrorInit, type ApiResponse, type ApiRunOptions, type ApiSchemas, type ApisClient, type AppIdentity, type AppType, type AuthenticatedFetch, type AvatarOption, type BooleanDescriptor, type BooleanEntry, type CatalogDescriptor, type CatalogEntry, type CatalogItem, type CatalogModel, type CatalogModelsResponse, type CatalogPage, type CatalogPageOptions, type CatalogParam, type CatalogPreview, type CatalogProvider, type CatalogQuery, type CatalogResult, type CatalogSource, type CatalogsClient, type CatalogsOptions, type ClientConfig, type CreditRange, type CreditRangeContext, type CreditTier, type CreditUsage, DEFAULT_VISIBLE_RELEASES, type DeepLinkResult, type DriveAttributes, type DriveClient, type DriveConfig, type DriveDraftInfo, type DriveFile, type DriveFileDetails, type DriveFolder, type DriveMediaItem, type DriveSaveResult, type EntryMeta, type EnumDescriptor, type EnumEntry, type EnumOption, type FileDescriptor, type FileEntry, type FlatParamEntry, type GenerateOptions, type GenerateResult, type GenerateResultItem, type GenerateResultItemMetadata, type GenerateTextResult, type GenerationContext, type GenerationEvent, GenerationEventType, type GenerationFile, type GenerationMode, type GenerationOptions, type GenerationProgress, type GenerationProvenance, type InitModelCatalogOptions, type ListOptions, type MediaModelId, type MediaTypeFilter, Model, type ModelCatalogFilters, type ModelDefinition, type ModelDescriptor, type ModelFilter, type ModelMeta, type ModelParams, type ModelParamsAccessor, type ModelsCommand, type ModelsGenAIOptions, type ObjectDescriptor, type ObjectEntry, type OptionsAvailability, type OptionsResult, type ParamDescriptor, type ParamEntry, type ParamOption, type PayloadDriveFolderOptions, type PayloadDriveOptions, type PayloadInputsTransformationOptions, type PriceOptions, type PricingOptions, type ProviderInfo, type RangeDescriptor, type RangeEntry, type ReleaseTag, type RunResponse, type SaveParams, type SdkPayload, type SdkTransport, type SeedanceDraftTask, type ServiceTier, type TextDescriptor, type TextEntry, type ToolUsage, type TransportPollOptions, type TransportResult, type UnknownDescriptor, type UnknownEntry, type UserReaction, type ValidationResult, type VoiceOption, type WorkflowJobHandle, type WorkflowSubmitRequest, buildFilename, buildGenerationAttributes, catalog, createClient, decodeDeepLinkPayload, encodeDeepLinkPayload, expectedOutputFormat, findModel, getModel, getVoiceById, inferResourceType, isVisibleForReleases, parseGeneration, releaseOf, resolveExtension, toAvatarOption, toVoiceOption };
|
|
1747
|
+
export { type AiClient, ApiError, type ApiErrorCode, type ApiErrorInit, type ApiResponse, type ApiRunOptions, type ApiSchemas, type ApisClient, type AppIdentity, type AppType, type AuthenticatedFetch, type AvatarOption, type BooleanDescriptor, type BooleanEntry, type CatalogDescriptor, type CatalogEntry, type CatalogItem, type CatalogModel, type CatalogModelsResponse, type CatalogPage, type CatalogPageOptions, type CatalogParam, type CatalogPreview, type CatalogProvider, type CatalogQuery, type CatalogResult, type CatalogSource, type CatalogsClient, type CatalogsOptions, type ClientConfig, type CreditRange, type CreditRangeContext, type CreditTier, type CreditUsage, DEFAULT_VISIBLE_RELEASES, type DeepLinkResult, type DriveAttributes, type DriveClient, type DriveConfig, type DriveDraftInfo, type DriveFile, type DriveFileDetails, type DriveFolder, type DriveMediaItem, type DriveSaveResult, type EntryMeta, type EnumDescriptor, type EnumEntry, type EnumOption, type FileDescriptor, type FileEntry, type FlatParamEntry, type GenerateOptions, type GenerateResult, type GenerateResultItem, type GenerateResultItemMetadata, type GenerateTextResult, type GenerationContext, type GenerationEvent, GenerationEventType, type GenerationFile, type GenerationMode, type GenerationOptions, type GenerationProgress, type GenerationProvenance, type InitModelCatalogOptions, type ListOptions, type MediaModelId, type MediaTypeFilter, Model, type ModelCatalogFilters, type ModelDefinition, type ModelDescriptor, type ModelFilter, type ModelMeta, type ModelParams, type ModelParamsAccessor, type ModelsCommand, type ModelsGenAIOptions, type ObjectDescriptor, type ObjectEntry, type OptionsAvailability, type OptionsResult, type ParamDescriptor, type ParamEntry, type ParamOption, type PayloadDriveFolderOptions, type PayloadDriveOptions, type PayloadInputsNormalizationOptions, type PayloadInputsTransformationOptions, type PriceOptions, type PricingOptions, type ProviderInfo, type RangeDescriptor, type RangeEntry, type ReleaseTag, type RunResponse, type SaveParams, type SdkPayload, type SdkTransport, type SeedanceDraftTask, type ServiceTier, type TextDescriptor, type TextEntry, type ToolUsage, type TransportPollOptions, type TransportResult, type UnknownDescriptor, type UnknownEntry, type UserReaction, type ValidationResult, type VoiceOption, type WorkflowJobHandle, type WorkflowSubmitRequest, buildFilename, buildGenerationAttributes, catalog, createClient, decodeDeepLinkPayload, encodeDeepLinkPayload, expectedOutputFormat, findModel, getModel, getVoiceById, inferResourceType, isVisibleForReleases, parseGeneration, releaseOf, resolveExtension, toAvatarOption, toVoiceOption };
|
package/index.js
CHANGED
|
@@ -2721,11 +2721,28 @@ function buildTransport(wc) {
|
|
|
2721
2721
|
|
|
2722
2722
|
// src/client/prepare.ts
|
|
2723
2723
|
var MODELS_WORKFLOW = "v1/models";
|
|
2724
|
+
var INPUTS_NORMALIZATION_FIELDS = [
|
|
2725
|
+
["all", "all"],
|
|
2726
|
+
["upscaleUndersizedImages", "upscale_undersized_images"],
|
|
2727
|
+
["resizeOutOfRangeVideos", "resize_out_of_range_videos"],
|
|
2728
|
+
["reduceVideoFrameRate", "reduce_video_frame_rate"],
|
|
2729
|
+
["transcodeUnsupportedAudio", "transcode_unsupported_audio"]
|
|
2730
|
+
];
|
|
2731
|
+
function toInputsNormalization(options) {
|
|
2732
|
+
if (!options) return void 0;
|
|
2733
|
+
const out = {};
|
|
2734
|
+
for (const [from, to] of INPUTS_NORMALIZATION_FIELDS) {
|
|
2735
|
+
if (options[from] !== void 0) out[to] = options[from];
|
|
2736
|
+
}
|
|
2737
|
+
return Object.keys(out).length > 0 ? out : void 0;
|
|
2738
|
+
}
|
|
2724
2739
|
function buildModelsCommand(model, params, media, serviceTier) {
|
|
2725
2740
|
if (!media && !serviceTier) return { model, params };
|
|
2741
|
+
const inputsNormalization = toInputsNormalization(media?.inputsNormalization);
|
|
2726
2742
|
return {
|
|
2727
2743
|
model,
|
|
2728
2744
|
params,
|
|
2745
|
+
...inputsNormalization ? { inputs_normalization: inputsNormalization } : {},
|
|
2729
2746
|
options: {
|
|
2730
2747
|
...media ? {
|
|
2731
2748
|
inputs_transformation: {
|
|
@@ -3708,7 +3725,7 @@ function createClient(config) {
|
|
|
3708
3725
|
};
|
|
3709
3726
|
}
|
|
3710
3727
|
function resolveDownscale(options) {
|
|
3711
|
-
return options?.inputsTransformation?.downscaleOversizedImages ?? inputsTransformationConfig?.downscaleOversizedImages ??
|
|
3728
|
+
return options?.inputsTransformation?.downscaleOversizedImages ?? inputsTransformationConfig?.downscaleOversizedImages ?? options?.inputsNormalization?.all === true;
|
|
3712
3729
|
}
|
|
3713
3730
|
function resolveServiceTier(options) {
|
|
3714
3731
|
return options?.serviceTier ?? config.serviceTier;
|
|
@@ -3800,7 +3817,8 @@ function createClient(config) {
|
|
|
3800
3817
|
const drive = buildDynamicDriveOptions(model, params, options);
|
|
3801
3818
|
const command = buildModelsCommand(model, params, {
|
|
3802
3819
|
drive,
|
|
3803
|
-
downscaleOversizedImages: resolveDownscale(options)
|
|
3820
|
+
downscaleOversizedImages: resolveDownscale(options),
|
|
3821
|
+
inputsNormalization: options?.inputsNormalization
|
|
3804
3822
|
}, resolveServiceTier(options));
|
|
3805
3823
|
const completed = await executeDynamic(command, options);
|
|
3806
3824
|
return parseDynamicResult(completed, model);
|
|
@@ -3843,7 +3861,8 @@ function createClient(config) {
|
|
|
3843
3861
|
const drive = buildDynamicDriveOptions(model, params, options);
|
|
3844
3862
|
const command = buildModelsCommand(model, params, {
|
|
3845
3863
|
drive,
|
|
3846
|
-
downscaleOversizedImages: resolveDownscale(options)
|
|
3864
|
+
downscaleOversizedImages: resolveDownscale(options),
|
|
3865
|
+
inputsNormalization: options?.inputsNormalization
|
|
3847
3866
|
}, resolveServiceTier(options));
|
|
3848
3867
|
try {
|
|
3849
3868
|
return await submitJob(MODELS_WORKFLOW, command, options?.signal);
|