@huggingface/hub
Version:
Utilities to interact with the Hugging Face hub
46 lines (41 loc) • 1.17 kB
text/typescript
import { HUB_URL } from "../../consts";
import { createApiError } from "../../error";
import type { CredentialsParams } from "../../types/public";
import { checkCredentials } from "../../utils/checkCredentials";
import type { ApiJob } from "../../types/api/api-jobs";
/**
* Duplicate a job (re-run with the same spec).
*/
export async function duplicateJob(
params: {
/**
* The namespace (username or organization name)
*/
namespace: string;
/**
* The job ID to duplicate
*/
jobId: string;
hubUrl?: string;
/**
* Custom fetch function to use instead of the default one, for example to use a proxy or edit headers.
*/
fetch?: typeof fetch;
} & CredentialsParams,
): Promise<ApiJob> {
const accessToken = checkCredentials(params);
const response = await (params.fetch || fetch)(
`${params.hubUrl || HUB_URL}/api/jobs/${params.namespace}/${params.jobId}/duplicate`,
{
method: "POST",
headers: {
"Content-Type": "application/json",
...(accessToken ? { Authorization: `Bearer ${accessToken}` } : {}),
},
},
);
if (!response.ok) {
throw await createApiError(response);
}
return await response.json();
}