Class GenerativeModel (1.38.0)

publicfinalclass GenerativeModel

Deprecated. This class and its package are deprecated. See the migration guide for more details.

This class holds a generative model that can complete what you provided. This class is thread-safe.

Note: The instances of ChatSession returned by GenerativeModel#startChat() are NOT thread-safe.

Inheritance

java.lang.Object > GenerativeModel

Constructors

GenerativeModel(String modelName, VertexAI vertexAi) (deprecated)

publicGenerativeModel(StringmodelName,VertexAIvertexAi)

Constructs a GenerativeModel instance.

Parameters
Name Description
modelName String

the name of the generative model. Supported format: "gemini-pro", "models/gemini-pro", "publishers/google/models/gemini-pro", where "gemini-pro" is the model name. Valid model names can be found at https://cloud.google.com/vertex-ai/docs/generative-ai/learn/models#gemini-models

vertexAi VertexAI

a com.google.cloud.vertexai.VertexAI that contains the default configs for the generative model

Methods

countTokens(Content content) (deprecated)

publicCountTokensResponsecountTokens(Contentcontent)

Counts tokens in a single content.

Parameter
Name Description
content Content

a com.google.cloud.vertexai.api.Content to count tokens

Returns
Type Description
CountTokensResponse

a com.google.cloud.vertexai.api.CountTokensResponse instance that contains the total tokens and total billable characters of the given list of contents

Exceptions
Type Description
IOException

if an I/O error occurs while making the API call

countTokens(String text) (deprecated)

publicCountTokensResponsecountTokens(Stringtext)

Counts tokens in a text message.

Parameter
Name Description
text String

a text message to count tokens

Returns
Type Description
CountTokensResponse

a com.google.cloud.vertexai.api.CountTokensResponse instance that contains the total tokens and total billable characters of the given list of contents

Exceptions
Type Description
IOException

if an I/O error occurs while making the API call

countTokens(List<Content> contents) (deprecated)

publicCountTokensResponsecountTokens(List<Content>contents)

Counts tokens in a list of contents.

Parameter
Name Description
contents List<Content>

a list of com.google.cloud.vertexai.api.Content to count tokens

Returns
Type Description
CountTokensResponse

a com.google.cloud.vertexai.api.CountTokensResponse instance that contains the total tokens and total billable characters of the given list of contents

Exceptions
Type Description
IOException

if an I/O error occurs while making the API call

generateContent(Content content) (deprecated)

publicGenerateContentResponsegenerateContent(Contentcontent)

Generates content from this model given a single content.

Parameter
Name Description
content Content

a com.google.cloud.vertexai.api.Content to send to the generative model

Returns
Type Description
GenerateContentResponse

a com.google.cloud.vertexai.api.GenerateContentResponse instance that contains response contents and other metadata

Exceptions
Type Description
IOException

if an I/O error occurs while making the API call

generateContent(String text) (deprecated)

publicGenerateContentResponsegenerateContent(Stringtext)

Generates content from generative model given a text.

Parameter
Name Description
text String

a text message to send to the generative model

Returns
Type Description
GenerateContentResponse

a com.google.cloud.vertexai.api.GenerateContentResponse instance that contains response contents and other metadata

Exceptions
Type Description
IOException

if an I/O error occurs while making the API call

generateContent(List<Content> contents) (deprecated)

publicGenerateContentResponsegenerateContent(List<Content>contents)

Generates content from this model given a list of contents.

Parameter
Name Description
contents List<Content>

a list of com.google.cloud.vertexai.api.Content to send to the generative model

Returns
Type Description
GenerateContentResponse

a com.google.cloud.vertexai.api.GenerateContentResponse instance that contains response contents and other metadata

Exceptions
Type Description
IOException

if an I/O error occurs while making the API call

generateContentAsync(Content content) (deprecated)

publicApiFuture<GenerateContentResponse>generateContentAsync(Contentcontent)

Asynchronously generates content from generative model given a single Content.

Parameter
Name Description
content Content

a com.google.cloud.vertexai.api.Content to send to the generative model. The role of the content is "user".

Returns
Type Description
ApiFuture<GenerateContentResponse>

a com.google.api.core.ApiFuture represents the response of an asynchronous generateContent request

Exceptions
Type Description
IOException

if an I/O error occurs while making the API call

generateContentAsync(String text) (deprecated)

publicApiFuture<GenerateContentResponse>generateContentAsync(Stringtext)

Asynchronously generates content from generative model given a text.

Parameter
Name Description
text String

a text message to send to the generative model

Returns
Type Description
ApiFuture<GenerateContentResponse>

a com.google.api.core.ApiFuture represents the response of an asynchronous generateContent request

Exceptions
Type Description
IOException

if an I/O error occurs while making the API call

generateContentAsync(List<Content> contents) (deprecated)

publicApiFuture<GenerateContentResponse>generateContentAsync(List<Content>contents)

Asynchronously generates content from generative model given a list of contents.

Parameter
Name Description
contents List<Content>

a list of com.google.cloud.vertexai.api.Content to send to the generative model

Returns
Type Description
ApiFuture<GenerateContentResponse>

a com.google.api.core.ApiFuture represents the response of an asynchronous generateContent request

