Class AssetLibrary

The AssetLibrary class. Generally accessed through the client through client.asset, but can be instantiated directly if a different endpoint is desired.

Constructors

Properties

client: Client
endpoint: string

Methods

  • Private

    Parameters

    • id: string

    Returns Promise<void>

  • Creates and uploads asset, then returns the Asset.

    Will select the most efficient transfer_api_type if left undefined.

    Returns Promise<Asset>

    Throws

    OctoAIValidationError if no token was found when creating the Client class.

    Remarks

    This is used with CreateAssetRequest. The data field requires data from the matching asset_type. This includes FileData, CheckpointData, LoraData, VAEData, and TextualInversionData.

    Example

    Creating an asset from a local file:

    import { Client, LoraData } from "@octoai/client";

    const client = new Client(process.env.OCTOAI_TOKEN);

    const loraData = {
    asset_type: "lora",
    data_type: "fp16",
    engine: "image/stable-diffusion-v1-5",
    file_format: "safetensors",
    trigger_words: ["origami paper"],
    } as LoraData;

    const createdAsset = await client.asset.create({
    file: "./test_assets/origami-paper.safetensors",
    asset_type: "lora",
    description: "origami paper lora",
    data: loraData,
    name: "origami-paper",
    is_public: false,
    });

    Example

    Creating an asset via URL upload:

    import { Client, LoraData } from "@octoai/client";

    const client = new Client(process.env.OCTOAI_TOKEN);

    const loraData = {
    asset_type: "lora",
    data_type: "fp16",
    engine: "image/stable-diffusion-xl-v1-0",
    file_format: "safetensors",
    trigger_words: ["my trigger word"],
    } as LoraData;

    const createdAsset = await client.asset.create({
    url: "<ASSET_DOWNLOAD_URL>",
    asset_type: "lora",
    description: "My SDXL LoRA",
    data: loraData,
    name: "my-sdxl-lora",
    is_public: false,
    });
  • Private

    Parameters

    • file: string | ArrayBuffer | Buffer

    Returns Promise<Buffer>

  • List assets based on the search parameters provided. Array of assets can be accessed in response's data field.

    Parameters

    Returns Promise<ListAssetsResponse>

    Remarks

    This method is used with the ListAssetsRequest class to query the assets and return. If there are more assets, the ListAssetsResponse will return true for has_more as well as the total number of assets.

    You can search by name, data_type such as "fp16", set a limit, or start the next request at a certain offset for larger requests.

    An example of how to request octoai public assets is below:

      const client = new Client(process.env.OCTOAI_TOKEN);
    const octoAssets = await client.asset.list({
    is_public: true,
    owner: "octoai",
    engine: "image/stable-diffusion-v1-5",
    asset_type: "lora",
    });

    Throws

    OctoAIValidationError if there isn't a token set in the client.

  • Private

    Parameters

    • nameOrId: string

    Returns void

  • Waits for an Asset to be ready to use. Useful when uploading assets via URL.

    Parameters

    • asset: Asset

      The Asset to poll.

    • Optional options: WaitForOptions

      Additional options for changing the poll interval and timeout durations.

    Returns Promise<Asset>

    A ready Asset.

    Throws

    OctoAIValidationError Thrown if the asset has an upload error or if the asset is rejected for safety.

    Throws

    OctoAITimeoutError Thrown if the asset isn't ready by the specified timeout. Doesn't necessarily indicate a failure.

Generated using TypeDoc