GenerativeModelFutures

public abstract class GenerativeModelFutures


Helper method for interacting with a GenerativeModel from Java.

See also
from

Summary

Nested types

Public methods

abstract @NonNull ListenableFuture<@NonNull CountTokensResponse>

Counts the number of tokens used in a prompt.

static final @NonNull GenerativeModelFutures
abstract @NonNull ListenableFuture<@NonNull GenerateContentResponse>

Generates a response from the backend with the provided Content.

abstract @NonNull Publisher<@NonNull GenerateContentResponse>

Generates a streaming response from the backend with the provided Content.

abstract @NonNull GenerativeModel

Returns the GenerativeModel instance that was used to create this object

abstract @NonNull ChatFutures

Creates a chat instance which internally tracks the ongoing conversation with the model

abstract @NonNull ChatFutures

Creates a chat instance which internally tracks the ongoing conversation with the model

Public methods

countTokens

public abstract @NonNull ListenableFuture<@NonNull CountTokensResponsecountTokens(@NonNull Content prompt)

Counts the number of tokens used in a prompt.

Parameters
@NonNull Content prompt

A group of Content to count tokens of.

from

public static final @NonNull GenerativeModelFutures from(@NonNull GenerativeModel model)
Returns
@NonNull GenerativeModelFutures

a GenerativeModelFutures created around the provided GenerativeModel

generateContent

public abstract @NonNull ListenableFuture<@NonNull GenerateContentResponsegenerateContent(@NonNull Content prompt)

Generates a response from the backend with the provided Content.

Parameters
@NonNull Content prompt

A group of Content to send to the model.

generateContentStream

public abstract @NonNull Publisher<@NonNull GenerateContentResponsegenerateContentStream(@NonNull Content prompt)

Generates a streaming response from the backend with the provided Content.

Parameters
@NonNull Content prompt

A group of Content to send to the model.

getGenerativeModel

public abstract @NonNull GenerativeModel getGenerativeModel()

Returns the GenerativeModel instance that was used to create this object

startChat

public abstract @NonNull ChatFutures startChat()

Creates a chat instance which internally tracks the ongoing conversation with the model

startChat

public abstract @NonNull ChatFutures startChat(@NonNull List<@NonNull Content> history)

Creates a chat instance which internally tracks the ongoing conversation with the model

Parameters
@NonNull List<@NonNull Content> history

an existing history of context to use as a starting point