brain

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2024 License: MPL-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidProvider = errors.New("not a valid Provider")
View Source
var (
	ErrProviderNotFound = errors.New("provider not found")
)

Functions

This section is empty.

Types

type Brain

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

func New

func New(ctx context.Context, db *ent.Client, toolbox types.Toolbox, definition Definition) (*Brain, error)

func NewFromFile

func NewFromFile(ctx context.Context, db *ent.Client, toolbox types.Toolbox, file string) (*Brain, error)

func (*Brain) Append added in v0.0.6

func (m *Brain) Append(ctx context.Context, thread string, messages []types.Message) (Response, error)

Append messages to thread.

func (*Brain) Chat added in v0.0.6

func (m *Brain) Chat(ctx context.Context, thread string, messages ...types.Message) (Response, error)

func (*Brain) Definition added in v0.0.6

func (m *Brain) Definition() Definition

func (*Brain) Run

func (m *Brain) Run(ctx context.Context, messages []types.Message, thread string) (Response, error)

Run model using only provided state.

type Definition

type Definition struct {
	types.Config  `yaml:",inline"`    // model configuration
	Parallel      bool                `yaml:"parallel"`                       // allow parallel execution for calls
	Vision        *Vision             `yaml:"vision,omitempty" json:"vision"` // separate model for vision
	MaxIterations int                 `json:"max_iterations" yaml:"maxIterations"`
	Provider      Provider            `json:"provider" yaml:"provider"` // provider name (openai, bedrock)
	URL           string              `json:"url" yaml:"url"`           // provider URL
	Secret        utils.Value[string] `json:"secret" yaml:"secret"`     // provider secret
	Depth         int                 `yaml:"depth" json:"depth"`       // history depth
}

func Default

func Default() Definition

type Provider added in v0.0.4

type Provider string

Provider name ENUM(openai,bedrock,ollama,google)

const (
	// ProviderOpenai is a Provider of type openai.
	ProviderOpenai Provider = "openai"
	// ProviderBedrock is a Provider of type bedrock.
	ProviderBedrock Provider = "bedrock"
	// ProviderOllama is a Provider of type ollama.
	ProviderOllama Provider = "ollama"
	// ProviderGoogle is a Provider of type google.
	ProviderGoogle Provider = "google"
)

func ParseProvider added in v0.0.4

func ParseProvider(name string) (Provider, error)

ParseProvider attempts to convert a string to a Provider.

func (Provider) IsValid added in v0.0.4

func (x Provider) IsValid() bool

IsValid provides a quick way to determine if the typed value is part of the allowed enumerated values

func (Provider) MarshalText added in v0.0.4

func (x Provider) MarshalText() ([]byte, error)

MarshalText implements the text marshaller method.

func (Provider) String added in v0.0.4

func (x Provider) String() string

String implements the Stringer interface.

func (*Provider) UnmarshalText added in v0.0.4

func (x *Provider) UnmarshalText(text []byte) error

UnmarshalText implements the text unmarshaller method.

type Response added in v0.0.3

type Response []*types.Invoke

func (Response) Called added in v0.0.3

func (r Response) Called(name string) int

Called returns how many times function (tool) with specified name has been called.

func (Response) Messages added in v0.0.6

func (r Response) Messages() []types.Message

Messages of all responses.

func (Response) Reply added in v0.0.3

func (r Response) Reply() types.Content

Reply returns first non-tool calling model response. If nothing found, empty text content returned.

func (Response) TotalInputTokens added in v0.0.3

func (r Response) TotalInputTokens() int

TotalInputTokens returns sum of all used input tokens.

func (Response) TotalOutputTokens added in v0.0.3

func (r Response) TotalOutputTokens() int

TotalOutputTokens returns sum of all used output tokens.

func (Response) TotalTokens added in v0.0.3

func (r Response) TotalTokens() int

TotalTokens returns sum of all tokens.

type Vision added in v0.0.3

type Vision struct {
	Model string `json:"model" yaml:"model"`
}

Jump to

Keyboard shortcuts

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