GenerativeModel


public final class GenerativeModel implements AutoCloseable


给定系统模型的协助者。

摘要

公共构造函数

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

公共方法

void

关闭客户端并释放其资源。

final @NonNull GenerateContentResponse

使用提供的 Content 从系统模型生成响应。

final @NonNull GenerateContentResponse

从系统模型生成回答,其中提供的文本表示为 Content

final @NonNull Flow<@NonNull GenerateContentResponse>

使用提供的 Content 从系统模型生成流式响应。

final @NonNull Flow<@NonNull GenerateContentResponse>

从系统模型生成流式传输回答,其中所提供的文本表示为 Content

final @NonNull DownloadConfig

系统模型下载的配置

final @NonNull GenerationConfig

用于生成内容的配置参数

final @NonNull <Error class: unknown class>

提前准备引擎,以便将时间开销从推理中移出。

公共构造函数

GenerativeModel

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

公共方法

关闭

public void close()

关闭客户端并释放其资源。

generateContent

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

使用提供的 Content 从系统模型生成响应。

参数
@NonNull Content prompt

要发送给模型的一组 Content

返回
@NonNull GenerateContentResponse

延迟一段时间后发送 GenerateContentResponse。应在挂起上下文中调用函数,以便正确管理并发性。

generateContent

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

从系统模型生成回答,其中提供的文本表示为 Content

参数
@NonNull String prompt

要转换为单个 Content 以发送给模型的文本。

返回
@NonNull GenerateContentResponse

延迟一段时间后发送 GenerateContentResponse。应在挂起上下文中调用函数,以便正确管理并发性。

generateContentStream

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

使用提供的 Content 从系统模型生成流式响应。

参数
@NonNull Content prompt

要发送给模型的一组 Content

返回
@NonNull Flow<@NonNull GenerateContentResponse>

一个 Flow,用于在模型返回响应时发出响应。

generateContentStream

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

从系统模型生成流式传输响应,其中所提供的文本表示为 Content

参数
@NonNull String prompt

要转换为单个 Content 以发送给模型的文本。

返回
@NonNull Flow<@NonNull GenerateContentResponse>

一个 Flow,用于在模型返回响应时发出响应。

getDownloadConfig

public final @NonNull DownloadConfig getDownloadConfig()

系统模型下载的配置

getGenerationConfig

public final @NonNull GenerationConfig getGenerationConfig()

用于生成内容的配置参数

prepareInferenceEngine

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

提前准备引擎,以便将时间开销从推理中移出。调用此方法完全是可选的,但我们建议您在首次推理调用之前调用此方法,以最大限度地缩短首次推理的延迟时间。