@picsart/ai-sdk 7.45.0 → 7.46.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 +17 -0
- package/index.d.ts +14 -0
- package/index.js +17 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -257,6 +257,23 @@ const credits = await ai.getCredits(modelId, { prompt }, { serviceTier: 'priorit
|
|
|
257
257
|
|
|
258
258
|
Left unset, the option is not sent and the platform applies `auto`.
|
|
259
259
|
|
|
260
|
+
## Config ID
|
|
261
|
+
|
|
262
|
+
`configId` runs a generation under a specific platform config. It is sent as the
|
|
263
|
+
`x-config-id` header on every generation route — `generate()`, `generateText()`,
|
|
264
|
+
`run()` and `submit()` — and the model's workflow loads that config in place of
|
|
265
|
+
its default.
|
|
266
|
+
|
|
267
|
+
```typescript
|
|
268
|
+
await ai.generate(modelId, { prompt }, { configId: 'my-config-id' });
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
The price calls (`getCredits()`, `options()`) do not take a `configId`: they quote under the default config.
|
|
272
|
+
|
|
273
|
+
The id must exist for the model being called: a workflow that cannot find it
|
|
274
|
+
fails the request with `config_not_found`. Left unset, no id is sent and the
|
|
275
|
+
default config applies.
|
|
276
|
+
|
|
260
277
|
## Text Generation (LLMs)
|
|
261
278
|
|
|
262
279
|
Claude, GPT, Gemini, Kimi, Grok and MiniMax text models are called with `generateText()`. Single-shot:
|
package/index.d.ts
CHANGED
|
@@ -8,6 +8,12 @@ interface WorkflowSubmitRequest<TPayload = Record<string, unknown>> {
|
|
|
8
8
|
workflow: string;
|
|
9
9
|
payload: TPayload;
|
|
10
10
|
signal?: AbortSignal;
|
|
11
|
+
/**
|
|
12
|
+
* Config id to run the workflow under — the caller's `configId` option. The
|
|
13
|
+
* built-in transport sends it as the `x-config-id` header; unset, the
|
|
14
|
+
* workflow's default config applies.
|
|
15
|
+
*/
|
|
16
|
+
configId?: string;
|
|
11
17
|
}
|
|
12
18
|
interface WorkflowJobHandle {
|
|
13
19
|
workflow: string;
|
|
@@ -1425,6 +1431,14 @@ interface GenerateOptions {
|
|
|
1425
1431
|
* `generateText()` and `submit()`.
|
|
1426
1432
|
*/
|
|
1427
1433
|
serviceTier?: ServiceTier;
|
|
1434
|
+
/**
|
|
1435
|
+
* Config id to run this generation under, sent as the `x-config-id` header.
|
|
1436
|
+
* The model's workflow loads the config with this id in place of its
|
|
1437
|
+
* default, so the id must exist for the model being called. Unset, no id is
|
|
1438
|
+
* sent and the default config applies. Applies to `run()`, `generate()`,
|
|
1439
|
+
* `generateText()` and `submit()`.
|
|
1440
|
+
*/
|
|
1441
|
+
configId?: string;
|
|
1428
1442
|
/**
|
|
1429
1443
|
* App identity stamped onto the saved generation (appId/appType).
|
|
1430
1444
|
* TODO(backend-autosave): temporary — remove once the backend stamps these.
|
package/index.js
CHANGED
|
@@ -2620,7 +2620,7 @@ function toApiError(err, workflow, id) {
|
|
|
2620
2620
|
|
|
2621
2621
|
// package.json
|
|
2622
2622
|
var package_default = {
|
|
2623
|
-
version: "7.
|
|
2623
|
+
version: "7.46.0"};
|
|
2624
2624
|
|
|
2625
2625
|
// src/client/transport.ts
|
|
2626
2626
|
var GATEWAY_HEADERS = {
|
|
@@ -2653,6 +2653,10 @@ function maybeFetch(config) {
|
|
|
2653
2653
|
}
|
|
2654
2654
|
return null;
|
|
2655
2655
|
}
|
|
2656
|
+
var CONFIG_ID_HEADER = "x-config-id";
|
|
2657
|
+
function configIdHeaders(configId) {
|
|
2658
|
+
return configId ? { [CONFIG_ID_HEADER]: configId } : void 0;
|
|
2659
|
+
}
|
|
2656
2660
|
function createWorkflowsClient(apiUrl, authedFetch) {
|
|
2657
2661
|
return new WorkflowsClient_default({
|
|
2658
2662
|
baseUrl: apiUrl,
|
|
@@ -2684,7 +2688,8 @@ function buildTransport(wc) {
|
|
|
2684
2688
|
try {
|
|
2685
2689
|
const res = await wc.run(request.workflow, request.payload, {
|
|
2686
2690
|
mode: ExecutionMode.SYNC,
|
|
2687
|
-
abortSignal: request.signal
|
|
2691
|
+
abortSignal: request.signal,
|
|
2692
|
+
headers: configIdHeaders(request.configId)
|
|
2688
2693
|
});
|
|
2689
2694
|
return asResult(res);
|
|
2690
2695
|
} catch (err) {
|
|
@@ -2693,7 +2698,10 @@ function buildTransport(wc) {
|
|
|
2693
2698
|
},
|
|
2694
2699
|
async submit(request) {
|
|
2695
2700
|
try {
|
|
2696
|
-
const id = await wc.submit(request.workflow, request.payload, {
|
|
2701
|
+
const id = await wc.submit(request.workflow, request.payload, {
|
|
2702
|
+
abortSignal: request.signal,
|
|
2703
|
+
headers: configIdHeaders(request.configId)
|
|
2704
|
+
});
|
|
2697
2705
|
if (!id) {
|
|
2698
2706
|
throw new ApiError("No task id in response", { status: 502, code: "invalid_response" });
|
|
2699
2707
|
}
|
|
@@ -3669,12 +3677,12 @@ function createClient(config) {
|
|
|
3669
3677
|
if (!transport.submit) throw unsupportedTransport("submit");
|
|
3670
3678
|
if (!transport.poll) throw unsupportedTransport("polling");
|
|
3671
3679
|
}
|
|
3672
|
-
async function submitJob(workflow, payload, signal) {
|
|
3680
|
+
async function submitJob(workflow, payload, signal, configId) {
|
|
3673
3681
|
if (signal?.aborted) {
|
|
3674
3682
|
throw new ApiError("Operation aborted", { status: 499, code: "aborted" });
|
|
3675
3683
|
}
|
|
3676
3684
|
if (!transport.submit) throw unsupportedTransport("submit");
|
|
3677
|
-
const id = await transport.submit({ workflow, payload, signal });
|
|
3685
|
+
const id = await transport.submit({ workflow, payload, signal, configId });
|
|
3678
3686
|
if (!id) {
|
|
3679
3687
|
throw new ApiError("No task id in response", { status: 502, code: "invalid_response" });
|
|
3680
3688
|
}
|
|
@@ -3713,13 +3721,14 @@ function createClient(config) {
|
|
|
3713
3721
|
}
|
|
3714
3722
|
async function executeDynamic(command, options) {
|
|
3715
3723
|
const signal = options?.signal;
|
|
3724
|
+
const configId = options?.configId;
|
|
3716
3725
|
const payload = command;
|
|
3717
3726
|
try {
|
|
3718
3727
|
if (!supportsAsync) {
|
|
3719
|
-
const res2 = await transport.execute({ workflow: MODELS_WORKFLOW, payload, signal });
|
|
3728
|
+
const res2 = await transport.execute({ workflow: MODELS_WORKFLOW, payload, signal, configId });
|
|
3720
3729
|
return toCompletedStatus({ workflow: MODELS_WORKFLOW, id: "" }, res2.result, res2.raw ?? res2.result, res2.usage);
|
|
3721
3730
|
}
|
|
3722
|
-
const id = await submitJob(MODELS_WORKFLOW, payload, signal);
|
|
3731
|
+
const id = await submitJob(MODELS_WORKFLOW, payload, signal, configId);
|
|
3723
3732
|
const res = await pollJob({ workflow: MODELS_WORKFLOW, id }, pollOptionsFor(options));
|
|
3724
3733
|
return asCompleted({ workflow: MODELS_WORKFLOW, id }, res);
|
|
3725
3734
|
} catch (err) {
|
|
@@ -3883,7 +3892,7 @@ function createClient(config) {
|
|
|
3883
3892
|
inputsNormalization: options?.inputsNormalization
|
|
3884
3893
|
}, resolveServiceTier(options));
|
|
3885
3894
|
try {
|
|
3886
|
-
return await submitJob(MODELS_WORKFLOW, command, options?.signal);
|
|
3895
|
+
return await submitJob(MODELS_WORKFLOW, command, options?.signal, options?.configId);
|
|
3887
3896
|
} catch (err) {
|
|
3888
3897
|
throw toApiError2(err, options?.signal);
|
|
3889
3898
|
}
|