schema

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2024 License: Apache-2.0 Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Agent added in v1.0.4

type Agent interface {
	// Enumerate the tools available
	Tools() []Tool

	// Run a tool with parameters and return the result
	Run(context.Context, string, any) (any, error)
}

An agent is a collection of tools that can be called

type Content added in v1.0.2

type Content struct {
	Id     string         `json:"id,omitempty"`
	Type   string         `json:"type" writer:",width:4"`
	Text   string         `json:"text,omitempty" writer:",width:60,wrap"`
	Source *contentSource `json:"source,omitempty"`
	Url    *contentImage  `json:"image_url,omitempty"`

	// Tool Result
	ToolId string `json:"tool_use_id,omitempty"`
	Result string `json:"content,omitempty"`
	// contains filtered or unexported fields
}

Message Content

func Image added in v1.0.2

func Image(r io.Reader) (*Content, error)

Return a new content object of type image, from a io.Reader

func ImageData added in v1.0.2

func ImageData(path string) (*Content, error)

Return a new content object of type image, from a file

func ImageUrl added in v1.0.5

func ImageUrl(v, detail string) (*Content, error)

Return a new content object of type image, from a Url

func Text added in v1.0.2

func Text(v string) *Content

Return a new content object of type text

func ToolResult added in v1.0.3

func ToolResult(id string, result string) *Content

Return a tool result

func ToolUse added in v1.0.5

func ToolUse(t ToolCall) *Content

Return tool usage

func (Content) GetString added in v1.0.3

func (c Content) GetString(name, input string) (string, bool)

Return an input parameter as a string, returns false if the name is incorrect or the input doesn't exist

func (Content) String added in v1.0.2

func (c Content) String() string

type Embedding

type Embedding struct {
	Embedding []float64 `json:"embedding"`
	Index     int       `json:"index"`
}

An embedding object

func (Embedding) CosineDistance

func (e Embedding) CosineDistance(other Embedding) float64

type Embeddings

type Embeddings struct {
	Id    string      `json:"id" writer:",width:32"`
	Data  []Embedding `json:"data" writer:",wrap"`
	Model string      `json:"model"`
	Usage struct {
		PromptTokerns int `json:"prompt_tokens"`
		TotalTokens   int `json:"total_tokens"`
	} `json:"usage" writer:",wrap"`
}

An set of created embeddings

type Message

type Message struct {
	// user, system or assistant
	Role string `json:"role,omitempty"`

	// Message Id
	Id string `json:"id,omitempty"`

	// Model
	Model string `json:"model,omitempty"`

	// Content can be a string, array of strings, content
	// object or an array of content objects
	Content any `json:"content,omitempty"`

	// Any tool calls
	ToolCalls []ToolCall `json:"tool_calls,omitempty"`

	// Time the message was created, in unix seconds
	Created int64 `json:"created,omitempty"`
}

A chat completion message

func NewMessage added in v1.0.2

func NewMessage(role string, content ...any) *Message

Create a new message, with optional content

func (*Message) Add added in v1.0.2

func (m *Message) Add(content ...any) *Message

Append content to the message

func (*Message) IsValid added in v1.0.2

func (m *Message) IsValid() bool

func (Message) String added in v1.0.2

func (m Message) String() string

type MessageChoice

type MessageChoice struct {
	Message      *Message      `json:"message,omitempty"`
	Delta        *MessageDelta `json:"delta,omitempty"`
	Index        int           `json:"index"`
	FinishReason string        `json:"finish_reason,omitempty"`
}

One choice of chat completion messages

func (MessageChoice) String added in v1.0.4

func (m MessageChoice) String() string

type MessageChunk added in v1.0.5

type MessageChunk struct {
	Id                string          `json:"id,omitempty"`
	Model             string          `json:"model,omitempty"`
	Created           int64           `json:"created,omitempty"`
	SystemFingerprint string          `json:"system_fingerprint,omitempty"`
	TokenUsage        *TokenUsage     `json:"usage,omitempty"`
	Choices           []MessageChoice `json:"choices,omitempty"`
}

Chat completion chunk

func (MessageChunk) String added in v1.0.5

func (m MessageChunk) String() string

type MessageDelta added in v1.0.4

type MessageDelta struct {
	Role    string `json:"role,omitempty"`
	Content string `json:"content,omitempty"`
}

Delta between messages (for streaming responses)

func (MessageDelta) String added in v1.0.4

func (m MessageDelta) String() string

type Model

type Model struct {
	Id      string `json:"id" writer:",width:30"`
	Created int64  `json:"created,omitempty"`
	Owner   string `json:"owned_by,omitempty"`
}

A model object

type TokenUsage added in v1.0.5

type TokenUsage struct {
	PromptTokens     int `json:"prompt_tokens,omitempty"`
	CompletionTokens int `json:"completion_tokens,omitempty"`
	TotalTokens      int `json:"total_tokens,omitempty"`
}

Token usage

type Tool added in v1.0.2

type Tool struct {
	Name        string          `json:"name"`
	Description string          `json:"description"`
	Type        string          `json:"type,omitempty"`
	Parameters  *toolParameters `json:"parameters,omitempty"`   // Used by OpenAI, Mistral
	InputSchema *toolParameters `json:"input_schema,omitempty"` // Used by anthropic
}

A tool function

func NewTool added in v1.0.2

func NewTool(name, description string) *Tool

func NewToolEx added in v1.0.4

func NewToolEx(name, description string, parameters any) (*Tool, error)

func (*Tool) Add added in v1.0.4

func (tool *Tool) Add(name, description string, required bool, t reflect.Type) error

func (Tool) String added in v1.0.2

func (t Tool) String() string

type ToolCall added in v1.0.5

type ToolCall struct {
	Id       string       `json:"id,omitempty"`
	Type     string       `json:"type,omitempty"`
	Function ToolFunction `json:"function,omitempty"`
}

Tool Call

type ToolFunction added in v1.0.5

type ToolFunction struct {
	Name      string `json:"name,omitempty"`
	Arguments string `json:"arguments,omitempty"`
}

Tool Function and Arguments

Jump to

Keyboard shortcuts

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