Stream HelpersGoogleGenerativeAIStream

GoogleGenerativeAIStream

The GoogleGenerativeAIStream function is a utility that transforms the output from Google's Generative AI SDK into a ReadableStream. It uses AIStream under the hood, applying a specific parser for the Google's response data structure. This works with the official Generative AI SDK, and it's supported in both Node.js, Edge Runtime, and browser environments.

Import

React

import { GoogleGenerativeAIStream } from "ai"

Parameters

response:

Response
The response object returned by a call made by the Provider SDK.

callback?:

AIStreamCallbacks
An object containing callback functions to handle the start, each token, and completion of the AI response. In the absence of this parameter, default behavior is implemented.

Returns

A ReadableStream.