graphapi

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2024 License: MIT Imports: 11 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseProperty

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

func (*BaseProperty) AttachSecondaryProperty

func (b *BaseProperty) AttachSecondaryProperty(p Property)

func (*BaseProperty) GetAlias added in v0.6.0

func (b *BaseProperty) GetAlias() string

func (*BaseProperty) GetTargetNode

func (b *BaseProperty) GetTargetNode() *GraphNode

func (*BaseProperty) GetTargetWidget

func (b *BaseProperty) GetTargetWidget() int

func (*BaseProperty) GetValue

func (b *BaseProperty) GetValue() interface{}

func (*BaseProperty) Index

func (b *BaseProperty) Index() int

func (*BaseProperty) Serializable

func (b *BaseProperty) Serializable() bool

func (*BaseProperty) SetAlias added in v0.6.0

func (b *BaseProperty) SetAlias(a string)

func (*BaseProperty) SetDirectValue added in v0.5.0

func (b *BaseProperty) SetDirectValue(v *interface{})

func (*BaseProperty) SetIndex added in v0.2.0

func (b *BaseProperty) SetIndex(index int)

func (*BaseProperty) SetSerializable

func (b *BaseProperty) SetSerializable(val bool)

func (*BaseProperty) SetTargetWidget

func (b *BaseProperty) SetTargetWidget(node *GraphNode, index int)

func (*BaseProperty) SetValue

func (b *BaseProperty) SetValue(v interface{}) error

SetValue calls the protocol implementation for valueFromString to get the actual value that will be set. valueFromString should perform conversion to its native type and constrain it when needed

func (*BaseProperty) TargetIndex added in v0.2.0

func (b *BaseProperty) TargetIndex() int

func (*BaseProperty) ToBoolProperty

func (b *BaseProperty) ToBoolProperty() (*BoolProperty, bool)

func (*BaseProperty) ToCascadeProperty added in v0.4.0

func (b *BaseProperty) ToCascadeProperty() (*CascadingProperty, bool)

func (*BaseProperty) ToComboProperty

func (b *BaseProperty) ToComboProperty() (*ComboProperty, bool)

func (*BaseProperty) ToFloatProperty

func (b *BaseProperty) ToFloatProperty() (*FloatProperty, bool)

func (*BaseProperty) ToImageUploadProperty

func (b *BaseProperty) ToImageUploadProperty() (*ImageUploadProperty, bool)

func (*BaseProperty) ToIntProperty

func (b *BaseProperty) ToIntProperty() (*IntProperty, bool)

func (*BaseProperty) ToStringProperty

func (b *BaseProperty) ToStringProperty() (*StringProperty, bool)

func (*BaseProperty) ToUnknownProperty

func (b *BaseProperty) ToUnknownProperty() (*UnknownProperty, bool)

func (*BaseProperty) UpdateParent

func (b *BaseProperty) UpdateParent(parent Property)

type BoolProperty

type BoolProperty struct {
	BaseProperty
	Default  bool
	LabelOn  string
	LabelOff string
}

func (*BoolProperty) Name

func (p *BoolProperty) Name() string

func (*BoolProperty) Optional

func (p *BoolProperty) Optional() bool

func (*BoolProperty) Settable

func (p *BoolProperty) Settable() bool

func (*BoolProperty) TypeString

func (p *BoolProperty) TypeString() string

type ByGraphOrdinal

type ByGraphOrdinal []*GraphNode

allow us to order nodes by thier execution order (ordinality)

func (ByGraphOrdinal) Len

func (a ByGraphOrdinal) Len() int

func (ByGraphOrdinal) Less

func (a ByGraphOrdinal) Less(i, j int) bool

func (ByGraphOrdinal) Swap

func (a ByGraphOrdinal) Swap(i, j int)

type CascadeGroup added in v0.4.0

type CascadeGroup struct {
	Name    string
	Entries []CasdcadeEntry
}

func (*CascadeGroup) Properties added in v0.4.0

func (c *CascadeGroup) Properties() []Property

type CascadingProperty added in v0.4.0

type CascadingProperty struct {
	BaseProperty
	Groups         []CascadeGroup
	SelectionIndex string
}

func (*CascadingProperty) GetGroupByName added in v0.4.0

func (p *CascadingProperty) GetGroupByName(name string) *CascadeGroup

