# GenerativeModelFutures

# GenerativeModelFutures


```
abstract class GenerativeModelFutures
```

<br />

*** ** * ** ***

A Java-friendly wrapper for the `GenerativeModel` class, providing `ListenableFuture` for asynchronous operations.

## Summary

| ### Public companion functions |
|---|---|
| `GenerativeModelFutures` | `from(generativeModel: GenerativeModel)` |

| ### Public functions |
|---|---|
| `abstract ListenableFuture<Int>` | `checkStatus()` Checks the current availability status of the content generation feature. |
| `abstract ListenableFuture<Void>` | `clearImplicitCaches()` Clears all caches created by implicit prefix caching. |
| `abstract ListenableFuture<CountTokensResponse>` | `countTokens(request: GenerateContentRequest)` Counts the number of tokens in the request. |
| `abstract ListenableFuture<Void>` | `download(callback: DownloadCallback)` Downloads the required model assets for the content generation feature if they are not already available. |
| `abstract ListenableFuture<GenerateContentResponse>` | `generateContent(prompt: String)` Runs a non-streaming inference call to the model for the provided prompt. |
| `abstract ListenableFuture<GenerateContentResponse>` | `generateContent(request: GenerateContentRequest)` Runs a non-streaming inference call to the model for the provided `GenerateContentRequest`. |
| `abstract ListenableFuture<GenerateContentResponse>` | `generateContent(prompt: String, callback: StreamingCallback)` Runs a streaming inference call to the model for the provided prompt. |
| `abstract ListenableFuture<GenerateContentResponse>` | `generateContent( request: GenerateContentRequest, callback: StreamingCallback )` Runs a streaming inference call to the model for the provided `GenerateContentRequest`. |
| `abstract ListenableFuture<List<Int>>` | `getAvailableFeatures()` Returns the list of features (capabilities) available for this model. |
| `abstract ListenableFuture<String>` | `getBaseModelName()` Returns the name of the base model used by this generator instance. |
| `abstract GenerativeModel` | `getGenerativeModel()` Returns the underlying `GenerativeModel` instance that was used to create this object. |
| `abstract ListenableFuture<Int>` | `getTokenLimit()` Returns total token limit for the API including both input and output tokens. |
| `abstract ListenableFuture<Boolean>` | `[isSystemPromptAvailable](https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/prompt/java/GenerativeModelFutures#isSystemPromptAvailable())()` **This function is deprecated.** Use getAvailableFeatures() instead. |
| `abstract ListenableFuture<Boolean>` | `[isThinkingModeAvailable](https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/prompt/java/GenerativeModelFutures#isThinkingModeAvailable())()` **This function is deprecated.** Use getAvailableFeatures() instead. |
| `abstract ListenableFuture<Void>` | `warmup()` Warms up the inference engine for use by loading necessary models. |

## Public companion functions

### from

```
fun from(generativeModel: GenerativeModel): GenerativeModelFutures
```

| Parameters |
|---|---|
| `generativeModel: GenerativeModel` | the `GenerativeModel` instance to wrap. |

| Returns |
|---|---|
| `GenerativeModelFutures` | a `GenerativeModelFutures` created around the provided `GenerativeModel` instance. |

## Public functions

### checkStatus

```
abstract fun checkStatus(): ListenableFuture<Int>
```

Checks the current availability status of the content generation feature.

### clearImplicitCaches

```
abstract fun clearImplicitCaches(): ListenableFuture<Void>
```

Clears all caches created by implicit prefix caching.

This experimental method clears all caches created by implicit prefix caching. When `promptPrefix` is provided in `GenerateContentRequest`, the system caches its processing implicitly to reduce inference time for subsequent requests sharing the same prefix. This method clears all such created caches.

### countTokens

```
abstract fun countTokens(request: GenerateContentRequest): ListenableFuture<CountTokensResponse>
```

Counts the number of tokens in the request.

The number of tokens counted includes input and output tokens. The result can be compared with `getTokenLimit` to check if the request is within the token limit.

| Parameters |
|---|---|
| `request: GenerateContentRequest` | a non-null `GenerateContentRequest` containing input content. |

