@toloka-platform/sdk 0.12.2 → 0.13.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/dist/cli/toloka.js +153 -151
- package/dist/cli/toloka.js.jsc +0 -0
- package/dist/cli/toloka.js.jsc.sha256 +1 -1
- package/dist/cli/toloka.js.sha256 +1 -1
- package/docs/cli.md +17 -0
- package/openapi/gen/api.ts +142 -0
- package/openapi/gen/models/batchInferenceMode.ts +3 -0
- package/openapi/gen/models/batchInferenceModeOneOf.ts +4 -0
- package/openapi/gen/models/batchInferenceModel.ts +4 -0
- package/openapi/gen/models/batchInferenceModelOneOf.ts +6 -0
- package/openapi/gen/models/batchInferenceModelOneOfBaseModelId.ts +2 -0
- package/openapi/gen/models/batchInferenceModelOneOfThree.ts +5 -0
- package/openapi/gen/models/batchInferenceRun.ts +35 -0
- package/openapi/gen/models/batchInferenceRunBlockedReason.ts +2 -0
- package/openapi/gen/models/batchInferenceRunChargedAmount.ts +2 -0
- package/openapi/gen/models/batchInferenceRunError.ts +3 -0
- package/openapi/gen/models/batchInferenceRunErrorAnyOf.ts +6 -0
- package/openapi/gen/models/batchInferenceRunErrorAnyOfCode.ts +2 -0
- package/openapi/gen/models/batchInferenceRunId.ts +2 -0
- package/openapi/gen/models/batchInferenceRunMessage.ts +2 -0
- package/openapi/gen/models/batchInferenceRunOutput.ts +9 -0
- package/openapi/gen/models/batchInferenceRunOutputType.ts +2 -0
- package/openapi/gen/models/batchInferenceRunProgress.ts +3 -0
- package/openapi/gen/models/batchInferenceRunProgressAnyOf.ts +7 -0
- package/openapi/gen/models/batchInferenceRunProgressAnyOfPhase.ts +2 -0
- package/openapi/gen/models/batchInferenceRunProgressAnyOfRequests.ts +5 -0
- package/openapi/gen/models/batchInferenceRunQuote.ts +3 -0
- package/openapi/gen/models/batchInferenceRunQuoteAnyOf.ts +9 -0
- package/openapi/gen/models/batchInferenceRunQuoteAnyOfConfirmBefore.ts +2 -0
- package/openapi/gen/models/batchInferenceRunResult.ts +3 -0
- package/openapi/gen/models/batchInferenceRunResultAnyOf.ts +12 -0
- package/openapi/gen/models/batchInferenceRunResultAnyOfErrorCounts.ts +2 -0
- package/openapi/gen/models/batchInferenceRunResultAnyOfErrorSamplesItem.ts +6 -0
- package/openapi/gen/models/batchInferenceRunSampling.ts +9 -0
- package/openapi/gen/models/batchInferenceRunStatus.ts +2 -0
- package/openapi/gen/models/createBatchInferenceRunBody.ts +14 -0
- package/openapi/gen/models/createBatchInferenceRunBodyItemFilter.ts +14 -0
- package/openapi/gen/models/createBatchInferenceRunBodyItemFilterExcludePartsItem.ts +5 -0
- package/openapi/gen/models/createBatchInferenceRunBodyItemFilterFieldSourcesItem.ts +6 -0
- package/openapi/gen/models/createBatchInferenceRunBodyItemFilterFieldSourcesItemSourcesItem.ts +4 -0
- package/openapi/gen/models/createBatchInferenceRunBodyItemFilterFieldSourcesItemSourcesItemOneOf.ts +5 -0
- package/openapi/gen/models/createBatchInferenceRunBodyItemFilterFieldSourcesItemSourcesItemOneOfTwo.ts +5 -0
- package/openapi/gen/models/createBatchInferenceRunBodyItemFilterFieldValuesItem.ts +12 -0
- package/openapi/gen/models/createBatchInferenceRunBodyItemFilterFieldValuesItemOperator.ts +2 -0
- package/openapi/gen/models/createBatchInferenceRunBodyItemFilterFieldValuesItemSourcesItem.ts +4 -0
- package/openapi/gen/models/createBatchInferenceRunBodyItemFilterFieldValuesItemSourcesItemOneOf.ts +5 -0
- package/openapi/gen/models/createBatchInferenceRunBodyItemFilterFieldValuesItemSourcesItemOneOfTwo.ts +5 -0
- package/openapi/gen/models/createBatchInferenceRunBodyItemFilterFieldValuesItemValue.ts +2 -0
- package/openapi/gen/models/createBatchInferenceRunBodyItemFilterParts.ts +5 -0
- package/openapi/gen/models/createBatchInferenceRunBodyItemFilterSlice.ts +4 -0
- package/openapi/gen/models/createBatchInferenceRunBodyOutput.ts +4 -0
- package/openapi/gen/models/createBatchInferenceRunBodyOutputOneOf.ts +5 -0
- package/openapi/gen/models/createBatchInferenceRunBodyOutputOneOfTwo.ts +5 -0
- package/openapi/gen/models/createBatchInferenceRunBodySampling.ts +9 -0
- package/openapi/gen/models/datasetFieldOperation.ts +2 -1
- package/openapi/gen/models/datasetFieldWriteOperation.ts +8 -0
- package/openapi/gen/models/datasetFieldWriteOperationProgress.ts +3 -0
- package/openapi/gen/models/datasetFieldWriteOperationProgressAnyOf.ts +5 -0
- package/openapi/gen/models/index.ts +53 -0
- package/openapi/gen/models/listBatchInferenceRuns200.ts +7 -0
- package/openapi/gen/models/listBatchInferenceRunsParams.ts +5 -0
- package/package.json +2 -2
- package/skills/catalog.json +6 -6
- package/skills/toloka-build/references/workflow-and-cli.md +5 -1
- package/src/cli/analytics.ts +8 -0
- package/src/cli/batch-inference.ts +267 -0
- package/src/cli/commands/batch-inference.ts +116 -0
- package/src/cli/context.ts +14 -0
- package/src/cli/models.ts +1 -1
- package/src/cli/program.ts +2 -0
- package/src/cli/splits.ts +40 -0
- package/src/cli/trainings.ts +1 -19
- package/src/client.ts +49 -0
package/src/cli/splits.ts
CHANGED
|
@@ -111,6 +111,46 @@ export const formatSplitColumn = (field: DatasetField, fieldNames: ReadonlyMap<s
|
|
|
111
111
|
return formatTable(rows);
|
|
112
112
|
};
|
|
113
113
|
|
|
114
|
+
export const splitColumnId = async (
|
|
115
|
+
client: Pick<PotatoClient, "datasets">,
|
|
116
|
+
datasetId: string,
|
|
117
|
+
column: string,
|
|
118
|
+
): Promise<string> => {
|
|
119
|
+
for await (const field of client.datasets.listAllFields({ datasetId })) {
|
|
120
|
+
if (field.id === column || field.name === column) {
|
|
121
|
+
assertCli(field.split !== null, `Column ${field.name} is not a split column.`, {
|
|
122
|
+
hint: { description: `Make it one with toloka dataset split ${datasetId} --column ${field.name}.` },
|
|
123
|
+
});
|
|
124
|
+
return field.id;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
assertCli(false, `Dataset ${datasetId} has no column ${column}.`, {
|
|
128
|
+
hint: { description: `List its columns with toloka dataset columns ${datasetId}.` },
|
|
129
|
+
});
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
export const resolveSplitParts = async (
|
|
133
|
+
client: Pick<PotatoClient, "datasets">,
|
|
134
|
+
datasetId: string,
|
|
135
|
+
{ splitColumn, parts }: { splitColumn: string | undefined; parts: string[] },
|
|
136
|
+
): Promise<{ fieldId: string; names: string[] }> => {
|
|
137
|
+
if (splitColumn !== undefined) return { fieldId: await splitColumnId(client, datasetId, splitColumn), names: parts };
|
|
138
|
+
const splitColumns: DatasetField[] = [];
|
|
139
|
+
for await (const field of client.datasets.listAllFields({ datasetId })) {
|
|
140
|
+
if (field.split !== null) splitColumns.push(field);
|
|
141
|
+
}
|
|
142
|
+
const [only, ...others] = splitColumns;
|
|
143
|
+
assertCli(only !== undefined, `Dataset ${datasetId} has no split column.`, {
|
|
144
|
+
hint: { description: `Make one with toloka dataset split ${datasetId}.` },
|
|
145
|
+
});
|
|
146
|
+
assertCli(
|
|
147
|
+
others.length === 0,
|
|
148
|
+
`Dataset ${datasetId} has the split columns ${splitColumns.map((field) => field.name).join(", ")}.`,
|
|
149
|
+
{ hint: { description: "Pass --split-column <name> to choose one." } },
|
|
150
|
+
);
|
|
151
|
+
return { fieldId: only.id, names: parts };
|
|
152
|
+
};
|
|
153
|
+
|
|
114
154
|
export const waitForSplitColumn = async (
|
|
115
155
|
client: SplitApi,
|
|
116
156
|
{ datasetId, field, waitFor }: { datasetId: string; field: DatasetField; waitFor?: WaitForOptions },
|
package/src/cli/trainings.ts
CHANGED
|
@@ -19,7 +19,7 @@ import { assertCli, RETRY_OR_REPORT_HINT, TolokaCliError } from "./cli-error";
|
|
|
19
19
|
import type { CliErrorHint } from "./cli-error";
|
|
20
20
|
import { resolveLiveDataset } from "./data";
|
|
21
21
|
import { formatCount, waitForFilledFields, waitUntilDone } from "./slices";
|
|
22
|
-
import { DEFAULT_SPLIT_COLUMN, waitForSplitColumn } from "./splits";
|
|
22
|
+
import { DEFAULT_SPLIT_COLUMN, splitColumnId, waitForSplitColumn } from "./splits";
|
|
23
23
|
import { uploadedFieldHint } from "./uploaded-fields";
|
|
24
24
|
import { formatTable, type TableIo as TrainingIo, writeOutput } from "./table";
|
|
25
25
|
|
|
@@ -280,24 +280,6 @@ const AUTO_WAIT = { timeoutMs: 10 * 60_000 };
|
|
|
280
280
|
|
|
281
281
|
type ResolvedRows = ResolvedSelections & { readonly notes: readonly string[] };
|
|
282
282
|
|
|
283
|
-
const splitColumnId = async (
|
|
284
|
-
client: TrainingDraftApi,
|
|
285
|
-
datasetId: string,
|
|
286
|
-
column: string,
|
|
287
|
-
): Promise<string> => {
|
|
288
|
-
for await (const field of client.datasets.listAllFields({ datasetId })) {
|
|
289
|
-
if (field.id === column || field.name === column) {
|
|
290
|
-
assertCli(field.split !== null, `Column ${field.name} is not a split column.`, {
|
|
291
|
-
hint: { description: `Make it one with toloka dataset split ${datasetId} --column ${field.name}.` },
|
|
292
|
-
});
|
|
293
|
-
return field.id;
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
assertCli(false, `Dataset ${datasetId} has no column ${column}.`, {
|
|
297
|
-
hint: { description: `List its columns with toloka dataset columns ${datasetId}.` },
|
|
298
|
-
});
|
|
299
|
-
};
|
|
300
|
-
|
|
301
283
|
const fillTrainingSplitColumn = async (
|
|
302
284
|
client: TrainingDraftApi,
|
|
303
285
|
{
|
package/src/client.ts
CHANGED
|
@@ -4,8 +4,10 @@ import * as wire from "../openapi/gen/api";
|
|
|
4
4
|
import type {
|
|
5
5
|
AddDatasetItemsBody,
|
|
6
6
|
AttachPipelineDatasetBody,
|
|
7
|
+
BatchInferenceRun as GeneratedBatchInferenceRun,
|
|
7
8
|
CheckJob as GeneratedCheckJob,
|
|
8
9
|
CopyPipelineBody,
|
|
10
|
+
CreateBatchInferenceRunBody,
|
|
9
11
|
CreateDatasetBody,
|
|
10
12
|
CreateDatasetExportBody,
|
|
11
13
|
CreateDatasetFieldsFromUploadedRowsBody,
|
|
@@ -39,6 +41,7 @@ import type {
|
|
|
39
41
|
ListProjectDatasetsParams,
|
|
40
42
|
ListProjectPipelinesParams,
|
|
41
43
|
ListAudienceSpecializationsParams,
|
|
44
|
+
ListBatchInferenceRunsParams,
|
|
42
45
|
ListProjectModelsParams,
|
|
43
46
|
ListProjectsParams,
|
|
44
47
|
ListProjectTokensParams,
|
|
@@ -85,6 +88,7 @@ declare const __brand: unique symbol;
|
|
|
85
88
|
type Brand<B> = { [__brand]: B };
|
|
86
89
|
export type Branded<T extends string, B> = T & Brand<B>;
|
|
87
90
|
|
|
91
|
+
export type BatchInferenceRunId = Branded<string, "BatchInferenceRunId">;
|
|
88
92
|
export type CheckRunId = Branded<string, "CheckRunId">;
|
|
89
93
|
export type DatasetFieldId = Branded<string, "DatasetFieldId">;
|
|
90
94
|
export type DatasetId = Branded<string, "DatasetId">;
|
|
@@ -108,6 +112,7 @@ type ResourceIdInput<T extends Branded<string, unknown>> = string & {
|
|
|
108
112
|
};
|
|
109
113
|
|
|
110
114
|
type ResourceIdsByProperty = {
|
|
115
|
+
batchInferenceRunId: BatchInferenceRunId;
|
|
111
116
|
checkRunId: CheckRunId;
|
|
112
117
|
datasetFieldId: DatasetFieldId;
|
|
113
118
|
datasetId: DatasetId;
|
|
@@ -164,6 +169,7 @@ type PublicInput<T> = T extends readonly unknown[]
|
|
|
164
169
|
|
|
165
170
|
type BrandResourceUnion<T> = T extends object ? BrandResourceReferences<T> : T;
|
|
166
171
|
|
|
172
|
+
export type BatchInferenceRun = BrandedResource<GeneratedBatchInferenceRun, BatchInferenceRunId>;
|
|
167
173
|
export type CheckJob = BrandedResource<GeneratedCheckJob, CheckRunId>;
|
|
168
174
|
export type Dataset = BrandedResource<GeneratedDataset, DatasetId>;
|
|
169
175
|
export type DatasetField = BrandedResource<GeneratedDatasetField, DatasetFieldId>;
|
|
@@ -592,6 +598,46 @@ const createClientImplementation = (config: ClientConfig) => {
|
|
|
592
598
|
wire.getTrainingRunMetricHistory(trainingRunId, metricKey, params, requestOptions),
|
|
593
599
|
};
|
|
594
600
|
|
|
601
|
+
const batchInference = {
|
|
602
|
+
createRun: ({
|
|
603
|
+
projectId,
|
|
604
|
+
idempotencyKey,
|
|
605
|
+
...body
|
|
606
|
+
}: { projectId: ProjectId; idempotencyKey: string } & CreateBatchInferenceRunBody) => {
|
|
607
|
+
const headers = new Headers(requestOptions.headers);
|
|
608
|
+
headers.set("Idempotency-Key", idempotencyKey);
|
|
609
|
+
return wire.createBatchInferenceRun(projectId, body, {
|
|
610
|
+
...requestOptions,
|
|
611
|
+
headers: Object.fromEntries(headers.entries()),
|
|
612
|
+
});
|
|
613
|
+
},
|
|
614
|
+
listRunsPage: ({
|
|
615
|
+
projectId,
|
|
616
|
+
...params
|
|
617
|
+
}: { projectId: ProjectId } & ListBatchInferenceRunsParams) =>
|
|
618
|
+
wire.listBatchInferenceRuns(projectId, params, requestOptions),
|
|
619
|
+
listAllRuns: ({
|
|
620
|
+
projectId,
|
|
621
|
+
...params
|
|
622
|
+
}: { projectId: ProjectId } & ListBatchInferenceRunsParams) =>
|
|
623
|
+
listAllPages(async (pageOptions) => {
|
|
624
|
+
const page = await wire.listBatchInferenceRuns(
|
|
625
|
+
projectId,
|
|
626
|
+
{ ...params, ...pageOptions },
|
|
627
|
+
requestOptions,
|
|
628
|
+
);
|
|
629
|
+
return { items: page.batchInferenceRuns, pagination: page.pagination };
|
|
630
|
+
}, params),
|
|
631
|
+
getRun: ({ batchInferenceRunId }: { batchInferenceRunId: BatchInferenceRunId }) =>
|
|
632
|
+
wire.getBatchInferenceRun(batchInferenceRunId, requestOptions),
|
|
633
|
+
confirmRun: ({ batchInferenceRunId }: { batchInferenceRunId: BatchInferenceRunId }) =>
|
|
634
|
+
wire.confirmBatchInferenceRun(batchInferenceRunId, requestOptions),
|
|
635
|
+
resumeRun: ({ batchInferenceRunId }: { batchInferenceRunId: BatchInferenceRunId }) =>
|
|
636
|
+
wire.resumeBatchInferenceRun(batchInferenceRunId, requestOptions),
|
|
637
|
+
cancelRun: ({ batchInferenceRunId }: { batchInferenceRunId: BatchInferenceRunId }) =>
|
|
638
|
+
wire.cancelBatchInferenceRun(batchInferenceRunId, requestOptions),
|
|
639
|
+
};
|
|
640
|
+
|
|
595
641
|
const datasets = {
|
|
596
642
|
create: ({ projectId, ...body }: { projectId: ProjectId } & CreateDatasetBody) =>
|
|
597
643
|
wire.createDataset(projectId, body, requestOptions),
|
|
@@ -778,6 +824,7 @@ const createClientImplementation = (config: ClientConfig) => {
|
|
|
778
824
|
generationModels,
|
|
779
825
|
models,
|
|
780
826
|
trainings,
|
|
827
|
+
batchInference,
|
|
781
828
|
runs,
|
|
782
829
|
secrets,
|
|
783
830
|
files,
|
|
@@ -807,6 +854,8 @@ type PublicOutput<T> = T extends GeneratedCheckJob
|
|
|
807
854
|
? TrainingCostEstimate
|
|
808
855
|
: T extends GeneratedTrainingRun
|
|
809
856
|
? TrainingRun
|
|
857
|
+
: T extends GeneratedBatchInferenceRun
|
|
858
|
+
? BatchInferenceRun
|
|
810
859
|
: T extends GeneratedProject
|
|
811
860
|
? Project
|
|
812
861
|
: T extends GeneratedPipeline
|