func (*CascadingProperty) GroupNames added in v0.4.0

func (p *CascadingProperty) GroupNames() []string

func (*CascadingProperty) Name added in v0.4.0

func (p *CascadingProperty) Name() string

func (*CascadingProperty) Optional added in v0.4.0

func (p *CascadingProperty) Optional() bool

func (*CascadingProperty) Settable added in v0.4.0

func (p *CascadingProperty) Settable() bool

func (*CascadingProperty) TypeString added in v0.4.0

func (p *CascadingProperty) TypeString() string

type CasdcadeEntry added in v0.4.0

type CasdcadeEntry struct {
	Name     string
	Property *Property
}

type ComboProperty

type ComboProperty struct {
	BaseProperty
	Values []string
	IsBool bool
}

func (*ComboProperty) Append

func (p *ComboProperty) Append(newValue string)

Append will add the new value to the combo if it's not already available, and then sets the target property to the given value

func (*ComboProperty) Name

func (p *ComboProperty) Name() string

func (*ComboProperty) Optional

func (p *ComboProperty) Optional() bool

func (*ComboProperty) Settable

func (p *ComboProperty) Settable() bool

func (*ComboProperty) TypeString

func (p *ComboProperty) TypeString() string

type FloatProperty

type FloatProperty struct {
	BaseProperty
	Default float64
	Min     float64
	Max     float64
	Step    float64
	// contains filtered or unexported fields
}

func (*FloatProperty) HasRange

func (p *FloatProperty) HasRange() bool

func (*FloatProperty) HasStep

func (p *FloatProperty) HasStep() bool

func (*FloatProperty) Name

func (p *FloatProperty) Name() string

func (*FloatProperty) Optional

func (p *FloatProperty) Optional() bool

func (*FloatProperty) Settable

func (p *FloatProperty) Settable() bool

func (*FloatProperty) TypeString

func (p *FloatProperty) TypeString() string

type Graph

type Graph struct {
	Nodes                 []*GraphNode       `json:"nodes"`
	Links                 []*Link            `json:"links"`
	Groups                []*Group           `json:"groups"`
	LastNodeID            int                `json:"last_node_id"`
	LastLinkID            int                `json:"last_link_id"`
	Version               float32            `json:"version"`
	NodesByID             map[int]*GraphNode `json:"-"`
	LinksByID             map[int]*Link      `json:"-"`
	NodesInExecutionOrder []*GraphNode       `json:"-"`
	HasErrors             bool               `json:"-"`
}

func NewGraphFromJsonFile

func NewGraphFromJsonFile(path string, node_objects *NodeObjects) (*Graph, *[]string, error)

func NewGraphFromJsonReader

func NewGraphFromJsonReader(r io.Reader, node_objects *NodeObjects) (*Graph, *[]string, error)

func NewGraphFromJsonString added in v0.3.0

func NewGraphFromJsonString(data string, node_objects *NodeObjects) (*Graph, *[]string, error)

func (*Graph) CreateNodeProperties

func (t *Graph) CreateNodeProperties(node_objects *NodeObjects) *[]string

CreateNodeProperties generates the properties required to allow setting values

Parameters:

  • node_objects: NodeObjects returned from server

Returns:

  • A pointer to an array of strings containing any missing nodes in the node_objects

func (*Graph) GetFirstNodeWithTitle

func (t *Graph) GetFirstNodeWithTitle(title string) *GraphNode

GetFirstNodeWithTitle retrieves the first node from the graph based on a given title. If a node's title is not set, it falls back to matching against the node's display name.

Parameters:

  • title: The title (or display name if title is absent) to filter nodes by.

Returns:

  • A pointer to a GraphNode

func (*Graph) GetGroupWithTitle

func (t *Graph) GetGroupWithTitle(title string) *Group

GetGroupWithTitle returns the 'first' group with the given title

func (*Graph) GetLinkById

func (t *Graph) GetLinkById(id int) *Link

func (*Graph) GetNodeById

func (t *Graph) GetNodeById(id int) *GraphNode

func (*Graph) GetNodesInGroup

func (t *Graph) GetNodesInGroup(g *Group) []*GraphNode

func (*Graph) GetNodesWithTitle

func (t *Graph) GetNodesWithTitle(title string) []*GraphNode

