Media Gen SolutionManaging custom assets with Asset Library

Asset Library in the TypeScript SDK

Manage assets using the TypeScript SDK.

The AssetLibrary client in the TypeScript SDK allows create, list, get, and delete actions of assets. These assets allow integration with Fine-tuning Stable Diffusion.

This guide will walk you through using this API to see a list of our public assets, create your own asset, and use your asset to generate an image.

Requirements

Overview of AssetLibrary API

TypeScript
1import { OctoAIClient } from "@octoai/sdk";
2
3const octoai = new OctoAIClient({
4 apiKey: process.env.OCTOAI_TOKEN
5});
6
7const assetListResponse = await octoai.assetLibrary.list();
8console.log(JSON.stringify(assetListResponse.data, undefined, 2));
9
10const assetListStableDiffusion = await octoai.assetLibrary.list({
11 isPublic: true,
12 owner: "octoai",
13 engine: "image/stable-diffusion-v1-5",
14});
15console.log(JSON.stringify(assetListStableDiffusion, undefined, 2));
16
17
18const { asset } = await octoai.assetLibrary.get("origami-paper");
19console.log(JSON.stringify(asset, undefined, 2));
20
21await octoai.assetLibrary.delete(asset.id);

Creating a LoRA

You will need a safetensors file in order to use this example, and in our case one is named origami-paper.safetensors. I’ll be using a LoRA trained on origami that I can use with the words “origami” and “paper”.

In this example, we will be adding a LoRA then using it to generate an image.

The id field for the created asset can be used when Getting started with our Media Gen Solution and running inferences.

TypeScript
1import { OctoAIClient } from "@octoai/sdk";
2
3const octoai = new OctoAIClient({
4 apiKey: process.env.OCTOAI_TOKEN
5});
6
7await octoai.assetLibrary.upload("origami-paper.safetensors", {
8 assetType: "lora",
9 description: "Origami",
10 data: {
11 assetType: "lora",
12 dataType: "fp16",
13 engine: "image/stable-diffusion-v1-5",
14 fileFormat: "safetensors",
15 triggerWords: ["origami", "paper"],
16 },
17 name: "origami-paper",
18 isPublic: false,
19});

astropus.png

rainbow-origami-tailong-dragon.png generated on ImageGen service using AssetLibrary created LoRA