Welcome to Portkey Forum

Updated 3 days ago

"fn.function is not a function" error when using function calling with Gemini in Portkey

Title: "fn.function is not a function" error when using function calling with Gemini in Portkey
Description:
When trying to use function calling with Gemini model (virtualKey: "google") in Portkey, the following error occurs: fn.function is not a function. This happens when executing the runTools method. While function calling works correctly with other models (GPT-4, Mistral), it fails specifically with Gemini.
Steps to reproduce:

Configure Portkey with Gemini virtual key:

javascriptCopyconst portkey = new Portkey({
apiKey: process.env.PORTKEY_API_KEY,
virtualKey: "google",
traceID: "some-trace-id",
config: { cache: { mode: "semantic", max_age: 60000 } }
});

Define a tool:

javascriptCopyconst tools = [{
type: 'function',
function: {
name: 'cm6zksl7v00002v9f8asxnvpq',
description: "Get a random cat image",
parameters: {
type: "object",
properties: {
style: {
type: "string",
enum: ["cute", "funny", "sleepy"],
description: "Cat image style"
}
},
required: []
}
}
}];

Error occurs when running:

javascriptCopyconst runner = await portkey.beta.chat.completions.runTools({
messages: [...],
model: "gemini-model-name",
tools,
tool_choice: "auto",
stream: true,
temperature: 0,
user: "agentId"
});
Expected behavior: Portkey should properly execute the function calling with Gemini model as it does with other models.
V
H
s
17 comments
Gemini calling funcitons does not work
Hi @Heisenberg sorry we were away yesterday, will get back to you today ASAP
Hey @Heisenberg this doesn't appear to be a portkey error, can you send your error logs in the chat?
does it say provider error?
Hi @sega

I wanted to let you know that while the other models are using function, the only model using function_declaration is Gemini. This discrepancy is breaking my workflow with all the models.
but you're sending function only right, with both the calls, non-gemini and gemini??
portkey handles the transformation for you
Hello Portkey Team,

I'm experiencing the following error in my application. Please see the details below:

Plain Text
400 google error: * GenerateContentRequest.tools[0].function_declarations[0].parameters.properties: should be non-empty for OBJECT type
    at APIError.generate (/home/gonza/Desktop/chastapp/chatsappai-data/node_modules/.pnpm/openai@4.55.3_encoding@0.1.13_zod@3.22.4/node_modules/openai/error.js:45:20)
    at OpenAI.makeStatusError (/home/gonza/Desktop/chastapp/chatsappai-data/node_modules/.pnpm/openai@4.55.3_encoding@0.1.13_zod@3.22.4/node_modules/openai/core.js:275:33)
    at OpenAI.makeRequest (/home/gonza/Desktop/chastapp/chatsappai-data/node_modules/.pnpm/openai@4.55.3_encoding@0.1.13_zod@3.22.4/node_modules/openai/core.js:318:30)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async ChatCompletionRunner._createChatCompletion (/home/gonza/Desktop/chastapp/chatsappai-data/node_modules/.pnpm/openai@4.55.3_encoding@0.1.13_zod@3.22.4/node_modules/openai/lib/AbstractChatCompletionRunner.js:127:32)
    at async ChatCompletionRunner._runTools (/home/gonza/Desktop/chastapp/chatsappai-data/node_modules/.pnpm/openai@4.55.3_encoding@0.1.13_zod@3.22.4/node_modules/openai/lib/AbstractChatCompletionRunner.js:249:36) {
  status: 400,
  headers: {
  },
  request_id: undefined,
  error: {
    message: 'google error: * GenerateContentRequest.tools[0].function_declarations[0].parameters.properties: should be non-empty for OBJECT type\n',
    type: 'INVALID_ARGUMENT',
    param: null,
    code: 400
  },
}


It appears that the error is related to the parameter validation in: GenerateContentRequest.tools[0].function_declarations[0].parameters.properties
model: gemini_1.5_flash
I would appreciate your assistance in resolving this issue.

Thank you very much! @sega
Hey @Heisenberg when you’re sending a json object, you need to have properties field

Your OpenAI requests might be passing because they have a rather flexible validation system for json schema
Let me see if I can find an example
example:
Plain Text
        {
            "type": "function",
            "function": {
                "strict": true,
                "name": "get_current_temperature",
                "description": "Get the current temperature for a specific location",
                "parameters": {
                    "type": "object",
                    "properties": {
                        "additional_properties": true,
                        "location": {
                            "type": "string",
                            "description": "The city and state, e.g., San Francisco, CA"
                        },
                        "unit": {
                            "type": "string",
                            "enum": [
                                "Celsius",
                                "Fahrenheit"
                            ],
                            "description": "The temperature unit to use. Infer this from the user's location."
                        }
                    },
                    "required": [
                        "location",
                        "unit"
                    ]
                }
            }
        }
Thanks Sega, what I did for the moment was improve my schema how I send the requests of my tools action and I created a child class of LLM that only uses function_declaration for gemini and it worked normally
sweet, what's your setup if I may ask?
what language/frameworks are you building your services with?
Add a reply
Sign up and join the conversation on Discord