ballerinax/stabilityai Ballerina library

1.0.1

Overview

This is a generated connector from Stability.ai REST API (v1) OpenAPI specification.

Prerequisites

Quickstart

To use the Stability AI connector in your Ballerina application, update the .bal file as follows:

Step 1: Import connector

Import the ballerinax/stabilityai module into the Ballerina project.

Copy
import ballerinax/stabilityai;

Step 2: Create a new connector instance

Create and initialize a stabilityai:Client with the obtained apiKey from the Satbility AI

Copy
final stabilityai:Client stabilityaiClient = check new ({authorization: api_key});

Step 3: Invoke connector operation

  1. Now you can use the operations available within the connector.

Note: that they are in the form of remote operations.

Following is an example on generating an image based on the text prompt:

Copy
stabilityai:TextToImageRequestBody payload = {
    text_prompts: [
        {
            "text": "A lighthouse on a cliff",
            "weight": 1
        }
    ]
};

stabilityai:ImageRes listResult = check stabilityaiClient->/v1/generation/["stable-diffusion-v1"]/text\-to\-image.post(payload);

listResult.artifacts.forEach(function(stabilityai:Image image) {
    string? imageBytesString = image.'base64;
    if imageBytesString is () {
        io:println("Image byte string is Empty");
        return;
    }
    byte[] imageBytes = imageBytesString.toBytes();
    var base64Decode = mime:base64Decode(imageBytes);
    if base64Decode is error {
        io:println("Error: ", base64Decode);
        return;
    }
    if base64Decode is byte[] {
        io:Error? fileWrite = io:fileWriteBytes("./output.png", base64Decode);
        if fileWrite is io:Error {
            io:println("Error: ", fileWrite);
        }
    }
});
  1. Use bal run command to compile and run the Ballerina program.

Import

import ballerinax/stabilityai;Copy

Metadata

Released date: over 1 year ago

Version: 1.0.1

License: Apache-2.0


Compatibility

Platform: any

Ballerina version: 2201.4.1

GraalVM compatible: Yes


Pull count

Total: 6

Current verison: 3


Weekly downloads


Source repository


Keywords

AI/Images

Vendor/Stability AI

Cost/Paid

Stable Diffusion


Contributors

Other versions

1.0.1

1.0.0