| Returns |
|---|---|
| `ListenableFuture<CountTokensResponse>` | a `ListenableFuture` resolving to a `CountTokensResponse`. |

### download

```
abstract fun download(callback: DownloadCallback): ListenableFuture<Void>
```

Downloads the required model assets for the content generation feature if they are not already available.

### generateContent

```
abstract fun generateContent(prompt: String): ListenableFuture<GenerateContentResponse>
```

Runs a non-streaming inference call to the model for the provided prompt.

### generateContent

```
abstract fun generateContent(request: GenerateContentRequest): ListenableFuture<GenerateContentResponse>
```

Runs a non-streaming inference call to the model for the provided `GenerateContentRequest`.

### generateContent

```
abstract fun generateContent(prompt: String, callback: StreamingCallback): ListenableFuture<GenerateContentResponse>
```

Runs a streaming inference call to the model for the provided prompt.

| Parameters |
|---|---|
| `prompt: String` | the input prompt text. |
| `callback: StreamingCallback` | the callback to receive streaming results. |

| Returns |
|---|---|
| `ListenableFuture<GenerateContentResponse>` | a `ListenableFuture` that completes with the final `GenerateContentResponse`. |

### generateContent

```
abstract fun generateContent(
    request: GenerateContentRequest,
    callback: StreamingCallback
): ListenableFuture<GenerateContentResponse>
```

Runs a streaming inference call to the model for the provided `GenerateContentRequest`.

| Parameters |
|---|---|
| `request: GenerateContentRequest` | the request containing the prompt of text and images. |
| `callback: StreamingCallback` | the callback to receive streaming results. |

| Returns |
|---|---|
| `ListenableFuture<GenerateContentResponse>` | A `ListenableFuture` that completes with the final `GenerateContentResponse`. |

### getAvailableFeatures

```
abstract fun getAvailableFeatures(): ListenableFuture<List<Int>>
```

Returns the list of features (capabilities) available for this model.

| Returns |
|---|---|
| `ListenableFuture<List<Int>>` | a `ListenableFuture` resolving to the list of available features. |

### getBaseModelName

```
abstract fun getBaseModelName(): ListenableFuture<String>
```

Returns the name of the base model used by this generator instance.

### getGenerativeModel

```
abstract fun getGenerativeModel(): GenerativeModel
```

Returns the underlying `GenerativeModel` instance that was used to create this object.

### getTokenLimit

```
abstract fun getTokenLimit(): ListenableFuture<Int>
```

Returns total token limit for the API including both input and output tokens.

This limit can be used with `countTokens` to check if a request is within limits before running inference. The input size returned by `countTokens` plusing the output size specified by `GenerateContentRequest.maxOutputTokens` should be no larger than the limit returned by this method.

| Returns |
|---|---|
| `ListenableFuture<Int>` | a `ListenableFuture` resolving to the token limit. |

### isSystemPromptAvailable

```
abstract fun [isSystemPromptAvailable](https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/prompt/java/GenerativeModelFutures#isSystemPromptAvailable())(): ListenableFuture<Boolean>
```

> [!CAUTION]
> **This function is deprecated.**   
> Use getAvailableFeatures() instead.

Checks if the system prompt feature is supported on the device.

| Returns |
|---|---|
| `ListenableFuture<Boolean>` | a `ListenableFuture` resolving to `true` if the system prompt feature is available, `false` otherwise. |

### isThinkingModeAvailable

```
abstract fun [isThinkingModeAvailable](https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/prompt/java/GenerativeModelFutures#isThinkingModeAvailable())(): ListenableFuture<Boolean>
```

> [!CAUTION]
> **This function is deprecated.**   
> Use getAvailableFeatures() instead.

Checks if the thinking mode feature is supported on the device.

| Returns |
|---|---|
| `ListenableFuture<Boolean>` | a `ListenableFuture` resolving to `true` if the thinking mode feature is available, `false` otherwise. |

### warmup

```
abstract fun warmup(): ListenableFuture<Void>
```

Warms up the inference engine for use by loading necessary models.