类 GeminiLlmConnection

java.lang.Object
com.google.adk.models.GeminiLlmConnection
All Implemented Interfaces:
BaseLlmConnection

public final class GeminiLlmConnection extends Object implements BaseLlmConnection
通过 WebSockets 管理与 Gemini 模型的持久性、双向连接,以实现实时交互。

该连接支持发送对话记录、单条消息、功能响应以及实时媒体数据(例如音频片段),同时能够持续接收来自模型的响应。

  • 方法概述

    Modifier and Type
    Method
    Description
    void
    关闭连接。
    void
    close(Throwable throwable)
    以错误状态关闭连接。
    io.reactivex.rxjava3.core.Flowable<LlmResponse>
    接收模型的响应结果。
    io.reactivex.rxjava3.core.Completable
    sendContent(com.google.genai.types.Content content)
    将用户生成的内容发送给模型。
    io.reactivex.rxjava3.core.Completable
    sendContent(com.google.genai.types.Content content, boolean partial)
    将用户内容发送给模型;同时可以选择让当前轮次保持开放状态,以便用户继续添加更多内容。
    io.reactivex.rxjava3.core.Completable
    sendHistory(List<com.google.genai.types.Content> history)
    发送 history 如果视频没有音频内容,那么这样的直播环节就无法被重新播放(即无法被回放)。 _adk_live 这些工件引用(artifact references)无法被模型解析(model cannot resolve them)。
    io.reactivex.rxjava3.core.Completable
    sendRealtime(com.google.genai.types.Blob blob)
    实时将一段音频或一帧视频数据发送给模型。

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 方法详细信息(Method Details)

    • sendHistory

      public io.reactivex.rxjava3.core.Completable sendHistory(List<com.google.genai.types.Content> history)
      发送 history 如果视频没有音频内容,那么这样的直播环节就无法被重新播放(即无法被回放)。 _adk_live 模型无法解析的工件引用(artifact references)。模型会完成当前轮次的处理,并只有在剩余的对话历史记录以用户的操作(user turn)结束时才会给出答案。
      Specified by:
      sendHistory in interface BaseLlmConnection
    • sendContent

      public io.reactivex.rxjava3.core.Completable sendContent(com.google.genai.types.Content content)
      描述内容复制自接口文档: BaseLlmConnection
      将用户生成的内容发送给模型。

      该模型在接收到内容后会立即作出响应。如果您发送的是函数响应(function responses),那么内容中的所有部分都必须是函数响应。

      Specified by:
      sendContent in interface BaseLlmConnection
    • sendContent

      public io.reactivex.rxjava3.core.Completable sendContent(com.google.genai.types.Content content, boolean partial)
      描述内容复制自接口文档: BaseLlmConnection
      将用户内容发送给模型;同时可以选择让当前轮次保持开放状态,以便用户继续添加更多内容。

      默认的实现会忽略这一点。 partial 并调用(相关函数或方法) BaseLlmConnection.sendContent(Content)仅由函数返回的结果组成的内容,总是以“工具响应”(tool response)的形式被发送出去。

      Specified by:
      sendContent in interface BaseLlmConnection
      Parameters:
      content - the content to send
      partial - whether this content is a partial update that does not complete the current turn
    • sendRealtime

      public io.reactivex.rxjava3.core.Completable sendRealtime(com.google.genai.types.Blob blob)
      描述内容复制自接口文档: BaseLlmConnection
      实时将一段音频或一帧视频数据发送给模型。

      该模型在接收到数据后可能不会立即做出响应。它会先进行语音活动检测,然后决定何时再作出回应。

      Specified by:
      sendRealtime in interface BaseLlmConnection
    • receive

      public io.reactivex.rxjava3.core.Flowable<LlmResponse> receive()
      描述内容复制自接口文档: BaseLlmConnection
      接收模型的响应结果。
      Specified by:
      receive in interface BaseLlmConnection
    • close

      public void close()
      描述内容复制自接口文档: BaseLlmConnection
      关闭连接。
      Specified by:
      close in interface BaseLlmConnection
    • close

      public void close(Throwable throwable)
      描述内容复制自接口文档: BaseLlmConnection
      以错误状态关闭连接。
      Specified by:
      close in interface BaseLlmConnection