Class ChatCompletionsStreamingService
java.lang.Object
io.agentscope.spring.boot.chat.service.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
ConstructorsConstructorDescriptionChatCompletionsStreamingService(io.agentscope.core.chat.completions.streaming.ChatCompletionsStreamingAdapter streamingAdapter) Constructs a newChatCompletionsStreamingService. -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.http.codec.ServerSentEvent<String>createErrorSseEvent(Throwable error, String requestId, String model) Create an error SSE event.reactor.core.publisher.Flux<org.springframework.http.codec.ServerSentEvent<String>>streamAsSse(io.agentscope.core.ReActAgent agent, List<io.agentscope.core.message.Msg> messages, String requestId, String model) Stream agent events as Server-Sent Events (SSE).
-
Constructor Details
-
ChatCompletionsStreamingService
public ChatCompletionsStreamingService(io.agentscope.core.chat.completions.streaming.ChatCompletionsStreamingAdapter streamingAdapter) Constructs a newChatCompletionsStreamingService.- Parameters:
streamingAdapter- The framework-agnostic streaming adapter
-
-
Method Details
-
streamAsSse
public reactor.core.publisher.Flux<org.springframework.http.codec.ServerSentEvent<String>> streamAsSse(io.agentscope.core.ReActAgent agent, List<io.agentscope.core.message.Msg> messages, String requestId, String model) Stream agent events as Server-Sent Events (SSE).Each SSE "data" field contains a JSON-serialized
ChatCompletionsChunkfollowing OpenAI's streaming format. The stream ends with a "data: [DONE]" event.- Parameters:
agent- The agent to stream frommessages- The messages to send to the agentrequestId- The request ID for trackingmodel- The model name for the response- Returns:
- A
FluxofServerSentEventobjects
-
createErrorSseEvent
public org.springframework.http.codec.ServerSentEvent<String> createErrorSseEvent(Throwable error, String requestId, String model) Create an error SSE event.- Parameters:
error- The error that occurredrequestId- The request ID for trackingmodel- The model name- Returns:
- A
ServerSentEventwith error information
-