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{
|
||||
handlers: &map[string]ToolHandler{},
|
||||
handlers: map[string]ToolHandler{},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ type ToolHandler 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.")
|
||||
@ -33,7 +33,7 @@ func (handler ToolsHandlers) Handle(info ToolHandlerInfo, toolCallMessage AgentA
|
||||
fnName := toolCall.Function.Name
|
||||
arguments := toolCall.Function.Arguments
|
||||
|
||||
fnHandler, exists := (*handler.handlers)[fnName]
|
||||
fnHandler, exists := handler.handlers[fnName]
|
||||
if !exists {
|
||||
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
|
||||
}
|
||||
|
||||
func (handler ToolsHandlers) AddTool(name string, fn func(info ToolHandlerInfo, args string, call ToolCall) (any, error)) {
|
||||
(*handler.handlers)[name] = ToolHandler{
|
||||
func (handler *ToolsHandlers) AddTool(name string, fn func(info ToolHandlerInfo, args string, call ToolCall) (any, error)) {
|
||||
handler.handlers[name] = ToolHandler{
|
||||
Fn: func(info ToolHandlerInfo, args string, call ToolCall) (string, error) {
|
||||
res, err := fn(info, args, call)
|
||||
if err != nil {
|
||||
|
@ -16,7 +16,7 @@ type ToolTestSuite struct {
|
||||
|
||||
func (suite *ToolTestSuite) SetupTest() {
|
||||
suite.handler = ToolsHandlers{
|
||||
handlers: &map[string]ToolHandler{},
|
||||
handlers: map[string]ToolHandler{},
|
||||
}
|
||||
|
||||
suite.handler.AddTool("a", func(info ToolHandlerInfo, args string, call ToolCall) (any, error) {
|
||||
|
Reference in New Issue
Block a user