llmflow

package module
v0.0.0-...-aba7d2c Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2024 License: Apache-2.0 Imports: 15 Imported by: 1

README

LLMFlow

Go Reference

Orchestration engine & UI for your customized LLM flow.

LLMFlow

Installation

go install github.com/go-aie/llmflow/cmd/llmflow@latest

Quick Start

Run the basic flow:

OPENAI_API_KEY=<YOUR_API_KEY> llmflow run examples/basic.flow.yaml

Start LLMFlow

API

Start LLMFlow:

OPENAI_API_KEY=<YOUR_API_KEY> llmflow serve

Add the basic flow (in YAML format):

curl -XPUT -H 'Content-Type: application/yaml' 'http://127.0.0.1:8888/api/flows/basic' --data-binary @examples/basic.flow.yaml

Or add the basic flow (in JSON format):

curl -XPUT -H 'Content-Type: application/json' 'http://127.0.0.1:8888/api/flows/basic' -d @examples/basic.flow.json

Execute the basic flow:

curl -XPOST -H 'Content-Type: application/json' 'http://127.0.0.1:8888/api/flows/basic:run' -d '{"query":"colorful socks"}'

NOTE:

  • Setting environment variables is not mandatory when running LLMFlow in this example.
  • As an alternative, you can change api_key to your API key in basic.flow.yaml (see UI), and then run llmflow instead.
UI

Open LLMFlow UI through your browser: http://127.0.0.1:8888.

Then click the Open button and select basic.flow.yaml to view it in the UI.

Tasks & Flows

In addition to Orchestrator's built-in tasks, LLMFlow defines the following tasks and flows:

Examples

Documentation

Check out the documentation.

License

Apache License 2.0

Documentation

Index

Constants

View Source
const TypeJSONLinesLoader = "jsonlines_loader"
View Source
const TypeSplitter = "splitter"
View Source
const TypeTemplate = "template"
View Source
const TypeTextLoader = "text_loader"

Variables

View Source
var FlowSchemas map[string]map[string]any

Schemas for flows defined in llmflow.

View Source
var TaskSchemas map[string]map[string]any

Schemas for tasks defined in llmflow.

Functions

func MustExtractFlowSchema

func MustExtractFlowSchema(def map[string]any) map[string]any

MustExtractFlowSchema extracts the schema from a flow definition.

func MustRegisterJSONLinesLoader

func MustRegisterJSONLinesLoader(r *orchestrator.Registry)

func MustRegisterSplitter

func MustRegisterSplitter(r *orchestrator.Registry)

func MustRegisterTemplate

func MustRegisterTemplate(r *orchestrator.Registry)

func MustRegisterTextLoader

func MustRegisterTextLoader(r *orchestrator.Registry)

Types

type BoundedContainer

type BoundedContainer[E any] struct {
	// contains filtered or unexported fields
}

BoundedContainer is a container with a bounded length.

func NewBoundedContainer

func NewBoundedContainer[E any](size int) *BoundedContainer[E]

func (*BoundedContainer[E]) Append

func (bc *BoundedContainer[E]) Append(item E) (isFull bool)

Append adds item to the right side of the container. It will return a boolean value indicates whether the container is full after this addition.

func (*BoundedContainer[E]) PopAll

func (bc *BoundedContainer[E]) PopAll() []E

PopAll removes and returns all items from the container.

type Document

type Document struct {
	ID       string   `json:"id,omitempty"`
	Text     string   `json:"text,omitempty"`
	Vector   Vector   `json:"vector,omitempty"`
	Metadata Metadata `json:"metadata,omitempty"`

	// Extra data as a JSON string.
	Extra string `json:"extra,omitempty"`
}

type JSONLinesLoader

type JSONLinesLoader struct {
	orchestrator.TaskHeader

	Input struct {
		ID        string                    `json:"id"`
		Filename  orchestrator.Expr[string] `json:"filename"`
		Content   orchestrator.Expr[string] `json:"content"`
		Pointer   string                    `json:"pointer"`
		BatchSize int                       `json:"batch_size"`
	} `json:"input"`

	Output struct {
		Documents []*Document `json:"documents"`
	}
}

func (*JSONLinesLoader) Execute

func (*JSONLinesLoader) String

func (l *JSONLinesLoader) String() string

type JSONLinesLoaderBuilder

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

func NewJSONLinesLoader

func NewJSONLinesLoader(name string) *JSONLinesLoaderBuilder

func (*JSONLinesLoaderBuilder) Build

type Metadata

type Metadata struct {
	// The source ID of the document.
	//
	// Source/Document has different meanings in different scenarios. For example:
	//
	// 1. Document Splitting
	//   Source => The whole Document
	//   Document => Single Chunk
	//
	// 2. Knowledge Base
	//   Source => The whole Knowledge Base
	//   Document => Single Knowledge Point
	SourceID string `json:"source_id,omitempty"`

	// The user ID. Typically useful in multi-tenant scenario.
	UserID string `json:"user_id,omitempty"`

	// The collection name. Only useful for vector stores that support the
	// concept of Collection (e.g. Milvus, Typesense).
	CollectionID string `json:"collection_id,omitempty"`
}

type Similarity

type Similarity struct {
	*Document `json:",squash"`

	Score float64 `json:"score,omitempty"`
}

type Splitter

type Splitter struct {
	orchestrator.TaskHeader

	Input struct {
		Documents  orchestrator.Expr[[]*Document] `json:"documents"`
		SplitChars []string                       `json:"split_chars"`
		ChunkSize  int                            `json:"chunk_size"`
	} `json:"input"`
}

func (*Splitter) Execute

func (s *Splitter) Execute(ctx context.Context, input orchestrator.Input) (orchestrator.Output, error)

func (*Splitter) Init

func (s *Splitter) Init(r *orchestrator.Registry) error

func (*Splitter) String

func (s *Splitter) String() string

type SplitterBuilder

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

func NewSplitter

func NewSplitter(name string) *SplitterBuilder

func (*SplitterBuilder) Build

func (b *SplitterBuilder) Build() orchestrator.Task

type Template

type Template struct {
	orchestrator.TaskHeader

	Input struct {
		Template string                            `json:"template"`
		Args     orchestrator.Expr[map[string]any] `json:"args"`
	} `json:"input"`
}

Template is a leaf task that is used to render a template by applying given arguments.

func (*Template) Execute

func (t *Template) Execute(ctx context.Context, input orchestrator.Input) (output orchestrator.Output, err error)

func (*Template) String

func (t *Template) String() string

type TemplateBuilder

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

func NewTemplate

func NewTemplate(name string) *TemplateBuilder

func (*TemplateBuilder) Build

func (b *TemplateBuilder) Build() orchestrator.Task

type TextLoader

type TextLoader struct {
	orchestrator.TaskHeader

	Input struct {
		ID       string `json:"id"`
		Filename string `json:"filename"`
	} `json:"input"`
}

func (*TextLoader) Execute

func (*TextLoader) String

func (l *TextLoader) String() string

type TextLoaderBuilder

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

func NewTextLoader

func NewTextLoader(name string) *TextLoaderBuilder

func (*TextLoaderBuilder) Build

func (b *TextLoaderBuilder) Build() orchestrator.Task

type Vector

type Vector []float64

Directories

Path Synopsis
cmd
llmflow Module

Jump to

Keyboard shortcuts

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