novitalabs/golang-sdk
Go
Captured source
source ↗published Sep 26, 2023seen 5dcaptured 9hhttp 200method plain
novitalabs/golang-sdk
Description: Golang SDK for Novita AI API (Txt2Img, Img2Img, ControlNet, VAE, LoRA)
Language: Go
License: MIT
Stars: 4
Forks: 3
Open issues: 0
Created: 2023-09-26T14:11:28Z
Pushed: 2023-11-21T04:10:37Z
Default branch: main
Fork: no
Archived: yes
README:
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/](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](./example/lora/main.go)
Model Search
Refer to [./example/model_search/main.go](./example/model_search/main.go)
ControlNet QRCode
Refer to [./example/qrcode/main.go](./example/qrcode/main.go)
Testing
API_KEY= go test ./...