Documentation
¶
Index ¶
- func Execute[T any, R any](r *Registry, name string, params T) (R, error)
- func ExecuteWithParams[T any, R any](fn func(T) (R, error), params map[string]interface{}) (interface{}, error)
- func RegisterTyped[T any, R any](r *Registry, fn *Function[T, R]) error
- type Function
- func (f *Function[T, R]) ExecuteWithJson(jsonParams string) (interface{}, error)
- func (f *Function[T, R]) ExecuteWithMap(params map[string]interface{}) (interface{}, error)
- func (f *Function[T, R]) GetDescription() string
- func (f *Function[T, R]) GetName() string
- func (f *Function[T, R]) GetParameters() map[string]generator.ParameterSchema
- type FunctionWrapper
- type Gopilot
- func (g *Gopilot) FunctionExecute(name string, params interface{}) (interface{}, error)
- func (g *Gopilot) FunctionGet(name string) (FunctionWrapper, error)
- func (g *Gopilot) FunctionRegister(fn FunctionWrapper) error
- func (g *Gopilot) FunctionsList() []FunctionWrapper
- func (g *Gopilot) Generate(input string) (*clients.LLMResponse, error)
- func (g *Gopilot) GenerateAndExecute(input string) (interface{}, error)
- func (g *Gopilot) SetSystemPrompt(importantRules []string, unsupportedFunction ...FunctionWrapper)
- type LLMProvider
- type ParamsMapper
- type Registry
- type UnsupportedParams
- type UnsupportedResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Function ¶
type Function[T any, R any] struct { Name string `json:"name"` Description string `json:"description"` Parameters map[string]generator.ParameterSchema `json:"parameters"` Execute func(params T) (R, error) }
Function represents a registered function in the system
func UnsupportedFunction ¶ added in v1.2.0
func UnsupportedFunction() *Function[UnsupportedParams, UnsupportedResponse]
UnsupportedFunction creates a new unsupported function handler
func (*Function[T, R]) ExecuteWithJson ¶ added in v1.2.0
ExecuteWithJson executes the function with JSON string parameters
func (*Function[T, R]) ExecuteWithMap ¶ added in v1.2.0
ExecuteWithMap executes the function with a parameter map
func (*Function[T, R]) GetDescription ¶ added in v1.2.0
GetDescription returns the function description
func (*Function[T, R]) GetParameters ¶ added in v1.2.0
func (f *Function[T, R]) GetParameters() map[string]generator.ParameterSchema
GetParameters returns the function parameters
type FunctionWrapper ¶ added in v1.2.0
type FunctionWrapper interface {
GetName() string
GetDescription() string
GetParameters() map[string]generator.ParameterSchema
ExecuteWithMap(map[string]interface{}) (interface{}, error)
}
FunctionWrapper is an interface that all functions must implement
type Gopilot ¶
type Gopilot struct {
// contains filtered or unexported fields
}
func NewGopilot ¶
func NewGopilot(llm LLMProvider) (*Gopilot, error)
func (*Gopilot) FunctionExecute ¶
FunctionExecute executes a registered function
func (*Gopilot) FunctionGet ¶
func (g *Gopilot) FunctionGet(name string) (FunctionWrapper, error)
FunctionGet retrieves a registered function
func (*Gopilot) FunctionRegister ¶
func (g *Gopilot) FunctionRegister(fn FunctionWrapper) error
FunctionRegister registers a new function
func (*Gopilot) FunctionsList ¶
func (g *Gopilot) FunctionsList() []FunctionWrapper
FunctionsList returns all registered functions
func (*Gopilot) Generate ¶
func (g *Gopilot) Generate(input string) (*clients.LLMResponse, error)
Generate generates a response from the LLM
func (*Gopilot) GenerateAndExecute ¶
GenerateAndExecute generates a response and executes the corresponding function
func (*Gopilot) SetSystemPrompt ¶
func (g *Gopilot) SetSystemPrompt(importantRules []string, unsupportedFunction ...FunctionWrapper)
SetSystemPrompt configures the system prompt
type LLMProvider ¶
type LLMProvider interface {
// Generate generates a response based on the given prompt
Generate(prompt string) (*clients.LLMResponse, error)
SetSystemPrompt(systemPrompt string)
}
LLMProvider defines the basic interface that any LLM provider must implement
type ParamsMapper ¶ added in v1.2.0
type ParamsMapper struct{}
ParamsMapper helps convert generic parameters to strongly typed structs
func (*ParamsMapper) Map ¶ added in v1.2.0
func (pm *ParamsMapper) Map(params map[string]interface{}, target interface{}) error
Map converts generic parameters to a strongly typed struct
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry represents a thread-safe function registry
func (*Registry) ExecuteFunction ¶ added in v1.2.0
ExecuteFunction executes a registered function with the given parameters
func (*Registry) Get ¶ added in v1.2.0
func (r *Registry) Get(name string) (FunctionWrapper, bool)
Get retrieves a function from the registry
func (*Registry) List ¶ added in v1.2.0
func (r *Registry) List() []FunctionWrapper
List returns all registered functions
func (*Registry) Register ¶ added in v1.2.0
func (r *Registry) Register(fn FunctionWrapper) error
Register adds a new function to the registry
type UnsupportedParams ¶ added in v1.2.0
type UnsupportedParams struct {
Message string `json:"message" description:"Contains a simple explanation of the error." required:"true"`
}
UnsupportedParams represents parameters for unsupported function
type UnsupportedResponse ¶ added in v1.2.0
type UnsupportedResponse struct {
Message string `json:"message"`
}
UnsupportedResponse represents the response from unsupported function