wanx

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DashScopeBaseURL  = "https://dashscope.aliyuncs.com"
	ImageSynthesisURI = "/api/v1/services/aigc/text2image/image-synthesis"
	TaskURI           = "/api/v1/tasks/%s"
)

Variables

View Source
var (
	ErrEmptyResponse = errors.New("empty response")
	ErrEmptyTaskID   = errors.New("task id is empty")
	ErrTaskUnsuccess = errors.New("task is not success")
	ErrModelNotSet   = errors.New("model is not set")
)

Functions

func ImageSynthesisURL

func ImageSynthesisURL() string

func TaskURL

func TaskURL(taskID string) string

Types

type ImageResponse

type ImageResponse struct {
	StatusCode int    `json:"status_code"`
	RequestID  string `json:"request_id"`
	Code       string `json:"code"`
	Message    string `json:"message"`
	Output     Output `json:"output"`
	Usage      Usage  `json:"usage"`
}

func AsyncCall

calling tongyi-wanx-api to get image-generation async task id.

type ImageSynthesisInput

type ImageSynthesisInput struct {
	Prompt        string `json:"prompt"`
	NegativePromp string `json:"negative_promp,omitempty"`
}

type ImageSynthesisParams

type ImageSynthesisParams struct {
	/*
	  The style of the output image, currently supports the following style values:
	  "<auto>" default,
	  "<3d cartoon>" 3D cartoon,
	  "<anime>" animation,
	  "<oil painting>" oil painting,
	  "<watercolor>" watercolor,
	  "<sketch>" sketch,
	  "<chinese painting>" Chinese painting,
	  "<flat illustration>" flat illustration,
	*/
	Style string `json:"style,omitempty"`
	/*
	  The resolution of the generated image,
	  currently only supports '1024*1024', '720*1280', '1280*720' three resolutions,
	  default is 1024*1024 pixels.
	*/
	Size string `json:"size,omitempty"`
	// The number of images generated, currently supports 1~4, default is 1.
	N int `json:"n,omitempty"`
	// seed.
	Seed int `json:"seed,omitempty"`
}

type ImageSynthesisRequest

type ImageSynthesisRequest struct {
	Model    string               `json:"model"`
	Input    ImageSynthesisInput  `json:"input"`
	Params   ImageSynthesisParams `json:"parameters"`
	Download bool                 `json:"-"`
}

type ImgBlob

type ImgBlob struct {
	//	types include: "image/png".
	ImgType string `json:"img_type"`
	ImgURL  string `json:"img_url"`
	// Raw bytes for media formats.
	Data []byte `json:"-"`
}

func CreateImageGeneration

func CreateImageGeneration(ctx context.Context, payload *ImageSynthesisRequest, httpcli httpclient.IHttpClient, token string) ([]*ImgBlob, error)

type ModelWanx

type ModelWanx = string
const (
	WanxV1             ModelWanx = "wanx-v1"
	WanxStyleRepaintV1 ModelWanx = "wanx-style-repaint-v1"
	WanxBgGenV2        ModelWanx = "wanx-background-generation-v2"
)

type Output

type Output struct {
	TaskID     string `json:"task_id"`
	TaskStatus string `json:"task_status"`
	Results    []struct {
		URL string `json:"url"`
	} `json:"results"`
	TaskMetrics struct {
		Total     int `json:"TOTAL"`
		Succeeded int `json:"SUCCEEDED"`
		Failed    int `json:"FAILED"`
	} `json:"task_metrics"`
}

func SyncCall

func SyncCall(ctx context.Context, req *ImageSynthesisRequest, httpcli httpclient.IHttpClient, options ...httpclient.HTTPOption) (*Output, error)

tongyi-wanx-api only support AsyncCall, so we need to warp it to be Sync.

type TaskRequest

type TaskRequest struct {
	TaskID string `json:"task_id"`
}

type TaskResponse

type TaskResponse struct {
	RequestID string `json:"request_id"`
	Output    Output `json:"output"`
	Usage     Usage  `json:"usage"`
}

func CheckTaskStatus

func CheckTaskStatus(ctx context.Context, req *TaskRequest, httpcli httpclient.IHttpClient, options ...httpclient.HTTPOption) (*TaskResponse, error)

type TaskStatus

type TaskStatus string
const (
	TaskSucceeded TaskStatus = "SUCCEEDED"
	TaskFailed    TaskStatus = "FAILED"
	TaskCanceled  TaskStatus = "CANCELED"
	TaskPending   TaskStatus = "PENDING"
	TaskSuspended TaskStatus = "SUSPENDED"
	TaskRunning   TaskStatus = "RUNNING"
)

type Usage

type Usage struct {
	ImageCount int `json:"image_count"`
}

Jump to

Keyboard shortcuts

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