GetNodesWithTitle retrieves nodes from the graph based on a given title. If a node's title is not set, it falls back to matching against the node's display name.

Parameters:

  • title: The title (or display name if title is absent) to filter nodes by.

Returns:

  • A slice of pointers to GraphNodes that match the specified title or display name.

func (*Graph) GetNodesWithType

func (t *Graph) GetNodesWithType(nodeType string) []*GraphNode

GetNodesWithType retrieves all nodes in the graph that match a specified type.

Parameters:

  • nodeType: The type of node to filter by.

Returns:

  • A slice of pointers to GraphNodes that match the specified type.

func (*Graph) GetSimpleAPI

func (t *Graph) GetSimpleAPI(title *string) *SimpleAPI

GetSimpleAPI returns an instance of SimpleAPI SimpleAPI is a collection of nodes in the graph that are contained within a group with the given title. When title is nil, the default "API" group will be used

func (*Graph) GraphToJSON added in v0.4.0

func (t *Graph) GraphToJSON() (string, error)

func (*Graph) GraphToPrompt

func (t *Graph) GraphToPrompt(clientID string) (Prompt, error)

func (*Graph) ProcessSettableProperties added in v0.4.0

func (t *Graph) ProcessSettableProperties(n *GraphNode, props *[]Property, pindex *int)

func (*Graph) SaveGraphToFile added in v0.4.0

func (t *Graph) SaveGraphToFile(path string) error

func (*Graph) UnmarshalJSON

func (t *Graph) UnmarshalJSON(b []byte) error

type GraphNode

type GraphNode struct {
	ID                 int                     `json:"id"`
	Type               string                  `json:"type"`
	Position           interface{}             `json:"pos"`
	Size               Size                    `json:"size"`
	Flags              *interface{}            `json:"flags"`
	Order              int                     `json:"order"`
	Mode               int                     `json:"mode"`
	Title              string                  `json:"title"`
	InternalProperties *map[string]interface{} `json:"properties"` // node properties, not value properties!
	// widgets_values can be an array of values, or a map of values
	// maps of values can represent cascading style properties in which the setting
	// of one property makes certain other properties available
	WidgetValues interface{}         `json:"widgets_values"`
	Color        string              `json:"color"`
	BGColor      string              `json:"bgcolor"`
	Inputs       []Slot              `json:"inputs,omitempty"`
	Outputs      []Slot              `json:"outputs,omitempty"`
	Graph        *Graph              `json:"-"`
	CustomData   *interface{}        `json:"-"`
	Widgets      []*Widget           `json:"-"`
	Properties   map[string]Property `json:"-"`
	DisplayName  string              `json:"-"`
	Description  string              `json:"-"`
	IsOutput     bool                `json:"-"`
}

GraphNode represents the encapsulation of an individual functionality within a Graph

func (*GraphNode) ApplyToGraph

func (n *GraphNode) ApplyToGraph()
func (n *GraphNode) GetInputLink(slotIndex int) *Link

func (*GraphNode) GetInputWithName

func (n *GraphNode) GetInputWithName(name string) *Slot
func (n *GraphNode) GetLinks() []int

GetLinks returns a slice of Link Ids

func (*GraphNode) GetNodeForInput

func (n *GraphNode) GetNodeForInput(slotIndex int) *GraphNode

func (*GraphNode) GetPropertiesByIndex added in v0.5.0

func (n *GraphNode) GetPropertiesByIndex() []Property

GetPropertesByIndex returns a slice of Properties ordered by thier order in the node desciption Because a properties index is for it's index in the node description, and not the index of the property in the node's properties, non-indexed properties will be nil in the returned slice

func (*GraphNode) GetPropertyWithName

func (n *GraphNode) GetPropertyWithName(name string) Property

func (*GraphNode) IsVirtual

func (n *GraphNode) IsVirtual() bool

func (*GraphNode) IsWidgetValueArray added in v0.4.0

func (n *GraphNode) IsWidgetValueArray() bool

func (*GraphNode) IsWidgetValueMap added in v0.4.0

func (n *GraphNode) IsWidgetValueMap() bool

func (*GraphNode) WidgetValueCount added in v0.4.0

func (n *GraphNode) WidgetValueCount() int

func (*GraphNode) WidgetValuesArray added in v0.4.0

func (n *GraphNode) WidgetValuesArray() []interface{}

func (*GraphNode) WidgetValuesMap added in v0.4.0

