program

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MaxIterationNum = 20
View Source
var ReactPrompt = `` /* 2740-byte string literal not displayed */

Functions

func COT

func COT() *predictor

COT ...

func FunCall

func FunCall(opts ...option) *predictor

FunCall ...

func NewPredictor

func NewPredictor(opts ...option) *predictor

func Predictor

func Predictor(opts ...option) *predictor

Predictor ...

func ReAct

func ReAct(opts ...option) *react

ReAct ...

func SetLLM

func SetLLM(provider, model string)

SetLLM can not set concurrent

func WithLLM

func WithLLM(provider string, model string, opts ...llm.Option) option

func WithLLMInstance added in v0.0.8

func WithLLMInstance(model *llm.Instance) option

Types

type Action added in v0.0.7

type Action struct {
	Name        string
	Description string
	Parameters  map[string]any
}

type Adapter

type Adapter interface {
	InputAdapter
	OutputAdapter
}

Adapter ...

type DefaultAdapter added in v0.0.7

type DefaultAdapter struct {
	RawInputAdapter
	MarkableOutputAdapter
}

type Field

type Field struct {
	Name        string
	Type        reflect.Kind
	Description string
	Marker      string
	Kind        string // input or output
}

Field represents an input or output field in a signature

type InputAdapter added in v0.0.7

type InputAdapter interface {
	Format(p *predictor, inputs map[string]any, target any) ([]llm.Message, error)
}

type Invoker added in v0.0.8

type Invoker interface {
	Invokex(ctx context.Context, query string) *predictor
	Invoke(ctx context.Context, inputs map[string]any) *predictor
}

type JSONAdapter

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

JSONAdapter ...

func (*JSONAdapter) Format

func (ada *JSONAdapter) Format(p *predictor, inputs map[string]any, target any) ([]llm.Message, error)

Format ...

func (*JSONAdapter) Parse

func (ada *JSONAdapter) Parse(completion string, target any) error

Parse ...

type MarkableAdapter

type MarkableAdapter struct {
	MarkableInputAdapter
	MarkableOutputAdapter
}

type MarkableInputAdapter added in v0.0.7

type MarkableInputAdapter struct {
}

MarkableInputAdapter ...

func (*MarkableInputAdapter) Format added in v0.0.7

func (ada *MarkableInputAdapter) Format(p *predictor, inputs map[string]any, _ any) ([]llm.Message, error)

Format ...

type MarkableOutputAdapter added in v0.0.7

type MarkableOutputAdapter struct {
}

func (*MarkableOutputAdapter) Parse added in v0.0.7

func (ada *MarkableOutputAdapter) Parse(completion string, object any) error

Parse ...

type OutputAdapter added in v0.0.7

type OutputAdapter interface {
	Parse(string, any) error
}

type Program

type Program interface {
	Prompt() *Promptx
	Update(...option)
	Forward(context.Context, map[string]any) (any, error)
}

Program defines the interface for a program Program 定义了一个可运行的程序,不会保存状态,随用随 new

type ProgramFunc

type ProgramFunc func(context.Context, string) (string, error)

ProgramFunc is a function that implements the Program interface

type Promptx

type Promptx struct {
	Name         string
	Description  string
	Instruction  string
	InputFields  map[string]*Field
	OutputFields map[string]*Field
}

Promptx defines the instruction and input/output about a program

func (*Promptx) ValidateInputs

func (m *Promptx) ValidateInputs(inputs map[string]any) error

ValidateInputs checks if the provided inputs match the signature

func (*Promptx) ValidateOutputs

func (m *Promptx) ValidateOutputs(outputs map[string]any) error

ValidateOutputs checks if the outputs match the signature

type RawAdapter

type RawAdapter struct {
	RawInputAdapter
	RawOutputAdapter
}

RawAdapter ...

type RawInputAdapter added in v0.0.7

type RawInputAdapter struct {
}

func (*RawInputAdapter) Format added in v0.0.7

func (ada *RawInputAdapter) Format(p *predictor, inputs map[string]any, _ any) ([]llm.Message, error)

Format ...

type RawOutputAdapter added in v0.0.7

type RawOutputAdapter struct {
}

func (*RawOutputAdapter) Parse added in v0.0.7

func (ada *RawOutputAdapter) Parse(completion string, target any) error

Parse ...

type ReactResult

type ReactResult struct {
	Tool *struct {
		Name string         `json:"name"`
		Args map[string]any `json:"args"`
	}
	Thoughts *struct {
		SelfReason string `json:"self_reason"`
		Text       string `json:"text"`
		Reason     string `json:"reasoning"`
		Plan       any    `json:"plan"`
		Critism    string `json:"criticism"`
		Speak      string `json:"speak"`
	} `json:"thoughts"`
}

type Response added in v0.0.8

type Response struct {
	HasToolCalls bool
	// contains filtered or unexported fields
}

func NewResponse added in v0.0.8

func NewResponse() *Response

func (*Response) Completion added in v0.0.8

func (r *Response) Completion() string

func (*Response) Error added in v0.0.8

func (r *Response) Error() error

func (*Response) Get added in v0.0.8

func (r *Response) Get(value any) error

func (*Response) Stream added in v0.0.8

func (r *Response) Stream() chan *llm.Chunk

func (*Response) ToolCalls added in v0.0.8

func (r *Response) ToolCalls() []*llm.ToolCall

Jump to

Keyboard shortcuts

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