Skip to content

novitalabs/golang-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Novita AI Golang SDK

This SDK is based on the official API documentation.

Join our discord server for help

Installation

go get -u github.com/novitalabs/golang-sdk

Quick Start

Get api key refer to https://novita.ai/get-started/

package main

import (
	"context"
	"fmt"
	"time"

	"github.com/novitalabs/golang-sdk/request"
	"github.com/novitalabs/golang-sdk/types"
)

func main() {
	// Get your API key refer to https://novita.ai/get-started/ .
	const apiKey = "Your-API-Key"
	client, err := request.NewClient(apiKey)
	if err != nil {
		fmt.Printf("new client failed, %v\n", err)
		return
	}
	ctx, cancel := context.WithTimeout(context.Background(), time.Minute*3)
	defer cancel()
	txt2ImgReq := types.NewTxt2ImgRequest("a dog flying in the sky", "", "AnythingV5_v5PrtRE.safetensors")
	res, err := client.SyncTxt2img(ctx, txt2ImgReq,
		request.WithSaveImage("out", 0777, func(taskId string, fileIndex int, fileName string) string {
			return "test_txt2img_sync.png"
		}))
	if err != nil {
		fmt.Printf("generate image failed, %v\n", err)
		return
	}
	for _, s3Url := range res.Data.Imgs {
		fmt.Printf("generate image url: %v\n", s3Url)
	}
}

Examples

Txt2Img with LoRA

Refer to ./example/lora/main.go

Model Search

Refer to ./example/model_search/main.go

ControlNet QRCode

Refer to ./example/qrcode/main.go

Testing

API_KEY=<your-key> go test ./...

About

Golang SDK for Stable Diffusion API (Txt2Img/Img2Img/LoRA/ControlNet/VAE).

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages