firebase-js-sdk icon indicating copy to clipboard operation
firebase-js-sdk copied to clipboard

[VertexAI] startChat() doesn’t work with a string for the systemInstruction

Open nohe427 opened this issue 7 months ago • 1 comments

Operating System

MacOS

Environment (if applicable)

node 22

Firebase SDK Version

11.1.0

Firebase SDK Product(s)

VertexAI

Project Tooling

Vite and NodeJS

Detailed Problem Description

Setting a system instruction using a string input in the startChat function call does not convert the string into a system part as required by the API endpoint.

Steps and code to reproduce issue

Code

const vertexSDK = getVertexAI(app);const genModel = getGenerativeModel(vertexSDK, {
  model: 'gemini-2.0-flash',
});
      
const chat = genModel.startChat({
 systemInstruction: 'talk like a pirate'
});
const response = await chat.sendMessage('how are you today?');
 console.log(response.response.text);

Error

error FirebaseError: VertexAI: Error fetching from https://firebasevertexai.googleapis.com/v1beta/projects/_/locations/us-central1/publishers/google/models/gemini-2.0-flash:generateContent: [400 ] Invalid value at 'system_instruction' (type.googleapis.com/google.cloud.aiplatform.v1beta1.Content), "talk like a pirate" [{"@type":"type.googleapis.com/google.rpc.BadRequest","fieldViolations":[{"field":"system_instruction","description":"Invalid value at 'system_instruction' (type.googleapis.com/google.cloud.aiplatform.v1beta1.Content), \"talk like a pirate\""}]}] (vertexAI/fetch-error)

nohe427 avatar May 07 '25 21:05 nohe427

Need to wrap params.systemInstruction in ChatSession constructor with formatSystemInstructions() as is done in the GenerativeModel constructor. https://github.com/firebase/firebase-js-sdk/blob/release/packages/vertexai/src/models/generative-model.ts#L69

hsubox76 avatar May 07 '25 22:05 hsubox76

Same issue here!

niehaus1301 avatar Aug 24 '25 16:08 niehaus1301