refactor(tools): removing pointer map
This is not needed
This commit is contained in:
@ -204,7 +204,7 @@ func CreateAgentClient(prompt string) (AgentClient, error) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
ToolHandler: ToolsHandlers{
|
ToolHandler: ToolsHandlers{
|
||||||
handlers: &map[string]ToolHandler{},
|
handlers: map[string]ToolHandler{},
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ type ToolHandler struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ToolsHandlers struct {
|
type ToolsHandlers struct {
|
||||||
handlers *map[string]ToolHandler
|
handlers map[string]ToolHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
var NoToolCallError = errors.New("An assistant tool call with no tool calls was provided.")
|
var NoToolCallError = errors.New("An assistant tool call with no tool calls was provided.")
|
||||||
@ -33,7 +33,7 @@ func (handler ToolsHandlers) Handle(info ToolHandlerInfo, toolCallMessage AgentA
|
|||||||
fnName := toolCall.Function.Name
|
fnName := toolCall.Function.Name
|
||||||
arguments := toolCall.Function.Arguments
|
arguments := toolCall.Function.Arguments
|
||||||
|
|
||||||
fnHandler, exists := (*handler.handlers)[fnName]
|
fnHandler, exists := handler.handlers[fnName]
|
||||||
if !exists {
|
if !exists {
|
||||||
return []AgentTextMessage{}, errors.New("Could not find tool with this name.")
|
return []AgentTextMessage{}, errors.New("Could not find tool with this name.")
|
||||||
}
|
}
|
||||||
@ -58,8 +58,8 @@ func (handler ToolsHandlers) Handle(info ToolHandlerInfo, toolCallMessage AgentA
|
|||||||
return responses, nil
|
return responses, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (handler ToolsHandlers) AddTool(name string, fn func(info ToolHandlerInfo, args string, call ToolCall) (any, error)) {
|
func (handler *ToolsHandlers) AddTool(name string, fn func(info ToolHandlerInfo, args string, call ToolCall) (any, error)) {
|
||||||
(*handler.handlers)[name] = ToolHandler{
|
handler.handlers[name] = ToolHandler{
|
||||||
Fn: func(info ToolHandlerInfo, args string, call ToolCall) (string, error) {
|
Fn: func(info ToolHandlerInfo, args string, call ToolCall) (string, error) {
|
||||||
res, err := fn(info, args, call)
|
res, err := fn(info, args, call)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -16,7 +16,7 @@ type ToolTestSuite struct {
|
|||||||
|
|
||||||
func (suite *ToolTestSuite) SetupTest() {
|
func (suite *ToolTestSuite) SetupTest() {
|
||||||
suite.handler = ToolsHandlers{
|
suite.handler = ToolsHandlers{
|
||||||
handlers: &map[string]ToolHandler{},
|
handlers: map[string]ToolHandler{},
|
||||||
}
|
}
|
||||||
|
|
||||||
suite.handler.AddTool("a", func(info ToolHandlerInfo, args string, call ToolCall) (any, error) {
|
suite.handler.AddTool("a", func(info ToolHandlerInfo, args string, call ToolCall) (any, error) {
|
||||||
|
Reference in New Issue
Block a user