PromptPrefix

public final class PromptPrefix


Represents a prompt prefix for on-device prompt caching.

By providing the shared prefix, the system can cache the processing of this prefix on supported devices, potentially reducing inference time. To enable prefix caching, use PromptPrefix for the static part of your prompt and TextPart for the dynamic part.

Note: Pre-processing the prefix may introduce a small amount of one-time latency. It's recommended to only use this for prefixes that are expected to be used multiple times.

Summary

Public constructors

Public methods

final @NonNull String

Kotlin destructuring operator returning textString.

final @NonNull PromptPrefix
copy(@NonNull String textString)

Creates a copy of this PromptPrefix with an updated textString, preserving internal prefix caching configuration.

boolean
equals(Object other)
final @NonNull String

The static text prefix to cache.

int
@NonNull String

Public constructors

PromptPrefix

public PromptPrefix(@NonNull String textString)
Parameters
@NonNull String textString

The static text prefix to cache.

Public methods

component1

public final @NonNull String component1()

Kotlin destructuring operator returning textString.

Retained for binary backwards compatibility with the previous data class definition of PromptPrefix.

copy

public final @NonNull PromptPrefix copy(@NonNull String textString)

Creates a copy of this PromptPrefix with an updated textString, preserving internal prefix caching configuration.

equals

public boolean equals(Object other)

getTextString

public final @NonNull String getTextString()

The static text prefix to cache.

hashCode

public int hashCode()

toString

public @NonNull String toString()