Skip to content

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

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

Open
nohe427 opened this issue May 7, 2025 · 1 comment
Assignees

Comments

@nohe427
Copy link

nohe427 commented May 7, 2025

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 nohe427 added question new A new issue that hasn't be categoirzed as question, bug or feature request labels May 7, 2025
@hsubox76
Copy link
Contributor

hsubox76 commented May 7, 2025

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 hsubox76 self-assigned this May 7, 2025
@jbalidiong jbalidiong removed question new A new issue that hasn't be categoirzed as question, bug or feature request labels May 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants