Skip to content

Vertex AI - generateContentStream aggregated output undefined #8566

@andrewheard

Description

@andrewheard

Operating System

macOS Sonoma 14.1

Environment (if applicable)

NodeJS

Firebase SDK Version

main

Firebase SDK Product(s)

VertexAI

Project Tooling

N/A - @dlarocque may have more details

Detailed Problem Description

Vertex AI omits default values (index == 0) when serializing its responses as JSON but the SDK assumes the index value will always be there in aggregateResponses(). See FirebaseExtended/vertexai-sdk-test-data#21 for more details (test failure).

Steps and code to reproduce issue

The following snippet demonstrates the issue:

async function run() {
  const prompt = "Write a story about a magic backpack."

  const result = await model.generateContentStream(prompt);
  for await (const chunk of result.stream) {
    const chunkText = chunk.text();

    // No issues - WAI
    console.log(chunkText);
  }

  // Not working because of the undefined index
  console.log('aggregated response: ', await result.response);
}

run()

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions