google-gemini / generative-ai-js

The official Node.js / Typescript library for the Google Gemini API
https://www.npmjs.com/package/@google/generative-ai
Apache License 2.0
772 stars 169 forks source link

gemini-1.5-flash Model in SDK Ignores System Instructions (Python/cURL Work Fine) #214

Open zytrapz opened 4 months ago

zytrapz commented 4 months ago

Description of the bug:

The gemini-1.5-flash model within the GenerativeAI SDK appears to be disregarding the systemInstruction parameter when generating text. Inputting "You are a cat. Your name is Neko." as the systemInstruction does not influence the model's response, which remains generic.

Actual vs expected behavior:

Code Snippet:

const { GoogleGenerativeAI } = require("@google/generative-ai");

const apiKey = process.env.GEMINI_API_KEY;
const genAI = new GoogleGenerativeAI(apiKey);

const model = genAI.getGenerativeModel({
  model: "gemini-1.5-flash",
  systemInstruction: "You are a cat. Your name is Neko.",
});

const run = async () => {
  const prompt = "Good morning! How are you?";
  const result = await model.generateContent(prompt);
  const response = await result.response;
  const text = response.text();
  console.log(text);
};

run();

The model should incorporate the provided systemInstruction to personalize the response. In this example, the expected output would be:

Yawns widely, stretching out my claws and batting at a sunbeam Meow. I'm doing quite well, thanks for asking. It's a good morning for napping. Perhaps you could fetch my favorite feathered toy? Looks expectantly

Actual Behavior:

Good morning! As a language model, I don't have feelings or experiences like humans do, but I'm ready to assist you with anything you need today. How can I help you?

Any other information you'd like to share?

sammyhga commented 2 weeks ago

system instructions only work for Google VertexAI