core

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package core implements Genkit actions and other essential machinery. This package is primarily intended for Genkit internals and for plugins. Genkit applications should use the genkit package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterSpanProcessor

func RegisterSpanProcessor(sp sdktrace.SpanProcessor)

RegisterSpanProcessor registers an OpenTelemetry SpanProcessor for tracing.

Types

type Action

type Action[In, Out, Stream any] struct {
	// contains filtered or unexported fields
}

An Action is a named, observable operation. It consists of a function that takes an input of type I and returns an output of type O, optionally streaming values of type S incrementally by invoking a callback. It optionally has other metadata, like a description and JSON Schemas for its input and output.

Each time an Action is run, it results in a new trace span.

func DefineAction

func DefineAction[In, Out any](
	provider, name string,
	atype atype.ActionType,
	metadata map[string]any,
	fn func(context.Context, In) (Out, error),
) *Action[In, Out, struct{}]

DefineAction creates a new non-streaming Action and registers it.

func DefineActionInRegistry added in v0.0.2

func DefineActionInRegistry[In, Out, Stream any](
	r *registry.Registry,
	provider, name string,
	atype atype.ActionType,
	metadata map[string]any,
	inputSchema *jsonschema.Schema,
	fn Func[In, Out, Stream],
) *Action[In, Out, Stream]

DefineActionInRegistry creates an action and registers it with the given Registry. For use by the Genkit module only.

func DefineActionWithInputSchema

func DefineActionWithInputSchema[Out any](
	provider, name string,
	atype atype.ActionType,
	metadata map[string]any,
	inputSchema *jsonschema.Schema,
	fn func(context.Context, any) (Out, error),
) *Action[any, Out, struct{}]

DefineActionWithInputSchema creates a new Action and registers it. This differs from DefineAction in that the input schema is defined dynamically; the static input type is "any". This is used for prompts.

func DefineCustomAction

func DefineCustomAction[In, Out, Stream any](provider, name string, metadata map[string]any, fn Func[In, Out, Stream]) *Action[In, Out, Stream]

DefineCustomAction defines a streaming action with type Custom.

func DefineStreamingAction

func DefineStreamingAction[In, Out, Stream any](
	provider, name string,
	atype atype.ActionType,
	metadata map[string]any,
	fn Func[In, Out, Stream],
) *Action[In, Out, Stream]

DefineStreamingAction creates a new streaming action and registers it.

func LookupActionFor

func LookupActionFor[In, Out, Stream any](typ atype.ActionType, provider, name string) *Action[In, Out, Stream]

LookupActionFor returns the action for the given key in the global registry, or nil if there is none. It panics if the action is of the wrong type.

func (*Action[I, O, S]) Desc added in v0.0.2

func (a *Action[I, O, S]) Desc() action.Desc

Desc returns a description of the action.

func (*Action[In, Out, Stream]) Name

func (a *Action[In, Out, Stream]) Name() string

Name returns the Action's Name.

func (*Action[In, Out, Stream]) Run

func (a *Action[In, Out, Stream]) Run(ctx context.Context, input In, cb func(context.Context, Stream) error) (output Out, err error)

Run executes the Action's function in a new trace span.

func (*Action[In, Out, Stream]) RunJSON added in v0.0.2

func (a *Action[In, Out, Stream]) RunJSON(ctx context.Context, input json.RawMessage, cb func(context.Context, json.RawMessage) error) (json.RawMessage, error)

RunJSON runs the action with a JSON input, and returns a JSON result.

func (*Action[In, Out, Stream]) SetTracingState added in v0.0.2

func (a *Action[In, Out, Stream]) SetTracingState(tstate *tracing.State)

setTracingState sets the action's tracing.State.

type FileFlowStateStore

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

A FileFlowStateStore is a FlowStateStore that writes flowStates to files.

func NewFileFlowStateStore

func NewFileFlowStateStore(dir string) (*FileFlowStateStore, error)

NewFileFlowStateStore creates a FileFlowStateStore that writes traces to the given directory. The directory is created if it does not exist.

func (*FileFlowStateStore) Load

func (s *FileFlowStateStore) Load(ctx context.Context, id string, pfs any) error

func (*FileFlowStateStore) Save

type FlowStateStore

type FlowStateStore interface {
	// Save saves the FlowState to the store, overwriting an existing one.
	Save(ctx context.Context, id string, fs base.FlowStater) error
	// Load reads the FlowState with the given ID from the store.
	// It returns an error that is fs.ErrNotExist if there isn't one.
	// pfs must be a pointer to a flowState[I, O] of the correct type.
	Load(ctx context.Context, id string, pfs any) error
}

A FlowStateStore stores flow states. Every flow state has a unique string identifier. A durable FlowStateStore is necessary for durable flows.

type Func

type Func[In, Out, Stream any] func(context.Context, In, func(context.Context, Stream) error) (Out, error)

Func is the type of function that Actions and Flows execute. It takes an input of type Int and returns an output of type Out, optionally streaming values of type Stream incrementally by invoking a callback. If the StreamingCallback is non-nil and the function supports streaming, it should stream the results by invoking the callback periodically, ultimately returning with a final return value. Otherwise, it should ignore the StreamingCallback and just return a result.

Directories

Path Synopsis
Package logger provides a context-scoped slog.Logger.
Package logger provides a context-scoped slog.Logger.
Package gtime provides time functionality for Go Genkit.
Package gtime provides time functionality for Go Genkit.

Jump to

Keyboard shortcuts

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