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

Internal error when 1.function calls enabled 2. multilingual prompt #284

Open
blindFS opened this issue Oct 17, 2024 · 3 comments
Open

Internal error when 1.function calls enabled 2. multilingual prompt #284

blindFS opened this issue Oct 17, 2024 · 3 comments
Assignees
Labels
component:js sdk Issue/PR related to JavaScript SDK status:triaged Issue/PR triaged to the corresponding sub-team type:bug Something isn't working

Comments

@blindFS
Copy link

blindFS commented Oct 17, 2024

Description of the bug:

const googleSearchDeclaration = {
  name: "google",
  parameters: {
    type: "OBJECT",
    description: "Set the query and how many docs to return.",
    properties: {
      query: {
        type: "STRING",
        description: "The query to search google for.",
      },
      topN: {
        type: "NUMBER",
        description: "Return top N related documents.",
      },
    },
    required: ["query"],
  },
};

import { GoogleGenerativeAI } from "@google/generative-ai";

// Access your API key as an environment variable (see "Set up your API key" above)
const genAI = new GoogleGenerativeAI(process.env.API_KEY);
const generativeModel = genAI.getGenerativeModel({
  // Use a model that supports function calling, like a Gemini 1.5 model
  model: "gemini-1.5-flash",
  // Specify the function declaration.
  tools: [{
    functionDeclarations: [googleSearchDeclaration],
  }],
});

const chat = generativeModel.startChat();
const prompt = "谁是xxx\nxxx";

// Send the message to the model.
const result = await chat.sendMessage([prompt]);

if (result.response.functionCalls()) {
  const call = result.response.functionCalls()[0];
  // Send the API response back to the model so it can generate
  // a text response that can be displayed to the user.
  const result2 = await chat.sendMessage([{functionResponse: {
    name: 'google',
    response: {
      docs: "answer is 42"
    }
  }}]);

  // Log the text response.
  console.log(result2.response.text());
}
console.log(result.response.text());

This script can trigger internal error with large probability.

    throw new GoogleGenerativeAIFetchError(`Error fetching from ${url.toString()}: [${response.status} ${response.statusText}] ${message}`, response.status, response.statusText, errorDetails);
          ^

GoogleGenerativeAIFetchError: [GoogleGenerativeAI Error]: Error fetching from https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent: [500 Internal Server Error] An internal error has occurred. Please retry or report in https://developers.generativeai.google/guide/troubleshooting

Actual vs expected behavior:

Should be no internal error.

Any other information you'd like to share?

Here's what I have tested:

  1. disable function call fixes the issue
  2. language unification also fixes this
  3. REST api has no such problem
@blindFS blindFS changed the title Internal error when 1.function calls enabled 2. multiline multilingual prompt Internal error when 1.function calls enabled 2. multilingual prompt Oct 17, 2024
@manojssmk manojssmk added type:bug Something isn't working status:triaged Issue/PR triaged to the corresponding sub-team component:js sdk Issue/PR related to JavaScript SDK labels Oct 21, 2024
@manojssmk
Copy link

manojssmk commented Oct 21, 2024

Hi @blindFS

Thank you reporting this issue. This looks like an intermittent error and should work now.
This repository is for issues related to JS SDK client bugs or improvements and the client doesn't control the service's responses. For issues related to Gemini API, we would suggest you to use "Send Feedback" option in Gemini docs. Ref: Screenshot below. You can also post this issue on Google AI forum.

image

@blindFS
Copy link
Author

blindFS commented Oct 21, 2024

Hi @blindFS

Thank you reporting this issue. This looks like an intermittent error and should work now. This repository is for issues related to JS SDK client bugs or improvements and the client doesn't control the service's responses. For issues related to Gemini API, we would suggest you to use "Send Feedback" option in Gemini docs. Ref: Screenshot below. You can also post this issue on Google AI forum.

image

Thanks for your response, but I don't think it is an intermittent error. Still getting internal error with the script above. And it seems to me a bug only exists in JS SDK, since when I tested on REST api, it works fine.

@blindFS
Copy link
Author

blindFS commented Oct 21, 2024

@manojssmk I'd like to mention that, with that script, I get errors with large probability but not 100%, please test it more if not reproduced at once. I have also sent this link to the feedback channel in your screenshot. If it's not JS specific, I suppose someone will take a look at it and respond in this thread? If you don't mind, I'd like this to remain open at the time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component:js sdk Issue/PR related to JavaScript SDK status:triaged Issue/PR triaged to the corresponding sub-team type:bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants