client

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2024 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetPngMetadata

func GetPngMetadata(r io.Reader) (map[string]string, error)

Types

type ComfyClient

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

ComfyClient is the top level object that allows for interaction with the ComfyUI backend

func NewComfyClient

func NewComfyClient(server_address string, server_port int, callbacks *ComfyClientCallbacks) *ComfyClient

NewComfyClient creates a new instance of a Comfy2go client

func NewComfyClientWithTimeout

func NewComfyClientWithTimeout(server_address string, server_port int, callbacks *ComfyClientCallbacks, timeout int, retry int) *ComfyClient

NewComfyClientWithTimeout creates a new instance of a Comfy2go client with a connection timeout

func (*ComfyClient) CheckConnection

func (c *ComfyClient) CheckConnection() error

CheckConnection checks if the websocket connection is still active and tries to reinitialize if not

func (*ComfyClient) ClientID

func (c *ComfyClient) ClientID() string

ClientID returns the unique client ID for the connection to the ComfyUI backend

func (*ComfyClient) EraseHistory

func (c *ComfyClient) EraseHistory() error

func (*ComfyClient) EraseHistoryItem

func (c *ComfyClient) EraseHistoryItem(promptID string) error

func (*ComfyClient) GetEmbeddings

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

GetEmbeddings retrieves the list of Embeddings models installed on the ComfyUI server.

func (*ComfyClient) GetExtensions

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

GetExtensions retrieves the list of extensions installed on the ComfyUI server.

func (*ComfyClient) GetImage

func (c *ComfyClient) GetImage(image_data DataOutput) (*[]byte, error)

GetImage

func (*ComfyClient) GetObjectInfos

func (c *ComfyClient) GetObjectInfos() (*graphapi.NodeObjects, error)

func (*ComfyClient) GetPromptHistoryByID

func (c *ComfyClient) GetPromptHistoryByID() (map[string]PromptHistoryItem, error)

func (*ComfyClient) GetPromptHistoryByIndex

func (c *ComfyClient) GetPromptHistoryByIndex() ([]PromptHistoryItem, error)

func (*ComfyClient) GetQueueExecutionInfo

func (c *ComfyClient) GetQueueExecutionInfo() (*QueueExecInfo, error)

func (*ComfyClient) GetQueuedItem

func (c *ComfyClient) GetQueuedItem(prompt_id string) *QueueItem

GetQueuedItem returns a QueueItem that was queued with the ComfyClient, that has not been processed yet or is currently being processed. Once a QueueItem has been processed, it will not be available with this method.

func (*ComfyClient) GetSharedNodeObject added in v1.0.4

func (c *ComfyClient) GetSharedNodeObject() *graphapi.NodeObjects

func (*ComfyClient) GetSystemStats

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

func (*ComfyClient) GetViewMetadata

func (c *ComfyClient) GetViewMetadata(folder string, file string) (string, error)

GetViewMetadata retrieves the '__metadata__' field in a safetensors file. checkpoints vae loras clip unet controlnet style_models clip_vision gligen configs hypernetworks upscale_models onnx fonts

func (*ComfyClient) Init

func (c *ComfyClient) Init() error

Init starts the websocket connection (if not already connected) and retrieves the collection of node objects

func (*ComfyClient) Interrupt

func (c *ComfyClient) Interrupt() error

func (*ComfyClient) IsInitialized

func (c *ComfyClient) IsInitialized() bool

IsInitialized returns true if the client's websocket is connected and initialized

func (*ComfyClient) NewGraphFromJsonFile

func (c *ComfyClient) NewGraphFromJsonFile(path string) (*graphapi.Graph, *[]string, error)

NewGraphFromJsonFile creates a new graph from a JSON file

func (*ComfyClient) NewGraphFromJsonReader

func (c *ComfyClient) NewGraphFromJsonReader(r io.Reader) (*graphapi.Graph, *[]string, error)

NewGraphFromJsonReader creates a new graph from the data read from an io.Reader

func (*ComfyClient) NewGraphFromJsonString

func (c *ComfyClient) NewGraphFromJsonString(path string) (*graphapi.Graph, *[]string, error)

