Class VertexAI (1.4.0)

The VertexAI class is the base class for authenticating to Vertex AI. To use Vertex AI's generative AI models, use the getGenerativeModel method. To use generative AI features that are in Preview, use the preview namespace.

Package

@google-cloud/vertexai

Constructors

(constructor)(init)

constructor(init: VertexInit);

Constructs a new instance of the VertexAI class

Parameter
Name Description
init VertexInit

assign authentication related information, including the project and location strings, to instantiate a Vertex AI client.

Properties

preview

readonly preview: VertexAIPreview;

Methods

getGenerativeModel(modelParams, requestOptions)

getGenerativeModel(modelParams: ModelParams, requestOptions?: RequestOptions): GenerativeModel;

Gets the GenerativeModel class instance.

This method creates a new instance of the GenerativeModel class with the platform initialization parameters provided in VertexInit and model initialization parameters provided in ModelParams. You can optionally provide RequestOptions to override the default request options.

Parameters
Name Description
modelParams ModelParams

ModelParams Parameters to specify the generative model.

requestOptions RequestOptions

RequestOptions Parameters to specify request options

Returns
Type Description
GenerativeModel

Instance of the GenerativeModel class.

Example

const project = 'your-cloud-project';
const location = 'us-central1';
const textModel =  'gemini-1.0-pro';
const visionModel = 'gemini-1.0-pro-vision';

const vertexAI = new VertexAI({project: project, location: location});

// Instantiate models
const generativeModel = vertexAI.getGenerativeModel({
  model: textModel,
  // The following parameters are optional
  // They can also be passed to individual content generation requests
  safetySettings: [{
                     category: HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT,
                     threshold: HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE
                    }],
  generationConfig: {maxOutputTokens: 256},
});

const generativeVisionModel = vertexAI.getGenerativeModel({
  model: visionModel,
});

const generativeModelPreview = vertexAI.preview.getGenerativeModel({
  model: textModel,
});

getLocation()

protected getLocation(): string;
Returns
Type Description
string

getProject()

protected getProject(): string;
Returns
Type Description
string