ChatCompletionsStreamingService
public class ChatCompletionsStreamingService
io/agentscope/spring/boot/chat/service/ChatCompletionsStreamingService.java:52–126聊天补全流式服务,承载智能体的部署、调度与服务化运行。位于 io.agentscope.spring.boot.chat.service 包。核心成员包括 streamAsSse、createErrorSseEvent、ChatCompletionsStreamingService。
Spring-specific service for streaming chat completion responses.
This service is a thin adapter layer that:
-
Delegates core streaming logic to
ChatCompletionsStreamingAdapter -
Converts
ChatCompletionsChunkto Spring'sServerSentEvent -
Handles JSON serialization for SSE data field
Architecture:
ChatCompletionsStreamingAdapter (framework-agnostic, in extension-core)
↓ Flux<ChatCompletionsChunk>
ChatCompletionsStreamingService (Spring-specific, in starter)
↓ Flux<ServerSentEvent<String>>
HTTP Response (SSE stream)
This design allows the core streaming logic to be reused across different frameworks (Spring, Quarkus, etc.) while keeping framework-specific concerns in the starter modules.
构造器摘要Constructor Summary
| 构造器Constructor | 说明Description |
|---|---|
public ChatCompletionsStreamingService(ChatCompletionsStreamingAdapter streamingAdapter) | 初始化 `ChatCompletionsStreamingService` 实例。 Constructs a new `ChatCompletionsStreamingService`. |
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public Flux<ServerSentEvent<String>> streamAsSse(ReActAgent agent, List<Msg> messages, String requestId, String model) | 执行As SSE。 Stream agent events as Server-Sent Events (SSE). |
public ServerSentEvent<String> createErrorSseEvent(Throwable error, String requestId, String model) | 创建错误 SSE 事件。 Create an error SSE event. |
构造器详情Constructor Detail
ChatCompletionsStreamingService
public ChatCompletionsStreamingService(ChatCompletionsStreamingAdapter streamingAdapter)
初始化 ChatCompletionsStreamingService 实例。
Constructs a new ChatCompletionsStreamingService.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
streamingAdapter | ChatCompletionsStreamingAdapter | 流式适配器(类型 `ChatCompletionsStreamingAdapter`)。The framework-agnostic streaming adapter |
io/agentscope/spring/boot/chat/service/ChatCompletionsStreamingService.java:63–65方法详情Method Detail
streamAsSse
public Flux<ServerSentEvent<String>> streamAsSse(ReActAgent agent, List<Msg> messages, String requestId, String model)
执行As SSE。
Stream agent events as Server-Sent Events (SSE).
| 名称Name | 类型Type | 说明Description |
|---|---|---|
agent | ReActAgent | 智能体到流来自。The agent to stream from |
messages | List<Msg> | 消息到发送到智能体。The messages to send to the agent |
requestId | String | 请求标识(类型 `String`)。The request ID for tracking |
model | String | 模型名称用于响应。The model name for the response |
Flux<ServerSentEvent<String>>io/agentscope/spring/boot/chat/service/ChatCompletionsStreamingService.java:79–84createErrorSseEvent
public ServerSentEvent<String> createErrorSseEvent(Throwable error, String requestId, String model)
创建错误 SSE 事件。
Create an error SSE event.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
error | Throwable | 错误(类型 `Throwable`)。The error that occurred |
requestId | String | 请求标识(类型 `String`)。The request ID for tracking |
model | String | 模型名称。The model name |
ServerSentEvent<String>io/agentscope/spring/boot/chat/service/ChatCompletionsStreamingService.java:120–125