comfyUIclient

package module
v0.0.0-...-4efa6f0 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: MIT Imports: 15 Imported by: 0

README

ComfyUIClient

GitHub watchers GitHub stars GitHub forks GitHub last commit GitHub repo size GitHub license

English | 中文

Install

go get

go get -u github.com/XdpCs/comfyUIclient

go mod

require github.com/XdpCs/comfyUIclient

Support the ComfyUI API

  • POST /prompt => func QueuePromptByString, QueuePromptByNodes
  • POST /queue => func DeleteAllQueues, DeleteQueueByPromptID
  • POST /history => func DeleteAllHistories, DeleteHistoryByPromptID
  • POST /interrupt => func InterruptExecution
  • POST /upload/image => func UploadImage
  • POST /upload/mask => func UploadMask
  • GET /embeddings => func GetEmbeddings
  • GET /extensions => func GetExtensions
  • GET /view => func GetFile
  • GET /view_metadata/{folder_name} => func GetViewMetadata
  • GET /system_stats => func GetSystemStats
  • GET /prompt => func GetQueueRemaining
  • GET /history => func GetAllHistories
  • GET /history/{prompt_id} => func GetHistoryByPromptID
  • GET /queue => func GetQueueInfo
  • GET /object_info => func GetObjectInfos
  • GET /object_info/{node_class} => func GetObjectInfoByNodeName

Examples

All examples are in the examples directory.

License

ComfyUIClient is under the MIT. Please refer to LICENSE for more information.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

func NewClient

func NewClient(endPoint *EndPoint, httpClient *http.Client) *Client

func NewDefaultClient

func NewDefaultClient(endPoint *EndPoint) *Client

func NewDefaultClientStr

func NewDefaultClientStr(baseURL string) (*Client, error)

func (*Client) ConnectAndListen

func (c *Client) ConnectAndListen()

func (*Client) DeleteAllHistories

func (c *Client) DeleteAllHistories() error

DeleteAllHistories deletes all histories

func (*Client) DeleteAllQueues

func (c *Client) DeleteAllQueues() error

DeleteAllQueues deletes all prompts in queue Delete all prompts in queue with this client sent, or it will not work

func (*Client) DeleteHistoryByPromptID

func (c *Client) DeleteHistoryByPromptID(promptID string) error

DeleteHistoryByPromptID deletes history by promptID

func (*Client) DeleteQueueByPromptID

func (c *Client) DeleteQueueByPromptID(promptID string) error

DeleteQueueByPromptID deletes prompt in queue by promptID You must input promptID with this client sent, or it will not work

func (*Client) GetAllHistories

func (c *Client) GetAllHistories() ([]*PromptHistoryItem, error)

GetAllHistories returns all histories

func (*Client) GetEmbeddings

func (c *Client) GetEmbeddings() ([]string, error)

GetEmbeddings returns embeddings

func (*Client) GetExtensions

func (c *Client) GetExtensions() ([]string, error)

GetExtensions returns extensions for frontend

func (*Client) GetFile

func (c *Client) GetFile(image *DataOutputFile) (*[]byte, error)

GetFile returns file byte data

func (*Client) GetHistoryByPromptID

func (c *Client) GetHistoryByPromptID(promptID string) (*PromptHistoryItem, error)

GetHistoryByPromptID returns history info by promptID

func (*Client) GetObjectInfoByNodeName

func (c *Client) GetObjectInfoByNodeName(name string) (*NodeObject, error)

GetObjectInfoByNodeName returns node info by nodeName

func (*Client) GetObjectInfos

func (c *Client) GetObjectInfos() (map[string]*NodeObject, error)

GetObjectInfos returns node infos in workflow

func (*Client) GetQueueCount

func (c *Client) GetQueueCount() int

func (*Client) GetQueueInfo

func (c *Client) GetQueueInfo() (*QueueInfo, error)

GetQueueInfo returns queue info

func (*Client) GetQueueRemaining

func (c *Client) GetQueueRemaining() (uint64, error)

GetQueueRemaining returns queue remaining

func (*Client) GetSystemStats

func (c *Client) GetSystemStats() (*SystemStats, error)

GetSystemStats returns system stats

func (*Client) GetTaskStatus

func (c *Client) GetTaskStatus() chan *WSMessage

func (*Client) GetViewMetadata

func (c *Client) GetViewMetadata(folderName string, fileName string) ([]byte, error)

GetViewMetadata returns view metadata

func (*Client) Handle

func (c *Client) Handle(msg string) error

func (*Client) InterruptExecution

func (c *Client) InterruptExecution() error

InterruptExecution interrupts execution

func (*Client) IsInitialized

func (c *Client) IsInitialized() bool

func (*Client) QueuePromptByNodes

func (c *Client) QueuePromptByNodes(nodes map[string]PromptNode, extraDataString string) (*QueuePromptResp, error)

QueuePromptByNodes queues a prompt and starts execution by workflow which type is map[string]PromptNode extraData must be a json string

func (*Client) QueuePromptByString

func (c *Client) QueuePromptByString(workflow string, extraDataString string) (*QueuePromptResp, error)

