Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues using tool calls with Google Gemeni #837

Open
au-re opened this issue Dec 22, 2024 · 1 comment
Open

Issues using tool calls with Google Gemeni #837

au-re opened this issue Dec 22, 2024 · 1 comment
Labels
bug Something isn't working triage

Comments

@au-re
Copy link

au-re commented Dec 22, 2024

What Happened?

Hi all! I noticed some inconsistent behavior when switching models to google gemini regarding tool calls:

The same call works with either Anthropic or OpenAI but fails with Google.

If additionalProperties is provided to the tool parameter definition we receive the error response below, although this is a valid parameter in the JSON Schema definition and is accepted by OpenAI.

400 Invalid response received from google: [{"error":{"code":400,"message":"Invalid JSON payload received. Unknown name \"additionalProperties\" at 'tools[0].function_declarations[0].parameters'

If strict: true is specified in the tool definition we get the following error:

400 Invalid response received from google: [{"error":{"code":400,"message":"Invalid JSON payload received. Unknown name \"strict\" at 'tools[0].function_declarations[0]'

Lastly even after removing these parameters we still get an error and the gateway crashes:

TypeError: Cannot read properties of undefined (reading 'parts')

Additional information: running version 1.8.5 of the gateway locally using node.

What Should Have Happened?

  1. Switching providers / model id should have been enough for making this request.
  2. It should be possible to make tool calls to google gemini models

Relevant Code Snippet

import { codeBlock } from "common-tags";
import { createHeaders } from "portkey-ai";
import OpenAI from "openai";

const openai = new OpenAI({
  apiKey: "...",
  baseURL: "...",
  defaultHeaders: createHeaders({
    provider: "google",
    apiKey: "...",
  }),
});

async function createChatCompletion() {
  const chat_complete = await openai.chat.completions.create({
    model: "gemini-1.5-flash",
    messages: [
      { role: "system", content: "You are a helpful assistant." },
      { role: "user", content: "..." },
    ],
    tool_choice: "auto",
    parallel_tool_calls: true,
    temperature: 0,
    stream: true,
    tools: [
      {
        type: "function",
        function: {
          name: "run_code",
          description: codeBlock`...`,
          parameters: {
            type: "object",
            properties: {
              foo: {
                type: "string",
                description: codeBlock`...`,
              },
              bar: {
                type: "string",
                description: "...",
              },
            },
            required: ["foo", "bar"],
          },
          // strict: true,
        },
      },
    ],
  });

  for await (const message of chat_complete) {
    console.log(JSON.stringify(message, null, 2));
  }
}

createChatCompletion();

Your Twitter/LinkedIn

No response

@au-re au-re added the bug Something isn't working label Dec 22, 2024
@narengogi
Copy link
Collaborator

thankyou, for reporting this @au-re I've seen the same issue reported in discord too. I'll take a look at this today

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage
Projects
None yet
Development

No branches or pull requests

2 participants