pipeline

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2024 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

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

func SetNextTubeExit

func SetNextTubeExit(output types.M) types.M

Types

type Callback

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

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

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

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

func (*Pipeline) WithPreCallbacks

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

type Prompt

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

type Splitter

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

func NewSplitter

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

func (*Splitter) Run

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

func (*Splitter) WithDecoder

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

func (*Splitter) WithMemory

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

type SplitterFn

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

type Tube

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

func NewTube

func NewTube(
	llm Llm,
) *Tube

func (*Tube) Namespace

func (t *Tube) Namespace() string

func (*Tube) Run

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

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

func (*Tube) WithHistory

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

func (*Tube) WithMemory

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