QueuePromptByString queues a prompt and starts execution by workflow which type is string workflow must be a json string extraDataString must be a json string

func (*Client) SendTaskStatus

func (c *Client) SendTaskStatus(w *WSMessage) error

func (*Client) UploadImage

func (c *Client) UploadImage(reader io.Reader, fileName string, overwrite bool, filetype ImageType, subFolder string) (*UploadFile, error)

UploadImage uploads image

func (*Client) UploadMask

func (c *Client) UploadMask(reader io.Reader, fileName string, overwrite bool, filetype ImageType, subFolder string) (*UploadFile, error)

UploadMask uploads mask image

type DataOutputFile

type DataOutputFile struct {
	Filename  string `json:"filename"`
	SubFolder string `json:"subfolder"`
	Type      string `json:"type"`
}

DataOutputFile export data address, name and type

type EndPoint

type EndPoint struct {
	Protocol string
	Address  string
	Port     string
}

func NewEndPoint

func NewEndPoint(protocol, address, port string) *EndPoint

func (*EndPoint) String

func (e *EndPoint) String() string

type GPU

type GPU struct {
	Name           string `json:"name"`
	Type           string `json:"type"`
	Index          int    `json:"index"`
	VRAMTotal      int64  `json:"vram_total"`
	VRAMFree       int64  `json:"vram_free"`
	TorchVRAMTotal int64  `json:"torch_vram_total"`
	TorchVRAMFree  int64  `json:"torch_vram_free"`
}

GPU contains gpu info

type Handler

type Handler interface {
	Handle(string) error
}

type ImageType

type ImageType string
const (
	InputImageType  ImageType = "input"
	TempImageType   ImageType = "temp"
	OutputImageType ImageType = "output"
)

type NodeInfo

type NodeInfo struct {
	Num           uint64
	PromptID      string
	Prompt        map[string]PromptNode `json:"prompt"`
	ExtraData     json.RawMessage       // extra data is just for user's custom data
	OutputNodeIDs []string
}

NodeInfo contains the node info

func (*NodeInfo) UnmarshalJSON

func (n *NodeInfo) UnmarshalJSON(data []byte) error

type NodeObject

type NodeObject struct {
	Input        *NodeObjectInput `json:"input"`
	Output       []string         `json:"output"`
	OutputIsList []bool           `json:"output_is_list"`
	OutputName   []string         `json:"output_name"`
	Name         string           `json:"name"`
	DisplayName  string           `json:"display_name"`
	Description  string           `json:"description"`
	Category     string           `json:"category"`
	OutputNode   bool             `json:"output_node"`
}

NodeObject is a part of workflow

type NodeObjectInput

type NodeObjectInput struct {
	Required map[string]interface{} `json:"required"`
	Optional map[string]interface{} `json:"optional,omitempty"`
}

NodeObjectInput exposes the input information of a node

type PromptHistoryItem

type PromptHistoryItem struct {
	PromptID string
	PromptHistoryMember
}

PromptHistoryItem contains prompt id, WorkFlow, output info

type PromptHistoryMember

type PromptHistoryMember struct {
	NodeInfo *NodeInfo                            `json:"prompt"`
	Outputs  map[string]PromptHistoryMemberImages `json:"outputs"`
}

PromptHistoryMember is part of prompt history

type PromptHistoryMemberImages

type PromptHistoryMemberImages struct {
	Images *[]DataOutputFile `json:"images"`
}

type PromptNode

type PromptNode struct {
	Inputs    map[string]interface{} `json:"inputs"`
	ClassType string                 `json:"class_type"`
}

PromptNode is the data that inputs into ComfyUI

type QueueExecInfo

type QueueExecInfo struct {
	ExecInfo struct {
		QueueRemaining uint64 `json:"queue_remaining"`
	} `json:"exec_info"`
}

QueueExecInfo contains queue remaining number

type QueueInfo

type QueueInfo struct {
	QueueRunning []*NodeInfo `json:"queue_running"`
	QueuePending []*NodeInfo `json:"queue_pending"`
}

QueueInfo exposes the queue info

type QueuePromptResp

type QueuePromptResp struct {
	PromptID   string                 `json:"prompt_id"`
	Number     int                    `json:"number"`
	NodeErrors map[string]interface{} `json:"node_errors"`
}

QueuePromptResp contains prompt id, number and node errors

type Router

type Router string
const (
	PromptRouter       Router = "/prompt"
	HistoryRouter      Router = "/history"
	ViewRouter         Router = "/view"
	ViewMetadataRouter Router = "/view_metadata"
	EmbeddingsRouter   Router = "/embeddings"
	ExtensionsRouter   Router = "/extensions"
	SystemStatsRouter  Router = "/system_stats"
	InterruptRouter    Router = "/interrupt"
	QueueRouter        Router = "/queue"
	ObjectInfoRouter   Router = "/object_info"
	UploadImageRouter  Router = "/upload/image"
	UploadMaskRouter   Router = "/upload/mask"
)

type System

type System struct {
	OS             string `json:"os"`
	PythonVersion  string `json:"python_version"`
	EmbeddedPython bool   `json:"embedded_python"`
}

