Edits history of script submission #12541 for ' Train a Custom Element (leonardoai)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Leonardoai = {
      apiKey: string;
    };
    /**
     * Train a Custom Element
     * This endpoint will train a new custom element.
     */
    export async function main(
      auth: Leonardoai,
      body: {
        name: string;
        description?: string;
        datasetId: string;
        instance_prompt: string;
        lora_focus: string;
        train_text_encoder: false | true;
        resolution?: number;
        sd_version:
          | "SDXL_0_9"
          | "SDXL_1_0"
          | "LEONARDO_DIFFUSION_XL"
          | "LEONARDO_LIGHTNING_XL"
          | "VISION_XL"
          | "KINO_XL"
          | "ALBEDO_XL";
        num_train_epochs: number;
        learning_rate: number;
      },
    ) {
      const url = new URL(`https://cloud.leonardo.ai/api/rest/v1/elements`);
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Bearer " + auth.apiKey,
        },
        body: JSON.stringify(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 428 days ago