Documentation
¶
Index ¶
- Variables
- func OpenAiFunctions(tools []Tool) []openai.Tool
- func WithNumWorkers(n int) func(*GraphExecuteOptions)
- type Edge
- type Graph
- func (g *Graph) AddEdge(sourceHash, targetHash string) error
- func (g *Graph) AddNode(name string, node Node) error
- func (g *Graph) Edge(sourceHash string, targetHash string) (Edge, error)
- func (g *Graph) Execute(ctx context.Context, logger *zap.Logger, args map[string]any, ...) (map[string]map[string]any, error)
- func (g *Graph) Node(hash string) (Node, error)
- func (g *Graph) PredecessorMap() (map[string]map[string]Edge, error)
- func (g *Graph) SuccessorMap() (map[string]map[string]Edge, error)
- type GraphExecuteOptions
- type Node
- type Store
- type Tool
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrNodeNotFound = errors.New("vertex not found") ErrNodeAlreadyExists = errors.New("vertex already exists") ErrEdgeNotFound = errors.New("edge not found") ErrEdgeAlreadyExists = errors.New("edge already exists") ErrEdgeCreatesCycle = errors.New("edge would create a cycle") ErrNodeHasEdges = errors.New("vertex has edges") ErrGraphNotInit = errors.New("graph not Init()") )
Functions ¶
func OpenAiFunctions ¶
func WithNumWorkers ¶
func WithNumWorkers(n int) func(*GraphExecuteOptions)
Types ¶
type Graph ¶
type Graph struct {
// contains filtered or unexported fields
}
func (*Graph) Execute ¶
func (g *Graph) Execute(ctx context.Context, logger *zap.Logger, args map[string]any, opts ...func(*GraphExecuteOptions)) (map[string]map[string]any, error)
Execute executes the graph starting from the given node. You need to call Init before calling Execute. This method is safe to call concurrently but might break if the graph is modified while executing.
type GraphExecuteOptions ¶
type GraphExecuteOptions struct {
NumWorkers int
}
type Store ¶
type Store interface {
// AddNode should add the given node with the given hash value and node properties to the
// graph. If the node already exists, it is up to you whether ErrNodeAlreadyExists or no
// error should be returned.
AddNode(hash string, value Node) error
// Node should return the node with the given hash value. If the
// node doesn't exist, ErrNodeNotFound should be returned.
Node(hash string) (Node, error)
// RemoveNode should remove the node with the given hash value. If the node doesn't
// exist, ErrNodeNotFound should be returned. If the node has edges to other vertices,
// ErrNodeHasEdges should be returned.
RemoveNode(hash string) error
// ListNodes should return all vertices in the graph in a slice.
ListNodes() ([]string, error)
// NodeCount should return the number of vertices in the graph. This should be equal to the
// length of the slice returned by ListNodes.
NodeCount() (int, error)
// AddEdge should add an edge between the vertices with the given source and target hashes.
//
// If either node doesn't exit, ErrNodeNotFound should be returned for the respective
// node. If the edge already exists, ErrEdgeAlreadyExists should be returned.
AddEdge(sourceHash, targetHash string, edge Edge) error
// UpdateEdge should update the edge between the given vertices with the data of the given
// Edge instance. If the edge doesn't exist, ErrEdgeNotFound should be returned.
UpdateEdge(sourceHash string, targetHash string, edge Edge) error
// RemoveEdge should remove the edge between the vertices with the given source and target
// hashes.
//
// If either node doesn't exist, it is up to you whether ErrNodeNotFound or no error should
// be returned. If the edge doesn't exist, it is up to you whether ErrEdgeNotFound or no error
// should be returned.
RemoveEdge(sourceHash string, targetHash string) error
// Edge should return the edge joining the vertices with the given hash values. It should
// exclusively look for an edge between the source and the target node, not vice versa. The
// graph implementation does this for undirected graphs itself.
//
// Note that unlike Graph.Edge, this function is supposed to return an Edge[string], i.e. an edge
// that only contains the node hashes instead of the vertices themselves.
//
// If the edge doesn't exist, ErrEdgeNotFound should be returned.
Edge(sourceHash string, targetHash string) (Edge, error)
// ListEdges should return all edges in the graph in a slice.
ListEdges() ([]Edge, error)
CreatesCycle(source, target string) (bool, error)
}
Source Files
¶
Click to show internal directories.
Click to hide internal directories.