func (n *GraphNode) WidgetValuesMap() map[string]interface{}

type Group

type Group struct {
	Title    string `json:"title"`
	Bounding []int  `json:"bounding"`
	Color    string `json:"color"`
}

func (*Group) IntersectsOrContains

func (r *Group) IntersectsOrContains(node *GraphNode) bool

type ImageUploadProperty

type ImageUploadProperty struct {
	BaseProperty
	TargetProperty *ComboProperty
}

func (*ImageUploadProperty) Name

func (p *ImageUploadProperty) Name() string

func (*ImageUploadProperty) Optional

func (p *ImageUploadProperty) Optional() bool

func (*ImageUploadProperty) SetFilename

func (p *ImageUploadProperty) SetFilename(filename string)

func (*ImageUploadProperty) Settable

func (p *ImageUploadProperty) Settable() bool

func (*ImageUploadProperty) TypeString

func (p *ImageUploadProperty) TypeString() string

type IntProperty

type IntProperty struct {
	BaseProperty
	Default int64
	Min     int64 // optional
	Max     int64 // optional
	Step    int64 // optional
	// contains filtered or unexported fields
}

func (*IntProperty) HasRange

func (p *IntProperty) HasRange() bool

func (*IntProperty) HasStep

func (p *IntProperty) HasStep() bool

func (*IntProperty) Name

func (p *IntProperty) Name() string

func (*IntProperty) Optional

func (p *IntProperty) Optional() bool

func (*IntProperty) Settable

func (p *IntProperty) Settable() bool

func (*IntProperty) TypeString

func (p *IntProperty) TypeString() string
type Link struct {
	ID         int
	OriginID   int
	OriginSlot int
	TargetID   int
	TargetSlot int
	Type       string
}

func (*Link) MarshalJSON

func (l *Link) MarshalJSON() ([]byte, error)

func (*Link) UnmarshalJSON

func (l *Link) UnmarshalJSON(b []byte) error

type NodeObject

type NodeObject struct {
	Input               *NodeObjectInput     `json:"input"`
	Output              *[]interface{}       `json:"output"` // output type
	OutputIsList        *[]bool              `json:"output_is_list"`
	OutputName          *interface{}         `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"`
	InputProperties     []*Property          `json:"-"`
	InputPropertiesByID map[string]*Property `json:"-"`
}

NodeObject represents the metadata that describes how to generate an instance of a node for a graph.

func (*NodeObject) GetSettableProperties

func (n *NodeObject) GetSettableProperties() []Property

GetSettablePropertiesByID returns a slice of Properties that are settable.

func (*NodeObject) GetSettablePropertiesByID

func (n *NodeObject) GetSettablePropertiesByID() map[string]Property

GetSettablePropertiesByID returns a map of Properties that are settable.

type NodeObjectInput

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

func (*NodeObjectInput) UnmarshalJSON

func (noi *NodeObjectInput) UnmarshalJSON(b []byte) error

NodeObjectInput custom UnmarshalJSON deserializtion maintains the order of the properties in the JSON

type NodeObjects

type NodeObjects struct {
	Objects map[string]*NodeObject
}

func (*NodeObjects) GetNodeObjectByName

func (n *NodeObjects) GetNodeObjectByName(name string) *NodeObject

func (*NodeObjects) PopulateInputProperties

func (n *NodeObjects) PopulateInputProperties()

type Pos

type Pos struct {
	X float64
	Y float64
}

func (*Pos) MarshalJSON

func (p *Pos) MarshalJSON() ([]byte, error)

func (*Pos) UnmarshalJSON

func (p *Pos) UnmarshalJSON(b []byte) error

type Prompt

type Prompt struct {
	ClientID  string             `json:"client_id"`
	Nodes     map[int]PromptNode `json:"prompt"`
	ExtraData PromptExtraData    `json:"extra_data"`
	PID       string             `json:"pid"`
}

Prompt is the data that is enqueued to an instance of ComfyUI

type PromptExtraData

type PromptExtraData struct {
	PngInfo PromptWorkflow `json:"extra_pnginfo"`
}

type PromptNode

type PromptNode struct {
	// Inputs can be one of:
	//	float64
	//	string
	//	[]interface{} where: [0] is string of target node
	//					     [1] is float64 (int) of slot index
	Inputs    map[string]interface{} `json:"inputs"`
	ClassType string                 `json:"class_type"`
}

type PromptWorkflow

type PromptWorkflow struct {
	Workflow *Graph `json:"workflow"`
}

PromptWorkflow is the original Graph that was used to create the Prompt. It is added to generated PNG files such that the information needed to recreate the image is available.

type Property

type Property interface {
	TypeString() string
	Optional() bool
	Settable() bool
	Name() string
	SetTargetWidget(node *GraphNode, index int)
	GetTargetWidget() int
	GetTargetNode() *GraphNode
	GetValue() interface{}
	SetValue(v interface{}) error
	Serializable() bool
	SetSerializable(bool)
	AttachSecondaryProperty(p Property)
	Index() int
	SetIndex(index int)
	TargetIndex() int
	SetAlias(string)
	GetAlias() string

	UpdateParent(parent Property)
	ToIntProperty() (*IntProperty, bool)
	ToFloatProperty() (*FloatProperty, bool)
	ToBoolProperty() (*BoolProperty, bool)
	ToStringProperty() (*StringProperty, bool)
	ToComboProperty() (*ComboProperty, bool)
	ToCascadeProperty() (*CascadingProperty, bool)
	ToImageUploadProperty() (*ImageUploadProperty, bool)
	ToUnknownProperty() (*UnknownProperty, bool)

	SetDirectValue(v *interface{})
	// contains filtered or unexported methods
}

Property is a node's input that can be a settable value Settable property types: "INT" an int64 "FLOAT" a float64 "STRING" a single line, or multiline string "COMBO" one of a given list of strings "BOOLEAN" a labeled bool value "IMAGEUPLOAD" image uploader "CASCADE" collection cascading style properties "UNKNOWN" everything else (unsettable)

func NewPropertyFromInput

func NewPropertyFromInput(input_name string, optional bool, input *interface{}, index int) *Property

type SimpleAPI

type SimpleAPI struct {
	Properties  map[string]Property
	OutputNodes []*GraphNode
}

type Size

type Size struct {
	Width  float64
	Height float64
}

func (*Size) MarshalJSON

func (s *Size) MarshalJSON() ([]byte, error)

it seems the json code can have either an array of values, or a dictionary of values when marshaling, we'll always output as an array.

func (*Size) UnmarshalJSON

func (s *Size) UnmarshalJSON(b []byte) error

type Slot

type Slot struct {
	Name       string     `json:"name"` // The name of the slot
	CustomType int        `json:"-"`
	Node       *GraphNode `json:"-"`                // The node the slot belongs to
	Type       string     `json:"type"`             // The type of the data the slot accepts
	Link       int        `json:"link,omitempty"`   // Index of the link for an input slot
	Links      *[]int     `json:"links,omitempty"`  // Array of links for output slots
	Widget     *Widget    `json:"widget,omitempty"` // Collection of widgets that allow setting properties
	Shape      *int       `json:"shape,omitempty"`
	SlotIndex  *int       `json:"slot_index,omitempty"` // Index of the Slot in relation to other Slots
	Property   Property   `json:"-"`                    // non-null for inputs that are exported widgets
}

Slot represents a connection point within a GraphNode. It holds various properties that define the behavior and appearance of the connection, such as the name, type, associated widget, and more.

type StringProperty

type StringProperty struct {
	BaseProperty
	Default   string
	Multiline bool
}

func (*StringProperty) Name

func (p *StringProperty) Name() string

func (*StringProperty) Optional

func (p *StringProperty) Optional() bool

func (*StringProperty) Settable

func (p *StringProperty) Settable() bool

func (*StringProperty) TypeString

func (p *StringProperty) TypeString() string

type UnknownProperty

type UnknownProperty struct {
	BaseProperty
	TypeName string
}

func (*UnknownProperty) Name

func (p *UnknownProperty) Name() string

func (*UnknownProperty) Optional

func (p *UnknownProperty) Optional() bool

func (*UnknownProperty) Settable

func (p *UnknownProperty) Settable() bool

func (*UnknownProperty) TypeString

func (p *UnknownProperty) TypeString() string

type Widget

type Widget struct {
	Name   *string      `json:"name"`
	Config *interface{} `json:"config"`
}

Widget represents the input points for setting properties within a Node

Jump to

Keyboard shortcuts

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