Exceptions
Type Description
IOException

if an I/O error occurs while making the API call

generateContentStream(Content content) (deprecated)

publicResponseStream<GenerateContentResponse>generateContentStream(Contentcontent)

Generates content with streaming support from generative model given a single Content.

Parameter
Name Description
content Content

a com.google.cloud.vertexai.api.Content to send to the generative model. The role of the content is "user".

Returns
Type Description
ResponseStream<GenerateContentResponse>

a ResponseStream that contains a streaming of com.google.cloud.vertexai.api.GenerateContentResponse

Exceptions
Type Description
IOException

if an I/O error occurs while making the API call

generateContentStream(String text) (deprecated)

publicResponseStream<GenerateContentResponse>generateContentStream(Stringtext)

Generates content with streaming support from generative model given a text.

Parameter
Name Description
text String

a text message to send to the generative model

Returns
Type Description
ResponseStream<GenerateContentResponse>

a ResponseStream that contains a streaming of com.google.cloud.vertexai.api.GenerateContentResponse

Exceptions
Type Description
IOException

if an I/O error occurs while making the API call

generateContentStream(List<Content> contents) (deprecated)

publicResponseStream<GenerateContentResponse>generateContentStream(List<Content>contents)

Generates content with streaming support from generative model given a list of contents.

Parameter
Name Description
contents List<Content>

a list of com.google.cloud.vertexai.api.Content to send to the generative model

Returns
Type Description
ResponseStream<GenerateContentResponse>

a ResponseStream that contains a streaming of com.google.cloud.vertexai.api.GenerateContentResponse

Exceptions
Type Description
IOException

if an I/O error occurs while making the API call

getGenerationConfig() (deprecated)

publicGenerationConfiggetGenerationConfig()

Returns the com.google.cloud.vertexai.api.GenerationConfig of this generative model.

Returns
Type Description
GenerationConfig

getModelName() (deprecated)

publicStringgetModelName()

Returns the model name of this generative model.

Returns
Type Description
String

getSafetySettings() (deprecated)

publicImmutableList<SafetySetting>getSafetySettings()

Returns a list of com.google.cloud.vertexai.api.SafetySetting of this generative model.

Returns
Type Description
com.google.common.collect.ImmutableList<SafetySetting>

getSystemInstruction() (deprecated)

publicOptional<Content>getSystemInstruction()

Returns the optional system instruction of this generative model.

Returns
Type Description
Optional<Content>

getToolConfig() (deprecated)

publicOptional<ToolConfig>getToolConfig()

Returns the optional com.google.cloud.vertexai.api.ToolConfig of this generative model.

Returns
Type Description
Optional<ToolConfig>

getTools() (deprecated)

publicImmutableList<Tool>getTools()

Returns a list of com.google.cloud.vertexai.api.Tool of this generative model.

Returns
Type Description
com.google.common.collect.ImmutableList<Tool>

startChat() (deprecated)

publicChatSessionstartChat()

Returns a new ChatSession instance that can be used to start a chat with this model.

Note: the returned ChatSession instance is NOT thread-safe.

Returns
Type Description
ChatSession

withGenerationConfig(GenerationConfig generationConfig) (deprecated)

publicGenerativeModelwithGenerationConfig(GenerationConfiggenerationConfig)

Creates a copy of the current model with updated GenerationConfig.

Parameter
Name Description
generationConfig GenerationConfig

a com.google.cloud.vertexai.api.GenerationConfig that will be used in the new model.

Returns
Type Description
GenerativeModel

a new GenerativeModel instance with the specified GenerationConfig.

withSafetySettings(List<SafetySetting> safetySettings) (deprecated)

publicGenerativeModelwithSafetySettings(List<SafetySetting>safetySettings)

Creates a copy of the current model with updated safetySettings.

Parameter
Name Description
safetySettings List<SafetySetting>

a list of com.google.cloud.vertexai.api.SafetySetting that will be used in the new model.

Returns
Type Description
GenerativeModel

a new GenerativeModel instance with the specified safetySettings.

withSystemInstruction(Content systemInstruction) (deprecated)

publicGenerativeModelwithSystemInstruction(ContentsystemInstruction)

Creates a copy of the current model with updated system instructions.

Parameter
Name Description
systemInstruction Content

a com.google.cloud.vertexai.api.Content containing system instructions.

Returns
Type Description
GenerativeModel

a new GenerativeModel instance with the specified tools.

withToolConfig(ToolConfig toolConfig) (deprecated)

publicGenerativeModelwithToolConfig(ToolConfigtoolConfig)

Creates a copy of the current model with updated tool config.

Parameter
Name Description
toolConfig ToolConfig

a com.google.cloud.vertexai.api.ToolConfig that will be used in the new model.

Returns
Type Description
GenerativeModel

a new GenerativeModel instance with the specified tool config.

withTools(List<Tool> tools) (deprecated)

publicGenerativeModelwithTools(List<Tool>tools)

Creates a copy of the current model with updated tools.

Parameter
Name Description
tools List<Tool>

a list of com.google.cloud.vertexai.api.Tool that will be used in the new model.

Returns
Type Description
GenerativeModel

a new GenerativeModel instance with the specified tools.

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025年11月19日 UTC.