stability

package module
v0.0.0-...-99e9a5b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 23, 2023 License: MIT Imports: 5 Imported by: 0

README

Stability

Unofficial Go implemention for Stability AI REST API.

Usage

Get account information
package main

import (
	"fmt"
	"os"

	"github.com/wikylyu/stability"
)

func main() {
	ai := stability.New(&stability.Config{
		ApiKey:     os.Getenv("STABILITY_API_KEY"),
	})
	user, err := ai.User.GetAccount()
	if err != nil {
		panic(err)
	}
	fmt.Printf("ID: %s\n", user.ID)
	fmt.Printf("Email: %s\n", user.Email)
	fmt.Printf("Profile Pictures: %s\n", user.ProfilePicture)
	for _, org := range user.Organizations {
		fmt.Printf("\t Org Name: %s\n", org.Name)
	}
}

Text to image generation
package main

import (
	"fmt"
	"os"

	"github.com/wikylyu/stability"
	"github.com/wikylyu/stability/generation"
)

func main() {
	ai := stability.New(&stability.Config{
		ApiKey:     os.Getenv("STABILITY_API_KEY"),
	})

	textPrompts := []generation.TextPrompt{}
	textPrompts = append(textPrompts, generation.TextPrompt{
		Text:   "Surrounded by his loyal allies, The Mandalorian leads a daring mission across the galactic landscape. His determined presence and poised demeanor exemplify leadership and determination. The painting captures the cooperation and camaraderie of the group.",
		Weight: 0.5,
	})
	resp, err := ai.Generation.Text2Image("stable-diffusion-512-v2-1", &generation.Text2ImageRequest{
		TextPrompts: textPrompts,
		StylePreset: generation.StylePresetCinematic,
		Samples:     1,
	})
	if err != nil {
		panic(err)
	}
	for _, image := range resp.Artifacts {
		fmt.Printf("%s: %s\n", image.FinishReason, image.Base64)
	}
}

API List

  • user
    • account
    • balance
  • engines
    • list
  • generation
    • text-to-image
    • image-to-image
    • image-to-image/upscale
    • image-to-image/masking

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	BaseURL         string // endpoint, optional
	ApiKey          string // api key, required
	MaxIdleConns    int
	IdleConnTimeout time.Duration
	HttpsProxy      string
}

type Session

type Session struct {
	User       *user.UserClient
	Engine     *engine.EngineClient
	Generation *generation.GenerationClient
}

func New

func New(cfg *Config) *Session

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL