Documentation
¶
Index ¶
- Variables
- func SavePromptTemplate(filepath string, header PromptHeader, body string) error
- func Validate(schema Definition, data any) bool
- func VerifySchemaAndUnmarshal(schema Definition, content []byte, v any) error
- type CallableFunc
- type ContentGenerator
- type DataType
- type Definition
- type Embedder
- type FunctionCall
- type KVStore
- type Message
- type Messages
- type Metadata
- type NoopThreadHandler
- type Prompt
- type PromptHeader
- type Request
- type RequestOption
- type RequestOptions
- type Response
- type ResponseHandler
- type ResponseSchema
- type ResponseType
- type Role
- type ThreadContext
- type ThreadHandler
- type ThreadHandlerFunc
- type TokenCounter
- type Tool
- type ToolCall
- type ToolRegistry
- type ToolType
Constants ¶
This section is empty.
Variables ¶
View Source
var (
ErrNoMessages = errors.New("no messages in thread")
)
Functions ¶
func SavePromptTemplate ¶
func SavePromptTemplate(filepath string, header PromptHeader, body string) error
func Validate ¶
func Validate(schema Definition, data any) bool
func VerifySchemaAndUnmarshal ¶
func VerifySchemaAndUnmarshal(schema Definition, content []byte, v any) error
Types ¶
type ContentGenerator ¶
type Definition ¶
type Definition struct {
// Type specifies the data type of the schema.
Type DataType `json:"type,omitempty"`
// Description is the description of the schema.
Description string `json:"description,omitempty"`
// Enum is used to restrict a value to a fixed set of values. It must be an array with at least
// one element, where each element is unique. You will probably only use this with strings.
Enum []string `json:"enum,omitempty"`
// Properties describes the properties of an object, if the schema type is Object.
Properties map[string]Definition `json:"properties,omitempty"`
// Required specifies which properties are required, if the schema type is Object.
Required []string `json:"required,omitempty"`
// Items specifies which data type an array contains, if the schema type is Array.
Items *Definition `json:"items,omitempty"`
// AdditionalProperties is used to control the handling of properties in an object
// that are not explicitly defined in the properties section of the schema. example:
// additionalProperties: true
// additionalProperties: false
// additionalProperties: Definition{Type: String}
AdditionalProperties any `json:"additionalProperties,omitempty"`
}
Definition is a struct for describing a JSON Schema. It is fairly limited, and you may have better luck using a third-party library.
func GenerateSchema ¶
func GenerateSchema(v any) (*Definition, error)
func (*Definition) MarshalJSON ¶
func (d *Definition) MarshalJSON() ([]byte, error)
type FunctionCall ¶
type Message ¶
type Message struct {
Role Role `json:"role"`
Content string `json:"content"`
Name string `json:"name,omitempty"` // For function calls
Metadata map[string]any `json:"metadata,omitempty"` // For additional context
ToolCallID string `json:"tool_call_id,omitempty"`
ToolCalls []ToolCall `json:"func_response,omitempty"`
}
func (Message) TokenCount ¶
func (m Message) TokenCount(tokenizer TokenCounter) (int, error)
type Messages ¶
type Messages []*Message
func (Messages) Exclude ¶
Exclude returns a new slice of Message with messages with the specified roles removed
func (Messages) TokenCount ¶
func (m Messages) TokenCount(tokenizer TokenCounter) (int, error)
type NoopThreadHandler ¶
type NoopThreadHandler struct{}
func (NoopThreadHandler) HandleThread ¶
func (h NoopThreadHandler) HandleThread(tc ThreadContext, next ThreadHandler) (ThreadContext, error)
type Prompt ¶
type Prompt struct {
Header PromptHeader
Template *template.Template
}
type PromptHeader ¶
type Request ¶
type Request struct {
Options RequestOptions
Messages Messages `json:"messages"`
}
func NewRequest ¶
func NewRequest(messages Messages, opts ...RequestOption) Request
func (Request) TokenCount ¶
func (r Request) TokenCount(tokenizer TokenCounter) (int, error)
type RequestOption ¶
type RequestOption func(*RequestOptions)
func WithMaxOutputTokens ¶
func WithMaxOutputTokens(tokens int) RequestOption
func WithModel ¶
func WithModel(model string) RequestOption
func WithResponseSchema ¶
func WithResponseSchema(schema ResponseSchema) RequestOption
func WithTemperature ¶
func WithTemperature(temperature float32) RequestOption
type RequestOptions ¶
type RequestOptions struct {
ModelName *string
Temperature *float32
MaxOutputTokens *int
ResponseSchema *ResponseSchema
ToolRegistry ToolRegistry
}
type Response ¶
type Response interface {
// String returns a string representation of the response
String() string
// Type returns the type of this response (text, function call, etc.)
Type() ResponseType
// Text returns the text content if this is a text response.
Text() (string, bool)
// ToolCall returns the tool call details if this is a tool call response.
ToolCalls() ([]ToolCall, bool)
ToMessages() (Messages, error)
}
func HandleFunctionCalls ¶
func NewToolCallResponse ¶
type ResponseHandler ¶
func (ResponseHandler) HandleResponse ¶
func (h ResponseHandler) HandleResponse(resp Response) error
type ResponseSchema ¶
type ResponseSchema struct {
Name string `json:"name"`
Description string `json:"description"`
Definition Definition `json:"schema"`
}
func NewResponseSchema ¶
func NewResponseSchema(name, desc string, v any) (*ResponseSchema, error)
type ResponseType ¶
type ResponseType int
ResponseType indicates what kind of response we received
const ( ResponseTypeUnknown ResponseType = iota ResponseTypeText ResponseTypeToolCall )
type ThreadContext ¶
type ThreadContext interface {
Context() context.Context
UUID() string
Messages() Messages
Metadata() Metadata
WithUUID(uuid string) ThreadContext
WithMessages(messages Messages) ThreadContext
WithMetadata(metadata Metadata) ThreadContext
}
func NewThreadContext ¶
func NewThreadContext(ctx context.Context) ThreadContext
type ThreadHandler ¶
type ThreadHandler interface {
HandleThread(thread ThreadContext, next ThreadHandler) (ThreadContext, error)
}
type ThreadHandlerFunc ¶
type ThreadHandlerFunc func(thread ThreadContext, next ThreadHandler) (ThreadContext, error)
func (ThreadHandlerFunc) HandleThread ¶
func (f ThreadHandlerFunc) HandleThread(thread ThreadContext, next ThreadHandler) (ThreadContext, error)
type TokenCounter ¶
TokenCounter defines how to count tokens for different models
type Tool ¶
type Tool interface {
Type() string
Name() string
Description() string
Parameters() Definition
Call(context.Context, []byte) ([]byte, error)
}
Tool is an interface for a tool that can be executed by an LLM. It is similar to a function in that it takes input and produces output, but it can be more complex than a simple function and doesn't require a wrapper.
func WrapFunction ¶
func WrapFunction(name, description string, args interface{}, fn CallableFunc) (Tool, error)
type ToolCall ¶
type ToolCall struct {
ID string `json:"id,omitempty"`
Type string `json:"type,omitempty"`
Function FunctionCall `json:"function,omitempty"`
}
type ToolRegistry ¶
type ToolRegistry interface {
// Register adds a new function to the registry
Register(t Tool) error
// Lookup retrieves a function by name
Lookup(name string) (Tool, bool)
// List returns all registered functions
List() []Tool
}
func NewToolRegistry ¶
func NewToolRegistry() ToolRegistry
Source Files
¶
Click to show internal directories.
Click to hide internal directories.