Files
genai-toolbox/internal/tools/tools.go
Yuan e815dc49f4 chore: update params type (#98)
Different databases require different types for `Params` field when
adding parameters to their statement. e.g. alloydb, cloudsql, and
postgres uses `pgxpool` to query and build sql statement, whereas
spanner uses `Spanner` library.

Added a new `ParamValue` struct. `ParseParams` helper function parses
arbitraryJSON object into `[]ParamValue`, and the tool's invoke will
convert `[]ParamValue` into it's required type.

---------

Co-authored-by: Kurtis Van Gent <31518063+kurtisvg@users.noreply.github.com>
2024-12-05 16:05:09 -08:00

37 lines
1.1 KiB
Go

// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package tools
import (
"github.com/googleapis/genai-toolbox/internal/sources"
)
type ToolConfig interface {
ToolConfigKind() string
Initialize(map[string]sources.Source) (Tool, error)
}
type Tool interface {
Invoke(ParamValues) (string, error)
ParseParams(data map[string]any) (ParamValues, error)
Manifest() Manifest
}
// Manifest is the representation of tools sent to Client SDKs.
type Manifest struct {
Description string `json:"description"`
Parameters []ParameterManifest `json:"parameters"`
}