llms

package
v0.0.0-...-a6528fc Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2025 License: MIT Imports: 8 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrorUpdate

type ErrorUpdate struct {
	Error error
}

func (ErrorUpdate) Type

func (u ErrorUpdate) Type() UpdateType

type LLM

type LLM struct {

	// SystemPrompt should return the system prompt for the LLM. It's a function
	// to allow the system prompt to dynamically change throughout a single
	// conversation.
	SystemPrompt func() content.Content
	// contains filtered or unexported fields
}

func New

func New(provider Provider, allTools ...tools.Tool) *LLM

func (*LLM) AddTool

func (l *LLM) AddTool(t tools.Tool)

func (*LLM) Chat

func (l *LLM) Chat(message string) <-chan Update

Chat sends a text message to the LLM and immediately returns a channel over which updates will come in. The LLM will use the tools available and keep generating more messages until it's done using tools.

func (*LLM) ChatUsingContent

func (l *LLM) ChatUsingContent(ctx context.Context, message content.Content) <-chan Update

ChatUsingContent sends a message (which can contain images) to the LLM and immediately returns a channel over which updates will come in. The LLM will use the tools available and keep generating more messages until it's done using tools. The provided context can be used to pass values to tools, set deadlines, cancel, etc.

func (*LLM) ChatWithContext

func (l *LLM) ChatWithContext(ctx context.Context, message string) <-chan Update

ChatWithContext sends a text message to the LLM and immediately returns a channel over which updates will come in. The LLM will use the tools available and keep generating more messages until it's done using tools. The provided context can be used to pass values to tools, set deadlines, cancel, etc.

func (*LLM) SetDebug

func (l *LLM) SetDebug(enabled bool)

func (*LLM) TotalCost

func (l *LLM) TotalCost() float64

type Message

type Message struct {
	// Role can be "system", "user", "assistant", or "tool".
	Role string
	// Name can be used to identify different identities within the same role.
	Name string
	// Content is the message content.
	Content content.Content
	// ToolCalls is the list of tool calls that this message is part of.
	ToolCalls []ToolCall
	// ToolCallID is the ID of the tool call that this message is part of.
	ToolCallID string
}

type Provider

type Provider interface {
	Company() string
	Generate(systemPrompt content.Content, messages []Message, toolbox *tools.Toolbox) ProviderStream
}

type ProviderStream

type ProviderStream interface {
	Err() error
	Iter() func(yield func(StreamStatus) bool)
	Message() Message
	Text() string
	ToolCall() ToolCall
	CostUSD() float64
	Usage() (inputTokens, outputTokens int)
}

type StreamStatus

type StreamStatus int
const (
	// StreamStatusNone means either the stream hasn't started, or it has finished.
	StreamStatusNone StreamStatus = iota
	// StreamStatusText means the stream produced more text content.
	StreamStatusText
	// StreamStatusToolCallBegin means the stream started a tool call. The name of the function is available, but not the arguments.
	StreamStatusToolCallBegin
	// StreamStatusToolCallData means the stream is streaming the arguments for a tool call.
	StreamStatusToolCallData
	// StreamStatusToolCallReady means the stream finished streaming the arguments for a tool call.
	StreamStatusToolCallReady
)

type TextUpdate

type TextUpdate struct {
	Text string
}

func (TextUpdate) Type

func (u TextUpdate) Type() UpdateType

type ToolCall

type ToolCall struct {
	ID        string
	Name      string
	Arguments json.RawMessage
}

type ToolDoneUpdate

type ToolDoneUpdate struct {
	Result tools.Result
	Tool   tools.Tool
}

func (ToolDoneUpdate) Type

func (u ToolDoneUpdate) Type() UpdateType

type ToolStartUpdate

type ToolStartUpdate struct {
	Tool tools.Tool
}

func (ToolStartUpdate) Type

func (u ToolStartUpdate) Type() UpdateType

type ToolStatusUpdate

type ToolStatusUpdate struct {
	Status string
	Tool   tools.Tool
}

func (ToolStatusUpdate) Type

func (u ToolStatusUpdate) Type() UpdateType

type Update

type Update interface {
	Type() UpdateType
}

type UpdateType

type UpdateType string
const (
	UpdateTypeToolStart  UpdateType = "tool_start"
	UpdateTypeToolStatus UpdateType = "tool_status"
	UpdateTypeToolDone   UpdateType = "tool_done"
	UpdateTypeError      UpdateType = "error"
	UpdateTypeText       UpdateType = "text"
)

Jump to

Keyboard shortcuts

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