AS AgentScopeAPI 手册 / API Reference

ChatCompletionsStreamingService

public class ChatCompletionsStreamingService
源码Source 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 ChatCompletionsChunk to Spring's ServerSentEvent

  • 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.

参数Parameters
名称Name类型Type说明Description
streamingAdapterChatCompletionsStreamingAdapter流式适配器(类型 `ChatCompletionsStreamingAdapter`)。The framework-agnostic streaming adapter
源码Source 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).

参数Parameters
名称Name类型Type说明Description
agentReActAgent智能体到流来自。The agent to stream from
messagesList<Msg>消息到发送到智能体。The messages to send to the agent
requestIdString请求标识(类型 `String`)。The request ID for tracking
modelString模型名称用于响应。The model name for the response
返回Returns Flux<ServerSentEvent<String>>
返回Flux>。A `Flux` of `ServerSentEvent` objects
源码Source io/agentscope/spring/boot/chat/service/ChatCompletionsStreamingService.java:79–84

createErrorSseEvent

public ServerSentEvent<String> createErrorSseEvent(Throwable error, String requestId, String model)

创建错误 SSE 事件。

Create an error SSE event.

参数Parameters
名称Name类型Type说明Description
errorThrowable错误(类型 `Throwable`)。The error that occurred
requestIdString请求标识(类型 `String`)。The request ID for tracking
modelString模型名称。The model name
返回Returns ServerSentEvent<String>
返回ServerSentEvent。A `ServerSentEvent` with error information
源码Source io/agentscope/spring/boot/chat/service/ChatCompletionsStreamingService.java:120–125
基于官方固定版本源码静态生成Generated from pinned official sources · Python 2.0.11 · Java 2.0.4
签名与文档为静态抽取;如有疑问请以源码为准。Signatures and docs are extracted statically; verify against the source when in doubt.