chore: Access params by maps for execute-sql tools (#1097)

It's safer and also more readable to access params by map.
This commit is contained in:
Wenxin Du
2025-08-06 16:42:02 -04:00
committed by GitHub
parent 99978bc697
commit 4fd19bf9af
6 changed files with 19 additions and 19 deletions

View File

@@ -118,10 +118,10 @@ type Tool struct {
}
func (t Tool) Invoke(ctx context.Context, params tools.ParamValues) (any, error) {
sliceParams := params.AsSlice()
sql, ok := sliceParams[0].(string)
paramsMap := params.AsMap()
sql, ok := paramsMap["sql"].(string)
if !ok {
return nil, fmt.Errorf("unable to get cast %s", sliceParams[0])
return nil, fmt.Errorf("unable to get cast %s", paramsMap["sql"])
}
// Log the query executed for debugging.

View File

@@ -118,10 +118,10 @@ type Tool struct {
}
func (t Tool) Invoke(ctx context.Context, params tools.ParamValues) (any, error) {
sliceParams := params.AsSlice()
sql, ok := sliceParams[0].(string)
paramsMap := params.AsMap()
sql, ok := paramsMap["sql"].(string)
if !ok {
return nil, fmt.Errorf("unable to get cast %s", sliceParams[0])
return nil, fmt.Errorf("unable to get cast %s", paramsMap["sql"])
}
// Log the query executed for debugging.

View File

@@ -124,10 +124,10 @@ type Tool struct {
}
func (t Tool) Invoke(ctx context.Context, params tools.ParamValues) (any, error) {
sliceParams := params.AsSlice()
cypherStr, ok := sliceParams[0].(string)
paramsMap := params.AsMap()
cypherStr, ok := paramsMap["cypher"].(string)
if !ok {
return nil, fmt.Errorf("unable to get cast %s", sliceParams[0])
return nil, fmt.Errorf("unable to get cast %s", paramsMap["cypher"])
}
if cypherStr == "" {
@@ -145,7 +145,7 @@ func (t Tool) Invoke(ctx context.Context, params tools.ParamValues) (any, error)
}
config := neo4j.ExecuteQueryWithDatabase(t.Database)
results, err := neo4j.ExecuteQuery[*neo4j.EagerResult](ctx, t.Driver, cypherStr, nil,
results, err := neo4j.ExecuteQuery(ctx, t.Driver, cypherStr, nil,
neo4j.EagerResultTransformer, config)
if err != nil {
return nil, fmt.Errorf("unable to execute query: %w", err)

View File

@@ -120,10 +120,10 @@ type Tool struct {
}
func (t Tool) Invoke(ctx context.Context, params tools.ParamValues) (any, error) {
sliceParams := params.AsSlice()
sql, ok := sliceParams[0].(string)
paramsMap := params.AsMap()
sql, ok := paramsMap["sql"].(string)
if !ok {
return nil, fmt.Errorf("unable to get cast %s", sliceParams[0])
return nil, fmt.Errorf("unable to get cast %s", paramsMap["sql"])
}
// Log the query executed for debugging.
logger, err := util.LoggerFromContext(ctx)

View File

@@ -146,10 +146,10 @@ func processRows(iter *spanner.RowIterator) ([]any, error) {
}
func (t Tool) Invoke(ctx context.Context, params tools.ParamValues) (any, error) {
sliceParams := params.AsSlice()
sql, ok := sliceParams[0].(string)
paramsMap := params.AsMap()
sql, ok := paramsMap["sql"].(string)
if !ok {
return nil, fmt.Errorf("unable to get cast %s", sliceParams[0])
return nil, fmt.Errorf("unable to get cast %s", paramsMap["sql"])
}
// Log the query executed for debugging.

View File

@@ -116,10 +116,10 @@ type Tool struct {
}
func (t Tool) Invoke(ctx context.Context, params tools.ParamValues) (any, error) {
sliceParams := params.AsSlice()
sql, ok := sliceParams[0].(string)
paramsMap := params.AsMap()
sql, ok := paramsMap["sql"].(string)
if !ok {
return nil, fmt.Errorf("unable to get cast %s", sliceParams[0])
return nil, fmt.Errorf("unable to get cast %s", paramsMap["sql"])
}
// Log the query executed for debugging.