System contains system info

type SystemStats

type SystemStats struct {
	System  *System `json:"system"`
	Devices []*GPU  `json:"devices"`
}

SystemStats contains a system info and gpu infos

type TaskStatusType

type TaskStatusType = WsMessageType

type UploadFile

type UploadFile struct {
	Filename  string `json:"name"`
	SubFolder string `json:"subfolder"`
	Type      string `json:"type"`
}

UploadFile export data address, name and type

type WSMessage

type WSMessage struct {
	Type WsMessageType `json:"type"`
	Data interface{}   `json:"data"`
}

func (*WSMessage) UnmarshalJSON

func (m *WSMessage) UnmarshalJSON(b []byte) error

type WSMessageDataExecuted

type WSMessageDataExecuted struct {
	Node     string `json:"node"`
	PromptID string `json:"prompt_id"`
	Output   map[string][]*DataOutputFile
}

type WSMessageDataExecuting

type WSMessageDataExecuting struct {
	Node     string `json:"node"`
	PromptID string `json:"prompt_id"`
}

WSMessageDataExecuting json {"type": "executing", "data": {"node": "12", "prompt_id": "ed986d60-2a27-4d28-8871-2fdb36582902"}}

type WSMessageDataExecutionCached

type WSMessageDataExecutionCached struct {
	Nodes    []string `json:"nodes"`
	PromptID string   `json:"prompt_id"`
}

WSMessageDataExecutionCached json {"type": "execution_cached", "data": {"nodes": [], "prompt_id": "ed986d60-2a27-4d28-8871-2fdb36582902"}}

type WSMessageDataExecutionStart

type WSMessageDataExecutionStart struct {
	PromptID string `json:"prompt_id"`
}

WSMessageDataExecutionStart Json {"type": "execution_start", "data": {"prompt_id": "ed986d60-2a27-4d28-8871-2fdb36582902"}}

type WSMessageDataProgress

type WSMessageDataProgress struct {
	Value int `json:"value"`
	Max   int `json:"max"`
}

WSMessageDataProgress

{
  "type": "progress",
  "data": {
    "value": 18,
    "max": 20
  }
}

type WSMessageDataStatus

type WSMessageDataStatus struct {
	Status struct {
		ExecInfo struct {
			QueueRemaining int `json:"queue_remaining"`
		} `json:"exec_info"`
	} `json:"status"`
	SID string `json:"sid"`
}
WSMessageDataStatus

Json {"type": "status", "data": {"status": {"exec_info": {"queue_remaining": 1}}}}

type WSMessageExecutionError

type WSMessageExecutionError struct {
	PromptID         string                 `json:"prompt_id"`
	Node             string                 `json:"node_id"`
	NodeType         string                 `json:"node_type"`
	Executed         []string               `json:"executed"`
	ExceptionMessage string                 `json:"exception_message"`
	ExceptionType    string                 `json:"exception_type"`
	Traceback        []string               `json:"traceback"`
	CurrentInputs    map[string]interface{} `json:"current_inputs"`
	CurrentOutputs   map[int]interface{}    `json:"current_outputs"`
}

type WSMessageExecutionInterrupted

type WSMessageExecutionInterrupted struct {
	PromptID string   `json:"prompt_id"`
	NodeID   string   `json:"node_id"`
	NodeType string   `json:"node_type"`
	Executed []string `json:"executed"`
}

WSMessageExecutionInterrupted

{"type": "execution_interrupted", "data": {"prompt_id": "dc7093d7-980a-4fe6-bf0c-f6fef932c74b", "node_id": "19", "node_type": "SaveImage", "executed": ["5", "17", "10", "11"]}}

type WebSocketConnection

type WebSocketConnection struct {
	URL  string
	Conn *websocket.Conn

	MaxRetry int
	// contains filtered or unexported fields
}

func NewDefaultWebSocketConnection

func NewDefaultWebSocketConnection(url string, handler Handler) *WebSocketConnection

func NewWebSocketConnection

func NewWebSocketConnection(url string, maxRetry int, handler Handler) *WebSocketConnection

func (*WebSocketConnection) Close

func (w *WebSocketConnection) Close() error

func (*WebSocketConnection) Connect

func (w *WebSocketConnection) Connect() error

func (*WebSocketConnection) ConnectAndListen

func (w *WebSocketConnection) ConnectAndListen()

ConnectAndListen connects to the websocket and listens for messages

func (*WebSocketConnection) GetIsConnected

func (w *WebSocketConnection) GetIsConnected() bool

func (*WebSocketConnection) SetIsConnected

func (w *WebSocketConnection) SetIsConnected(iConnected bool)

type WsMessageType

type WsMessageType string
const (
	Status               WsMessageType = "status"
	Progress             WsMessageType = "progress"
	Executed             WsMessageType = "executed"
	Executing            WsMessageType = "executing"
	ExecutionStart       WsMessageType = "execution_start"
	ExecutionError       WsMessageType = "execution_error"
	ExecutionCached      WsMessageType = "execution_cached"
	ExecutionInterrupted WsMessageType = "execution_interrupted"
)

Jump to

Keyboard shortcuts

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