Package com.google.genai
Class AsyncModels
java.lang.Object
com.google.genai.AsyncModels
Async module of
Models-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncomputeTokens(String model, String text, ComputeTokensConfig config) Asynchronously computes tokens given a GenAI model and a text string.computeTokens(String model, List<Content> contents, ComputeTokensConfig config) Asynchronously computes tokens given a GenAI model and a list of content.countTokens(String model, String text, CountTokensConfig config) Asynchronously counts tokens given a GenAI model and a text string.countTokens(String model, List<Content> contents, CountTokensConfig config) Asynchronously counts tokens given a GenAI model and a list of content.delete(String model, DeleteModelConfig config) Asynchronously fetches information about a model by name.editImage(String model, String prompt, List<ReferenceImage> referenceImages, EditImageConfig config) Asynchronously edits an image given a GenAI model, a prompt, and a list of reference images.embedContent(String model, String text, EmbedContentConfig config) Asynchronously embeds content given a GenAI model and a text string.embedContent(String model, List<String> texts, EmbedContentConfig config) Asynchronously embeds content given a GenAI model and a list of text strings.generateContent(String model, Content content, GenerateContentConfig config) Asynchronously generates content given a GenAI model and a content object.generateContent(String model, String text, GenerateContentConfig config) Asynchronously generates content given a GenAI model and a text string.generateContent(String model, List<Content> contents, GenerateContentConfig config) Asynchronously generates content given a GenAI model and a list of content.generateContentStream(String model, Content content, GenerateContentConfig config) Asynchronously generates content with streaming support given a GenAI model and a content object.generateContentStream(String model, String text, GenerateContentConfig config) Asynchronously generates content with streaming support given a GenAI model and a text string.generateContentStream(String model, List<Content> contents, GenerateContentConfig config) Asynchronously generates content with streaming support given a GenAI model and a list of content.generateImages(String model, String prompt, GenerateImagesConfig config) Asynchronously generates images given a GenAI model and a prompt.generateVideos(String model, String prompt, Image image, GenerateVideosConfig config) Asynchronously generates videos given a GenAI model, and an input (text, image).generateVideos(String model, String prompt, Image image, Video video, GenerateVideosConfig config) Asynchronously generates videos given a GenAI model, and an input (text, image, or video).get(String model, GetModelConfig config) Asynchronously fetches information about a model by name.list(ListModelsConfig config) Asynchronously makes an API request to list the available models.update(String model, UpdateModelConfig config) Asynchronously updates a tuned model by its name.upscaleImage(String model, Image image, String upscaleFactor, UpscaleImageConfig config) Asynchronously upscales an image given a GenAI model and an image and an upscale factor.
-
Constructor Details
-
AsyncModels
public AsyncModels(com.google.genai.ApiClient apiClient)
-
-
Method Details
-
get
Asynchronously fetches information about a model by name. -
update
Asynchronously updates a tuned model by its name.- Parameters:
model- The name of the tuned model to updateconfig- AUpdateModelConfiginstance that specifies the optional configurations- Returns:
- A
Modelinstance
-
delete
Asynchronously fetches information about a model by name. -
countTokens
public CompletableFuture<CountTokensResponse> countTokens(String model, List<Content> contents, CountTokensConfig config) Asynchronously counts tokens given a GenAI model and a list of content.- Parameters:
model- the name of the GenAI model to use.contents- aList<Content>to send to count tokens for.config- aCountTokensConfiginstance that specifies the optional configurations- Returns:
- a
CountTokensResponseinstance that contains tokens count.
-
computeTokens
public CompletableFuture<ComputeTokensResponse> computeTokens(String model, List<Content> contents, ComputeTokensConfig config) Asynchronously computes tokens given a GenAI model and a list of content.- Parameters:
model- the name of the GenAI model to use.contents- aList<Content>to send to compute tokens for.config- aComputeTokensConfiginstance that specifies the optional configurations- Returns:
- a
ComputeTokensResponseinstance that contains tokens results.
-
countTokens
public CompletableFuture<CountTokensResponse> countTokens(String model, String text, CountTokensConfig config) Asynchronously counts tokens given a GenAI model and a text string.- Parameters:
model- the name of the GenAI model to use.text- the text string to send to count tokens for.config- aCountTokensConfiginstance that specifies the optional configurations- Returns:
- a
CountTokensResponseinstance that contains tokens count.
-
computeTokens
public CompletableFuture<ComputeTokensResponse> computeTokens(String model, String text, ComputeTokensConfig config) Asynchronously computes tokens given a GenAI model and a text string.- Parameters:
model- the name of the GenAI model to use.text- the text string to send to count tokens for.config- aComputeTokensConfiginstance that specifies the optional configurations- Returns:
- a
ComputeTokensResponseinstance that contains tokens results.
-
generateContent
public CompletableFuture<GenerateContentResponse> generateContent(String model, List<Content> contents, GenerateContentConfig config) Asynchronously generates content given a GenAI model and a list of content.- Parameters:
model- the name of the GenAI model to use for generationcontents- aList<Content>to send to the generative modelconfig- aGenerateContentConfiginstance that specifies the optional configurations- Returns:
- a
GenerateContentResponseinstance that contains response contents and other metadata
-
generateContent
public CompletableFuture<GenerateContentResponse> generateContent(String model, Content content, GenerateContentConfig config) Asynchronously generates content given a GenAI model and a content object.- Parameters:
model- the name of the GenAI model to use for generationcontent- aContentto send to the generative modelconfig- aGenerateContentConfiginstance that specifies the optional configurations- Returns:
- a
GenerateContentResponseinstance that contains response contents and other metadata
-
generateContent
public CompletableFuture<GenerateContentResponse> generateContent(String model, String text, GenerateContentConfig config) Asynchronously generates content given a GenAI model and a text string.- Parameters:
model- the name of the GenAI model to use for generationtext- the text string to send to the generative modelconfig- aGenerateContentConfiginstance that specifies the optional configurations- Returns:
- a
GenerateContentResponseinstance that contains response contents and other metadata
-
generateContentStream
public CompletableFuture<ResponseStream<GenerateContentResponse>> generateContentStream(String model, List<Content> contents, GenerateContentConfig config) Asynchronously generates content with streaming support given a GenAI model and a list of content.- Parameters:
model- the name of the GenAI model to use for generationcontents- aList<Content>to send to the generative modelconfig- aGenerateContentConfiginstance that specifies the optional configurations- Returns:
- a
GenerateContentResponseinstance that contains response contents and other metadata
-
generateContentStream
public CompletableFuture<ResponseStream<GenerateContentResponse>> generateContentStream(String model, Content content, GenerateContentConfig config) Asynchronously generates content with streaming support given a GenAI model and a content object.- Parameters:
model- the name of the GenAI model to use for generationcontent- aContentto send to the generative modelconfig- aGenerateContentConfiginstance that specifies the optional configurations- Returns:
- a
GenerateContentResponseinstance that contains response contents and other metadata
-
generateContentStream
public CompletableFuture<ResponseStream<GenerateContentResponse>> generateContentStream(String model, String text, GenerateContentConfig config) Asynchronously generates content with streaming support given a GenAI model and a text string.- Parameters:
model- the name of the GenAI model to use for generationtext- the text string to send to the generative modelconfig- aGenerateContentConfiginstance that specifies the optional configurations- Returns:
- a
GenerateContentResponseinstance that contains response contents and other metadata
-
generateImages
public CompletableFuture<GenerateImagesResponse> generateImages(String model, String prompt, GenerateImagesConfig config) Asynchronously generates images given a GenAI model and a prompt.- Parameters:
model- the name of the GenAI model to use for generating imagesprompt- the prompt to generate imagesconfig- aGenerateImagesConfiginstance that specifies the optional configurations- Returns:
- a
GenerateImagesResponseinstance that contains the generated images.
-
editImage
public CompletableFuture<EditImageResponse> editImage(String model, String prompt, List<ReferenceImage> referenceImages, EditImageConfig config) Asynchronously edits an image given a GenAI model, a prompt, and a list of reference images.- Parameters:
model- the name of the GenAI model to use for editing capabilitiesprompt- the prompt to edit the imagereferenceImages- aList<ReferenceImage>to send to use for editing. The 5 types of reference images are:RawReferenceImage,MaskReferenceImage,ControlReferenceImage,StyleReferenceImage,SubjectReferenceImage,config- aEditImageConfiginstance that specifies the optional configurations- Returns:
- a
EditImageResponseinstance that contains the edited image.
-
upscaleImage
public CompletableFuture<UpscaleImageResponse> upscaleImage(String model, Image image, String upscaleFactor, UpscaleImageConfig config) Asynchronously upscales an image given a GenAI model and an image and an upscale factor.- Parameters:
model- the name of the GenAI model to use for upscalingimage- aImageto send to the generative modelupscaleFactor- the factor to upscale the imageconfig- aUpscaleImageConfiginstance that specifies the optional configurations- Returns:
- a
UpscaleImageResponseinstance that contains the upscaled image.
-
generateVideos
public CompletableFuture<GenerateVideosOperation> generateVideos(String model, String prompt, Image image, Video video, GenerateVideosConfig config) Asynchronously generates videos given a GenAI model, and an input (text, image, or video).This method is experimental.
- Parameters:
model- the name of the GenAI model to use for generating videosprompt- the text prompt for generating the videos. Optional for image to video and video extension use cases.image- the input image for generating the videos. Optional if prompt is provided.video- the input video for video extension use cases. Optional if prompt or image is provided.config- aGenerateVideosConfiginstance that specifies the optional configurations- Returns:
- a
GenerateVideosOperationinstance that contains the generated videos.
-
generateVideos
public CompletableFuture<GenerateVideosOperation> generateVideos(String model, String prompt, Image image, GenerateVideosConfig config) Asynchronously generates videos given a GenAI model, and an input (text, image).This method is experimental, and kept for backward compatibility.
- Parameters:
model- the name of the GenAI model to use for generating videosprompt- the text prompt for generating the videos. Optional for image to video use cases.image- the input image for generating the videos. Optional if prompt is provided.config- aGenerateVideosConfiginstance that specifies the optional configurations- Returns:
- a
GenerateVideosOperationinstance that contains the generated videos.
-
embedContent
public CompletableFuture<EmbedContentResponse> embedContent(String model, String text, EmbedContentConfig config) Asynchronously embeds content given a GenAI model and a text string.- Parameters:
model- the name of the GenAI model to use for embeddingtext- the text string to send to the embedding model- Returns:
- a
EmbedContentResponseinstance that contains the embedding.
-
embedContent
public CompletableFuture<EmbedContentResponse> embedContent(String model, List<String> texts, EmbedContentConfig config) Asynchronously embeds content given a GenAI model and a list of text strings.- Parameters:
model- the name of the GenAI model to use for embeddingtexts- the list of text strings to send to the embedding model- Returns:
- a
EmbedContentResponseinstance that contains the embedding.
-
list
Asynchronously makes an API request to list the available models.- Parameters:
config- AListModelsConfigfor configuring the list request.- Returns:
- A CompletableFuture that resolves to a
AsyncPager. The AsyncPager has a `forEach` method that can be used to asynchronously process items in the page and automatically query the next page once the current page is exhausted.
-