Base未来Live连接(Connection)

Java-friendly base for implementing a LiveConnection: override the ...Async methods, which return a CompletableFuture, and receiveJava, which returns a Publisher of one model turn. The base maps these to LiveConnection's calls and also enforces two of its rules, one receive collector at a time and a closeSession that is safe to call again; apply its content rules yourself. Return a new future from each call, because the base cancels a send's future when its caller is cancelled, and a new publisher from each receiveJava call; return each promptly, with any blocking work inside it, and fail a future rather than cancel it.

构造函数(Constructors)

Link copied to clipboard
constructor()

函数

Link copied to clipboard
override fun close()

该函数会一直阻塞,直到相关操作(如文件关闭)完成;因此,绝对不能在那些可能会在未来被修改的线程中调用它。 closeSessionAsync 为了完成某个操作,需要满足某些条件。这个过程是最终确定的(即不可更改的),因此子类不能将“优雅的关闭”方式替换为“突然的关闭”方式;必须保留原有的“teardown”(资源清理)机制。 closeSessionAsync.

Link copied to clipboard
suspend override fun closeSession()

关闭连接;数据收集器(collectors of) 接收;获取 操作过程正常完成。

Link copied to clipboard
override fun receive(): Flow<LlmResponse>

该模型在当前回合中的响应会在回合结束时完成收集;下一个回合需要再次收集这些响应数据。如果收集过程结束时没有收到任何响应,说明连接已经中断。这与之前的情况不同…… Model.generateContent在这里,每个数据集合都会单独发起请求;不过所有集合都共享同一个已建立的连接,因此一次只能有一个请求被执行。如果有多个请求同时尝试访问该连接,系统会拒绝这些并发请求。 IllegalStateException.

Link copied to clipboard
suspend override fun sendContent(content: Content, partial: Boolean = false)

发送用户内容;完成当前轮次后,系统会提示用户作出回应(除非另有说明)。 部分的;不完全的 这个条件是“true”(即成立的)。

Link copied to clipboard
suspend override fun sendHistory(history: List<Content>)

使用之前的对话内容来“初始化”会话(即:让会话包含这些之前的对话内容)。 Model.connect 调用方并不会主动触发该功能;因此,调用方最多只会在该功能连接成功后立即(且在发送任何其他数据之前)调用它一次。该模型只有在接收到用户发送的最新内容时才会作出响应;否则,它会继续等待新的输入。

Link copied to clipboard
suspend override fun sendRealtime(input: RealtimeInput)

发送实时数据:可以是媒体文件的一部分,也可以是一个用于标记用户活动开始的信号。