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
- func WrapFunction(name, description string, args any, fn CallableFunc) (*functionWrapper, error)
- type CallableFunc
- type ContentGenerator
- type DataType
- type Definition
- type Embedder
- type FunctionCall
- type HandlerExecutor
- type KVStore
- type MergeStrategy
- type Message
- type Messages
- type Metadata
- type Middleware
- type MiddlewareFunc
- type MiddlewareHandler
- 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 ¶
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
func WrapFunction ¶
func WrapFunction(name, description string, args any, fn CallableFunc) (*functionWrapper, error)
WrapFunction takes a `CallableFunc` and wraps it as a `minds.Tool` with the provided name and description.
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 HandlerExecutor ¶ added in v0.0.6
type HandlerExecutor func(tc ThreadContext, handlers []ThreadHandler, next ThreadHandler) (ThreadContext, error)
HandlerExecutor defines a strategy for executing child handlers. It receives the current ThreadContext, a slice of handlers to execute, and an optional next handler to call after all handlers have been processed. The executor is responsible for defining how and when each handler is executed.
type MergeStrategy ¶ added in v0.0.5
type MergeStrategy int
MergeStrategy defines how to handle metadata key conflicts
const ( // KeepExisting keeps the existing value on conflict KeepExisting MergeStrategy = iota // KeepNew overwrites with the new value on conflict KeepNew // Combine attempts to combine values (slice/map/string) Combine // Skip ignores conflicting keys Skip )
type Message ¶
type Message struct { Role Role `json:"role"` Content string `json:"content"` Name string `json:"name,omitempty"` // For function calls Metadata Metadata `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) Last ¶
Last returns the last message in the slice of messages. NOTE: This will return an empty message if there are no messages in the slice.
func (Messages) TokenCount ¶
func (m Messages) TokenCount(tokenizer TokenCounter) (int, error)
type Metadata ¶
func (Metadata) Merge ¶ added in v0.0.5
func (m Metadata) Merge(other Metadata, strategy MergeStrategy) Metadata
Merge combines the current metadata with another, using the specified strategy
func (Metadata) MergeWithCustom ¶ added in v0.0.5
func (m Metadata) MergeWithCustom(other Metadata, strategy MergeStrategy, customMerge map[string]func(existing, new any) any) Metadata
MergeWithCustom combines metadata with custom handlers for specific keys
type Middleware ¶ added in v0.0.6
type Middleware interface {
Wrap(next ThreadHandler) ThreadHandler
}
Middleware represents a function that can wrap a ThreadHandler
func NewMiddleware ¶ added in v0.0.6
func NewMiddleware(name string, fn func(tc ThreadContext) error) Middleware
NewMiddleware creates a new middleware that runs a function before passing control to the next handler. The provided function can modify the ThreadContext and return an error to halt processing.
type MiddlewareFunc ¶ added in v0.0.6
type MiddlewareFunc func(next ThreadHandler) ThreadHandler
MiddlewareFunc is a function that implements the Middleware interface
func (MiddlewareFunc) Wrap ¶ added in v0.0.6
func (f MiddlewareFunc) Wrap(next ThreadHandler) ThreadHandler
type MiddlewareHandler ¶ added in v0.0.6
type MiddlewareHandler interface { ThreadHandler // Use adds middleware to the handler Use(middleware ...Middleware) // WithMiddleware returns a new handler with the provided middleware applied With(middleware ...Middleware) ThreadHandler }
func SupportsMiddleware ¶ added in v0.0.6
func SupportsMiddleware(h ThreadHandler) (MiddlewareHandler, bool)
SupportsMiddleware checks if the given handler supports middleware operations
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 ToolChoice string }
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 { // Clone returns a deep copy of the ThreadContext. Clone() ThreadContext Context() context.Context UUID() string // Messages returns a copy of the messages in the context. Messages() Messages // Metadata returns a copy of the metadata in the context. Metadata() Metadata AppendMessages(message ...Message) // SetKeyValue sets a key-value pair in the metadata. SetKeyValue(key string, value any) // WithContext returns a new ThreadContext with the provided context. WithContext(ctx context.Context) ThreadContext // WithUUID returns a new ThreadContext with the provided UUID. WithUUID(uuid string) ThreadContext // WithMessages returns a new ThreadContext with the provided messages. WithMessages(message ...Message) ThreadContext // WithMetadata returns a new ThreadContext with the provided metadata. 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.
type ToolCall ¶
type ToolCall struct { ID string `json:"id,omitempty"` Type string `json:"type,omitempty"` Function FunctionCall `json:"function,omitempty"` }
func HandleFunctionCalls ¶
func HandleFunctionCalls(ctx context.Context, calls []ToolCall, registry ToolRegistry) ([]ToolCall, error)
HandleFunctionCalls takes an array of ToolCalls and executes the functions they represent using the provided ToolRegistry. It returns an array of ToolCalls with the results of the function calls.
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