Documentation
¶
Index ¶
- type Agent
- type Attachment
- func (a *Attachment) Append(other *Attachment)
- func (a *Attachment) Caption() string
- func (a *Attachment) Data() []byte
- func (a *Attachment) Filename() string
- func (a *Attachment) Hash() string
- func (a *Attachment) MarshalJSON() ([]byte, error)
- func (a *Attachment) String() string
- func (a *Attachment) Type() string
- func (a *Attachment) UnmarshalJSON(data []byte) error
- func (a *Attachment) Url() string
- func (a *Attachment) Write(w io.Writer) (int, error)
- type AttachmentMeta
- type Completion
- type Context
- type Err
- type ImageMeta
- 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 WithPrediction(v string) Opt
- func WithPresencePenalty(v float64) Opt
- func WithQuality(v string) Opt
- func WithSafePrompt() Opt
- func WithSeed(v uint64) Opt
- func WithSize(v string) Opt
- func WithStopSequence(v ...string) Opt
- func WithStream(fn func(Completion)) Opt
- func WithStyle(v string) 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
- func WithUser(v string) 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 NewAttachment ¶ added in v0.0.6
func NewAttachment() *Attachment
NewAttachment creates a new, empty attachment
func NewAttachmentWithImage ¶ added in v0.0.10
func NewAttachmentWithImage(image *ImageMeta) *Attachment
NewAttachment with OpenAI image
func ReadAttachment ¶
func ReadAttachment(r io.Reader, mimetype ...string) (*Attachment, error)
ReadAttachment returns an attachment from a reader object. It is the responsibility of the caller to close the reader.
func (*Attachment) Append ¶ added in v0.0.6
func (a *Attachment) Append(other *Attachment)
Streaming includes the ability to append data
func (*Attachment) Caption ¶ added in v0.0.6
func (a *Attachment) Caption() string
Return the caption for the attachment
func (*Attachment) Filename ¶
func (a *Attachment) Filename() string
Return the filename of an attachment
func (*Attachment) Hash ¶ added in v0.0.10
func (a *Attachment) Hash() string
Compute and print the MD5 hash
func (*Attachment) MarshalJSON ¶ added in v0.0.6
func (a *Attachment) MarshalJSON() ([]byte, error)
Convert an attachment into JSON
func (*Attachment) String ¶ added in v0.0.3
func (a *Attachment) String() string
Stringify an attachment
func (*Attachment) Type ¶ added in v0.0.3
func (a *Attachment) Type() string
Return the mime media type for the attachment, based on the data and/or filename extension. Returns an empty string if there is no data or filename
func (*Attachment) UnmarshalJSON ¶ added in v0.0.6
func (a *Attachment) UnmarshalJSON(data []byte) error
Convert JSON into an attachment
func (*Attachment) Url ¶ added in v0.0.3
func (a *Attachment) Url() string
type AttachmentMeta ¶ added in v0.0.6
type AttachmentMeta struct {
Id string `json:"id,omitempty"`
Filename string `json:"filename,omitempty"`
ExpiresAt uint64 `json:"expires_at,omitempty"`
Caption string `json:"transcript,omitempty"`
Data []byte `json:"data"`
Type string `json:"type"`
}
General attachment metadata
type Completion ¶ added in v0.0.3
type Completion interface {
// Return the number of completions, which is ususally 1 unless
// WithNumCompletions was used
Num() int
// Return a specific completion
Choice(int) Completion
// 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).
Text(int) string
// Return attachment (audio/image) for the last completion, with the
// argument as the completion index (usually 0).
Attachment(int) *Attachment
// 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 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
// Return the duration since the last completion was made
// or zero
SinceLast() time.Duration
}
Context is a context window fed to the agent to generate a response, with the ability to create the next completion
type ImageMeta ¶ added in v0.0.10
type ImageMeta struct {
Url string `json:"url,omitempty"`
Data []byte `json:"b64_json,omitempty"`
Prompt string `json:"revised_prompt,omitempty"`
}
OpenAI image metadata
type Model ¶
type Model interface {
// Return the name of the model
Name() string
// Return the description of the model
Description() string
// Return any model aliases
Aliases() []string
// Return am empty session context object for the model, setting
// session options
Context(...Opt) Context
// Create a completion from a text prompt, including image
// and audio (TTS) generation
Completion(context.Context, string, ...Opt) (Completion, error)
// 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. A back-and-forth interaction occurs through a session context object.
type Opt ¶
A generic option type, which can set options on an agent or session
func WithFormat ¶ added in v0.0.3
Set format for output, which is dependent on the model used
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 WithPrediction ¶ added in v0.0.6
Predicted output, which is most common when you are regenerating a file with only minor changes to most of the content.
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
func WithTopK ¶
Reduces the probability of generating nonsense. A higher value (e.g. 100) will give more diverse answers, while a lower value (e.g. 10) will be more conservative.
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
|
|
|
llm
command
|
|
|
examples
|
|
|
agents
command
|
|
|
completion
command
|
|
|
embedding
command
|
|
|
image_caption
command
|
|
|
image_generate
command
|
|
|
models
command
|
|
|
tool_adder
command
|
|
|
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 |
|
gemini
gemini implements an API client for Google's Gemini LLM (https://ai.google.dev/gemini-api/docs)
|
gemini implements an API client for Google's Gemini LLM (https://ai.google.dev/gemini-api/docs) |
|
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 |
|
openai
openai implements an API client for OpenAI https://platform.openai.com/docs/api-reference
|
openai implements an API client for OpenAI https://platform.openai.com/docs/api-reference |