NewGraphFromJsonString creates a new graph from a JSON string

func (*ComfyClient) NewGraphFromPNGFile

func (c *ComfyClient) NewGraphFromPNGFile(path string) (*graphapi.Graph, *[]string, error)

NewGraphFromPNGReader extracts the workflow from PNG data read from a file and creates a new graph

func (*ComfyClient) NewGraphFromPNGReader

func (c *ComfyClient) NewGraphFromPNGReader(r io.Reader) (*graphapi.Graph, *[]string, error)

NewGraphFromPNGReader extracts the workflow from PNG data read from an io.Reader and creates a new graph

func (*ComfyClient) OnMessage

func (cc *ComfyClient) OnMessage(message string)

func (*ComfyClient) OnWindowSocketMessage

func (c *ComfyClient) OnWindowSocketMessage(msg string)

OnWindowSocketMessage processes each message received from the websocket connection to ComfyUI. The messages are parsed, and translated into PromptMessage structs and placed into the correct QueuedItem's message channel.

func (*ComfyClient) QueuePrompt

func (c *ComfyClient) QueuePrompt(graph *graphapi.Graph) (*QueueItem, error)

func (*ComfyClient) SetSharedNodeObject added in v1.0.3

func (c *ComfyClient) SetSharedNodeObject(sharedNodeObject *graphapi.NodeObjects)

func (*ComfyClient) UploadFileFromPath

func (c *ComfyClient) UploadFileFromPath(filePath string, overwrite bool, filetype ImageType, subfolder string, targetProperty *graphapi.ImageUploadProperty) (string, error)

func (*ComfyClient) UploadFileFromReader

func (c *ComfyClient) UploadFileFromReader(r io.Reader, filename string, overwrite bool, filetype ImageType, subfolder string, targetProperty *graphapi.ImageUploadProperty) (string, error)

func (*ComfyClient) UploadImage

func (c *ComfyClient) UploadImage(img image.Image, filename string, overwrite bool, filetype ImageType, subfolder string, targetProperty *graphapi.ImageUploadProperty) (string, error)

type ComfyClientCallbacks

type ComfyClientCallbacks struct {
	ClientQueueCountChanged func(*ComfyClient, int)
	QueuedItemStarted       func(*ComfyClient, *QueueItem)
	QueuedItemStopped       func(*ComfyClient, *QueueItem, QueuedItemStoppedReason)
	QueuedItemDataAvailable func(*ComfyClient, *QueueItem, *PromptMessageData)
}

type DataOutput

type DataOutput struct {
	Filename  string `json:"filename"`
	Subfolder string `json:"subfolder"`
	Type      string `json:"type"`
	Text      string `json:"-"` // for "text" type data output
}

type GPU

type GPU struct {
	Name             string `json:"name"`
	Type             string `json:"type"`
	Index            int    `json:"index"`
	VRAM_Total       int64  `json:"vram_total"`
	VRAM_Free        int64  `json:"vram_free"`
	Torch_VRAM_Total int64  `json:"torch_vram_total"`
	Torch_VRAM_Free  int64  `json:"torch_vram_free"`
}

type ImageType

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

type PromptError

type PromptError struct {
	Type      string                 `json:"type"`
	Message   string                 `json:"message"`
	Details   string                 `json:"details"`
	ExtraInfo map[string]interface{} `json:"extra_info"`
}

type PromptErrorMessage

type PromptErrorMessage struct {
	Error      PromptError   `json:"error"`
	NodeErrors []interface{} `json:"node_errors"`
}

type PromptHistoryItem

type PromptHistoryItem struct {
	PromptID string
	Index    int
	Graph    *graphapi.Graph
	Outputs  map[int][]DataOutput
}

type PromptMessage

type PromptMessage struct {
	Type    string
	Message interface{}
}

func (*PromptMessage) ToPromptMessageData

func (p *PromptMessage) ToPromptMessageData() *PromptMessageData

func (*PromptMessage) ToPromptMessageExecuting

func (p *PromptMessage) ToPromptMessageExecuting() *PromptMessageExecuting

func (*PromptMessage) ToPromptMessageProgress

func (p *PromptMessage) ToPromptMessageProgress() *PromptMessageProgress

