public final class GenerativeModelDeprecated. 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.
Constructors
GenerativeModel(String modelName, VertexAI vertexAi) (deprecated)
public GenerativeModel(String modelName, VertexAI vertexAi)Constructs a GenerativeModel instance.
| Parameters | |
|---|---|
| Name | Description |
modelName |
Stringthe 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 |
VertexAIa com.google.cloud.vertexai.VertexAI that contains the default configs for the generative model |
Methods
countTokens(Content content) (deprecated)
public CountTokensResponse countTokens(Content content)Counts tokens in a single content.
| Parameter | |
|---|---|
| Name | Description |
content |
Contenta 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)
public CountTokensResponse countTokens(String text)Counts tokens in a text message.
| Parameter | |
|---|---|
| Name | Description |
text |
Stringa 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)
public CountTokensResponse countTokens(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)
public GenerateContentResponse generateContent(Content content)Generates content from this model given a single content.
| Parameter | |
|---|---|
| Name | Description |
content |
Contenta 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)
public GenerateContentResponse generateContent(String text)Generates content from generative model given a text.
| Parameter | |
|---|---|
| Name | Description |
text |
Stringa 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)
public GenerateContentResponse generateContent(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)
public ApiFuture<GenerateContentResponse> generateContentAsync(Content content)Asynchronously generates content from generative model given a single Content.
| Parameter | |
|---|---|
| Name | Description |
content |
Contenta 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)
public ApiFuture<GenerateContentResponse> generateContentAsync(String text)Asynchronously generates content from generative model given a text.
| Parameter | |
|---|---|
| Name | Description |
text |
Stringa 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)
public ApiFuture<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)
public ResponseStream<GenerateContentResponse> generateContentStream(Content content)Generates content with streaming support from generative model given a single Content.
| Parameter | |
|---|---|
| Name | Description |
content |
Contenta 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)
public ResponseStream<GenerateContentResponse> generateContentStream(String text)Generates content with streaming support from generative model given a text.
| Parameter | |
|---|---|
| Name | Description |
text |
Stringa 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)
public ResponseStream<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)
public GenerationConfig getGenerationConfig()Returns the com.google.cloud.vertexai.api.GenerationConfig of this generative model.
| Returns | |
|---|---|
| Type | Description |
GenerationConfig |
|
getModelName() (deprecated)
public String getModelName()Returns the model name of this generative model.
| Returns | |
|---|---|
| Type | Description |
String |
|
getSafetySettings() (deprecated)
public ImmutableList<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)
public Optional<Content> getSystemInstruction()Returns the optional system instruction of this generative model.
| Returns | |
|---|---|
| Type | Description |
Optional<Content> |
|
getToolConfig() (deprecated)
public Optional<ToolConfig> getToolConfig()Returns the optional com.google.cloud.vertexai.api.ToolConfig of this generative model.
| Returns | |
|---|---|
| Type | Description |
Optional<ToolConfig> |
|
getTools() (deprecated)
public ImmutableList<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)
public ChatSession startChat()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)
public GenerativeModel withGenerationConfig(GenerationConfig generationConfig)Creates a copy of the current model with updated GenerationConfig.
| Parameter | |
|---|---|
| Name | Description |
generationConfig |
GenerationConfiga 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)
public GenerativeModel withSafetySettings(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)
public GenerativeModel withSystemInstruction(Content systemInstruction)Creates a copy of the current model with updated system instructions.
| Parameter | |
|---|---|
| Name | Description |
systemInstruction |
Contenta 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)
public GenerativeModel withToolConfig(ToolConfig toolConfig)Creates a copy of the current model with updated tool config.
| Parameter | |
|---|---|
| Name | Description |
toolConfig |
ToolConfiga 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)
public GenerativeModel withTools(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. |