gocomfy

package module
v0.0.0-...-1b97063 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2024 License: MIT Imports: 23 Imported by: 0

README

ComfyUI client for Go

This package provides API client for ComfyUI.

Features:

  • Run arbitrary ComfyUI prompts.
  • Type-safe graph constructors for builtin ComfyUI node types.
  • Image upload and download. Handles cached images too!
  • Prompt execution events.

Example

See cmd/gocomfy/text_to_image.go.

License

MIT

Documentation

Index

Constants

View Source
const (
	ImageInput  = ImageType("input")
	ImageTemp   = ImageType("temp")
	ImageOutput = ImageType("output")
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(ctx context.Context, host string, opts ...ClientOption) (*Client, error)

func (*Client) CancelPrompts

func (c *Client) CancelPrompts(ctx context.Context, pids ...string) error

func (*Client) Close

func (c *Client) Close()

func (*Client) GetImage

func (c *Client) GetImage(ctx context.Context, ref ImageRef) (image.Image, error)

func (*Client) GetImageFile

func (c *Client) GetImageFile(ctx context.Context, ref ImageRef) (io.ReadCloser, error)

func (*Client) ID

func (c *Client) ID() string

func (*Client) ObjectsInfo

func (c *Client) ObjectsInfo(ctx context.Context) (classes.Classes, error)

func (*Client) ObjectsInfoRaw

func (c *Client) ObjectsInfoRaw(ctx context.Context) (io.ReadCloser, error)

func (*Client) Prompt

func (c *Client) Prompt(ctx context.Context, prompt *apigraph.Graph, opts ...PromptOption) (*Prompt, error)

func (*Client) PromptJSON

func (c *Client) PromptJSON(ctx context.Context, prompt json.RawMessage, opts ...PromptOption) (*Prompt, error)

func (*Client) PromptResults

func (c *Client) PromptResults(ctx context.Context, pid string) (Results, error)

func (*Client) RunPrompt

func (c *Client) RunPrompt(ctx context.Context, prompt *apigraph.Graph) (Results, error)

func (*Client) RunPromptJSON

func (c *Client) RunPromptJSON(ctx context.Context, prompt json.RawMessage) (Results, error)

func (*Client) StartPrompt

func (c *Client) StartPrompt(ctx context.Context, g *apigraph.Graph) (string, error)

func (*Client) StartPromptJSON

func (c *Client) StartPromptJSON(ctx context.Context, raw json.RawMessage) (string, error)

func (*Client) UploadImage

func (c *Client) UploadImage(ctx context.Context, ref ImageRef, img image.Image, overwrite bool) (*ImageRef, error)

func (*Client) UploadImageFile

func (c *Client) UploadImageFile(ctx context.Context, ref ImageRef, r io.Reader, overwrite bool) (*ImageRef, error)

type ClientOption

type ClientOption interface {
	// contains filtered or unexported methods
}

func WithHTTPClient

func WithHTTPClient(cli *http.Client) ClientOption

func WithOnQueueSize

func WithOnQueueSize(fnc func(queue int)) ClientOption

func WithWSDialer

func WithWSDialer(dialer *websocket.Dialer) ClientOption

func WithoutWebsocket

func WithoutWebsocket() ClientOption

type CommonOption

type CommonOption interface {
	ClientOption
}

func WithLog

func WithLog(log *slog.Logger) CommonOption

type Event

type Event interface {
	// contains filtered or unexported methods
}

type ExecCache

type ExecCache struct {
	Nodes []NodeID
}

type ExecDone

type ExecDone struct{}

type ExecStart

type ExecStart struct{}

type ImageRef

type ImageRef struct {
	Filename  string    `json:"filename"`
	Subfolder string    `json:"subfolder"`
	Type      ImageType `json:"type"`
}

func (ImageRef) AnnotatedPath

func (r ImageRef) AnnotatedPath() string

AnnotatedPath returns annotated path that is accepted by ComfyUI image load nodes.

type ImageType

type ImageType string

type NodeDone

type NodeDone struct {
	Node NodeID
	NodeResult
}

type NodeID

type NodeID = types.NodeID

type NodeProg

type NodeProg struct {
	Node  NodeID
	Value int
	Max   int
}

type NodeResult

type NodeResult struct {
	Images []ImageRef
}

type NodeStart

type NodeStart struct {
	Node NodeID
}

type Prompt

type Prompt struct {
	// contains filtered or unexported fields
}

func (*Prompt) Cancel

func (p *Prompt) Cancel(ctx context.Context) error

func (*Prompt) Close

func (p *Prompt) Close()

func (*Prompt) Events

func (p *Prompt) Events() <-chan Event

func (*Prompt) ID

func (p *Prompt) ID() string

func (*Prompt) Results

func (p *Prompt) Results(ctx context.Context) (Results, error)

type PromptOption

type PromptOption interface {
	// contains filtered or unexported methods
}

type Results

type Results map[types.NodeID]NodeResult

Directories

Path Synopsis
cmd
graph
internal

Jump to

Keyboard shortcuts

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