func (*PromptMessage) ToPromptMessageQueued

func (p *PromptMessage) ToPromptMessageQueued() *PromptMessageQueued

func (*PromptMessage) ToPromptMessageStarted

func (p *PromptMessage) ToPromptMessageStarted() *PromptMessageStarted

func (*PromptMessage) ToPromptMessageStopped

func (p *PromptMessage) ToPromptMessageStopped() *PromptMessageStopped

type PromptMessageData

type PromptMessageData struct {
	NodeID int
	Data   map[string][]DataOutput
}

type PromptMessageExecuting

type PromptMessageExecuting struct {
	NodeID int
	Title  string
}

type PromptMessageProgress

type PromptMessageProgress struct {
	Max   int
	Value int
}

type PromptMessageQueued

type PromptMessageQueued struct {
}

type PromptMessageStarted

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

type PromptMessageStopped

type PromptMessageStopped struct {
	QueueItem *QueueItem
	Exception *PromptMessageStoppedException
}

type PromptMessageStoppedException

type PromptMessageStoppedException struct {
	NodeID           int
	NodeType         string
	NodeName         string
	ExceptionMessage string
	ExceptionType    string
	Traceback        []string
}

type QueueExecInfo

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

type QueueItem

type QueueItem struct {
	PromptID   string                 `json:"prompt_id"`
	Number     int                    `json:"number"`
	NodeErrors map[string]interface{} `json:"node_errors"`
	Messages   chan PromptMessage     `json:"-"`
	Workflow   *graphapi.Graph        `json:"-"`
}

type QueuedItemStoppedReason

type QueuedItemStoppedReason string
const (
	QueuedItemStoppedReasonFinished    QueuedItemStoppedReason = "finished"
	QueuedItemStoppedReasonInterrupted QueuedItemStoppedReason = "interrupted"
	QueuedItemStoppedReasonError       QueuedItemStoppedReason = "error"
)

type System

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

type SystemStats

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

type WSMessageDataExecuted

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

func (*WSMessageDataExecuted) UnmarshalJSON

func (mde *WSMessageDataExecuted) UnmarshalJSON(b []byte) error

type WSMessageDataExecuting

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

func (*WSMessageDataExecuting) UnmarshalJSON

func (mde *WSMessageDataExecuting) UnmarshalJSON(b []byte) error

type WSMessageDataExecutionCached

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

type WSMessageDataExecutionStart

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

type WSMessageDataProgress

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

type WSMessageDataStatus

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

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"`
	Node     string   `json:"node_id"`
	NodeType string   `json:"node_type"`
	Executed []string `json:"executed"`
}

type WSStatusMessage

type WSStatusMessage struct {
	Type string      `json:"type"`
	Data interface{} `json:"Data"`
}

func (*WSStatusMessage) UnmarshalJSON

func (sm *WSStatusMessage) UnmarshalJSON(b []byte) error

type WebSocketCallback

type WebSocketCallback interface {
	OnMessage(message string)
}

Callback interface for handling incoming WebSocket messages

type WebSocketConnection

type WebSocketConnection struct {
	WebSocketURL   string
	Conn           *websocket.Conn
	ConnectionDone chan bool
	IsConnected    bool
	MaxRetry       int
	RetryCount     int
	ManagerStarted bool

	Callback WebSocketCallback

	// Exponential backoff configuration
	BaseDelay time.Duration // The initial delay, e.g., 1 second
	MaxDelay  time.Duration // The maximum delay, e.g., 1 minute
	// contains filtered or unexported fields
}

func (*WebSocketConnection) ConnectWithManager

func (w *WebSocketConnection) ConnectWithManager(timeoutSeconds int) error

ConnectWithManager connects to the WebSocket using a connection manager timeoutSeconds is the maximum time to wait for a successful connection (0 for no timeout)

func (*WebSocketConnection) LockRead

func (w *WebSocketConnection) LockRead()

func (*WebSocketConnection) Ping

func (w *WebSocketConnection) Ping() error

func (*WebSocketConnection) UnlockRead

func (w *WebSocketConnection) UnlockRead()

Jump to

Keyboard shortcuts

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