Documentation
¶
Index ¶
- func GoStruct2ParamsOneOf[T any](opts ...Option) (*schema.ParamsOneOf, error)
- func GoStruct2ToolInfo[T any](toolName, toolDesc string, opts ...Option) (*schema.ToolInfo, error)
- func InferOptionableStreamTool[T, D any](toolName, toolDesc string, s OptionableStreamFunc[T, D], opts ...Option) (tool.StreamableTool, error)
- func InferOptionableTool[T, D any](toolName, toolDesc string, i OptionableInvokeFunc[T, D], opts ...Option) (tool.InvokableTool, error)
- func InferStreamTool[T, D any](toolName, toolDesc string, s StreamFunc[T, D], opts ...Option) (tool.StreamableTool, error)
- func InferTool[T, D any](toolName, toolDesc string, i InvokeFunc[T, D], opts ...Option) (tool.InvokableTool, error)
- func NewStreamTool[T, D any](desc *schema.ToolInfo, s StreamFunc[T, D], opts ...Option) tool.StreamableTool
- func NewTool[T, D any](desc *schema.ToolInfo, i InvokeFunc[T, D], opts ...Option) tool.InvokableTool
- func WrapInvokableToolWithErrorHandler(t tool.InvokableTool, h ErrorHandler) tool.InvokableTool
- func WrapStreamableToolWithErrorHandler(t tool.StreamableTool, h ErrorHandler) tool.StreamableTool
- func WrapToolWithErrorHandler(t tool.BaseTool, h ErrorHandler) tool.BaseTool
- type ErrorHandler
- type InvokeFunc
- type MarshalOutput
- type Option
- type OptionableInvokeFunc
- type OptionableStreamFunc
- type SchemaCustomizerFn
- type StreamFunc
- type UnmarshalArguments
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GoStruct2ParamsOneOf ¶
func GoStruct2ParamsOneOf[T any](opts ...Option) (*schema.ParamsOneOf, error)
GoStruct2ParamsOneOf converts a go struct to a ParamsOneOf. if you attempt to use ResponseFormat of some ChatModel to get StructuredOutput, you can infer the JSONSchema from the go struct.
func GoStruct2ToolInfo ¶
GoStruct2ToolInfo converts a go struct to a ToolInfo. if you attempt to use BindTool to make ChatModel respond StructuredOutput, you can infer the ToolInfo from the go struct.
func InferOptionableStreamTool ¶ added in v0.3.18
func InferOptionableStreamTool[T, D any](toolName, toolDesc string, s OptionableStreamFunc[T, D], opts ...Option) (tool.StreamableTool, error)
InferOptionableStreamTool creates an StreamableTool from a given function by inferring the ToolInfo from the function's request parameters, with tool option.
func InferOptionableTool ¶ added in v0.3.18
func InferOptionableTool[T, D any](toolName, toolDesc string, i OptionableInvokeFunc[T, D], opts ...Option) (tool.InvokableTool, error)
InferOptionableTool creates an InvokableTool from a given function by inferring the ToolInfo from the function's request parameters, with tool option.
func InferStreamTool ¶
func InferStreamTool[T, D any](toolName, toolDesc string, s StreamFunc[T, D], opts ...Option) (tool.StreamableTool, error)
InferStreamTool creates an StreamableTool from a given function by inferring the ToolInfo from the function's request parameters End-user can pass a SchemaCustomizerFn in opts to customize the go struct tag parsing process, overriding default behavior.
func InferTool ¶
func InferTool[T, D any](toolName, toolDesc string, i InvokeFunc[T, D], opts ...Option) (tool.InvokableTool, error)
InferTool creates an InvokableTool from a given function by inferring the ToolInfo from the function's request parameters. End-user can pass a SchemaCustomizerFn in opts to customize the go struct tag parsing process, overriding default behavior.
func NewStreamTool ¶
func NewStreamTool[T, D any](desc *schema.ToolInfo, s StreamFunc[T, D], opts ...Option) tool.StreamableTool
NewStreamTool Create a streaming tool, where the input and output are both in JSON format. convert: convert the stream frame to string that could be concatenated to a string.
func NewTool ¶
func NewTool[T, D any](desc *schema.ToolInfo, i InvokeFunc[T, D], opts ...Option) tool.InvokableTool
NewTool Create a tool, where the input and output are both in JSON format.
func WrapInvokableToolWithErrorHandler ¶ added in v0.3.28
func WrapInvokableToolWithErrorHandler(t tool.InvokableTool, h ErrorHandler) tool.InvokableTool
WrapInvokableToolWithErrorHandler wraps an InvokableTool with custom error handling. When the wrapped tool returns an error, the error handler function 'h' will be called to convert the error into a string result, and no error will be returned from the wrapper.
Parameters:
- tool: The original InvokableTool to be wrapped
- h: A function that converts an error to a string
Returns:
- A wrapped InvokableTool that handles errors internally
func WrapStreamableToolWithErrorHandler ¶ added in v0.3.28
func WrapStreamableToolWithErrorHandler(t tool.StreamableTool, h ErrorHandler) tool.StreamableTool
WrapStreamableToolWithErrorHandler wraps a StreamableTool with custom error handling. When the wrapped tool returns an error, the error handler function 'h' will be called to convert the error into a string result, which will be returned as a single-item stream, and no error will be returned from the wrapper.
Parameters:
- tool: The original StreamableTool to be wrapped
- h: A function that converts an error to a string
Returns:
- A wrapped StreamableTool that handles errors internally
func WrapToolWithErrorHandler ¶ added in v0.3.28
func WrapToolWithErrorHandler(t tool.BaseTool, h ErrorHandler) tool.BaseTool
WrapToolWithErrorHandler wraps any BaseTool with custom error handling. This function detects the tool type (InvokableTool, StreamableTool, or both) and applies the appropriate error handling wrapper. When the wrapped tool returns an error, the error handler function 'h' will be called to convert the error into a string result, and no error will be returned from the wrapper.
Parameters:
- t: The original BaseTool to be wrapped
- h: A function that converts an error to a string
Returns:
- A wrapped BaseTool that handles errors internally based on its capabilities
Types ¶
type InvokeFunc ¶
InvokeFunc is the function type for the tool.
type MarshalOutput ¶
MarshalOutput is the function type for marshalling the output.
type Option ¶
type Option func(o *toolOptions)
Option is the option func for the tool.
func WithMarshalOutput ¶
func WithMarshalOutput(m MarshalOutput) Option
WithMarshalOutput wraps the marshal output option. when you want to marshal the output by yourself, you can use this option.
func WithSchemaCustomizer ¶
func WithSchemaCustomizer(sc SchemaCustomizerFn) Option
WithSchemaCustomizer sets a user-defined schema customizer for inferring tool parameter from tagged go struct. If this option is not set, the defaultSchemaCustomizer will be used.
func WithUnmarshalArguments ¶
func WithUnmarshalArguments(um UnmarshalArguments) Option
WithUnmarshalArguments wraps the unmarshal arguments option. when you want to unmarshal the arguments by yourself, you can use this option.
type OptionableInvokeFunc ¶ added in v0.3.18
type OptionableInvokeFunc[T, D any] func(ctx context.Context, input T, opts ...tool.Option) (output D, err error)
OptionableInvokeFunc is the function type for the tool with tool option.
type OptionableStreamFunc ¶ added in v0.3.18
type OptionableStreamFunc[T, D any] func(ctx context.Context, input T, opts ...tool.Option) (output *schema.StreamReader[D], err error)
OptionableStreamFunc is the function type for the streamable tool with tool option.
type SchemaCustomizerFn ¶
type SchemaCustomizerFn func(name string, t reflect.Type, tag reflect.StructTag, schema *openapi3.Schema) error
SchemaCustomizerFn is the schema customizer function for inferring tool parameter from tagged go struct. Within this function, end-user can parse custom go struct tags into corresponding openapi schema field. Parameters: 1. name: the name of current schema, usually the field name of the go struct. Specifically, the last 'name' visited is fixed to be '_root', which represents the entire go struct. Also, for array field, both the field itself and the element within the array will trigger this function. 2. t: the type of current schema, usually the field type of the go struct. 3. tag: the struct tag of current schema, usually the field tag of the go struct. Note that the element within an array field will use the same go struct tag as the array field itself. 4. schema: the current openapi schema object to be customized.
type StreamFunc ¶
type StreamFunc[T, D any] func(ctx context.Context, input T) (output *schema.StreamReader[D], err error)
StreamFunc is the function type for the streamable tool.