Edits history of script submission #20982 for ' Download model (togetherai)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Togetherai = {
      api_key: string;
    };
    /**
     * Download model
     * Download a compressed fine-tuned model or checkpoint to local disk.
     */
    export async function main(
      auth: Togetherai,
      ft_id: string | undefined,
      checkpoint_step: string | undefined,
      checkpoint: "merged" | "adapter" | undefined,
      output: string | undefined,
    ) {
      const url = new URL(`https://api.together.xyz/v1/finetune/download`);
      for (const [k, v] of [
        ["ft_id", ft_id],
        ["checkpoint_step", checkpoint_step],
        ["checkpoint", checkpoint],
        ["output", output],
      ]) {
        if (v !== undefined && v !== "" && k !== undefined) {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "GET",
        headers: {
          Authorization: "Bearer " + auth.api_key,
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 235 days ago