Class StreamingChatResponse
java.lang.Object
java.util.concurrent.CompletableFuture<String>
io.github.easy4j.opencode.api.sse.StreamingChatResponse
- All Implemented Interfaces:
CompletionStage<String>,Future<String>
OpenCode 流式聊天响应,逐段回调并在结束时返回累积全文。
- Since:
- 1.0.0
- Author:
- Loong Wan
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.concurrent.CompletableFuture
CompletableFuture.AsynchronousCompletionTaskNested classes/interfaces inherited from interface java.util.concurrent.Future
Future.State -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidacceptDelta(String delta) 追加一段文本增量并通知已注册的增量消费者。booleancancel(boolean mayInterruptIfRunning) 取消当前异步操作或 SSE 订阅。void以给定异常结束流式响应。voidfinish()以当前累计文本正常完成流式响应。通过 OpenCode Server HTTP API 获取累计的流式文本。绑定底层 EventSource 取消动作。注册文本增量消费者;后续到达的增量按接收顺序同步通知该消费者。Methods inherited from class java.util.concurrent.CompletableFuture
acceptEither, acceptEitherAsync, acceptEitherAsync, allOf, anyOf, applyToEither, applyToEitherAsync, applyToEitherAsync, complete, completeAsync, completeAsync, completedFuture, completedStage, completeExceptionally, completeOnTimeout, copy, defaultExecutor, delayedExecutor, delayedExecutor, exceptionally, exceptionallyAsync, exceptionallyAsync, exceptionallyCompose, exceptionallyComposeAsync, exceptionallyComposeAsync, exceptionNow, failedFuture, failedStage, get, get, getNow, getNumberOfDependents, handle, handleAsync, handleAsync, isCancelled, isCompletedExceptionally, isDone, join, minimalCompletionStage, newIncompleteFuture, obtrudeException, obtrudeValue, orTimeout, resultNow, runAfterBoth, runAfterBothAsync, runAfterBothAsync, runAfterEither, runAfterEitherAsync, runAfterEitherAsync, runAsync, runAsync, state, supplyAsync, supplyAsync, thenAccept, thenAcceptAsync, thenAcceptAsync, thenAcceptBoth, thenAcceptBothAsync, thenAcceptBothAsync, thenApply, thenApplyAsync, thenApplyAsync, thenCombine, thenCombineAsync, thenCombineAsync, thenCompose, thenComposeAsync, thenComposeAsync, thenRun, thenRunAsync, thenRunAsync, toCompletableFuture, toString, whenComplete, whenCompleteAsync, whenCompleteAsync
-
Constructor Details
-
StreamingChatResponse
public StreamingChatResponse()
-
-
Method Details
-
onDelta
注册文本增量消费者;后续到达的增量按接收顺序同步通知该消费者。- Parameters:
consumer- 事件或文本增量消费者;不得为null- Returns:
- 可观察文本增量、等待完成或主动取消的流式响应
-
acceptDelta
追加一段文本增量并通知已注册的增量消费者。- Parameters:
delta- 本次到达的文本增量;为空时忽略
-
finish
public void finish()以当前累计文本正常完成流式响应。 -
fail
以给定异常结束流式响应。- Parameters:
error- 导致流式响应失败的异常
-
getAccumulatedContent
通过 OpenCode Server HTTP API 获取累计的流式文本。- Returns:
- 服务端或 CLI 返回的文本值;无内容时可能为空字符串
-
onCancel
绑定底层 EventSource 取消动作。- Parameters:
action- 取消时执行的回调;不得为null- Returns:
- 可观察文本增量、等待完成或主动取消的流式响应
-
cancel
public boolean cancel(boolean mayInterruptIfRunning) 取消当前异步操作或 SSE 订阅。
-