googleapis / google-cloud-go

Google Cloud Client Libraries for Go.
https://cloud.google.com/go/docs/reference
Apache License 2.0
3.65k stars 1.24k forks source link

vertexai: more than one element in Tools throws an InvalidArgument rpc error #10393

Open mrothroc opened 2 weeks ago

mrothroc commented 2 weeks ago

Client

vertexai/genai

Environment

Local running on Mac OS X

Go Environment

go version go version go1.22.2 darwin/arm64

go env GO111MODULE='on' GOARCH='arm64' GOBIN='' GOCACHE='/Users/mrothroc/Library/Caches/go-build' GOENV='/Users/mrothroc/Library/Application Support/go/env' GOEXE='' GOEXPERIMENT='' GOFLAGS='' GOHOSTARCH='arm64' GOHOSTOS='darwin' GOINSECURE='' GOMODCACHE='/Users/mrothroc/go/pkg/mod' GONOPROXY='' GONOSUMDB='' GOOS='darwin' GOPATH='/Users/mrothroc/go' GOPRIVATE='' GOPROXY='https://proxy.golang.org,direct' GOROOT='/opt/homebrew/opt/go/libexec' GOSUMDB='sum.golang.org' GOTMPDIR='' GOTOOLCHAIN='auto' GOTOOLDIR='/opt/homebrew/opt/go/libexec/pkg/tool/darwin_arm64' GOVCS='' GOVERSION='go1.22.2' GCCGO='gccgo' AR='ar' CC='cc' CXX='c++' CGO_ENABLED='1' GOMOD='/Users/mrothroc/IdeaProjects/scrapertest2/go.mod' GOWORK='' CGO_CFLAGS='-O2 -g' CGO_CPPFLAGS='' CGO_CXXFLAGS='-O2 -g' CGO_FFLAGS='-O2 -g' CGO_LDFLAGS='-O2 -g' PKG_CONFIG='pkg-config' GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/5c/cwjs85zx5f73qtn3mv7_zh3r0000gn/T/go-build3282724130=/tmp/go-build -gno-record-gcc-switches -fno-common'

Code

    toolSet := make([]tools.Tool, 0)
    funcNames := make(map[string]tools.Tool)

    toolSet = append(toolSet, tools.NewFirstFunction())
    toolSet = append(toolSet, tools.NewSecondFunction())

    gTools := make([]*genai.Tool, 0)
    for _, tool := range toolSet {
        for _, name := range tool.GetNames() {
            funcNames[name] = tool
        }

        gTools = append(gTools, tool.GetDeclaration())
    }

    gemini.Tools = []*genai.Tool{toolSet[0].GetDeclaration(), toolSet[1].GetDeclaration()}

Expected behavior

Call to vertexai to work without an error.

Actual behavior

Error code returned: rpc error: code = InvalidArgument desc = Request contains an invalid argument.

Additional context

I have validated that providing either tool alone works, so the declaration is valid.

E.g. gemini.Tools = []genai.Tool{toolSet[0].GetDeclaration()} and gemini.Tools = []genai.Tool{toolSet[1].GetDeclaration()}

both work without error, but

gemini.Tools = []*genai.Tool{toolSet[0].GetDeclaration(), toolSet[1].GetDeclaration()}

fails with the above error.

codyoss commented 2 weeks ago

cc @jba @eliben

mrothroc commented 1 week ago

Can anyone suggest workarounds here? Has anyone been able to send multiple tools in an API call to gemini?

eliben commented 1 week ago

@mrothroc could you try to specify a single tool with a list of your functions? A tool (https://pkg.go.dev/cloud.google.com/go/vertexai/genai#Tool) has a list of function decls you can specify

mrothroc commented 1 week ago

I thought a tool was supposed to be a group of related functions. The functions I have are completely unrelated, so I thought I was supposed to do it this way.

As a workaround I can try stuffing them all the functions into a single tool.

mrothroc commented 1 week ago

I can confirm that putting all the functions in the single tool works.

eliben commented 1 week ago

Thanks for checking. I've labeled the issue aiplatform to indicate it's the underlying API that has the issue - it's not SDK specific.