Documentation
¶
Index ¶
- type Agent
- type Attachment
- type Completion
- type Context
- type Err
- type Model
- type Opt
- func WithAgent(agent Agent) Opt
- func WithAttachment(r io.Reader) Opt
- func WithFormat(v any) Opt
- func WithFrequencyPenalty(v float64) Opt
- func WithMaxTokens(v uint64) Opt
- func WithNumCompletions(v uint64) Opt
- func WithPresencePenalty(v float64) Opt
- func WithSafePrompt() Opt
- func WithSeed(v uint64) Opt
- func WithStopSequence(v ...string) Opt
- func WithStream(fn func(Completion)) Opt
- func WithSystemPrompt(v string) Opt
- func WithTemperature(v float64) Opt
- func WithToolChoice(v ...string) Opt
- func WithToolKit(toolkit ToolKit) Opt
- func WithTopK(v uint64) Opt
- func WithTopP(v float64) Opt
- type Opts
- func (o *Opts) Agents() []Agent
- func (o *Opts) Attachments() []*Attachment
- func (o *Opts) Get(key string) any
- func (o *Opts) GetBool(key string) bool
- func (o *Opts) GetDuration(key string) time.Duration
- func (o *Opts) GetFloat64(key string) float64
- func (o *Opts) GetString(key string) string
- func (o *Opts) GetUint64(key string) uint64
- func (o *Opts) Has(key string) bool
- func (o Opts) MarshalJSON() ([]byte, error)
- func (o *Opts) Set(key string, value any)
- func (o *Opts) StreamFn() func(Completion)
- func (o Opts) String() string
- func (o *Opts) SystemPrompt() string
- func (o *Opts) ToolKit() ToolKit
- type Tool
- type ToolCall
- type ToolKit
- type ToolResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Agent ¶
type Agent interface { // Return the name of the agent Name() string // Return the models Models(context.Context) ([]Model, error) // Return a model by name, or nil if not found. // Panics on error. Model(context.Context, string) Model }
An LLM Agent is a client for the LLM service
type Attachment ¶
type Attachment struct {
// contains filtered or unexported fields
}
Attachment for messages
func ReadAttachment ¶
func ReadAttachment(r io.Reader) (*Attachment, error)
ReadAttachment returns an attachment from a reader object. It is the responsibility of the caller to close the reader.
func (*Attachment) Data ¶
func (a *Attachment) Data() []byte
func (*Attachment) Filename ¶
func (a *Attachment) Filename() string
func (*Attachment) String ¶ added in v0.0.3
func (a *Attachment) String() string
func (*Attachment) Type ¶ added in v0.0.3
func (a *Attachment) Type() string
func (*Attachment) Url ¶ added in v0.0.3
func (a *Attachment) Url() string
type Completion ¶ added in v0.0.3
type Completion interface { // Return the number of completions, which is ususally 1 unless // WithNumCompletions was used when calling the model Num() int // Return the current session role, which can be system, assistant, user, tool, tool_result, ... // If this is a completion, the role is usually 'assistant' Role() string // Return the text for the last completion, with the argument as the // completion index (usually 0). If multiple completions are not // supported, the argument is ignored. Text(int) string // Return the current session tool calls given the completion index. // Will return nil if no tool calls were returned. ToolCalls(int) []ToolCall }
Completion is the content of the last context message
type Context ¶
type Context interface { Completion // Generate a response from a user prompt (with attachments and // other options) FromUser(context.Context, string, ...Opt) error // Generate a response from a tool, passing the results // from the tool call FromTool(context.Context, ...ToolResult) error }
Context is fed to the agent to generate a response
type Model ¶
type Model interface { // Return the name of the model Name() string // Return am empty session context object for the model, // setting session options Context(...Opt) Context // Convenience method to create a session context object // with a user prompt UserPrompt(string, ...Opt) Context // Embedding vector generation Embedding(context.Context, string, ...Opt) ([]float64, error) }
An Model can be used to generate a response to a user prompt, which is passed to an agent. The interaction occurs through a session context object.
type Opt ¶
A generic option type, which can set options on an agent or session
func WithFrequencyPenalty ¶ added in v0.0.3
func WithMaxTokens ¶ added in v0.0.3
The maximum number of tokens to generate in the completion.
func WithNumCompletions ¶ added in v0.0.3
Number of completions to return for each request
func WithPresencePenalty ¶ added in v0.0.3
func WithSafePrompt ¶ added in v0.0.3
func WithSafePrompt() Opt
Inject a safety prompt before all conversations.
func WithTemperature ¶
The temperature of the model. Increasing the temperature will make the model answer more creatively.
func WithToolChoice ¶ added in v0.0.3
Set tool choices: can be auto, none, required, any or a list of tool names
type Opts ¶
type Opts struct {
// contains filtered or unexported fields
}
set of options
func ApplyPromptOpts ¶ added in v0.0.3
ApplyPromptOpts returns a structure of options for a prompt
func (*Opts) GetDuration ¶
Get an option value as a duration
func (*Opts) GetFloat64 ¶
Get an option value as a float64
func (Opts) MarshalJSON ¶ added in v0.0.3
type Tool ¶
type Tool interface { // The name of the tool Name() string // The description of the tool Description() string // Run the tool with a deadline and return the result Run(context.Context) (any, error) }
Definition of a tool
type ToolCall ¶
type ToolCall interface { // The tool name Name() string // The tool identifier Id() string // Decode the calling parameters Decode(v any) error }
A call-out to a tool
type ToolKit ¶
type ToolKit interface { // Register a tool in the toolkit Register(Tool) error // Return all the tools Tools(Agent) []Tool // Run the tool calls in parallel and return the results Run(context.Context, ...ToolCall) ([]ToolResult, error) }
ToolKit is a collection of tools
type ToolResult ¶
type ToolResult interface { // The call associated with the result Call() ToolCall // The result, which can be encoded into json Value() any }
Results from calling tools
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
cmd
|
|
pkg
|
|
anthropic
anthropic implements an API client for anthropic (https://docs.anthropic.com/en/api/getting-started)
|
anthropic implements an API client for anthropic (https://docs.anthropic.com/en/api/getting-started) |
mistral
mistral implements an API client for mistral (https://docs.mistral.ai/api/)
|
mistral implements an API client for mistral (https://docs.mistral.ai/api/) |
newsapi
newsapi implements an API client for NewsAPI (https://newsapi.org/docs)
|
newsapi implements an API client for NewsAPI (https://newsapi.org/docs) |
ollama
ollama implements an API client for ollama https://github.com/ollama/ollama/blob/main/docs/api.md
|
ollama implements an API client for ollama https://github.com/ollama/ollama/blob/main/docs/api.md |