0

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.

1

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

based on your example, so it will automatically understand that it needs to multiple a by b? there is no need to add the following return a * b?
No it will tell your application that it needs to run the code you have defined for the multiply function. I have a video on how to make a chatbot with functions if you're interested

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.