mirror of
https://github.com/googleapis/genai-toolbox.git
synced 2026-02-06 21:24:58 -05:00
add gcp tools refactor
This commit is contained in:
@@ -17,11 +17,13 @@ package cloudsqlgetinstances
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
yaml "github.com/goccy/go-yaml"
|
||||
"github.com/googleapis/genai-toolbox/internal/embeddingmodels"
|
||||
"github.com/googleapis/genai-toolbox/internal/sources"
|
||||
"github.com/googleapis/genai-toolbox/internal/tools"
|
||||
"github.com/googleapis/genai-toolbox/internal/util"
|
||||
"github.com/googleapis/genai-toolbox/internal/util/parameters"
|
||||
)
|
||||
|
||||
@@ -117,23 +119,27 @@ func (t Tool) ToConfig() tools.ToolConfig {
|
||||
}
|
||||
|
||||
// Invoke executes the tool's logic.
|
||||
func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, params parameters.ParamValues, accessToken tools.AccessToken) (any, error) {
|
||||
func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, params parameters.ParamValues, accessToken tools.AccessToken) (any, util.ToolboxError) {
|
||||
source, err := tools.GetCompatibleSource[compatibleSource](resourceMgr, t.Source, t.Name, t.Type)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, util.NewClientServerError("source used is not compatible with the tool", http.StatusInternalServerError, err)
|
||||
}
|
||||
|
||||
paramsMap := params.AsMap()
|
||||
|
||||
projectId, ok := paramsMap["projectId"].(string)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("missing 'projectId' parameter")
|
||||
return nil, util.NewAgentError("missing 'projectId' parameter", nil)
|
||||
}
|
||||
instanceId, ok := paramsMap["instanceId"].(string)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("missing 'instanceId' parameter")
|
||||
return nil, util.NewAgentError("missing 'instanceId' parameter", nil)
|
||||
}
|
||||
return source.GetInstance(ctx, projectId, instanceId, string(accessToken))
|
||||
resp, err := source.GetInstance(ctx, projectId, instanceId, string(accessToken))
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (t Tool) EmbedParams(ctx context.Context, paramValues parameters.ParamValues, embeddingModelsMap map[string]embeddingmodels.EmbeddingModel) (parameters.ParamValues, error) {
|
||||
|
||||
Reference in New Issue
Block a user