pipeline

package
v0.0.12-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package pipeline provides a way to chain multiple llm executions.

Index

Constants

View Source
const (
	NextTubeKey  = "next_tube"
	NextTubeExit = -1
)

Variables

View Source
var (
	ErrDecoding       = errors.New("decoding input error")
	ErrInvalidLmmMode = errors.New("invalid LLM mode")
	ErrLLMExecution   = errors.New("llm execution error")
)
View Source
var (
	ErrSplitFunction = fmt.Errorf("split function error")
)

Functions

func SetNextTube added in v0.0.6

func SetNextTube(output types.M, nextTube int) types.M

func SetNextTubeExit added in v0.0.6

func SetNextTubeExit(output types.M) types.M

Types

type Callback added in v0.0.11

type Callback func(ctx context.Context, values types.M) (types.M, error)

type Decoder

type Decoder interface {
	Decode(input string) (types.M, error)
}

type History added in v0.0.9

type History interface {
	Add(content string, meta types.Meta) error
}

type Llm

type Llm struct {
	LlmEngine LlmEngine
	LlmMode   LlmMode
	Prompt    Prompt
	Chat      *chat.Chat
}

type LlmEngine

type LlmEngine interface {
	Completion(ctx context.Context, prompt string) (string, error)
	Chat(ctx context.Context, chat *chat.Chat) (string, error)
}

type LlmMode

type LlmMode int
const (
	LlmModeChat LlmMode = iota
	LlmModeCompletion
)

type Memory

type Memory interface {
	Get(key string) interface{}
	Set(key string, value interface{}) error
	All() types.M
	Delete(key string) error
	Clear() error
}

type Pipe added in v0.0.3

type Pipe interface {
	Run(ctx context.Context, input types.M) (types.M, error)
}

type Pipeline

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

func New

func New(pipes ...Pipe) *Pipeline

func (Pipeline) Run

func (p Pipeline) Run(ctx context.Context, input types.M) (types.M, error)

Run chains the steps of the pipeline and returns the output of the last step.

func (*Pipeline) WithPostCallbacks added in v0.0.6

func (p *Pipeline) WithPostCallbacks(callbacks ...Callback) *Pipeline

func (*Pipeline) WithPreCallbacks added in v0.0.6

func (p *Pipeline) WithPreCallbacks(callbacks ...Callback) *Pipeline

type Prompt

type Prompt interface {
	String() string
	Format(input types.M) error
}

type Splitter added in v0.0.3

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

func NewSplitter added in v0.0.3

func NewSplitter(
	llm Llm,
	splitterFn SplitterFn,
) *Splitter

func (*Splitter) Run added in v0.0.3

func (s *Splitter) Run(ctx context.Context, input types.M) (types.M, error)

func (*Splitter) WithDecoder added in v0.0.9

func (s *Splitter) WithDecoder(decoder Decoder) *Splitter

func (*Splitter) WithMemory added in v0.0.9

func (s *Splitter) WithMemory(name string, memory Memory) *Splitter

type SplitterFn added in v0.0.3

type SplitterFn func(input types.M) ([]types.M, error)

type Tube added in v0.0.3

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

func NewTube added in v0.0.3

func NewTube(
	llm Llm,
) *Tube

func (*Tube) Namespace added in v0.0.5

func (t *Tube) Namespace() string

func (*Tube) Run added in v0.0.3

func (t *Tube) Run(ctx context.Context, input types.M) (types.M, error)

Run execute the step and return the output. The prompt is formatted with the input and the output of the prompt is used as input for the LLM. If the step has a memory, the output is stored in the memory.

func (*Tube) WithDecoder added in v0.0.5

func (t *Tube) WithDecoder(decoder Decoder) *Tube

func (*Tube) WithHistory added in v0.0.9

func (t *Tube) WithHistory(history History) *Tube

func (*Tube) WithMemory added in v0.0.5

func (t *Tube) WithMemory(namespace string, memory Memory) *Tube

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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