Documentation ¶
Index ¶
- Variables
- func GenerateInputSchemaDocument[T any]() (document.Interface, error)
- func MarshalJSONSchema(v any) ([]byte, error)
- func NewContext(parent context.Context, cc *ConverseContext) context.Context
- func ToolName(ctx context.Context) string
- func ToolUseID(ctx context.Context) string
- func ValidateToolName(name string) error
- type BedrockConverseAPIClient
- type ConverseContext
- type Dispacher
- func (d *Dispacher) Converse(ctx context.Context, params *bedrockruntime.ConverseInput, ...) ([]types.Message, error)
- func (d *Dispacher) GetError() error
- func (d *Dispacher) NewToolConfiguration(ctx context.Context) *types.ToolConfiguration
- func (d *Dispacher) OnAfterModelCall(...)
- func (d *Dispacher) OnAfterToolUse(...)
- func (d *Dispacher) OnBeforeModelCall(f func(context.Context, *bedrockruntime.ConverseInput))
- func (d *Dispacher) OnBeforeToolUse(f func(context.Context, *types.ContentBlockMemberToolUse))
- func (d *Dispacher) Register(name string, description string, worker Worker, opts ...RegisterOption)
- func (d *Dispacher) RegisterTool(tool Tool, opts ...RegisterOption)
- func (d *Dispacher) ResolveWorker(ctx context.Context, name string) (Worker, bool)
- func (d *Dispacher) SetLogger(logger *slog.Logger)
- func (d *Dispacher) SetToolChoice(tc types.ToolChoice)
- func (d *Dispacher) SubToolSet() *ToolSet
- func (d *Dispacher) Use(middlewares ...Middleware)
- func (d *Dispacher) Worker(name string) (Worker, bool)
- type EmptyWorkerInput
- type ExecuteMiddlewareFunc
- type InputSchemaMiddlewareFunc
- type Middleware
- type RegisterOption
- type Registory
- type Tool
- type ToolSet
- func (ts *ToolSet) Exists(name string) bool
- func (ts *ToolSet) GetError() error
- func (ts *ToolSet) Register(name string, description string, worker Worker, opts ...RegisterOption)
- func (ts *ToolSet) RegisterTool(tool Tool, opts ...RegisterOption)
- func (ts *ToolSet) SubToolSet() *ToolSet
- func (ts *ToolSet) Tools(ctx context.Context) []types.Tool
- func (ts *ToolSet) Use(middlewares ...Middleware)
- func (ts *ToolSet) Worker(name string) (Worker, bool)
- type Worker
Constants ¶
This section is empty.
Variables ¶
var NoPanicOnRegisterError = false
flag of panic behavior, when the error occurred during the registration of the tool.
Functions ¶
func MarshalJSONSchema ¶ added in v0.3.1
func NewContext ¶
func NewContext(parent context.Context, cc *ConverseContext) context.Context
func ValidateToolName ¶ added in v0.2.0
Types ¶
type BedrockConverseAPIClient ¶
type BedrockConverseAPIClient interface {
Converse(ctx context.Context, params *bedrockruntime.ConverseInput, optFns ...func(*bedrockruntime.Options)) (*bedrockruntime.ConverseOutput, error)
}
BedrockConverseAPIClient is a client for BedrockConverseAPI. see: https://pkg.go.dev/github.com/aws/aws-sdk-go-v2/service/bedrockruntime#Client.Converse
type ConverseContext ¶
type ConverseContext struct {
// contains filtered or unexported fields
}
func FromContext ¶
func FromContext(ctx context.Context) (*ConverseContext, bool)
func (*ConverseContext) InputMessages ¶
func (cc *ConverseContext) InputMessages() []types.Message
func (*ConverseContext) ModelID ¶
func (cc *ConverseContext) ModelID() string
func (*ConverseContext) OutputMessages ¶
func (cc *ConverseContext) OutputMessages() []types.Message
func (*ConverseContext) SetModelID ¶
func (cc *ConverseContext) SetModelID(modelID string)
SetModelID sets the model ID for the conversation. for in tool use. model id upgrade/downgrade.
func (*ConverseContext) System ¶
func (cc *ConverseContext) System() []types.SystemContentBlock
type Dispacher ¶
type Dispacher struct {
// contains filtered or unexported fields
}
Dispacher is a tool use dispacher. It is used to send messages to the specified Amazon Bedrock model.
func New ¶
func New(options bedrockruntime.Options, optFns ...func(*bedrockruntime.Options)) *Dispacher
New creates a new instance of the Bedrock Tool Use Dispacher.
func NewFromConfig ¶
func NewFromConfig(cfg aws.Config, optFns ...func(*bedrockruntime.Options)) *Dispacher
NewFromConfig creates a new instance of the Bedrock Tool Use Dispacher.
func NewWithClient ¶
func NewWithClient(client BedrockConverseAPIClient) *Dispacher
NewWithClient creates a new instance of the Bedrock Tool Use Dispacher.
func (*Dispacher) Converse ¶
func (d *Dispacher) Converse(ctx context.Context, params *bedrockruntime.ConverseInput, optFns ...func(*bedrockruntime.Options)) ([]types.Message, error)
Converse sends messages to the specified Amazon Bedrock model. input same as https://pkg.go.dev/github.com/aws/aws-sdk-go-v2/service/bedrockruntime#Client.Converse but output is different. because this function is multiple call Converse API. if you need track api call, use OnBeforeModelCall and OnAfterModelCall.
func (*Dispacher) GetError ¶
GetError returns the error that occurred during the registration of the tool.
func (*Dispacher) NewToolConfiguration ¶
func (d *Dispacher) NewToolConfiguration(ctx context.Context) *types.ToolConfiguration
NewToolConfiguration returns a new ToolConfiguration.
func (*Dispacher) OnAfterModelCall ¶
func (d *Dispacher) OnAfterModelCall(f func(context.Context, *bedrockruntime.ConverseInput, *bedrockruntime.ConverseOutput))
OnAfterModelCall sets the function to be called after the model is called. After Call Bedrock Converse API.
func (*Dispacher) OnAfterToolUse ¶
func (d *Dispacher) OnAfterToolUse(f func(context.Context, *types.ContentBlockMemberToolUse, types.ToolResultBlock))
OnAfterToolUse sets the function to be called after the tool is used. After Call Worker.Execute.
func (*Dispacher) OnBeforeModelCall ¶
func (d *Dispacher) OnBeforeModelCall(f func(context.Context, *bedrockruntime.ConverseInput))
OnBeforeModelCall sets the function to be called before the model is called. Before Call Bedrock Converse API.
func (*Dispacher) OnBeforeToolUse ¶
func (d *Dispacher) OnBeforeToolUse(f func(context.Context, *types.ContentBlockMemberToolUse))
OnBeforeToolUse sets the function to be called before the tool is used. Before Call Worker.Execute.
func (*Dispacher) Register ¶
func (d *Dispacher) Register(name string, description string, worker Worker, opts ...RegisterOption)
Register registers a tool with the specified name and description. if occurs error during the registration, it will panic. if you want to handle the error, use GetError and NoPanicOnRegisterError=false.
func (*Dispacher) RegisterTool ¶ added in v0.2.0
func (d *Dispacher) RegisterTool(tool Tool, opts ...RegisterOption)
RegisterTool registers a tool. this is syntactic sugar for Register.
func (*Dispacher) ResolveWorker ¶ added in v0.2.0
ResolveWorker returns the worker registered with the specified name. diff of Worker: consider to temporary tool set.
func (*Dispacher) SetToolChoice ¶
func (d *Dispacher) SetToolChoice(tc types.ToolChoice)
SetToolChoice sets the tool choice for the dispacher.
func (*Dispacher) SubToolSet ¶
func (*Dispacher) Use ¶
func (d *Dispacher) Use(middlewares ...Middleware)
type EmptyWorkerInput ¶
type EmptyWorkerInput struct{}
type ExecuteMiddlewareFunc ¶
type ExecuteMiddlewareFunc func(context.Context, types.ToolUseBlock, Worker) (types.ToolResultBlock, error)
func (ExecuteMiddlewareFunc) HandleExecute ¶
func (f ExecuteMiddlewareFunc) HandleExecute(ctx context.Context, in types.ToolUseBlock, next Worker) (types.ToolResultBlock, error)
func (ExecuteMiddlewareFunc) HandleInputSchema ¶
func (f ExecuteMiddlewareFunc) HandleInputSchema(next Worker) document.Interface
type InputSchemaMiddlewareFunc ¶
func (InputSchemaMiddlewareFunc) HandleExecute ¶
func (f InputSchemaMiddlewareFunc) HandleExecute(ctx context.Context, in types.ToolUseBlock, next Worker) (types.ToolResultBlock, error)
func (InputSchemaMiddlewareFunc) HandleInputSchema ¶
func (f InputSchemaMiddlewareFunc) HandleInputSchema(next Worker) document.Interface
type Middleware ¶
type RegisterOption ¶
type RegisterOption func(*workerEntry)
RegisterOption is an option for registering a tool.
func WithToolEnabler ¶
func WithToolEnabler(f func(context.Context) bool) RegisterOption
WithToolEnabler sets the function to determine whether the tool is enabled. this function is called before the first time Bedorck Converse API If return false, not enabled the tool in this conversation.
type Registory ¶
type Registory interface {
Register(name string, description string, worker Worker, opts ...RegisterOption)
}
type ToolSet ¶
type ToolSet struct {
// contains filtered or unexported fields
}
func WithToolSet ¶ added in v0.2.0
func (*ToolSet) Register ¶
func (ts *ToolSet) Register(name string, description string, worker Worker, opts ...RegisterOption)
func (*ToolSet) RegisterTool ¶ added in v0.2.0
func (ts *ToolSet) RegisterTool(tool Tool, opts ...RegisterOption)
func (*ToolSet) SubToolSet ¶
func (*ToolSet) Use ¶
func (ts *ToolSet) Use(middlewares ...Middleware)