renakre
renakre

Reputation: 8291

"Invalid constructor input for Tool" error when using function calling with gemini-pro

I have the following code to enabling function calling with gemini-pro model (it is based on this example).

def getWordCount(sentence:str):
    return len(sentence.split(' '))


model = genai.GenerativeModel(model_name='models/gemini-pro', tools=[getWordCount])

model._tools.to_proto()

For some reason, I received the following error:

TypeError: Invalid constructor input for Tool: <function getWordCount at 0x7a9baaf95c60>

The error repeats for all the following models:

models/gemini-1.0-pro
models/gemini-1.0-pro-001
models/gemini-1.0-pro-latest
models/gemini-1.0-pro-vision-latest
models/gemini-pro
models/gemini-pro-vision

I could not find any resources to resolve this issue. I appreciate any help.

Upvotes: 0

Views: 239

Answers (1)

Linda Lawton - DaImTo
Linda Lawton - DaImTo

Reputation: 116868

This is how you declare a tool

calculator = glm.Tool(
function_declarations=[
  glm.FunctionDeclaration(
    name='multiply',
    description="Returns the product of two numbers.",
    parameters=glm.Schema(
        type=glm.Type.OBJECT,
        properties={
            'a':glm.Schema(type=glm.Type.NUMBER),
            'b':glm.Schema(type=glm.Type.NUMBER)
        },
        required=['a','b']
    )
  )
])

It's not just a python function

Upvotes: 1

Related Questions