types

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: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidMIME = errors.New("not a valid MIME")
View Source
var ErrInvalidRole = errors.New("not a valid Role")

Functions

This section is empty.

Types

type Config

type Config struct {
	Model     string `json:"model" yaml:"model"`
	Prompt    string `json:"prompt" yaml:"prompt"`
	MaxTokens int    `json:"max_tokens" yaml:"maxTokens"`
	ForceJSON bool   `json:"force_json" yaml:"forceJSON"`
}

type Content

type Content struct {
	Data []byte
	Mime MIME
}

func ParseDataURL

func ParseDataURL(data string) Content

func Text

func Text(content string) Content

func (*Content) DataURL

func (msg *Content) DataURL() string

func (*Content) String

func (msg *Content) String() string

type DynamicToolbox

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

func (*DynamicToolbox) Add

func (st *DynamicToolbox) Add(tools ...Tool)

Add tools. Basic wrapper around Provider. Should not be called after start.

func (*DynamicToolbox) Provider

func (st *DynamicToolbox) Provider(providerFunc ...ToolProviderFunc)

Provider registers provider which dynamically can Update internal set of tools. Should not be called after start.

func (*DynamicToolbox) Snapshot added in v0.0.3

func (st *DynamicToolbox) Snapshot() Snapshot

func (*DynamicToolbox) Update

func (st *DynamicToolbox) Update(ctx context.Context, strict bool) error

Update all providers. If strict enabled, stops on a first error.

type Invoke added in v0.0.3

type Invoke struct {
	Output      []Message
	InputToken  int
	OutputToken int
	TotalToken  int
}

func (*Invoke) ToolCalls added in v0.0.3

func (inv *Invoke) ToolCalls() []Message

type MIME

type MIME string

MIME for each message. ENUM( text = text/plain, json = application/json png = image/png jpeg = image/jpeg jpg = image/jpg webp = image/webp gif = image/gif )

const (
	// MIMEText is a MIME of type text.
	MIMEText MIME = "text/plain"
	// MIMEJson is a MIME of type json.
	MIMEJson MIME = "application/json"
	// MIMEPng is a MIME of type png.
	MIMEPng MIME = "image/png"
	// MIMEJpeg is a MIME of type jpeg.
	MIMEJpeg MIME = "image/jpeg"
	// MIMEJpg is a MIME of type jpg.
	MIMEJpg MIME = "image/jpg"
	// MIMEWebp is a MIME of type webp.
	MIMEWebp MIME = "image/webp"
	// MIMEGif is a MIME of type gif.
	MIMEGif MIME = "image/gif"
)

func MIMEValues added in v0.0.6

func MIMEValues() []MIME

MIMEValues returns a list of the values for MIME

func ParseMIME

func ParseMIME(name string) (MIME, error)

ParseMIME attempts to convert a string to a MIME.

func (MIME) ImageFormat added in v0.0.2

func (M MIME) ImageFormat() string

func (MIME) IsImage

func (M MIME) IsImage() bool

func (MIME) IsText

func (M MIME) IsText() bool

func (MIME) IsValid

func (x MIME) IsValid() bool

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

func (*MIME) Scan added in v0.0.6

func (x *MIME) Scan(value interface{}) (err error)

Scan implements the Scanner interface.

func (MIME) String

func (x MIME) String() string

String implements the Stringer interface.

func (MIME) Value added in v0.0.6

func (x MIME) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type Message

type Message struct {
	ToolID   string
	ToolName string
	Role     Role
	User     string
	Content  Content
}

type ModelMessage

type ModelMessage struct {
	Started     time.Time
	Duration    time.Duration
	InputToken  int
	OutputToken int
	TotalToken  int
	Input       json.RawMessage
	Output      json.RawMessage
	ToolCalls   []ToolCall
	Content     []Content
}

type Provider

type Provider interface {
	Invoke(ctx context.Context, config Config, messages []Message, tools []ToolDefinition) (*Invoke, error)
}

Provider to LLM. Should NOT call tools by it self.

type Request

type Request struct {
	Config  Config
	History []Message
	Tools   Toolbox
}

type Response

type Response struct {
	Request  *Request
	Started  time.Time
	Duration time.Duration
	Messages []ModelMessage
}

type Role

type Role string

Role for each message. ENUM(user,assistant,toolCall,toolResult)

const (
	// RoleUser is a Role of type user.
	RoleUser Role = "user"
	// RoleAssistant is a Role of type assistant.
	RoleAssistant Role = "assistant"
	// RoleToolCall is a Role of type toolCall.
	RoleToolCall Role = "toolCall"
	// RoleToolResult is a Role of type toolResult.
	RoleToolResult Role = "toolResult"
)

func ParseRole

func ParseRole(name string) (Role, error)

ParseRole attempts to convert a string to a Role.

func RoleValues added in v0.0.6

func RoleValues() []Role

RoleValues returns a list of the values for Role

func (Role) IsValid

func (x Role) IsValid() bool

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

func (*Role) Scan added in v0.0.6

func (x *Role) Scan(value interface{}) (err error)

Scan implements the Scanner interface.

func (Role) String

func (x Role) String() string

String implements the Stringer interface.

func (Role) Value added in v0.0.6

func (x Role) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type Snapshot added in v0.0.3

type Snapshot map[string]Tool

func (Snapshot) Call added in v0.0.3

func (s Snapshot) Call(ctx context.Context, name string, args json.RawMessage) (Content, error)

func (Snapshot) Definitions added in v0.0.3

func (s Snapshot) Definitions() []ToolDefinition

type Tool

type Tool interface {
	Name() string
	Description() string
	Input() *jsonschema.Schema
	Call(ctx context.Context, args json.RawMessage) (Content, error)
}

func MustTool

func MustTool[In any](name string, description string, callable func(ctx context.Context, payload In) (Content, error)) Tool

type ToolCall

type ToolCall struct {
	ID       string
	ToolName string
	Started  time.Time
	Duration time.Duration
	Input    json.RawMessage
	Output   Content
}

type ToolDefinition added in v0.0.3

type ToolDefinition interface {
	Name() string
	Description() string
	Input() *jsonschema.Schema
}

type ToolFunc

type ToolFunc func(context.Context, json.RawMessage) (Content, error)

type ToolProvider

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

func (*ToolProvider) Update

func (tp *ToolProvider) Update(ctx context.Context) error

type ToolProviderFunc

type ToolProviderFunc func(ctx context.Context) ([]Tool, error)

type Toolbox

type Toolbox interface {
	Snapshot() Snapshot
}

Jump to

Keyboard shortcuts

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