GenerativeModel


public final class GenerativeModel implements AutoCloseable


A facilitator for a given system model.

Summary

Public constructors

GenerativeModel(
    @NonNull GenerationConfig generationConfig,
    @NonNull DownloadConfig downloadConfig
)

Public methods

void

Closes the client and releases its resources.

final @NonNull GenerateContentResponse

Generates a response from the system model with the provided Contents.

final @NonNull GenerateContentResponse

Generates a response from the system model with the provided text represented Content.

final @NonNull Flow<@NonNull GenerateContentResponse>

Generates a streaming response from the system model with the provided Contents.

final @NonNull Flow<@NonNull GenerateContentResponse>

Generates a streaming response from the system model with the provided text represented Content.

final @NonNull DownloadConfig

the config for system model downloading

final @NonNull GenerationConfig

configuration parameters to use for content generation

final @NonNull <Error class: unknown class>

Prepares engine in advance so as to move timing overhead out of inference.

Public constructors

GenerativeModel

public GenerativeModel(
    @NonNull GenerationConfig generationConfig,
    @NonNull DownloadConfig downloadConfig
)

Public methods

close

public void close()

Closes the client and releases its resources.

generateContent

public final @NonNull GenerateContentResponse generateContent(@NonNull Content prompt)

Generates a response from the system model with the provided Contents.

Parameters
@NonNull Content prompt

A group of Contents to send to the model.

Returns
@NonNull GenerateContentResponse

A GenerateContentResponse after some delay. Function should be called within a suspend context to properly manage concurrency.

generateContent

public final @NonNull GenerateContentResponse generateContent(@NonNull String prompt)

Generates a response from the system model with the provided text represented Content.

Parameters
@NonNull String prompt

The text to be converted into a single piece of Content to send to the model.

Returns
@NonNull GenerateContentResponse

A GenerateContentResponse after some delay. Function should be called within a suspend context to properly manage concurrency.

generateContentStream

public final @NonNull Flow<@NonNull GenerateContentResponsegenerateContentStream(@NonNull Content prompt)

Generates a streaming response from the system model with the provided Contents.

Parameters
@NonNull Content prompt

A group of Contents to send to the model.

Returns
@NonNull Flow<@NonNull GenerateContentResponse>

A Flow which will emit responses as they are returned from the model.

generateContentStream

public final @NonNull Flow<@NonNull GenerateContentResponsegenerateContentStream(@NonNull String prompt)

Generates a streaming response from the system model with the provided text represented Content.

Parameters
@NonNull String prompt

The text to be converted into a single piece of Content to send to the model.

Returns
@NonNull Flow<@NonNull GenerateContentResponse>

A Flow which will emit responses as they are returned from the model.

getDownloadConfig

public final @NonNull DownloadConfig getDownloadConfig()

the config for system model downloading

getGenerationConfig

public final @NonNull GenerationConfig getGenerationConfig()

configuration parameters to use for content generation

prepareInferenceEngine

public final @NonNull <Error class: unknown class> prepareInferenceEngine()

Prepares engine in advance so as to move timing overhead out of inference. Calling this method is strictly optional, but we recommend calling it well before the first inference call to minimize the latency of the first inference.